Mesa (main): zink: reorder gfx program/pipeline/descriptor binds if dynamic state is present

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 27 02:50:21 UTC 2021


Module: Mesa
Branch: main
Commit: b06ef86020d35607010e5d032afd04069378009f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b06ef86020d35607010e5d032afd04069378009f

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Jun 11 09:32:35 2021 -0400

zink: reorder gfx program/pipeline/descriptor binds if dynamic state is present

this enables deferring the heavy lifting until the rest of the state updates are
done

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

---

 src/gallium/drivers/zink/zink_draw.cpp | 56 ++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 7ea8c3dd395..15d2010af28 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -391,6 +391,19 @@ update_barriers(struct zink_context *ctx, bool is_compute)
    }
 }
 
+template <bool BATCH_CHANGED>
+static bool
+update_gfx_pipeline(struct zink_context *ctx, struct zink_batch_state *bs, enum pipe_prim_type mode)
+{
+   VkPipeline prev_pipeline = ctx->gfx_pipeline_state.pipeline;
+   update_gfx_program(ctx);
+   VkPipeline pipeline = zink_get_gfx_pipeline(ctx, ctx->curr_program, &ctx->gfx_pipeline_state, mode);
+   bool pipeline_changed = prev_pipeline != pipeline;
+   if (BATCH_CHANGED || pipeline_changed)
+      vkCmdBindPipeline(bs->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+   return pipeline_changed;
+}
+
 template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, bool BATCH_CHANGED>
 void
 zink_draw_vbo(struct pipe_context *pctx,
@@ -440,7 +453,6 @@ zink_draw_vbo(struct pipe_context *pctx,
          ctx->dirty_shader_stages |= BITFIELD_BIT(PIPE_SHADER_FRAGMENT);
    }
    ctx->gfx_prim_mode = mode;
-   update_gfx_program(ctx);
 
    if (ctx->gfx_pipeline_state.primitive_restart != dinfo->primitive_restart)
       ctx->gfx_pipeline_state.dirty = true;
@@ -471,9 +483,6 @@ zink_draw_vbo(struct pipe_context *pctx,
       vkCmdBindIndexBuffer(batch->state->cmdbuf, res->obj->buffer, index_offset, index_type[index_size >> 1]);
    }
 
-   if (zink_program_has_descriptors(&ctx->curr_program->base))
-      screen->descriptors_update(ctx, false);
-
    bool have_streamout = !!ctx->num_so_targets;
    if (have_streamout) {
       if (ctx->xfb_barrier)
@@ -491,14 +500,9 @@ zink_draw_vbo(struct pipe_context *pctx,
       zink_update_descriptor_refs(ctx, false);
 
    batch = zink_batch_rp(ctx);
-
-   VkPipeline prev_pipeline = ctx->gfx_pipeline_state.pipeline;
-   VkPipeline pipeline = zink_get_gfx_pipeline(ctx, ctx->curr_program,
-                                               &ctx->gfx_pipeline_state,
-                                               mode);
-   bool pipeline_changed = prev_pipeline != pipeline;
-   if (BATCH_CHANGED || pipeline_changed)
-      vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+   bool pipeline_changed = false;
+   if (!HAS_DYNAMIC_STATE)
+      pipeline_changed = update_gfx_pipeline<BATCH_CHANGED>(ctx, batch->state, mode);
 
    if (BATCH_CHANGED || ctx->vp_state_changed || (!HAS_DYNAMIC_STATE && pipeline_changed)) {
       VkViewport viewports[PIPE_MAX_VIEWPORTS];
@@ -649,17 +653,6 @@ zink_draw_vbo(struct pipe_context *pctx,
    if (BATCH_CHANGED || ctx->vertex_buffers_dirty)
       zink_bind_vertex_buffers<HAS_DYNAMIC_STATE>(batch, ctx);
 
-   if (reads_basevertex) {
-      unsigned draw_mode_is_indexed = index_size > 0;
-      vkCmdPushConstants(batch->state->cmdbuf, ctx->curr_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
-                         offsetof(struct zink_gfx_push_constant, draw_mode_is_indexed), sizeof(unsigned),
-                         &draw_mode_is_indexed);
-   }
-   if (ctx->curr_program->shaders[PIPE_SHADER_TESS_CTRL] && ctx->curr_program->shaders[PIPE_SHADER_TESS_CTRL]->is_generated)
-      vkCmdPushConstants(batch->state->cmdbuf, ctx->curr_program->base.layout, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
-                         offsetof(struct zink_gfx_push_constant, default_inner_level), sizeof(float) * 6,
-                         &ctx->tess_levels[0]);
-
    zink_query_update_gs_states(ctx);
 
    if (have_streamout) {
@@ -684,6 +677,23 @@ zink_draw_vbo(struct pipe_context *pctx,
       zink_select_draw_vbo(ctx);
    }
 
+   if (HAS_DYNAMIC_STATE)
+      update_gfx_pipeline<BATCH_CHANGED>(ctx, batch->state, mode);
+
+   if (zink_program_has_descriptors(&ctx->curr_program->base))
+      screen->descriptors_update(ctx, false);
+
+   if (reads_basevertex) {
+      unsigned draw_mode_is_indexed = index_size > 0;
+      vkCmdPushConstants(batch->state->cmdbuf, ctx->curr_program->base.layout, VK_SHADER_STAGE_VERTEX_BIT,
+                         offsetof(struct zink_gfx_push_constant, draw_mode_is_indexed), sizeof(unsigned),
+                         &draw_mode_is_indexed);
+   }
+   if (ctx->curr_program->shaders[PIPE_SHADER_TESS_CTRL] && ctx->curr_program->shaders[PIPE_SHADER_TESS_CTRL]->is_generated)
+      vkCmdPushConstants(batch->state->cmdbuf, ctx->curr_program->base.layout, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
+                         offsetof(struct zink_gfx_push_constant, default_inner_level), sizeof(float) * 6,
+                         &ctx->tess_levels[0]);
+
    bool needs_drawid = reads_drawid && ctx->drawid_broken;
    work_count += num_draws;
    if (index_size > 0) {



More information about the mesa-commit mailing list