From 6eded1a7d05aefcdd6dfe3115eccc24ca0bacf19 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 5 Feb 2026 22:29:06 -0500 Subject: [PATCH] nir/lower_bool_to_bit_size: Use the correct num_components for conversions There's a nice little comment here saying we use the same write mask (an out of date term in NIR) and swizzle but we're no longer actually doing that. Depending on nir_builder magic, we may actually generate a scalar when we really want a vector. The fix is to use more builder helpers and just eat the potential copy. Fixes: 3180656bbc9d ("nir: don't use nir_build_alu() with incomplete sources") Reviewed-by: Christoph Pillmayer (cherry picked from commit 711b3358a8c8d5dd3f86e7298203668202fc381d) Part-of: --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_bool_to_bitsize.c | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 89a7d188a73..98d5cd54ce4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -984,7 +984,7 @@ "description": "nir/lower_bool_to_bit_size: Use the correct num_components for conversions", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "3180656bbc9d9494418ba2b827691559d729ee80", "notes": null diff --git a/src/compiler/nir/nir_lower_bool_to_bitsize.c b/src/compiler/nir/nir_lower_bool_to_bitsize.c index e1c5acb89e8..80879e67ce1 100644 --- a/src/compiler/nir/nir_lower_bool_to_bitsize.c +++ b/src/compiler/nir/nir_lower_bool_to_bitsize.c @@ -69,16 +69,12 @@ make_sources_canonical(nir_builder *b, nir_alu_instr *alu, uint32_t start_idx) if (nir_src_bit_size(alu->src[i].src) != bit_size) { b->cursor = nir_before_instr(&alu->instr); nir_op convert_op = get_bool_convert_opcode(bit_size); - nir_alu_instr *conv_instr = nir_alu_instr_create(b->shader, convert_op); - conv_instr->src[0].src = nir_src_for_ssa(alu->src[i].src.ssa); - /* Retain the write mask and swizzle of the original instruction so - * that we don’t unnecessarily create a vectorized instruction. + /* Retain the number of components and swizzle of the original + * instruction so that we don’t unnecessarily create a vectorized + * instruction. */ - memcpy(conv_instr->src[0].swizzle, - alu->src[i].swizzle, - sizeof(conv_instr->src[0].swizzle)); - - nir_def *new_src = nir_builder_alu_instr_finish_and_insert(b, conv_instr); + nir_def *new_src = + nir_build_alu1(b, convert_op, nir_ssa_for_alu_src(b, alu, i)); nir_src_rewrite(&alu->src[i].src, new_src); /* The swizzle will have been handled by the conversion instruction