From d84c7c2a85c01120f6fea1118fd467a664fce127 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 16 Mar 2021 13:54:21 -0400 Subject: [PATCH] zink: remove direct samplerview batch-tracking this moves tracking onto the surface/bufferview, which is more accurate and allows the removal of a temporary hack in resource invalidation Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_batch.c | 46 +++++++++++-------------- src/gallium/drivers/zink/zink_batch.h | 1 - src/gallium/drivers/zink/zink_context.c | 4 +-- src/gallium/drivers/zink/zink_context.h | 1 - 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 4422815c555..464667e38d0 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -33,22 +33,6 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) _mesa_set_remove(batch->resources, entry); } - /* 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); - if (sampler_view->base.target == PIPE_BUFFER) { - struct zink_buffer_view *buffer_view = sampler_view->buffer_view; - zink_buffer_view_reference(screen, &buffer_view, NULL); - } else { - struct zink_surface *surface = sampler_view->image_view; - pipe_surface_reference((struct pipe_surface**)&surface, NULL); - } - pipe_sampler_view_reference(&pres, NULL); - _mesa_set_remove(batch->sampler_views, entry); - } - set_foreach(batch->surfaces, entry) { struct zink_surface *surf = (struct zink_surface *)entry->key; surf->batch_uses &= ~BITFIELD64_BIT(batch->batch_id); @@ -238,22 +222,32 @@ zink_batch_reference_resource_rw(struct zink_batch *batch, struct zink_resource return batch_to_flush; } +static bool +ptr_add_usage(struct zink_batch *batch, struct set *s, void *ptr, uint32_t *u) +{ + bool found = false; + uint32_t bit = BITFIELD_BIT(batch->batch_id); + if ((*u) & bit) + return false; + _mesa_set_search_and_add(s, ptr, &found); + assert(!found); + *u |= bit; + return true; +} + void 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); - assert(!found); - sv->batch_uses |= bit; - pipe_reference(NULL, &sv->base.reference); - if (sv->base.target == PIPE_BUFFER) + if (sv->base.target == PIPE_BUFFER) { + if (!ptr_add_usage(batch, batch->bufferviews, sv->buffer_view, &sv->buffer_view->batch_uses)) + return; pipe_reference(NULL, &sv->buffer_view->reference); - else + } else { + if (!ptr_add_usage(batch, batch->surfaces, sv->image_view, &sv->image_view->batch_uses)) + return; pipe_reference(NULL, &sv->image_view->base.reference); + } batch->has_work = true; } diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h index 790b0d2b72d..1db1aed70b7 100644 --- a/src/gallium/drivers/zink/zink_batch.h +++ b/src/gallium/drivers/zink/zink_batch.h @@ -56,7 +56,6 @@ struct zink_batch { struct set *programs; struct set *resources; - struct set *sampler_views; struct set *surfaces; struct set *bufferviews; struct set *desc_sets; diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 5f17455d87c..55ed0c09e37 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -267,7 +267,6 @@ destroy_batch(struct zink_context* ctx, struct zink_batch* batch) zink_fence_reference(screen, &batch->fence, NULL); _mesa_set_destroy(batch->fbs, NULL); _mesa_set_destroy(batch->resources, NULL); - _mesa_set_destroy(batch->sampler_views, NULL); util_dynarray_fini(&batch->zombie_samplers); _mesa_set_destroy(batch->surfaces, NULL); _mesa_set_destroy(batch->programs, NULL); @@ -2171,13 +2170,12 @@ init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx) batch->fbs = _mesa_pointer_set_create(NULL); batch->resources = _mesa_pointer_set_create(NULL); - batch->sampler_views = _mesa_pointer_set_create(NULL); batch->surfaces = _mesa_pointer_set_create(NULL); batch->bufferviews = _mesa_pointer_set_create(NULL); batch->programs = _mesa_pointer_set_create(NULL); batch->desc_sets = _mesa_pointer_set_create(ctx); - if (!batch->resources || !batch->sampler_views || !batch->desc_sets || + if (!batch->resources || !batch->desc_sets || !batch->programs || !batch->surfaces || !batch->bufferviews) return false; diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 80b6bd3c208..161dce031e5 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -89,7 +89,6 @@ struct zink_sampler_view { struct zink_surface *image_view; struct zink_buffer_view *buffer_view; }; - uint32_t batch_uses; }; struct zink_image_view {