Mesa (staging/21.2): panfrost: Switch resources from an array to a set

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 26 17:46:44 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: 2987bf8761ab31c06b6dd26fa63da3ac73dda10d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2987bf8761ab31c06b6dd26fa63da3ac73dda10d

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

panfrost: Switch resources from an array to a set

This will help us reduce shared state and simplify multithreading, at
the expense of additional CPU overhead.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12528>
(cherry picked from commit 2f63ccd080342d9f61fdceb983f266972b8a7d97)

---

 .pick_status.json                      |  2 +-
 src/gallium/drivers/panfrost/pan_job.c | 27 ++++++++++++++-------------
 src/gallium/drivers/panfrost/pan_job.h |  4 ++--
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index e4b1d8a7144..b63aaf35281 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1192,7 +1192,7 @@
         "description": "panfrost: Switch resources from an array to a set",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
index 7011c7afa65..ce6722c3bc8 100644
--- a/src/gallium/drivers/panfrost/pan_job.c
+++ b/src/gallium/drivers/panfrost/pan_job.c
@@ -65,7 +65,8 @@ panfrost_batch_init(struct panfrost_context *ctx,
         batch->maxx = batch->maxy = 0;
 
         util_copy_framebuffer_state(&batch->key, key);
-        util_dynarray_init(&batch->resources, NULL);
+        batch->resources =_mesa_set_create(NULL, _mesa_hash_pointer,
+                                          _mesa_key_pointer_equal);
 
         /* Preallocate the main pool, since every batch has at least one job
          * structure so it will be used */
@@ -125,16 +126,17 @@ panfrost_batch_cleanup(struct panfrost_batch *batch)
                 panfrost_bo_unreference(bo);
         }
 
-        util_dynarray_foreach(&batch->resources, struct panfrost_resource *, rsrc) {
-                BITSET_CLEAR((*rsrc)->track.users, batch_idx);
+        set_foreach_remove(batch->resources, entry) {
+                struct panfrost_resource *rsrc = (void *) entry->key;
+                BITSET_CLEAR(rsrc->track.users, batch_idx);
 
-                if ((*rsrc)->track.writer == batch)
-                        (*rsrc)->track.writer = NULL;
+                if (rsrc->track.writer == batch)
+                        rsrc->track.writer = NULL;
 
-                pipe_resource_reference((struct pipe_resource **) rsrc, NULL);
+                pipe_resource_reference((struct pipe_resource **) &rsrc, NULL);
         }
 
-        util_dynarray_fini(&batch->resources);
+        _mesa_set_destroy(batch->resources, NULL);
         panfrost_pool_cleanup(&batch->pool);
         panfrost_pool_cleanup(&batch->invisible_pool);
 
@@ -263,16 +265,15 @@ panfrost_batch_update_access(struct panfrost_batch *batch,
         struct panfrost_context *ctx = batch->ctx;
         uint32_t batch_idx = panfrost_batch_idx(batch);
         struct panfrost_batch *writer = rsrc->track.writer;
+        bool found = false;
 
-        if (unlikely(!BITSET_TEST(rsrc->track.users, batch_idx))) {
+        _mesa_set_search_or_add(batch->resources, rsrc, &found);
+
+        if (!found) {
                 BITSET_SET(rsrc->track.users, batch_idx);
 
                 /* Reference the resource on the batch */
-                struct pipe_resource **dst = util_dynarray_grow(&batch->resources,
-                                struct pipe_resource *, 1);
-
-                *dst = NULL;
-                pipe_resource_reference(dst, &rsrc->base);
+                pipe_reference(NULL, &rsrc->base.reference);
         }
 
         /* Flush users if required */
diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h
index 2e5af79d73c..6f05af31e6b 100644
--- a/src/gallium/drivers/panfrost/pan_job.h
+++ b/src/gallium/drivers/panfrost/pan_job.h
@@ -130,8 +130,8 @@ struct panfrost_batch {
         mali_ptr uniform_buffers[PIPE_SHADER_TYPES];
         mali_ptr push_uniforms[PIPE_SHADER_TYPES];
 
-        /* Referenced resources for cleanup */
-        struct util_dynarray resources;
+        /* Referenced resources */
+        struct set *resources;
 };
 
 /* Functions for managing the above */



More information about the mesa-commit mailing list