From b7f2d480da6e49479c2a09fdb55344fb55375698 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 11 Nov 2024 14:20:20 -0400 Subject: [PATCH] agx: optimize scratch access so we can use designated initializers and other fun features. all affected shaders are in gfxbench: total instructions in shared programs: 2750549 -> 2750497 (<.01%) instructions in affected programs: 10832 -> 10780 (-0.48%) helped: 4 HURT: 2 Inconclusive result (value mean confidence interval includes 0). total alu in shared programs: 2278478 -> 2278760 (0.01%) alu in affected programs: 7040 -> 7322 (4.01%) helped: 2 HURT: 4 Alu are HURT. total fscib in shared programs: 2276985 -> 2277267 (0.01%) fscib in affected programs: 7040 -> 7322 (4.01%) helped: 2 HURT: 4 Fscib are HURT. total bytes in shared programs: 19922466 -> 19922734 (<.01%) bytes in affected programs: 71412 -> 71680 (0.38%) helped: 4 HURT: 2 Inconclusive result (value mean confidence interval includes 0). total regs in shared programs: 865070 -> 865086 (<.01%) regs in affected programs: 142 -> 158 (11.27%) helped: 0 HURT: 2 total uniforms in shared programs: 2120930 -> 2121034 (<.01%) uniforms in affected programs: 244 -> 348 (42.62%) helped: 0 HURT: 2 total scratch in shared programs: 11576 -> 11600 (0.21%) scratch in affected programs: 2744 -> 2768 (0.87%) helped: 0 HURT: 2 total spills in shared programs: 958 -> 868 (-9.39%) spills in affected programs: 958 -> 868 (-9.39%) helped: 6 HURT: 0 total fills in shared programs: 732 -> 626 (-14.48%) fills in affected programs: 732 -> 626 (-14.48%) helped: 4 HURT: 2 Signed-off-by: Alyssa Rosenzweig Reviewed-by: Mary Guillemard Part-of: --- src/asahi/compiler/agx_compile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index b330d7b3f2e..9a15d94ac1c 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -3692,8 +3692,7 @@ agx_preprocess_nir(nir_shader *nir, const nir_shader *libagx) /* Lower large arrays to scratch and small arrays to csel */ NIR_PASS(_, nir, nir_lower_vars_to_scratch, nir_var_function_temp, 256, - glsl_get_natural_size_align_bytes, - glsl_get_natural_size_align_bytes); + glsl_get_natural_size_align_bytes, glsl_get_word_size_align_bytes); NIR_PASS(_, nir, nir_lower_indirect_derefs, nir_var_function_temp, ~0); NIR_PASS(_, nir, nir_split_var_copies); NIR_PASS(_, nir, nir_lower_global_vars_to_local); @@ -3801,6 +3800,13 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, }; NIR_PASS(_, nir, nir_lower_mem_access_bit_sizes, &lower_mem_access_options); + /* Optimize scratch access */ + NIR_PASS(_, nir, nir_lower_scratch_to_var); + NIR_PASS(_, nir, nir_lower_vars_to_scratch, nir_var_function_temp, 256, + glsl_get_natural_size_align_bytes, + glsl_get_natural_size_align_bytes); + NIR_PASS(_, nir, nir_lower_indirect_derefs, nir_var_function_temp, ~0); + /* Cleanup 8-bit math before lowering */ bool progress; do {