[Mesa-dev] [PATCH v3 2/2] spirv: fix OpUConvert when the source is signed
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Tue Mar 13 12:40:49 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.
v2:
- Use src/dst bitsize to get the proper conversion opcode. (Jason)
---
src/compiler/spirv/vtn_alu.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index 9dcd183a48d..e4b4fb5716f 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:
@@ -367,6 +366,18 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
nir_alu_type dst_type = nir_type_int | dst_bit_size;
return nir_type_conversion_op(src_type, dst_type, nir_rounding_mode_undef);
}
+
+ case SpvOpUConvert: {
+ /* SPIR-V expects to interpret the signed value as unsigned and
+ * not sign extend. Return the opcode accordingly.
+ */
+ unsigned src_bit_size = nir_alu_type_get_type_size(src);
+ nir_alu_type src_type = nir_type_uint | src_bit_size;
+ unsigned dst_bit_size = nir_alu_type_get_type_size(dst);
+ nir_alu_type dst_type = nir_type_uint | dst_bit_size;
+ return nir_type_conversion_op(src_type, dst_type, 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