From dbdde903bb91992c66be6fdd069fdde94b3b9d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 10 Aug 2021 03:21:55 -0400 Subject: [PATCH] radeonsi: update most of the PS shader key in set & bind functions This decreases overhead of si_update_shaders and overall driver overhead. There is only one function that depends on the rasterized primitive type, and thus it can't be moved to set & bind functions. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/drivers/radeonsi/si_state.c | 21 ++++++++++++-- src/gallium/drivers/radeonsi/si_state.h | 7 +++++ .../drivers/radeonsi/si_state_shaders.c | 29 ++++++++++--------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 0ce9f50d250..cb4bf2d8ebf 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -709,8 +709,11 @@ static void si_bind_blend_state(struct pipe_context *ctx, void *state) old_blend->alpha_to_one != blend->alpha_to_one || old_blend->dual_src_blend != blend->dual_src_blend || old_blend->blend_enable_4bit != blend->blend_enable_4bit || - old_blend->need_src_alpha_4bit != blend->need_src_alpha_4bit) + old_blend->need_src_alpha_4bit != blend->need_src_alpha_4bit) { + si_ps_key_update_framebuffer_blend(sctx); + si_ps_key_update_blend_rasterizer(sctx); sctx->do_update_shaders = true; + } if (sctx->screen->dpbb_allowed && (old_blend->alpha_to_coverage != blend->alpha_to_coverage || @@ -1119,8 +1122,12 @@ static void si_bind_rs_state(struct pipe_context *ctx, void *state) old_rs->poly_smooth != rs->poly_smooth || old_rs->line_smooth != rs->line_smooth || old_rs->clamp_fragment_color != rs->clamp_fragment_color || old_rs->force_persample_interp != rs->force_persample_interp || - old_rs->polygon_mode_is_points != rs->polygon_mode_is_points) + old_rs->polygon_mode_is_points != rs->polygon_mode_is_points) { + si_ps_key_update_blend_rasterizer(sctx); + si_ps_key_update_rasterizer(sctx); + si_ps_key_update_framebuffer_rasterizer_sample_shading(sctx); sctx->do_update_shaders = true; + } } static void si_delete_rs_state(struct pipe_context *ctx, void *state) @@ -1336,8 +1343,10 @@ static void si_bind_dsa_state(struct pipe_context *ctx, void *state) si_mark_atom_dirty(sctx, &sctx->atoms.s.stencil_ref); } - if (old_dsa->alpha_func != dsa->alpha_func) + if (old_dsa->alpha_func != dsa->alpha_func) { + si_ps_key_update_dsa(sctx); sctx->do_update_shaders = true; + } if (sctx->screen->dpbb_allowed && ((old_dsa->depth_enabled != dsa->depth_enabled || old_dsa->stencil_enabled != dsa->stencil_enabled || @@ -2983,6 +2992,9 @@ static void si_set_framebuffer_state(struct pipe_context *ctx, si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_sample_locs); } + si_ps_key_update_framebuffer(sctx); + si_ps_key_update_framebuffer_blend(sctx); + si_ps_key_update_framebuffer_rasterizer_sample_shading(sctx); sctx->do_update_shaders = true; if (!sctx->decompression_enabled) { @@ -3635,6 +3647,9 @@ static void si_set_min_samples(struct pipe_context *ctx, unsigned min_samples) return; sctx->ps_iter_samples = min_samples; + + si_ps_key_update_sample_shading(sctx); + si_ps_key_update_framebuffer_rasterizer_sample_shading(sctx); sctx->do_update_shaders = true; si_update_ps_iter_samples(sctx); diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h index 3f230bcf271..8d42a186bea 100644 --- a/src/gallium/drivers/radeonsi/si_state.h +++ b/src/gallium/drivers/radeonsi/si_state.h @@ -582,6 +582,13 @@ void si_shader_selector_key_vs(struct si_context *sctx, struct si_shader_selecto struct si_shader_key *key, struct si_vs_prolog_bits *prolog_key); unsigned si_get_input_prim(const struct si_shader_selector *gs); bool si_update_ngg(struct si_context *sctx); +void si_ps_key_update_framebuffer(struct si_context *sctx); +void si_ps_key_update_framebuffer_blend(struct si_context *sctx); +void si_ps_key_update_blend_rasterizer(struct si_context *sctx); +void si_ps_key_update_rasterizer(struct si_context *sctx); +void si_ps_key_update_dsa(struct si_context *sctx); +void si_ps_key_update_sample_shading(struct si_context *sctx); +void si_ps_key_update_framebuffer_rasterizer_sample_shading(struct si_context *sctx); /* si_state_draw.c */ void si_init_draw_functions_GFX6(struct si_context *sctx); diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 6d467d9fa8f..c5e424ca975 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -1874,7 +1874,7 @@ static void si_shader_selector_key_hw_vs(struct si_context *sctx, struct si_shad key->opt.kill_pointsize = 1; } -static void si_ps_key_update_framebuffer(struct si_context *sctx) +void si_ps_key_update_framebuffer(struct si_context *sctx) { struct si_shader_selector *sel = sctx->shader.ps.cso; struct si_shader_key *key = &sctx->shader.ps.key; @@ -1909,7 +1909,7 @@ static void si_ps_key_update_framebuffer(struct si_context *sctx) } } -static void si_ps_key_update_framebuffer_blend(struct si_context *sctx) +void si_ps_key_update_framebuffer_blend(struct si_context *sctx) { struct si_shader_selector *sel = sctx->shader.ps.cso; struct si_shader_key *key = &sctx->shader.ps.key; @@ -1973,7 +1973,7 @@ static void si_ps_key_update_framebuffer_blend(struct si_context *sctx) key->opt.prefer_mono = 0; } -static void si_ps_key_update_blend_rasterizer(struct si_context *sctx) +void si_ps_key_update_blend_rasterizer(struct si_context *sctx) { struct si_shader_key *key = &sctx->shader.ps.key; struct si_state_blend *blend = sctx->queued.named.blend; @@ -1982,7 +1982,7 @@ static void si_ps_key_update_blend_rasterizer(struct si_context *sctx) key->part.ps.epilog.alpha_to_one = blend->alpha_to_one && rs->multisample_enable; } -static void si_ps_key_update_rasterizer(struct si_context *sctx) +void si_ps_key_update_rasterizer(struct si_context *sctx) { struct si_shader_selector *sel = sctx->shader.ps.cso; struct si_shader_key *key = &sctx->shader.ps.key; @@ -1996,7 +1996,7 @@ static void si_ps_key_update_rasterizer(struct si_context *sctx) key->part.ps.epilog.clamp_color = rs->clamp_fragment_color; } -static void si_ps_key_update_dsa(struct si_context *sctx) +void si_ps_key_update_dsa(struct si_context *sctx) { struct si_shader_key *key = &sctx->shader.ps.key; @@ -2017,7 +2017,7 @@ static void si_ps_key_update_primtype_shader_rasterizer_framebuffer(struct si_co sctx->framebuffer.nr_samples <= 1; } -static void si_ps_key_update_sample_shading(struct si_context *sctx) +void si_ps_key_update_sample_shading(struct si_context *sctx) { struct si_shader_selector *sel = sctx->shader.ps.cso; struct si_shader_key *key = &sctx->shader.ps.key; @@ -2031,7 +2031,7 @@ static void si_ps_key_update_sample_shading(struct si_context *sctx) key->part.ps.prolog.samplemask_log_ps_iter = 0; } -static void si_ps_key_update_framebuffer_rasterizer_sample_shading(struct si_context *sctx) +void si_ps_key_update_framebuffer_rasterizer_sample_shading(struct si_context *sctx) { struct si_shader_selector *sel = sctx->shader.ps.cso; struct si_shader_key *key = &sctx->shader.ps.key; @@ -2182,14 +2182,7 @@ static inline void si_shader_selector_key(struct pipe_context *ctx, struct si_sh key->part.gs.prolog.tri_strip_adj_fix = sctx->gs_tri_strip_adj_fix; break; case MESA_SHADER_FRAGMENT: - si_ps_key_update_framebuffer(sctx); - si_ps_key_update_framebuffer_blend(sctx); - si_ps_key_update_blend_rasterizer(sctx); - si_ps_key_update_rasterizer(sctx); - si_ps_key_update_dsa(sctx); si_ps_key_update_primtype_shader_rasterizer_framebuffer(sctx); - si_ps_key_update_sample_shading(sctx); - si_ps_key_update_framebuffer_rasterizer_sample_shading(sctx); break; default: assert(0); @@ -3348,6 +3341,14 @@ static void si_bind_ps_shader(struct pipe_context *ctx, void *state) si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config); } si_update_ps_colorbuf0_slot(sctx); + + si_ps_key_update_framebuffer(sctx); + si_ps_key_update_framebuffer_blend(sctx); + si_ps_key_update_blend_rasterizer(sctx); + si_ps_key_update_rasterizer(sctx); + si_ps_key_update_dsa(sctx); + si_ps_key_update_sample_shading(sctx); + si_ps_key_update_framebuffer_rasterizer_sample_shading(sctx); } static void si_delete_shader(struct si_context *sctx, struct si_shader *shader)