zink: split out lazy set updating
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 8 Sep 2021 16:14:17 +0000 (12:14 -0400)
committerMarge Bot <eric+marge@anholt.net>
Sun, 12 Sep 2021 23:58:48 +0000 (23:58 +0000)
make this reusable

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

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

index d3f095b..13f14d9 100644 (file)
@@ -286,6 +286,8 @@ 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);
 #ifdef __cplusplus
 }
 #endif
index e3af4ec..a727d8a 100644 (file)
@@ -444,49 +444,20 @@ zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *p
 }
 
 void
-zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
+zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, bool need_push, bool update_push)
 {
    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;
-
-   bool batch_changed = !bdd->pg[is_compute];
-   if (batch_changed) {
-      /* update all sets and bind null sets */
-      dd_lazy(ctx)->state_changed[is_compute] = pg->dd->binding_usage;
-      dd_lazy(ctx)->push_state_changed[is_compute] = !!pg->dd->push_usage;
-   }
-
-   if (pg != bdd->pg[is_compute]) {
-      /* if we don't already know that we have to update all sets,
-       * check to see if any dsls changed
-       *
-       * also always update the dsl pointers on program change
-       */
-       for (unsigned i = 0; i < ARRAY_SIZE(bdd->dsl[is_compute]); i++) {
-          /* push set is already detected, start at 1 */
-          if (bdd->dsl[is_compute][i] != pg->dsl[i + 1])
-             dd_lazy(ctx)->state_changed[is_compute] |= BITFIELD_BIT(i);
-          bdd->dsl[is_compute][i] = pg->dsl[i + 1];
-       }
-       dd_lazy(ctx)->push_state_changed[is_compute] |= bdd->push_usage[is_compute] != pg->dd->push_usage;
-       bdd->push_usage[is_compute] = pg->dd->push_usage;
-   }
-   bdd->pg[is_compute] = pg;
-
    VkDescriptorSet desc_sets[5];
-   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);
    if (!populate_sets(ctx, bdd, pg, &changed_sets, need_push, desc_sets)) {
       debug_printf("ZINK: couldn't get descriptor sets!\n");
       return;
    }
    /* no flushing allowed */
    assert(ctx->batch.state == bs);
-   bs = ctx->batch.state;
 
    if (pg->dd->binding_usage && changed_sets) {
       u_foreach_bit(type, changed_sets) {
@@ -502,32 +473,70 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
       dd_lazy(ctx)->state_changed[is_compute] = false;
    }
 
-   if (pg->dd->push_usage && dd_lazy(ctx)->push_state_changed[is_compute]) {
-      if (screen->info.have_KHR_push_descriptor)
-         VKSCR(CmdPushDescriptorSetWithTemplateKHR)(batch->state->cmdbuf, pg->dd->push_template,
-                                                     pg->layout, 0, ctx);
-      else {
-         assert(desc_sets[0]);
-         VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[0], pg->dd->push_template, ctx);
-         VKSCR(CmdBindDescriptorSets)(batch->state->cmdbuf,
+   if (update_push) {
+      if (pg->dd->push_usage && dd_lazy(ctx)->push_state_changed[is_compute]) {
+         if (screen->info.have_KHR_push_descriptor)
+            VKSCR(CmdPushDescriptorSetWithTemplateKHR)(batch->state->cmdbuf, pg->dd->push_template,
+                                                        pg->layout, 0, ctx);
+         else {
+            assert(desc_sets[0]);
+            VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[0], pg->dd->push_template, ctx);
+            VKSCR(CmdBindDescriptorSets)(batch->state->cmdbuf,
+                                    is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
+                                    pg->layout, 0, 1, &desc_sets[0],
+                                    0, NULL);
+         }
+         dd_lazy(ctx)->push_state_changed[is_compute] = false;
+      } else if (dd_lazy(ctx)->push_state_changed[is_compute]) {
+         VKSCR(CmdBindDescriptorSets)(bs->cmdbuf,
                                  is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                 pg->layout, 0, 1, &desc_sets[0],
+                                 pg->layout, 0, 1, &ctx->dd->dummy_set,
                                  0, NULL);
+         dd_lazy(ctx)->push_state_changed[is_compute] = false;
       }
-      dd_lazy(ctx)->push_state_changed[is_compute] = false;
-   } else if (dd_lazy(ctx)->push_state_changed[is_compute]) {
-      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;
    }
-   /* set again in case of flushing */
    bdd->pg[is_compute] = pg;
    ctx->dd->pg[is_compute] = pg;
 }
 
 void
+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;
+
+   bool batch_changed = !bdd->pg[is_compute];
+   if (batch_changed) {
+      /* update all sets and bind null sets */
+      dd_lazy(ctx)->state_changed[is_compute] = pg->dd->binding_usage;
+      dd_lazy(ctx)->push_state_changed[is_compute] = !!pg->dd->push_usage;
+   }
+
+   if (pg != bdd->pg[is_compute]) {
+      /* if we don't already know that we have to update all sets,
+       * check to see if any dsls changed
+       *
+       * also always update the dsl pointers on program change
+       */
+       for (unsigned i = 0; i < ARRAY_SIZE(bdd->dsl[is_compute]); i++) {
+          /* push set is already detected, start at 1 */
+          if (bdd->dsl[is_compute][i] != pg->dsl[i + 1])
+             dd_lazy(ctx)->state_changed[is_compute] |= BITFIELD_BIT(i);
+          bdd->dsl[is_compute][i] = pg->dsl[i + 1];
+       }
+       dd_lazy(ctx)->push_state_changed[is_compute] |= bdd->push_usage[is_compute] != pg->dd->push_usage;
+       bdd->push_usage[is_compute] = pg->dd->push_usage;
+   }
+   bdd->pg[is_compute] = pg;
+
+   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);
+}
+
+void
 zink_context_invalidate_descriptor_state_lazy(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned start, unsigned count)
 {
    if (type == ZINK_DESCRIPTOR_TYPE_UBO && !start)