zink: only rebind pipelines when necessary
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 26 Jan 2021 15:27:50 +0000 (10:27 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 31 May 2021 14:39:57 +0000 (14:39 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10997>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_context.h
src/gallium/drivers/zink/zink_draw.c

index a6173fe..73c6335 100644 (file)
@@ -1705,6 +1705,7 @@ flush_batch(struct zink_context *ctx, bool sync)
       if (zink_screen(ctx->base.screen)->info.have_EXT_transform_feedback && ctx->num_so_targets)
          ctx->dirty_so_targets = true;
       ctx->descriptor_refs_dirty[0] = ctx->descriptor_refs_dirty[1] = true;
+      ctx->pipeline_changed[0] = ctx->pipeline_changed[1] = true;
    }
 }
 
index 0196d3d..64ff527 100644 (file)
@@ -166,6 +166,7 @@ struct zink_context {
    struct zink_depth_stencil_alpha_state *dsa_state;
 
    struct hash_table desc_set_layouts[ZINK_DESCRIPTOR_TYPES];
+   bool pipeline_changed[2]; //gfx, compute
 
    struct zink_shader *gfx_stages[ZINK_SHADER_COUNT];
    struct zink_gfx_pipeline_state gfx_pipeline_state;
index fc8a2b7..241f6b6 100644 (file)
@@ -532,6 +532,15 @@ zink_draw_vbo(struct pipe_context *pctx,
       zink_update_descriptor_refs(ctx, false);
 
    struct zink_batch *batch = zink_batch_rp(ctx);
+
+   VkPipeline prev_pipeline = ctx->gfx_pipeline_state.pipeline;
+   VkPipeline pipeline = zink_get_gfx_pipeline(ctx, gfx_program,
+                                               &ctx->gfx_pipeline_state,
+                                               dinfo->mode);
+   bool pipeline_changed = prev_pipeline != pipeline || ctx->pipeline_changed[0];
+   if (pipeline_changed)
+      vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+
    VkViewport viewports[PIPE_MAX_VIEWPORTS];
    for (unsigned i = 0; i < ctx->vp_state.num_viewports; i++) {
       VkViewport viewport = {
@@ -635,12 +644,6 @@ zink_draw_vbo(struct pipe_context *pctx,
    if (ctx->gfx_pipeline_state.blend_state->need_blend_constants)
       vkCmdSetBlendConstants(batch->state->cmdbuf, ctx->blend_constants);
 
-
-   VkPipeline pipeline = zink_get_gfx_pipeline(ctx, gfx_program,
-                                               &ctx->gfx_pipeline_state,
-                                               dinfo->mode);
-   vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
-
    zink_bind_vertex_buffers(batch, ctx);
 
    if (BITSET_TEST(ctx->gfx_stages[PIPE_SHADER_VERTEX]->nir->info.system_values_read, SYSTEM_VALUE_BASE_VERTEX)) {
@@ -672,6 +675,8 @@ zink_draw_vbo(struct pipe_context *pctx,
       screen->vk_CmdBeginTransformFeedbackEXT(batch->state->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
    }
 
+   ctx->pipeline_changed[0] = false;
+
    unsigned draw_id = drawid_offset;
    bool needs_drawid = ctx->drawid_broken;
    batch->state->work_count[0] += num_draws;
@@ -779,6 +784,7 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
       return;
 
    zink_program_update_compute_pipeline_state(ctx, comp_program, info->block);
+   VkPipeline prev_pipeline = ctx->compute_pipeline_state.pipeline;
    VkPipeline pipeline = zink_get_compute_pipeline(screen, comp_program,
                                                &ctx->compute_pipeline_state);
 
@@ -788,7 +794,9 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
    if (ctx->descriptor_refs_dirty[1])
       zink_update_descriptor_refs(ctx, true);
 
-   vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
+   if (prev_pipeline != pipeline || ctx->pipeline_changed[1])
+      vkCmdBindPipeline(batch->state->cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
+   ctx->pipeline_changed[1] = false;
 
    if (BITSET_TEST(comp_program->shader->nir->info.system_values_read, SYSTEM_VALUE_WORK_DIM))
       vkCmdPushConstants(batch->state->cmdbuf, comp_program->base.layout, VK_SHADER_STAGE_COMPUTE_BIT,