Mesa (staging/21.3): zink: move push descriptor updating into lazy-only codepath

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 22 07:05:00 UTC 2021


Module: Mesa
Branch: staging/21.3
Commit: d74a709d47dcdfebb90a988e942bcd585c0c0f62
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d74a709d47dcdfebb90a988e942bcd585c0c0f62

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Oct 13 09:29:02 2021 -0400

zink: move push descriptor updating into lazy-only codepath

this was a bit confusing to read, and I originally left it in the hybrid
path to enable fallbacks to push descriptors in hybrid mode. the problem with
that idea is that it's impossible: the constant buffer set is the one set
that will never, ever trigger a fallback, so leaving it there just leaves
room for error and confusion

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13350>
(cherry picked from commit 7c840f510321c841518e26befd9c56c7d5a38beb)

---

 .pick_status.json                                |   2 +-
 src/gallium/drivers/zink/zink_descriptors.c      |   2 +-
 src/gallium/drivers/zink/zink_descriptors.h      |   2 +-
 src/gallium/drivers/zink/zink_descriptors_lazy.c | 105 ++++++++++++-----------
 4 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index df488240bd5..0c53188065f 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1210,7 +1210,7 @@
         "description": "zink: move push descriptor updating into lazy-only codepath",
         "nominated": false,
         "nomination_type": null,
-        "resolution": 4,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c
index dc83c0a8313..a8693465df7 100644
--- a/src/gallium/drivers/zink/zink_descriptors.c
+++ b/src/gallium/drivers/zink/zink_descriptors.c
@@ -1464,7 +1464,7 @@ zink_descriptors_update(struct zink_context *ctx, bool is_compute)
                                             0, NULL);
             }
          } else {
-            zink_descriptors_update_lazy_masked(ctx, is_compute, BITFIELD_BIT(h), false, false);
+            zink_descriptors_update_lazy_masked(ctx, is_compute, BITFIELD_BIT(h), 0);
          }
          ctx->dd->changed[is_compute][h] = false;
       }
diff --git a/src/gallium/drivers/zink/zink_descriptors.h b/src/gallium/drivers/zink/zink_descriptors.h
index 6e0040a6626..a66c2e6915a 100644
--- a/src/gallium/drivers/zink/zink_descriptors.h
+++ b/src/gallium/drivers/zink/zink_descriptors.h
@@ -298,7 +298,7 @@ zink_descriptors_deinit_lazy(struct zink_context *ctx);
 void
 zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set);
 void
-zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, bool need_push, bool update_push);
+zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, uint8_t bind_sets);
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/gallium/drivers/zink/zink_descriptors_lazy.c b/src/gallium/drivers/zink/zink_descriptors_lazy.c
index b4b5988cd5f..02f2396c560 100644
--- a/src/gallium/drivers/zink/zink_descriptors_lazy.c
+++ b/src/gallium/drivers/zink/zink_descriptors_lazy.c
@@ -434,22 +434,15 @@ get_descriptor_set_lazy(struct zink_descriptor_pool *pool)
 
 static bool
 populate_sets(struct zink_context *ctx, struct zink_batch_descriptor_data_lazy *bdd,
-              struct zink_program *pg, uint8_t *changed_sets, bool need_push, VkDescriptorSet *sets)
+              struct zink_program *pg, uint8_t *changed_sets, VkDescriptorSet *sets)
 {
-   if (need_push && !zink_screen(ctx->base.screen)->info.have_KHR_push_descriptor) {
-         struct zink_descriptor_pool *pool = check_push_pool_alloc(ctx, bdd->push_pool[pg->is_compute], bdd, pg->is_compute);
-         sets[0] = get_descriptor_set_lazy(pool);
-         if (!sets[0])
-            return false;
-   } else
-      sets[0] = VK_NULL_HANDLE;
    u_foreach_bit(type, *changed_sets) {
       if (pg->dd->layout_key[type]) {
          struct zink_descriptor_pool *pool = get_descriptor_pool_lazy(ctx, pg, type, bdd, pg->is_compute);
-         sets[type + 1] = get_descriptor_set_lazy(pool);
+         sets[type] = get_descriptor_set_lazy(pool);
       } else
-         sets[type + 1] = ctx->dd->dummy_set;
-      if (!sets[type + 1])
+         sets[type] = ctx->dd->dummy_set;
+      if (!sets[type])
          return false;
    }
    return true;
@@ -463,38 +456,31 @@ zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *p
 }
 
 void
-zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, bool need_push, bool is_lazy)
+zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, uint8_t bind_sets)
 {
    struct zink_screen *screen = zink_screen(ctx->base.screen);
-   struct zink_batch *batch = &ctx->batch;
    struct zink_batch_state *bs = ctx->batch.state;
    struct zink_batch_descriptor_data_lazy *bdd = bdd_lazy(bs);
    struct zink_program *pg = is_compute ? &ctx->curr_compute->base : &ctx->curr_program->base;
-   VkDescriptorSet desc_sets[5];
-   if (!populate_sets(ctx, bdd, pg, &changed_sets, need_push, desc_sets)) {
+   VkDescriptorSet desc_sets[ZINK_DESCRIPTOR_TYPES];
+   if (!populate_sets(ctx, bdd, pg, &changed_sets, desc_sets)) {
       debug_printf("ZINK: couldn't get descriptor sets!\n");
       return;
    }
    /* no flushing allowed */
    assert(ctx->batch.state == bs);
 
-   /*
-    * when binding a pipeline, the pipeline can correctly access any previously bound
-    * descriptor sets which were bound with compatible pipeline layouts
-    * VK 14.2.2
-    */
-   uint8_t bind_sets = !is_lazy || (bdd->pg[is_compute] && bdd->compat_id[is_compute] == pg->compat_id) ? 0 : pg->dd->binding_usage;
    if (pg->dd->binding_usage && (changed_sets || bind_sets)) {
       u_foreach_bit(type, changed_sets) {
          assert(type + 1 < pg->num_dsl);
          if (pg->dd->layout_key[type]) {
-            VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[type + 1], pg->dd->layouts[type + 1]->desc_template, ctx);
+            VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[type], pg->dd->layouts[type + 1]->desc_template, 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 */
-                                    pg->layout, type + 1, 1, &desc_sets[type + 1],
+                                    pg->layout, type + 1, 1, &desc_sets[type],
                                     0, NULL);
-            bdd->sets[is_compute][type + 1] = desc_sets[type + 1];
+            bdd->sets[is_compute][type + 1] = desc_sets[type];
          }
       }
       u_foreach_bit(type, bind_sets & ~changed_sets) {
@@ -509,33 +495,6 @@ zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, u
       }
       dd_lazy(ctx)->state_changed[is_compute] = false;
    }
-
-   if (is_lazy) {
-      if (pg->dd->push_usage && (dd_lazy(ctx)->push_state_changed[is_compute] || bind_sets)) {
-         if (screen->info.have_KHR_push_descriptor) {
-            if (dd_lazy(ctx)->push_state_changed[is_compute])
-               VKSCR(CmdPushDescriptorSetWithTemplateKHR)(batch->state->cmdbuf, pg->dd->push_template,
-                                                           pg->layout, 0, ctx);
-         } else {
-            if (dd_lazy(ctx)->push_state_changed[is_compute]) {
-               VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[0], pg->dd->push_template, ctx);
-               bdd->sets[is_compute][0] = desc_sets[0];
-            }
-            assert(desc_sets[0] || bdd->sets[is_compute][0]);
-            VKSCR(CmdBindDescriptorSets)(batch->state->cmdbuf,
-                                    is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                    pg->layout, 0, 1, desc_sets[0] ? &desc_sets[0] : &bdd->sets[is_compute][0],
-                                    0, NULL);
-         }
-         dd_lazy(ctx)->push_state_changed[is_compute] = false;
-      } else if (dd_lazy(ctx)->push_state_changed[is_compute] || bind_sets) {
-         VKSCR(CmdBindDescriptorSets)(bs->cmdbuf,
-                                 is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                 pg->layout, 0, 1, &ctx->dd->dummy_set,
-                                 0, NULL);
-         dd_lazy(ctx)->push_state_changed[is_compute] = false;
-      }
-   }
 }
 
 void
