From 2a7302075df61734c89f01ddfc84ead39dfdd6fc Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 20 Jun 2019 11:41:02 +0200 Subject: [PATCH] zink: ensure sampler-views survive a batch we don't need to track the resources for the samplers any longer, as the sampler view holds a reference instead. Acked-by: Jordan Justen --- src/gallium/drivers/zink/zink_batch.c | 19 +++++++++++++++++++ src/gallium/drivers/zink/zink_batch.h | 6 ++++++ src/gallium/drivers/zink/zink_context.c | 8 ++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 0db58c6a881..45466af5699 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -30,6 +30,13 @@ reset_batch(struct zink_screen *screen, struct zink_batch *batch) } _mesa_set_clear(batch->resources, NULL); + /* unref all used sampler-views */ + set_foreach(batch->sampler_views, entry) { + struct pipe_sampler_view *pres = (struct pipe_sampler_view *)entry->key; + pipe_sampler_view_reference(&pres, NULL); + } + _mesa_set_clear(batch->sampler_views, NULL); + util_dynarray_foreach(&batch->zombie_samplers, VkSampler, samp) { vkDestroySampler(screen->dev, *samp, NULL); } @@ -97,3 +104,15 @@ zink_batch_reference_resoure(struct zink_batch *batch, pipe_resource_reference(&tmp, &res->base); } } + +void +zink_batch_reference_sampler_view(struct zink_batch *batch, + struct zink_sampler_view *sv) +{ + struct set_entry *entry = _mesa_set_search(batch->sampler_views, sv); + if (!entry) { + struct pipe_sampler_view *tmp = NULL; + entry = _mesa_set_add(batch->sampler_views, sv); + pipe_sampler_view_reference(&tmp, &sv->base); + } +} diff --git a/src/gallium/drivers/zink/zink_batch.h b/src/gallium/drivers/zink/zink_batch.h index 517c7b76770..826f651df8e 100644 --- a/src/gallium/drivers/zink/zink_batch.h +++ b/src/gallium/drivers/zink/zink_batch.h @@ -33,6 +33,7 @@ struct zink_fence; struct zink_framebuffer; struct zink_render_pass; struct zink_resource; +struct zink_sampler_view; struct zink_batch { VkCommandBuffer cmdbuf; @@ -42,6 +43,7 @@ struct zink_batch { struct zink_framebuffer *fb; struct set *resources; + struct set *sampler_views; struct util_dynarray zombie_samplers; }; @@ -56,4 +58,8 @@ void zink_batch_reference_resoure(struct zink_batch *batch, struct zink_resource *res); +void +zink_batch_reference_sampler_view(struct zink_batch *batch, + struct zink_sampler_view *sv); + #endif diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index f6bf504cf71..2d565c19aaf 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -971,7 +971,7 @@ zink_draw_vbo(struct pipe_context *pctx, image_infos[num_image_info].sampler = ctx->samplers[i][index]; wds[num_wds].pImageInfo = image_infos + num_image_info; ++num_image_info; - zink_batch_reference_resoure(batch, res); + zink_batch_reference_sampler_view(batch, sampler_view); } wds[num_wds].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; @@ -1343,7 +1343,11 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) ctx->batches[i].resources = _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); - if (!ctx->batches[i].resources) + ctx->batches[i].sampler_views = _mesa_set_create(NULL, + _mesa_hash_pointer, + _mesa_key_pointer_equal); + + if (!ctx->batches[i].resources || !ctx->batches[i].sampler_views) goto fail; util_dynarray_init(&ctx->batches[i].zombie_samplers, NULL); -- 2.30.2