Mesa (main): zink: only rebind pipelines when necessary
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon May 31 14:46:38 UTC 2021
Module: Mesa
Branch: main
Commit: 6d6ef97035a6a5eb787950ff1c3505a862517919
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6d6ef97035a6a5eb787950ff1c3505a862517919
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Tue Jan 26 10:27:50 2021 -0500
zink: only rebind pipelines when necessary
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10997>
---
src/gallium/drivers/zink/zink_context.c | 1 +
src/gallium/drivers/zink/zink_context.h | 1 +
src/gallium/drivers/zink/zink_draw.c | 22 +++++++++++++++-------
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index a6173fea6c2..73c63354dfa 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -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;
}
}
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 0196d3dacce..64ff527117f 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -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;
diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c
index fc8a2b787f2..241f6b6aab4 100644
--- a/src/gallium/drivers/zink/zink_draw.c
+++ b/src/gallium/drivers/zink/zink_draw.c
@@ -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,
More information about the mesa-commit
mailing list