@@ -544,6 +503,8 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
    struct zink_batch_state *bs = ctx->batch.state;
    struct zink_batch_descriptor_data_lazy *bdd = bdd_lazy(bs);
    struct zink_program *pg = is_compute ? &ctx->curr_compute->base : &ctx->curr_program->base;
+   struct zink_screen *screen = zink_screen(ctx->base.screen);
+   bool have_KHR_push_descriptor = screen->info.have_KHR_push_descriptor;
 
    bool batch_changed = !bdd->pg[is_compute];
    if (batch_changed) {
@@ -571,7 +532,47 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
    uint8_t changed_sets = pg->dd->binding_usage & dd_lazy(ctx)->state_changed[is_compute];
    bool need_push = pg->dd->push_usage &&
                     (dd_lazy(ctx)->push_state_changed[is_compute] || batch_changed);
-   zink_descriptors_update_lazy_masked(ctx, is_compute, changed_sets, need_push, true);
+   VkDescriptorSet push_set = VK_NULL_HANDLE;
+   if (need_push && !have_KHR_push_descriptor) {
+      struct zink_descriptor_pool *pool = check_push_pool_alloc(ctx, bdd->push_pool[pg->is_compute], bdd, pg->is_compute);
+      push_set = get_descriptor_set_lazy(pool);
+      if (!push_set) {
+         mesa_loge("ZINK: failed to get push descriptor set!");
+         /* just jam something in to avoid a hang */
+         push_set = ctx->dd->dummy_set;
+      }
+   }
+   /*
+    * when binding a pipeline, the pipeline can correctly access any previously bound
+    * descriptor sets which were bound with compatible pipeline layouts
+    * VK 14.2.2
+    */
+   uint8_t bind_sets = bdd->pg[is_compute] && bdd->compat_id[is_compute] == pg->compat_id ? 0 : pg->dd->binding_usage;
+   if (pg->dd->push_usage && (dd_lazy(ctx)->push_state_changed[is_compute] || bind_sets)) {
+      if (have_KHR_push_descriptor) {
+         if (dd_lazy(ctx)->push_state_changed[is_compute])
+            VKCTX(CmdPushDescriptorSetWithTemplateKHR)(bs->cmdbuf, pg->dd->push_template,
+                                                        pg->layout, 0, ctx);
+      } else {
+         if (dd_lazy(ctx)->push_state_changed[is_compute]) {
+            VKCTX(UpdateDescriptorSetWithTemplate)(screen->dev, push_set, pg->dd->push_template, ctx);
+            bdd->sets[is_compute][0] = push_set;
+         }
+         assert(push_set || bdd->sets[is_compute][0]);
+         VKCTX(CmdBindDescriptorSets)(bs->cmdbuf,
+                                 is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
+                                 pg->layout, 0, 1, push_set ? &push_set : &bdd->sets[is_compute][0],
+                                 0, NULL);
+      }
+      dd_lazy(ctx)->push_state_changed[is_compute] = false;
+   } else if (dd_lazy(ctx)->push_state_changed[is_compute] || bind_sets) {
+      VKCTX(CmdBindDescriptorSets)(bs->cmdbuf,
+                              is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
+                              pg->layout, 0, 1, &ctx->dd->dummy_set,
+                              0, NULL);
+      dd_lazy(ctx)->push_state_changed[is_compute] = false;
+   }
+   zink_descriptors_update_lazy_masked(ctx, is_compute, changed_sets, bind_sets);
    if (pg->dd->bindless && unlikely(!ctx->dd->bindless_bound)) {
       VKCTX(CmdBindDescriptorSets)(ctx->batch.state->cmdbuf, is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
                                    pg->layout, ZINK_DESCRIPTOR_BINDLESS, 1, &ctx->dd->bindless_set,



More information about the mesa-commit mailing list