zink: decouple descriptor templates from layouts
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 13 Apr 2022 14:20:00 +0000 (10:20 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 10 May 2022 05:55:55 +0000 (05:55 +0000)
the same layout will in the future have multiple templates
depending on which resources are being updated

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15906>

src/gallium/drivers/zink/zink_descriptors.c
src/gallium/drivers/zink/zink_descriptors.h
src/gallium/drivers/zink/zink_descriptors_lazy.c

index 2292e09..d984789 100644 (file)
@@ -1757,8 +1757,6 @@ zink_descriptor_layouts_deinit(struct zink_context *ctx)
       hash_table_foreach(&ctx->desc_set_layouts[i], he) {
          struct zink_descriptor_layout *layout = he->data;
          VKSCR(DestroyDescriptorSetLayout)(screen->dev, layout->layout, NULL);
-         if (layout->desc_template)
-            VKSCR(DestroyDescriptorUpdateTemplate)(screen->dev, layout->desc_template, NULL);
          ralloc_free(layout);
          _mesa_hash_table_remove(&ctx->desc_set_layouts[i], he);
       }
index 0eb4cf5..b651f21 100644 (file)
@@ -97,7 +97,6 @@ struct zink_descriptor_layout_key {
 
 struct zink_descriptor_layout {
    VkDescriptorSetLayout layout;
-   VkDescriptorUpdateTemplateKHR desc_template;
 };
 
 struct zink_descriptor_pool_key {
@@ -119,6 +118,7 @@ struct zink_descriptor_data {
    struct zink_descriptor_layout_key *push_layout_keys[2]; //gfx, compute
    struct zink_descriptor_pool *push_pool[2]; //gfx, compute
    struct zink_descriptor_layout *push_dsl[2]; //gfx, compute
+   VkDescriptorUpdateTemplateKHR push_template[2]; //gfx, compute
    uint8_t last_push_usage[2];
    bool push_valid[2];
    uint32_t push_state[2];
@@ -128,6 +128,7 @@ struct zink_descriptor_data {
 
    VkDescriptorPool dummy_pool;
    struct zink_descriptor_layout *dummy_dsl;
+   VkDescriptorUpdateTemplateKHR dummy_template;
    VkDescriptorSet dummy_set;
 
    VkDescriptorSetLayout bindless_layout;
@@ -147,6 +148,7 @@ struct zink_program_descriptor_data {
    uint8_t binding_usage;
    struct zink_descriptor_pool_key *pool_key[ZINK_DESCRIPTOR_TYPES]; //push set doesn't need one
    struct zink_descriptor_layout *layouts[ZINK_DESCRIPTOR_TYPES + 1];
+   VkDescriptorUpdateTemplateKHR templates[ZINK_DESCRIPTOR_TYPES + 1];
    VkDescriptorUpdateTemplateKHR push_template;
 };
 
index a07c1d4..ba61c01 100644 (file)
@@ -307,7 +307,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
       /* no need for empty templates */
       if (pg->dsl[i] == ctx->dd->dummy_dsl->layout ||
           pg->dsl[i] == ctx->dd->bindless_layout ||
-          (!is_push && pg->dd->layouts[i]->desc_template))
+          (!is_push && pg->dd->templates[i]))
          continue;
       template[i].sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO;
       assert(wd_count[i]);
@@ -327,7 +327,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
       if (is_push)
          pg->dd->push_template = t;
       else
-         pg->dd->layouts[i]->desc_template = t;
+         pg->dd->templates[i] = t;
    }
    return true;
 }
@@ -340,6 +340,10 @@ zink_descriptor_program_deinit_lazy(struct zink_context *ctx, struct zink_progra
       if (pg->dd->pool_key[i])
          pg->dd->pool_key[i]->use_count--;
    }
+   for (unsigned i = 0; i < pg->num_dsl; i++) {
+      if (pg->dd->templates[i])
+         VKSCR(DestroyDescriptorUpdateTemplate)(screen->dev, pg->dd->templates[i], NULL);
+   }
    if (pg->dd && pg->dd->push_template)
       VKSCR(DestroyDescriptorUpdateTemplate)(screen->dev, pg->dd->push_template, NULL);
    ralloc_free(pg->dd);
@@ -480,7 +484,7 @@ void
 zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set)
 {
    struct zink_screen *screen = zink_screen(ctx->base.screen);
-   VKCTX(UpdateDescriptorSetWithTemplate)(screen->dev, set, pg->dd->layouts[type + 1]->desc_template, ctx);
+   VKCTX(UpdateDescriptorSetWithTemplate)(screen->dev, set, pg->dd->templates[type + 1], ctx);
 }
 
 void
@@ -504,7 +508,7 @@ zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, u
    u_foreach_bit(type, changed_sets) {
       assert(type + 1 < pg->num_dsl);
       if (pg->dd->pool_key[type]) {
-         VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[type], pg->dd->layouts[type + 1]->desc_template, ctx);
+         VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[type], pg->dd->templates[type + 1], ctx);
          VKSCR(CmdBindDescriptorSets)(bs->cmdbuf,
                                  is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
                                  /* set index incremented by 1 to account for push set */