From 75425f36dc2dac3ec66f8fc5bed1af635a8cb204 Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Fri, 6 Mar 2026 18:59:05 +0100 Subject: [PATCH] nir/opt_varyings: Skip code-motion for upconversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code-motion should not move back upconversions without any other instruction, that would only increase memory pressure without any significant performance benefit (conversions are usually cheap). This should also help lowering mediump varyings early by not reversing their work. Signed-off-by: Lorenzo Rossi Reviewed-by: Marek Olšák Reviewed-by: Eric R. Smith Part-of: --- src/compiler/nir/nir_opt_varyings.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/compiler/nir/nir_opt_varyings.c b/src/compiler/nir/nir_opt_varyings.c index d69741846e0..9d6ed76aa58 100644 --- a/src/compiler/nir/nir_opt_varyings.c +++ b/src/compiler/nir/nir_opt_varyings.c @@ -4092,6 +4092,18 @@ backward_inter_shader_code_motion(struct linkage_info *linkage, alu->src[1].src.ssa == load_def))))) continue; + /* Skip upconversions, those are usually cheap and moving them + * back just increases memory pressure without helping performance. + */ + unsigned input_size = 0; + for (int i = 0; i < nir_op_infos[alu->op].num_inputs; i++) { + nir_src *src = &alu->src[i].src; + input_size += nir_src_bit_size(*src) * + nir_src_num_components(*src); + } + if (input_size < alu->def.bit_size * alu->def.num_components) + continue; + bit_size = alu->def.bit_size; } else if (iter->type == nir_instr_type_intrinsic) { nir_intrinsic_instr *intr = nir_instr_as_intrinsic(iter);