Module: Mesa Branch: master Commit: 1b96e3e2b046ee6660b3637d2ea7202c0a76135c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1b96e3e2b046ee6660b3637d2ea7202c0a76135c
Author: Mike Blumenkrantz <michael.blumenkra...@gmail.com> Date: Tue Oct 27 20:41:15 2020 -0400 zink: massively beef up batch tracking for shader images the struct for these isn't allocated, so we need to ensure that the objects in it are explicitly tracked on batches when they're used Reviewed-by: Dave Airlie <airl...@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9543> --- src/gallium/drivers/zink/zink_batch.c | 35 +++++++++++++++++++++++++-------- src/gallium/drivers/zink/zink_batch.h | 6 ++++-- src/gallium/drivers/zink/zink_context.c | 3 ++- src/gallium/drivers/zink/zink_context.h | 1 + src/gallium/drivers/zink/zink_draw.c | 4 ++-- src/gallium/drivers/zink/zink_surface.h | 1 + 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 4de6c919218..b5814888364 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -50,10 +50,17 @@ zink_reset_batch(struct zink_context *ctx, struct zink_batch *batch) } set_foreach(batch->surfaces, entry) { - struct pipe_surface *surf = (struct pipe_surface *)entry->key; - pipe_surface_reference(&surf, NULL); + struct zink_surface *surf = (struct zink_surface *)entry->key; + surf->batch_uses &= ~BITFIELD64_BIT(batch->batch_id); + pipe_surface_reference((struct pipe_surface**)&surf, NULL); _mesa_set_remove(batch->surfaces, entry); } + set_foreach(batch->bufferviews, entry) { + struct zink_buffer_view *buffer_view = (struct zink_buffer_view *)entry->key; + buffer_view->batch_uses &= ~BITFIELD64_BIT(batch->batch_id); + zink_buffer_view_reference(ctx, &buffer_view, NULL); + _mesa_set_remove(batch->bufferviews, entry); + } util_dynarray_foreach(&batch->zombie_samplers, VkSampler, samp) { vkDestroySampler(screen->dev, *samp, NULL); @@ -286,13 +293,25 @@ zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zd } void -zink_batch_reference_surface(struct zink_batch *batch, - struct zink_surface *surface) +zink_batch_reference_image_view(struct zink_batch *batch, + struct zink_image_view *image_view) { - struct pipe_surface *surf = &surface->base; bool found = false; - _mesa_set_search_and_add(batch->surfaces, surf, &found); - if (!found) - pipe_reference(NULL, &surf->reference); + uint32_t bit = BITFIELD64_BIT(batch->batch_id); + if (image_view->base.resource->target == PIPE_BUFFER) { + if (image_view->buffer_view->batch_uses & bit) + return; + _mesa_set_search_and_add(batch->bufferviews, image_view->buffer_view, &found); + assert(!found); + image_view->buffer_view->batch_uses |= bit; + pipe_reference(NULL, &image_view->buffer_view->reference); + } else { + if (image_view->surface->batch_uses & bit) + return; + _mesa_set_search_and_add(batch->surfaces, image_view->surface, &found); + assert(!found); + image_view->surface->batch_uses |= bit; + pipe_reference(NULL, &image_view->surface->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 0554931afa3..790b0d2b72d 100644 --- a/src/gallium/drivers/zink/zink_batch.h +++ b/src/gallium/drivers/zink/zink_batch.h @@ -35,6 +35,7 @@ struct zink_context; struct zink_descriptor_set; struct zink_fence; struct zink_framebuffer; +struct zink_image_view; struct zink_program; struct zink_render_pass; struct zink_resource; @@ -57,6 +58,7 @@ struct zink_batch { struct set *resources; struct set *sampler_views; struct set *surfaces; + struct set *bufferviews; struct set *desc_sets; struct util_dynarray persistent_resources; @@ -96,8 +98,8 @@ zink_batch_reference_program(struct zink_batch *batch, struct zink_program *pg); void -zink_batch_reference_surface(struct zink_batch *batch, - struct zink_surface *surface); +zink_batch_reference_image_view(struct zink_batch *batch, + struct zink_image_view *image_view); bool zink_batch_add_desc_set(struct zink_batch *batch, struct zink_descriptor_set *zds); diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 5e6bca53849..3b2df2c9770 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -2123,11 +2123,12 @@ init_batch(struct zink_context *ctx, struct zink_batch *batch, unsigned idx) 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 || - !batch->programs || !batch->surfaces) + !batch->programs || !batch->surfaces || !batch->bufferviews) return false; util_dynarray_init(&batch->zombie_samplers, NULL); diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 6f92b6fa045..943fb0d6d29 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -78,6 +78,7 @@ struct zink_buffer_view { struct pipe_reference reference; VkBufferView buffer_view; uint32_t hash; + uint32_t batch_uses; }; struct zink_sampler_view { diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c index e9216e094a3..615d0869997 100644 --- a/src/gallium/drivers/zink/zink_draw.c +++ b/src/gallium/drivers/zink/zink_draw.c @@ -713,8 +713,8 @@ update_image_descriptors(struct zink_context *ctx, struct zink_descriptor_set *z NULL, imageview, bufferview, !k); struct zink_batch *batch = is_compute ? &ctx->compute_batch : zink_curr_batch(ctx); - if (image_view->surface) - zink_batch_reference_surface(batch, image_view->surface); + if (res) + zink_batch_reference_image_view(batch, image_view); } assert(num_wds < num_descriptors); diff --git a/src/gallium/drivers/zink/zink_surface.h b/src/gallium/drivers/zink/zink_surface.h index 7cba720ddbd..fddc48be433 100644 --- a/src/gallium/drivers/zink/zink_surface.h +++ b/src/gallium/drivers/zink/zink_surface.h @@ -35,6 +35,7 @@ struct zink_surface { VkImageViewCreateInfo ivci; VkImageView image_view; uint32_t hash; + uint32_t batch_uses; }; static inline struct zink_surface * _______________________________________________ mesa-commit mailing list mesa-commit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-commit