Mesa (master): zink: add batch usage flags for sampler views/states and desc sets
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Mar 16 01:20:18 UTC 2021
Module: Mesa
Branch: master
Commit: 839d609b8c89c5e4c8684779e625ae0a62520cb2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=839d609b8c89c5e4c8684779e625ae0a62520cb2
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Tue Oct 13 08:12:59 2020 -0400
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 <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9567>
---
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 7255eaf1264..f6cf4f22453 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 d4d770f1581..9283c70b0e3 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 043e9d651a9..8c84b78986b 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 9c56e356a37..5ad1b81fdbe 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 8cbf5fbf628..b51c9413a6d 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);
More information about the mesa-commit
mailing list