From 809e9462ce35b94eefa7a6cf5a2f41317f199ae8 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 2 Sep 2022 11:13:44 -0400 Subject: [PATCH] zink: be even more granular with optimal_key program updates since the bits of each key are easily and efficiently comparable, the draw-time updating here can be made extremely granular to update exactly the stages that have changed since the last time the program was used, further reducing overhead instead of updating every possible key value Reviewed-by: Adam Jackson Part-of: --- src/gallium/drivers/zink/zink_program.c | 15 +++++++++------ src/gallium/drivers/zink/zink_shader_keys.h | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 391c4716e25..73dfa01b240 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -571,13 +571,16 @@ zink_gfx_program_update(struct zink_context *ctx) if (screen->optimal_keys) { ctx->gfx_pipeline_state.optimal_key = ctx->gfx_pipeline_state.shader_keys_optimal.key.val; if (ctx->gfx_pipeline_state.optimal_key != prog->last_variant_hash) { - ctx->dirty_gfx_stages |= BITFIELD_BIT(ctx->last_vertex_stage->nir->info.stage); - ctx->dirty_gfx_stages |= BITFIELD_BIT(MESA_SHADER_FRAGMENT); - if (prog->shaders[MESA_SHADER_TESS_CTRL] && prog->shaders[MESA_SHADER_TESS_CTRL]->is_generated) + const union zink_shader_key_optimal *optimal_key = (union zink_shader_key_optimal*)&prog->last_variant_hash; + uint8_t dirty = ctx->dirty_gfx_stages & prog->stages_present; + if (ctx->gfx_pipeline_state.shader_keys_optimal.key.vs_bits != optimal_key->vs_bits) + ctx->dirty_gfx_stages |= BITFIELD_BIT(ctx->last_vertex_stage->nir->info.stage); + if (ctx->gfx_pipeline_state.shader_keys_optimal.key.fs_bits != optimal_key->fs_bits) + ctx->dirty_gfx_stages |= BITFIELD_BIT(MESA_SHADER_FRAGMENT); + if (prog->shaders[MESA_SHADER_TESS_CTRL] && prog->shaders[MESA_SHADER_TESS_CTRL]->is_generated && + ctx->gfx_pipeline_state.shader_keys_optimal.key.tcs_bits != optimal_key->tcs_bits) ctx->dirty_gfx_stages |= BITFIELD_BIT(MESA_SHADER_TESS_CTRL); - update_gfx_shader_modules_optimal(ctx, screen, prog, - ctx->dirty_gfx_stages & prog->stages_present, - &ctx->gfx_pipeline_state); + update_gfx_shader_modules_optimal(ctx, screen, prog, dirty, &ctx->gfx_pipeline_state); } } else { for (unsigned i = 0; i < ZINK_GFX_SHADER_COUNT; i++) { diff --git a/src/gallium/drivers/zink/zink_shader_keys.h b/src/gallium/drivers/zink/zink_shader_keys.h index 4ca013901ed..295cbe3cfef 100644 --- a/src/gallium/drivers/zink/zink_shader_keys.h +++ b/src/gallium/drivers/zink/zink_shader_keys.h @@ -99,6 +99,11 @@ union zink_shader_key_optimal { struct zink_tcs_key tcs; struct zink_fs_key fs; }; + struct { + uint8_t vs_bits; + uint8_t tcs_bits; + uint16_t fs_bits; + }; uint32_t val; };