From 0775d0f1b5c1fbc5e082cce36ee2ea41599c9c61 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Sat, 28 Feb 2026 09:21:54 -0800 Subject: [PATCH] spirv: Refactor ALU opcode translation to take bit sizes Only used by Convert operations, so just pass 0 from callers that are not Convert and clarify that in the code. Backport-to: 26.0 Reviewed-by: Georg Lehmann (cherry picked from commit 1c3c987d5c4ea84a91702083e0ad397386bf182e) Part-of: --- .pick_status.json | 2 +- src/compiler/spirv/spirv_to_nir.c | 3 ++- src/compiler/spirv/vtn_alu.c | 24 ++++++++++++------------ src/compiler/spirv/vtn_cmat.c | 8 ++------ src/compiler/spirv/vtn_private.h | 4 ++-- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e06646bc48d..3465c28c68f 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3034,7 +3034,7 @@ "description": "spirv: Refactor ALU opcode translation to take bit sizes", "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 9cf2c66cec9..deacf97f7ec 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -2894,7 +2894,8 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode, bool exact; nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, &exact, - src_type, dst_type); + glsl_get_bit_size(src_type), + glsl_get_bit_size(dst_type)); /* No SPIR-V opcodes handled through this path should set exact. * Since it is ignored, assert on it. diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c index 31d8a230211..dcaee176c44 100644 --- a/src/compiler/spirv/vtn_alu.c +++ b/src/compiler/spirv/vtn_alu.c @@ -280,12 +280,9 @@ vtn_convert_op_dst_type(SpvOp opcode) nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b, SpvOp opcode, bool *swap, bool *exact, - const glsl_type *src_type, - const glsl_type *dst_type) + unsigned conv_src_bit_size, + unsigned conv_dst_bit_size) { - const unsigned src_bit_size = glsl_get_bit_size(src_type); - const unsigned dst_bit_size = glsl_get_bit_size(dst_type); - /* Indicates that the first two arguments should be swapped. This is * used for implementing greater-than and less-than-or-equal. */ @@ -382,8 +379,12 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b, case SpvOpConvertUToF: case SpvOpSConvert: case SpvOpFConvert: { - nir_alu_type src_type = vtn_convert_op_src_type(opcode) | src_bit_size; - nir_alu_type dst_type = vtn_convert_op_dst_type(opcode) | dst_bit_size; + vtn_fail_if(conv_src_bit_size == 0, + "Need src bit_size to translate from SPIR-V convert opcodes to NIR."); + vtn_fail_if(conv_dst_bit_size == 0, + "Need dst bit_size to translate from SPIR-V convert opcodes to NIR."); + nir_alu_type src_type = vtn_convert_op_src_type(opcode) | conv_src_bit_size; + nir_alu_type dst_type = vtn_convert_op_dst_type(opcode) | conv_dst_bit_size; return nir_type_conversion_op(src_type, dst_type, nir_rounding_mode_undef); } @@ -909,8 +910,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, bool swap; bool unused_exact; nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, - &unused_exact, - vtn_src[0]->type, dest_type); + &unused_exact, 0, 0); if (swap) { nir_def *tmp = src[0]; @@ -986,8 +986,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, case SpvOpShiftRightLogical: { bool swap; bool exact; - nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, &exact, - vtn_src[0]->type, dest_type); + nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, &exact, 0, 0); assert(!exact); @@ -1046,7 +1045,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, bool exact; nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, &exact, - vtn_src[0]->type, dest_type); + glsl_get_bit_size(vtn_src[0]->type), + glsl_get_bit_size(dest_type)); if (swap) { nir_def *tmp = src[0]; diff --git a/src/compiler/spirv/vtn_cmat.c b/src/compiler/spirv/vtn_cmat.c index 1b4de345327..318173f4929 100644 --- a/src/compiler/spirv/vtn_cmat.c +++ b/src/compiler/spirv/vtn_cmat.c @@ -320,9 +320,7 @@ vtn_handle_cooperative_alu(struct vtn_builder *b, struct vtn_value *dest_val, nir_deref_instr *src = vtn_get_cmat_deref(b, w[3]); bool ignored = false; - nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &ignored, &ignored, - glsl_get_cmat_element(src->type), - glsl_get_cmat_element(dst_type->type)); + nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &ignored, &ignored, 0, 0); nir_deref_instr *dst = vtn_create_cmat_temporary(b, dst_type->type, "cmat_unary"); nir_cmat_unary_op(&b->nb, &dst->def, &src->def, @@ -346,9 +344,7 @@ vtn_handle_cooperative_alu(struct vtn_builder *b, struct vtn_value *dest_val, nir_deref_instr *mat_a = vtn_get_cmat_deref(b, w[3]); nir_deref_instr *mat_b = vtn_get_cmat_deref(b, w[4]); - nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &ignored, &ignored, - glsl_get_cmat_element(mat_a->type), - glsl_get_cmat_element(dst_type->type)); + nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &ignored, &ignored, 0, 0); nir_deref_instr *dst = vtn_create_cmat_temporary(b, dst_type->type, "cmat_binary"); nir_cmat_binary_op(&b->nb, &dst->def, &mat_a->def, &mat_b->def, diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 9aa6cb4c912..a8c4988a488 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -980,8 +980,8 @@ nir_alu_type vtn_convert_op_dst_type(SpvOp opcode); nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b, SpvOp opcode, bool *swap, bool *exact, - const glsl_type *src_type, - const glsl_type *dst_type); + unsigned conv_src_bit_size, + unsigned conv_dst_bit_size); void vtn_handle_alu(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count);