zink: only rebind pipelines when necessary

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10997>
This commit is contained in:
Mike Blumenkrantz 2021-01-26 10:27:50 -05:00 committed by Marge Bot
parent 1a7045acaf
commit 6d6ef97035
3 changed files with 17 additions and 7 deletions

View 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;
}
}

View 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;

View 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,