From 2f63ccd080342d9f61fdceb983f266972b8a7d97 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 17 Aug 2021 15:59:07 +0000 Subject: [PATCH] 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 Cc: mesa-stable Part-of: --- src/gallium/drivers/panfrost/pan_job.c | 27 +++++++++++++------------- src/gallium/drivers/panfrost/pan_job.h | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c index 6265cd175bf..f0c9f617e43 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -78,7 +78,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 */ @@ -121,16 +122,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); @@ -229,16 +231,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 a4eaf92fece..bc1420cf18a 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 */