zink: ensure sampler-views survive a batch
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 20 Jun 2019 09:41:02 +0000 (11:41 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 28 Oct 2019 08:51:45 +0000 (08:51 +0000)
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 <jordan.l.justen@intel.com>
src/gallium/drivers/zink/zink_batch.c
src/gallium/drivers/zink/zink_batch.h
src/gallium/drivers/zink/zink_context.c

index 0db58c6a8810242550e2fe99a1e7fe55e00dd0ce..45466af5699f2617d5200faf04c1c8c405f0f294 100644 (file)
@@ -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);
+   }
+}
index 517c7b767701d7c221dbe937d2e0606c663d1b38..826f651df8eb6c62af16c6a387a515f5167d473c 100644 (file)
@@ -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
index f6bf504cf714f568f39777c7f336d4863265c3dd..2d565c19aafeb06b6e403e1f7681be83f1ae5106 100644 (file)
@@ -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);