Re: [Mesa-dev] [PATCH 1/2] spirv: fix the translation of SPIR-V conversion opcodes to NIR

2018-03-14 Thread Jason Ekstrand

Rb


On March 14, 2018 03:42:01 Samuel Iglesias Gonsálvez  
wrote:



There are some SPIRV opcodes (like UConvert and SConvert) have some
expectations of the output that doesn't depend on the operands
data type. Generalize the solution of all of them.

Signed-off-by: Samuel Iglesias Gonsálvez 
---
 src/compiler/spirv/vtn_alu.c | 40 +---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index d0c9e316935..15158b39520 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -355,9 +355,43 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
case SpvOpConvertSToF:
case SpvOpConvertUToF:
case SpvOpSConvert:
-   case SpvOpFConvert:
-  return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);
-
+   case SpvOpFConvert: {
+  nir_alu_type src_type;
+  nir_alu_type dst_type;
+
+  switch (opcode) {
+  case SpvOpConvertFToS:
+ src_type = nir_type_float;
+ dst_type = nir_type_int;
+ break;
+  case SpvOpConvertFToU:
+ src_type = nir_type_float;
+ dst_type = nir_type_uint;
+ break;
+  case SpvOpFConvert:
+ src_type = dst_type = nir_type_float;
+ break;
+  case SpvOpConvertSToF:
+ src_type = nir_type_int;
+ dst_type = nir_type_float;
+ break;
+  case SpvOpSConvert:
+ src_type = dst_type = nir_type_int;
+ break;
+  case SpvOpConvertUToF:
+ src_type = nir_type_uint;
+ dst_type = nir_type_float;
+ break;
+  case SpvOpUConvert:
+ src_type = dst_type = nir_type_uint;
+ break;
+  default:
+ unreachable("Invalid opcode");
+  }
+  src_type |= nir_alu_type_get_type_size(src);
+  dst_type |= nir_alu_type_get_type_size(dst);
+  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

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev



___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] spirv: fix the translation of SPIR-V conversion opcodes to NIR

2018-03-14 Thread Samuel Iglesias Gonsálvez
There are some SPIRV opcodes (like UConvert and SConvert) have some
expectations of the output that doesn't depend on the operands
data type. Generalize the solution of all of them.

Signed-off-by: Samuel Iglesias Gonsálvez 
---
 src/compiler/spirv/vtn_alu.c | 40 +---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index d0c9e316935..15158b39520 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -355,9 +355,43 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
case SpvOpConvertSToF:
case SpvOpConvertUToF:
case SpvOpSConvert:
-   case SpvOpFConvert:
-  return nir_type_conversion_op(src, dst, nir_rounding_mode_undef);
-
+   case SpvOpFConvert: {
+  nir_alu_type src_type;
+  nir_alu_type dst_type;
+
+  switch (opcode) {
+  case SpvOpConvertFToS:
+ src_type = nir_type_float;
+ dst_type = nir_type_int;
+ break;
+  case SpvOpConvertFToU:
+ src_type = nir_type_float;
+ dst_type = nir_type_uint;
+ break;
+  case SpvOpFConvert:
+ src_type = dst_type = nir_type_float;
+ break;
+  case SpvOpConvertSToF:
+ src_type = nir_type_int;
+ dst_type = nir_type_float;
+ break;
+  case SpvOpSConvert:
+ src_type = dst_type = nir_type_int;
+ break;
+  case SpvOpConvertUToF:
+ src_type = nir_type_uint;
+ dst_type = nir_type_float;
+ break;
+  case SpvOpUConvert:
+ src_type = dst_type = nir_type_uint;
+ break;
+  default:
+ unreachable("Invalid opcode");
+  }
+  src_type |= nir_alu_type_get_type_size(src);
+  dst_type |= nir_alu_type_get_type_size(dst);
+  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

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev