[Mesa-dev] [PATCH v2 2/2] spirv: fix OpUConvert when the source is signed
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Tue Mar 6 06:21:24 UTC 2018
From: Iago Toral Quiroga <itoral at igalia.com>
In this case we don't want to do sign-extension, since the value is
interpreted as unsigned. If we want sign-extension, OpSConvert should
be used.
---
src/compiler/spirv/vtn_alu.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index a5cefc35773..0b279fe7e54 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -349,7 +349,6 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
/* Conversions: */
case SpvOpQuantizeToF16: return nir_op_fquantize2f16;
- case SpvOpUConvert:
case SpvOpConvertFToU:
case SpvOpConvertFToS:
case SpvOpConvertSToF:
@@ -374,6 +373,25 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
}
return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);
}
+
+ case SpvOpUConvert: {
+ nir_alu_type src_base = (nir_alu_type) nir_alu_type_get_base_type(src);
+ if (src_base == nir_type_int) {
+ /* SPIR-V expects to interpret the signed value as unsigned and
+ * not sign extend. Return the opcode accordingly.
+ */
+ unsigned dst_bit_size = nir_alu_type_get_type_size(dst);
+ switch (dst_bit_size) {
+ case 16: return nir_op_u2u16;
+ case 32: return nir_op_u2u32;
+ case 64: return nir_op_u2u64;
+ default:
+ vtn_fail("Invalid nir alu bit size");
+ }
+ }
+ return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);
+ }
+
/* Derivatives: */
case SpvOpDPdx: return nir_op_fddx;
case SpvOpDPdy: return nir_op_fddy;
--
2.14.1
More information about the mesa-dev
mailing list