panfrost: Cache number of users of a resource
authorAlyssa Rosenzweig <alyssa@collabora.com>
Tue, 17 Aug 2021 16:05:07 +0000 (16:05 +0000)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Aug 2021 19:39:51 +0000 (19:39 +0000)
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@collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12528>

src/gallium/drivers/panfrost/pan_job.c
src/gallium/drivers/panfrost/pan_resource.c
src/gallium/drivers/panfrost/pan_resource.h

index f0c9f617e43efe3cbf867ae92fe9c4b80ad93e6b..2bf544860a128936ca3a22c7b5594445fa173b95 100644 (file)
@@ -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);
         }
index d7a53474c276d07335471b310ebb0491f2c1b182..6f0c61b86ab9fc8bd41be92780ffd6913e182d4c 100644 (file)
@@ -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;
index 7ee2ef0e2452b006451b13e9eed9877ed77a88b6..5da26d6d6b59ce891755d42dbf893f27f7d40232 100644 (file)
@@ -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;