[Mesa-dev] [PATCH v2 13/29] spirv/nir: take into account the rounding mode in the conversions

Samuel Iglesias Gonsálvez siglesias at igalia.com
Tue Dec 18 10:34:08 UTC 2018


Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
 src/compiler/nir/nir.h       | 15 +++++++++++++++
 src/compiler/spirv/vtn_alu.c | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 05c87290858..9579b5939fe 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -875,6 +875,21 @@ nir_get_nir_type_for_glsl_type(const struct glsl_type *type)
 nir_op nir_type_conversion_op(nir_alu_type src, nir_alu_type dst,
                               nir_rounding_mode rnd);
 
+static inline nir_rounding_mode
+nir_get_rounding_mode_from_float_controls(unsigned rounding_mode,
+                                          nir_alu_type type)
+{
+   if (nir_alu_type_get_base_type(type) != nir_type_float)
+      return nir_rounding_mode_undef;
+
+   if (rounding_mode & SHADER_ROUNDING_MODE_RTZ)
+      return nir_rounding_mode_rtz;
+   if (rounding_mode & SHADER_ROUNDING_MODE_RTE)
+      return nir_rounding_mode_rtne;
+
+   return nir_rounding_mode_undef;
+}
+
 typedef enum {
    NIR_OP_IS_COMMUTATIVE = (1 << 0),
    NIR_OP_IS_ASSOCIATIVE = (1 << 1),
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index dc6fedc9129..681c68e3cd9 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -329,7 +329,12 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
       }
       src_type |= src_bit_size;
       dst_type |= dst_bit_size;
-      return nir_type_conversion_op(src_type, dst_type, nir_rounding_mode_undef);
+      unsigned float_controls =
+         b->shader->info.shader_float_controls_execution_mode;
+      nir_rounding_mode rounding_mode =
+         nir_get_rounding_mode_from_float_controls(float_controls,
+                                                   src_type);
+      return nir_type_conversion_op(src_type, dst_type, rounding_mode);
    }
    /* Derivatives: */
    case SpvOpDPdx:         return nir_op_fddx;
@@ -585,12 +590,21 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
                                          glsl_get_bit_size(type));
       break;
 
+   case SpvOpConvertFToS:
+   case SpvOpConvertFToU:
    case SpvOpFConvert: {
       nir_alu_type src_alu_type = nir_get_nir_type_for_glsl_type(vtn_src[0]->type);
       nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(type);
       nir_rounding_mode rounding_mode = nir_rounding_mode_undef;
+      unsigned float_controls = b->shader->info.shader_float_controls_execution_mode;
 
       vtn_foreach_decoration(b, val, handle_rounding_mode, &rounding_mode);
+
+      if (rounding_mode == nir_rounding_mode_undef && float_controls) {
+         rounding_mode =
+            nir_get_rounding_mode_from_float_controls(float_controls,
+                                                      src_alu_type);
+      }
       nir_op op = nir_type_conversion_op(src_alu_type, dst_alu_type, rounding_mode);
 
       val->ssa->def = nir_build_alu(&b->nb, op, src[0], src[1], NULL, NULL);
-- 
2.19.1



More information about the mesa-dev mailing list