Mesa (main): panfrost: Cache number of users of a resource

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 19:58:00 UTC 2021


Module: Mesa
Branch: main
Commit: b8da5b1b7f4b5c4663621fae3db319d244e5d0b0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8da5b1b7f4b5c4663621fae3db319d244e5d0b0

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Tue Aug 17 16:05:07 2021 +0000

panfrost: Cache number of users of a resource

This can be tracked efficiently with atomics, and reduces the places we
use the rsrc->track.users bitmap which has concurrency issues.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12528>

---

 src/gallium/drivers/panfrost/pan_job.c      | 5 +++++
 src/gallium/drivers/panfrost/pan_resource.c | 4 ++--
 src/gallium/drivers/panfrost/pan_resource.h | 4 ++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index f0c9f617e43..2bf544860a1 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -129,6 +129,8 @@ panfrost_batch_cleanup(struct panfrost_batch *batch)
                 if (rsrc->track.writer == batch)
                         rsrc->track.writer = NULL;
 
+                rsrc->track.nr_users--;
+
                 pipe_resource_reference((struct pipe_resource **) &rsrc, NULL);
         }
 
@@ -238,6 +240,9 @@ panfrost_batch_update_access(struct panfrost_batch *batch,
         if (!found) {
                 BITSET_SET(rsrc->track.users, batch_idx);
 
+                /* Cache number of batches accessing a resource */
+                rsrc->track.nr_users++;
+
                 /* Reference the resource on the batch */
                 pipe_reference(NULL, &rsrc->base.reference);
         }
diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index d7a53474c27..6f0c61b86ab 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -898,7 +898,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
             (usage & PIPE_MAP_WRITE) &&
             !(resource->target == PIPE_BUFFER
               && !util_ranges_intersect(&rsrc->valid_buffer_range, box->x, box->x + box->width)) &&
-            BITSET_COUNT(rsrc->track.users) != 0) {
+            rsrc->track.nr_users > 0) {
 
                 /* When a resource to be modified is already being used by a
                  * pending batch, it is often faster to copy the whole BO than
@@ -917,7 +917,7 @@ panfrost_ptr_map(struct pipe_context *pctx,
                  * not ready yet (still accessed by one of the already flushed
                  * batches), we try to allocate a new one to avoid waiting.
                  */
-                if (BITSET_COUNT(rsrc->track.users) ||
+                if (rsrc->track.nr_users > 0 ||
                     !panfrost_bo_wait(bo, 0, true)) {
                         /* We want the BO to be MMAPed. */
                         uint32_t flags = bo->flags & ~PAN_BO_DELAY_MMAP;
diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h
index 7ee2ef0e245..5da26d6d6b5 100644
--- a/src/gallium/drivers/panfrost/pan_resource.h
+++ b/src/gallium/drivers/panfrost/pan_resource.h
@@ -50,6 +50,10 @@ struct panfrost_resource {
         struct {
                 struct panfrost_batch *writer;
                 BITSET_DECLARE(users, PAN_MAX_BATCHES);
+
+                /** Number of batches accessing this resource. Used to check if
+                 * a resource is in use. */
+                _Atomic unsigned nr_users;
         } track;
 
         struct renderonly_scanout *scanout;



More information about the mesa-commit mailing list