From 61dc9201a1ecd20caec70825642a2b10ba2b9ca6 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 17 Nov 2025 15:51:33 -0500 Subject: [PATCH] brw: constant fold before texture lowering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures we don't need dynamic stuff. Noticed when debugging weird regressions around the mcs lowering. ARL: total instructions in shared programs: 19857061 -> 19854964 (-0.01%) instructions in affected programs: 91768 -> 89671 (-2.29%) helped: 154 HURT: 0 helped stats (abs) min: 9.0 max: 33.0 x̄: 13.62 x̃: 13 helped stats (rel) min: 0.51% max: 40.91% x̄: 4.66% x̃: 3.36% 95% mean confidence interval for instructions value: -14.04 -13.19 95% mean confidence interval for instructions %-change: -5.49% -3.84% Instructions are helped. total cycles in shared programs: 884538769 -> 884485530 (<.01%) cycles in affected programs: 10508994 -> 10455755 (-0.51%) helped: 116 HURT: 38 helped stats (abs) min: 4.0 max: 15238.0 x̄: 666.22 x̃: 148 helped stats (rel) min: 0.01% max: 34.53% x̄: 2.58% x̃: 1.07% HURT stats (abs) min: 4.0 max: 4027.0 x̄: 632.68 x̃: 302 HURT stats (rel) min: 0.01% max: 32.75% x̄: 3.46% x̃: 0.59% 95% mean confidence interval for cycles value: -631.32 -60.09 95% mean confidence interval for cycles %-change: -2.06% -0.12% Cycles are helped. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Lionel Landwerlin Reviewed-by: Caio Oliveira Part-of: --- src/intel/compiler/brw/brw_nir.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/intel/compiler/brw/brw_nir.c b/src/intel/compiler/brw/brw_nir.c index db0239a4780..6332cc0535c 100644 --- a/src/intel/compiler/brw/brw_nir.c +++ b/src/intel/compiler/brw/brw_nir.c @@ -2550,14 +2550,12 @@ brw_postprocess_nir_opts(nir_shader *nir, const struct brw_compiler *compiler, if (OPT(nir_lower_tex, &tex_options)) OPT(nir_lower_tex, &tex_options); - /* MCS lowering can introduce u2u16 conversions. We need to lower those to - * make constant offsets detectable by brw_nir_texture_backend_opcode(). - */ - if (OPT(brw_nir_lower_mcs_fetch, devinfo)) - OPT(nir_opt_constant_folding); - + OPT(brw_nir_lower_mcs_fetch, devinfo); OPT(intel_nir_lower_sparse_intrinsics); + /* Any constants leftover should be folded so we have constant textures */ + OPT(nir_opt_constant_folding); + /* Needs to happen before the backend opcode selection */ OPT(brw_nir_pre_lower_texture);