From 4588b025c88f5eeb3b22a9d333db28e7dc1e033f Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Sat, 28 Feb 2026 11:56:05 -0800 Subject: [PATCH] spirv: Pull constant source fixup to the existing loop Backport-to: 26.0 Reviewed-by: Georg Lehmann (cherry picked from commit b0c3b20bff4e6593f73fa554040fc6e6ede62e29) Part-of: --- .pick_status.json | 2 +- src/compiler/spirv/spirv_to_nir.c | 36 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 3465c28c68f..fb69677b91d 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3024,7 +3024,7 @@ "description": "spirv: Pull constant source fixup to the existing loop", "nominated": true, "nomination_type": 4, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index deacf97f7ec..1b863640fea 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -2936,26 +2936,28 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, else if (glsl_type_is_e5m2(org_src_type)) src[j][c].f32 = _mesa_e5m2_to_float(src[j][c].u8); } - } - /* fix up fixed size sources */ - switch (op) { - case nir_op_ishl: - case nir_op_ishr: - case nir_op_ushr: { - if (bit_size == 32) - break; - for (unsigned i = 0; i < num_components; ++i) { - switch (bit_size) { - case 64: src[1][i].u32 = src[1][i].u64; break; - case 16: src[1][i].u32 = src[1][i].u16; break; - case 8: src[1][i].u32 = src[1][i].u8; break; + /* Fix up source to respect NIR expected sizes. */ + switch (op) { + case nir_op_ishl: + case nir_op_ishr: + case nir_op_ushr: { + /* Shift amount in NIR ops must be 32-bit. */ + vtn_assert(!swap); + const unsigned shift_idx = 1; + const unsigned shift_bit_size = glsl_get_bit_size(src_val->type->type); + if (i != shift_idx || shift_bit_size == 32) + break; + for (unsigned c = 0; c < src_comps; c++) { + nir_const_value *shift = &src[shift_idx][c]; + *shift = nir_const_value_for_uint( + nir_const_value_as_uint(*shift, shift_bit_size), 32); } + break; + } + default: + break; } - break; - } - default: - break; } nir_const_value *srcs[3] = {