Mesa (main): zink: stop using dirty_shader_stages for shader binds

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 25 22:38:31 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Thu Jun 10 06:27:40 2021 -0400

zink: stop using dirty_shader_stages for shader binds

by only using this mask for variant updates, we can begin to do some
neat things

Reviewed-by: Hoe Hao Cheng <haochengho12907 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12532>

---

 src/gallium/drivers/zink/zink_context.h |  2 ++
 src/gallium/drivers/zink/zink_draw.cpp  |  7 +++++--
 src/gallium/drivers/zink/zink_program.c | 13 +++++--------
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 5aeb7d56dcb..594f5fd19a5 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -308,6 +308,8 @@ struct zink_context {
    bool first_frame_done;
    bool have_timelines;
 
+   bool gfx_dirty;
+
    bool is_device_lost;
    bool vertex_state_changed : 1;
    bool blend_state_changed : 1;
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index a76b44d7442..67aa5352719 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -187,7 +187,7 @@ update_gfx_program(struct zink_context *ctx)
       ctx->last_vertex_stage_dirty = false;
    }
    unsigned bits = BITFIELD_MASK(PIPE_SHADER_COMPUTE);
-   if (ctx->dirty_shader_stages & bits) {
+   if (ctx->gfx_dirty) {
       struct zink_gfx_program *prog = NULL;
 
       struct hash_table *ht = &ctx->program_cache[ctx->shader_stages >> 2];
@@ -205,8 +205,11 @@ update_gfx_program(struct zink_context *ctx)
          zink_batch_reference_program(&ctx->batch, &prog->base);
       }
       ctx->curr_program = prog;
-      ctx->dirty_shader_stages &= ~bits;
+      ctx->gfx_dirty = false;
+   } else if (ctx->dirty_shader_stages & bits) {
+      zink_update_gfx_program(ctx, ctx->curr_program);
    }
+   ctx->dirty_shader_stages &= ~bits;
 }
 
 static bool
diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c
index 7f3881c0a2c..a704be9de56 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -276,12 +276,12 @@ destroy_shader_cache(struct zink_screen *screen, struct hash_table *sc)
 }
 
 static void
-update_shader_modules(struct zink_context *ctx, struct zink_gfx_program *prog)
+update_shader_modules(struct zink_context *ctx, struct zink_gfx_program *prog, uint32_t mask)
 {
    bool hash_changed = false;
    bool default_variants = true;
    bool first = !prog->modules[PIPE_SHADER_VERTEX];
-   u_foreach_bit(pstage, ctx->dirty_shader_stages & prog->stages_present) {
+   u_foreach_bit(pstage, mask) {
       assert(prog->shaders[pstage]);
       struct zink_shader_module *zm = get_shader_module_for_stage(ctx, prog->shaders[pstage], prog);
       if (prog->modules[pstage] != zm)
@@ -299,7 +299,6 @@ update_shader_modules(struct zink_context *ctx, struct zink_gfx_program *prog)
       ctx->gfx_pipeline_state.combined_dirty = true;
    }
    ctx->gfx_pipeline_state.module_hash = prog->last_variant_hash;
-   ctx->dirty_shader_stages &= ~u_bit_consecutive(PIPE_SHADER_VERTEX, 5);
 }
 
 static uint32_t
@@ -342,7 +341,7 @@ equals_gfx_pipeline_state(const void *a, const void *b)
 void
 zink_update_gfx_program(struct zink_context *ctx, struct zink_gfx_program *prog)
 {
-   update_shader_modules(ctx, prog);
+   update_shader_modules(ctx, prog, ctx->dirty_shader_stages & prog->stages_present);
 }
 
 VkPipelineLayout
@@ -434,11 +433,9 @@ zink_create_gfx_program(struct zink_context *ctx,
       prog->stages_present |= BITFIELD_BIT(PIPE_SHADER_TESS_CTRL);
    }
 
-   /* always force shader creation during init */
-   ctx->dirty_shader_stages |= prog->stages_present;
    assign_io(prog, prog->shaders);
 
-   update_shader_modules(ctx, prog);
+   update_shader_modules(ctx, prog, prog->stages_present);
    prog->default_variant_hash = ctx->gfx_pipeline_state.module_hash;
 
    for (int i = 0; i < ARRAY_SIZE(prog->pipelines); ++i) {
@@ -894,6 +891,7 @@ bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
       zink_select_launch_grid(ctx);
    } else {
       ctx->gfx_stages[stage] = shader;
+      ctx->gfx_dirty = ctx->gfx_stages[PIPE_SHADER_FRAGMENT] && ctx->gfx_stages[PIPE_SHADER_VERTEX];
       ctx->gfx_pipeline_state.combined_dirty = true;
       if (shader)
          ctx->shader_stages |= BITFIELD_BIT(stage);
@@ -902,7 +900,6 @@ bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
          ctx->curr_program = NULL;
          ctx->shader_stages &= ~BITFIELD_BIT(stage);
       }
-      ctx->dirty_shader_stages |= 1 << stage;
    }
    if (shader && shader->nir->info.num_inlinable_uniforms)
       ctx->shader_has_inlinable_uniforms_mask |= 1 << stage;



More information about the mesa-commit mailing list