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: 3180656bbc ("nir: don't use nir_build_alu() with incomplete sources")
Reviewed-by: Christoph Pillmayer <christoph.pillmayer@arm.com>
(cherry picked from commit 711b3358a8)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39828>
This commit is contained in:
Faith Ekstrand 2026-02-05 22:29:06 -05:00 committed by Marge Bot
parent c0e5d821e1
commit 6eded1a7d0
2 changed files with 6 additions and 10 deletions

View file

@ -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

View file

@ -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 dont unnecessarily create a vectorized instruction.
/* Retain the number of components and swizzle of the original
* instruction so that we dont 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