<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 5, 2018 at 10:21 PM, Samuel Iglesias Gonsálvez <span dir="ltr"><<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OpSConvert interprets the MSB of the unsigned value as the sign bit and<br>
extends it to the new type. If we want to preserve the value, we need<br>
to use OpUConvert opcode.<br>
<br>
v2:<br>
- No need to check dst type.<br>
- Fix typo in comment.<br>
<br>
Signed-off-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
---<br>
src/compiler/spirv/vtn_alu.c | 18 +++++++++++++++++-<br>
1 file changed, 17 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c<br>
index d0c9e316935..a5cefc35773 100644<br>
--- a/src/compiler/spirv/vtn_alu.c<br>
+++ b/src/compiler/spirv/vtn_alu.c<br>
@@ -354,10 +354,26 @@ vtn_nir_alu_op_for_spirv_<wbr>opcode(struct vtn_builder *b,<br>
case SpvOpConvertFToS:<br>
case SpvOpConvertSToF:<br>
case SpvOpConvertUToF:<br>
- case SpvOpSConvert:<br>
case SpvOpFConvert:<br>
return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);<br>
<br>
+ case SpvOpSConvert: {<br>
+ nir_alu_type src_base = (nir_alu_type) nir_alu_type_get_base_type(<wbr>src);<br>
+ if (src_base == nir_type_uint) {<br></blockquote><div><br></div><div>Why are we predicating this on src_base == nir_type_uint? It seems to me as if we should just ignore the source and destination type except for the bit size.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ /* SPIR-V expects to interpret the unsigned value as signed and<br>
+ * do sign extend. Return the opcode accordingly.<br>
+ */<br>
+ unsigned dst_bit_size = nir_alu_type_get_type_size(<wbr>dst);<br>
+ switch (dst_bit_size) {<br>
+ case 16: return nir_op_i2i16;<br>
+ case 32: return nir_op_i2i32;<br>
+ case 64: return nir_op_i2i64;<br></blockquote><div><br></div><div>This can be nir_type_int | dst_bit_size. NIR types are convenient like that. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ default:<br>
+ vtn_fail("Invalid nir alu bit size");<br>
+ }<br>
+ }<br>
+ return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);<br>
+ }<br>
/* Derivatives: */<br>
case SpvOpDPdx: return nir_op_fddx;<br>
case SpvOpDPdy: return nir_op_fddy;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>