From 839d609b8c89c5e4c8684779e625ae0a62520cb2 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 13 Oct 2020 08:12:59 -0400 Subject: [PATCH] zink: add batch usage flags for sampler views/states and desc sets this massively cuts down cpu time for hashing and lookups, resulting in a noticeable performance increase the sampler_state batch usage for now is just being set for future use when it will be leveraged to permit immediate deletion Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_batch.c | 19 +++++++++++++++---- src/gallium/drivers/zink/zink_context.h | 2 ++ src/gallium/drivers/zink/zink_descriptors.c | 1 + src/gallium/drivers/zink/zink_descriptors.h | 1 + src/gallium/drivers/zink/zink_draw.c | 3 +++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 7255eaf..f6cf4f2 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -36,6 +36,8 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) /* unref all used sampler-views */ set_foreach(batch->sampler_views, entry) { struct pipe_sampler_view *pres = (struct pipe_sampler_view *)entry->key; + struct zink_sampler_view *sampler_view = zink_sampler_view(pres); + sampler_view->batch_uses &= ~BITFIELD_BIT(batch->batch_id); pipe_sampler_view_reference(&pres, NULL); _mesa_set_remove(batch->sampler_views, entry); } @@ -54,6 +56,7 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) set_foreach(batch->desc_sets, entry) { struct zink_descriptor_set *zds = (void*)entry->key; + zds->batch_uses &= ~BITFIELD_BIT(batch->batch_id); /* reset descriptor pools when no batch is using this program to avoid * having some inactive program hogging a billion descriptors */ @@ -226,9 +229,13 @@ zink_batch_reference_sampler_view(struct zink_batch *batch, struct zink_sampler_view *sv) { bool found = false; + uint32_t bit = BITFIELD_BIT(batch->batch_id); + if (sv->batch_uses & bit) + return; _mesa_set_search_and_add(batch->sampler_views, sv, &found); - if (!found) - pipe_reference(NULL, &sv->base.reference); + assert(!found); + sv->batch_uses |= bit; + pipe_reference(NULL, &sv->base.reference); batch->has_work = true; } @@ -257,9 +264,13 @@ bool zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds) { bool found = false; + uint32_t bit = BITFIELD_BIT(batch->batch_id); + if (zds->batch_uses & bit) + return false; _mesa_set_search_and_add(batch->desc_sets, zds, &found); - if (!found) - pipe_reference(NULL, &zds->reference); + assert(!found); + zds->batch_uses |= bit; + pipe_reference(NULL, &zds->reference); return !found; } diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index d4d770f..9283c70 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -71,6 +71,7 @@ struct zink_sampler_state { VkSampler sampler; uint32_t hash; struct zink_descriptor_refs desc_set_refs; + uint32_t batch_uses; bool custom_border_color; }; @@ -82,6 +83,7 @@ struct zink_sampler_view { VkBufferView buffer_view; }; uint32_t hash; + uint32_t batch_uses; }; struct zink_image_view { diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c index 043e9d6..8c84b78 100644 --- a/src/gallium/drivers/zink/zink_descriptors.c +++ b/src/gallium/drivers/zink/zink_descriptors.c @@ -232,6 +232,7 @@ allocate_desc_set(struct zink_screen *screen, struct zink_program *pg, enum zink pipe_reference_init(&zds->reference, 1); zds->pool = pool; zds->hash = 0; + zds->batch_uses = 0; zds->invalid = true; zds->recycled = false; if (num_resources) { diff --git a/src/gallium/drivers/zink/zink_descriptors.h b/src/gallium/drivers/zink/zink_descriptors.h index 9c56e35..5ad1b81 100644 --- a/src/gallium/drivers/zink/zink_descriptors.h +++ b/src/gallium/drivers/zink/zink_descriptors.h @@ -95,6 +95,7 @@ struct zink_descriptor_set { bool recycled; struct zink_descriptor_state_key key; struct util_dynarray barriers; + uint32_t batch_uses; #ifndef NDEBUG /* for extra debug asserts */ unsigned num_resources; diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c index 8cbf5fb..b51c941 100644 --- a/src/gallium/drivers/zink/zink_draw.c +++ b/src/gallium/drivers/zink/zink_draw.c @@ -625,6 +625,9 @@ update_sampler_descriptors(struct zink_context *ctx, struct zink_descriptor_set struct zink_batch *batch = is_compute ? &ctx->compute_batch : zink_curr_batch(ctx); if (sampler_view) zink_batch_reference_sampler_view(batch, sampler_view); + if (sampler) + /* this only tracks the most recent usage for now */ + sampler->batch_uses = BITFIELD_BIT(batch->batch_id); } assert(num_wds < num_descriptors); -- 2.7.4