From 36c547342ac8b41421ec30815bb866210e1457e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Thu, 10 Mar 2022 00:46:48 +0100 Subject: [PATCH] v3dv/pipeline: call nir_lower_explicit_io after first nir optimization loop That is what most others Vulkan drivers do (radv, anv, turnip at least). The origin of this change cames from a CTS test where the loop unrolling converted a ubo index defined inside a loop from constant to non constant. That is not desiderable on any driver, but a problem on v3dv, as v3dv doesn't support that case. Although we initially tried to fix it on the loop unroll, we discarded that approach, and focused on the existing nir lowerings/optimizations as this was not happening with other drivers. We noted that in other drivers this case of a ubo index going from const to non-const were also happening with nir_lower_explicit_io, but in that case it was able to be converted back to a const on following lowerings. The only difference with other drivers is that we were calling it before the first nir optimization loop. So this change helps with fixing the following CTS test (for that we also need to run additional lowerings, which we do in a later patch): dEQP-VK.graphicsfuzz.cov-loop-condition-clamp-vec-of-ones You can get further details on the following issue and RFC merge request, specially the merge request: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6051 https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15391 We also made some shaderdb stats with our usual Vulkan apps (ue4 demos, quake3, etc): Total instructions in shared programs: 125014 -> 124974 (-0.03%) instructions in affected programs: 7544 -> 7504 (-0.53%) helped: 7 HURT: 4 total uniforms in shared programs: 19026 -> 19019 (-0.04%) uniforms in affected programs: 514 -> 507 (-1.36%) helped: 5 HURT: 0 total max-temps in shared programs: 13430 -> 13438 (0.06%) max-temps in affected programs: 270 -> 278 (2.96%) helped: 0 HURT: 8 total sfu-stalls in shared programs: 739 -> 741 (0.27%) sfu-stalls in affected programs: 30 -> 32 (6.67%) helped: 0 HURT: 2 total inst-and-stalls in shared programs: 125753 -> 125715 (-0.03%) inst-and-stalls in affected programs: 7685 -> 7647 (-0.49%) helped: 7 HURT: 4 total nops in shared programs: 8228 -> 8203 (-0.30%) nops in affected programs: 546 -> 521 (-4.58%) helped: 9 HURT: 2 Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/vulkan/v3dv_pipeline.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 0a18d095051..a5d58e07899 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -367,14 +367,6 @@ preprocess_nir(nir_shader *nir) }); } - NIR_PASS_V(nir, nir_lower_explicit_io, - nir_var_mem_push_const, - nir_address_format_32bit_offset); - - NIR_PASS_V(nir, nir_lower_explicit_io, - nir_var_mem_ubo | nir_var_mem_ssbo, - nir_address_format_32bit_index_offset); - NIR_PASS_V(nir, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir), true, false); @@ -392,6 +384,14 @@ preprocess_nir(nir_shader *nir) nir_optimize(nir, true); + NIR_PASS_V(nir, nir_lower_explicit_io, + nir_var_mem_push_const, + nir_address_format_32bit_offset); + + NIR_PASS_V(nir, nir_lower_explicit_io, + nir_var_mem_ubo | nir_var_mem_ssbo, + nir_address_format_32bit_index_offset); + NIR_PASS_V(nir, nir_lower_load_const_to_scalar); /* Lower a bunch of stuff */