From ff13fc381d59fc8a5b06a40b6bb857503c6e7711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Mon, 2 May 2022 14:26:54 +0200 Subject: [PATCH] radv: Use NIR optimization to move discards to the top. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fossil stats on Sienna Cichlid: Totals from 1988 (1.55% of 128653) affected shaders: VGPRs: 68096 -> 67928 (-0.25%); split: -0.61%, +0.36% CodeSize: 5391936 -> 5391312 (-0.01%); split: -0.11%, +0.10% MaxWaves: 53020 -> 52946 (-0.14%); split: +0.05%, -0.19% Instrs: 992413 -> 992509 (+0.01%); split: -0.10%, +0.11% Latency: 8643141 -> 8789295 (+1.69%); split: -0.31%, +2.00% InvThroughput: 1680195 -> 1680605 (+0.02%); split: -0.04%, +0.07% SClause: 50886 -> 51318 (+0.85%); split: -0.73%, +1.57% Copies: 57017 -> 56741 (-0.48%); split: -1.28%, +0.80% PreSGPRs: 66766 -> 67048 (+0.42%); split: -0.24%, +0.66% PreVGPRs: 56832 -> 56935 (+0.18%); split: -0.44%, +0.62% Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: --- src/amd/vulkan/radv_shader.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 453f954fa7d..3977ac031bb 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -214,7 +214,13 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively, bool NIR_PASS(progress, shader, nir_opt_shrink_vectors); NIR_PASS(progress, shader, nir_remove_dead_variables, nir_var_function_temp | nir_var_shader_in | nir_var_shader_out, NULL); - NIR_PASS(progress, shader, nir_opt_conditional_discard); + + if (shader->info.stage == MESA_SHADER_FRAGMENT && + (shader->info.fs.uses_discard || shader->info.fs.uses_demote)) { + NIR_PASS(progress, shader, nir_opt_conditional_discard); + NIR_PASS(progress, shader, nir_opt_move_discards_to_top); + } + NIR_PASS(progress, shader, nir_opt_move, nir_move_load_ubo); }