[Mesa-dev] [PATCH v3 02/44] spirv/nir: keep track of SPV_KHR_shader_float_controls execution modes

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Feb 6 10:44:31 UTC 2019


v2:
- Add support for rounding modes for each floating point bit size.

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
 src/compiler/shader_enums.h       | 20 +++++++++++++++
 src/compiler/shader_info.h        |  3 +++
 src/compiler/spirv/spirv_to_nir.c | 41 +++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)

diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index 1dff01484b5..4dbfe715e21 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -768,6 +768,26 @@ enum compare_func
    COMPARE_FUNC_ALWAYS,
 };
 
+enum shader_float_controls
+{
+   SHADER_DEFAULT_FLOAT_CONTROL_MODE           = 0x0000,
+   SHADER_DENORM_PRESERVE_FP16                 = 0x0001,
+   SHADER_DENORM_PRESERVE_FP32                 = 0x0002,
+   SHADER_DENORM_PRESERVE_FP64                 = 0x0004,
+   SHADER_DENORM_FLUSH_TO_ZERO_FP16            = 0x0008,
+   SHADER_DENORM_FLUSH_TO_ZERO_FP32            = 0x0010,
+   SHADER_DENORM_FLUSH_TO_ZERO_FP64            = 0x0020,
+   SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP16    = 0x0040,
+   SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP32    = 0x0080,
+   SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP64    = 0x0100,
+   SHADER_ROUNDING_MODE_RTE_FP16               = 0x0200,
+   SHADER_ROUNDING_MODE_RTE_FP32               = 0x0400,
+   SHADER_ROUNDING_MODE_RTE_FP64               = 0x0800,
+   SHADER_ROUNDING_MODE_RTZ_FP16               = 0x1000,
+   SHADER_ROUNDING_MODE_RTZ_FP32               = 0x2000,
+   SHADER_ROUNDING_MODE_RTZ_FP64               = 0x4000,
+};
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index 45fb00a9cfe..d37dc52be61 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -144,6 +144,9 @@ typedef struct shader_info {
    /** Was this shader linked with any transform feedback varyings? */
    bool has_transform_feedback_varyings;
 
+   /* SPV_KHR_shader_float_controls: execution mode for floating point ops */
+   unsigned shader_float_controls_execution_mode;
+
    union {
       struct {
          /* Which inputs are doubles */
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index dea36b839a6..3f23e799431 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3933,6 +3933,47 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       vtn_assert(b->shader->info.stage == MESA_SHADER_FRAGMENT);
       break;
 
+   case SpvExecutionModeDenormPreserve:
+      switch (mode->literals[0]) {
+      case 16: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_PRESERVE_FP16; break;
+      case 32: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_PRESERVE_FP32; break;
+      case 64: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_PRESERVE_FP64; break;
+      default: vtn_fail("Floating point type not supported");
+      }
+      break;
+   case SpvExecutionModeDenormFlushToZero:
+      switch (mode->literals[0]) {
+      case 16: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_FLUSH_TO_ZERO_FP16; break;
+      case 32: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_FLUSH_TO_ZERO_FP32; break;
+      case 64: b->shader->info.shader_float_controls_execution_mode |= SHADER_DENORM_FLUSH_TO_ZERO_FP64; break;
+      default: vtn_fail("Floating point type not supported");
+      }
+       break;
+   case SpvExecutionModeSignedZeroInfNanPreserve:
+      switch (mode->literals[0]) {
+      case 16: b->shader->info.shader_float_controls_execution_mode |= SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP16; break;
+      case 32: b->shader->info.shader_float_controls_execution_mode |= SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP32; break;
+      case 64: b->shader->info.shader_float_controls_execution_mode |= SHADER_SIGNED_ZERO_INF_NAN_PRESERVE_FP64; break;
+      default: vtn_fail("Floating point type not supported");
+      }
+      break;
+   case SpvExecutionModeRoundingModeRTE:
+      switch (mode->literals[0]) {
+      case 16: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTE_FP16; break;
+      case 32: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTE_FP32; break;
+      case 64: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTE_FP64; break;
+      default: vtn_fail("Floating point type not supported");
+      }
+      break;
+   case SpvExecutionModeRoundingModeRTZ:
+      switch (mode->literals[0]) {
+      case 16: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTZ_FP16; break;
+      case 32: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTZ_FP32; break;
+      case 64: b->shader->info.shader_float_controls_execution_mode |= SHADER_ROUNDING_MODE_RTZ_FP64; break;
+      default: vtn_fail("Floating point type not supported");
+      }
+      break;
+
    default:
       vtn_fail("Unhandled execution mode");
    }
-- 
2.19.1



More information about the mesa-dev mailing list