Mesa (staging/21.3): tegra: Use private reference count for resources

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Feb 20 17:40:41 UTC 2022


Module: Mesa
Branch: staging/21.3
Commit: 361cfec167a9288655b810a9c07148bed6812fba
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=361cfec167a9288655b810a9c07148bed6812fba

Author: Thierry Reding <treding at nvidia.com>
Date:   Wed Oct  6 22:47:17 2021 +0200

tegra: Use private reference count for resources

With the recent addition of the shortcuts aiming to avoid atomic
operations, the reference count on resources can become unbalanced
in the Tegra driver since they are wrapped and then proxied to the
Nouveau driver.

Fix this by keeping a private reference count.

Fixes: 7688b8ae9802 ("st/mesa: eliminate all atomic ops when setting vertex buffers")
Reviewed-by: Karol Herbst <kherbst at redhat.com>
Tested-by: Karol Herbst <kherbst at redhat.com>
(cherry picked from commit 108e6eaa83eed3eb356f3cce835c5f5e3a836b8e)

---

 .pick_status.json                          | 2 +-
 src/gallium/drivers/tegra/tegra_resource.h | 1 +
 src/gallium/drivers/tegra/tegra_screen.c   | 6 ++++++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index d50aecb3d63..0427e48f959 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1057,7 +1057,7 @@
         "description": "tegra: Use private reference count for resources",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "7688b8ae980223f094be9c70fe695e2122caf3e3"
     },
diff --git a/src/gallium/drivers/tegra/tegra_resource.h b/src/gallium/drivers/tegra/tegra_resource.h
index 67507d64590..892afaf5e0f 100644
--- a/src/gallium/drivers/tegra/tegra_resource.h
+++ b/src/gallium/drivers/tegra/tegra_resource.h
@@ -31,6 +31,7 @@ struct winsys_handle;
 struct tegra_resource {
    struct pipe_resource base;
    struct pipe_resource *gpu;
+   unsigned int refcount;
 
    uint64_t modifier;
    uint32_t stride;
diff --git a/src/gallium/drivers/tegra/tegra_screen.c b/src/gallium/drivers/tegra/tegra_screen.c
index 2b108b07908..3c4c36e0c94 100644
--- a/src/gallium/drivers/tegra/tegra_screen.c
+++ b/src/gallium/drivers/tegra/tegra_screen.c
@@ -245,6 +245,10 @@ tegra_screen_resource_create(struct pipe_screen *pscreen,
    pipe_reference_init(&resource->base.reference, 1);
    resource->base.screen = &screen->base;
 
+   /* use private reference count for wrapped resources */
+   resource->gpu->reference.count += 100000000;
+   resource->refcount = 100000000;
+
    return &resource->base;
 
 destroy:
@@ -352,6 +356,8 @@ tegra_screen_resource_destroy(struct pipe_screen *pscreen,
 {
    struct tegra_resource *resource = to_tegra_resource(presource);
 
+   /* adjust private reference count */
+   p_atomic_add(&resource->gpu->reference.count, -resource->refcount);
    pipe_resource_reference(&resource->gpu, NULL);
    free(resource);
 }



More information about the mesa-commit mailing list