spirv: Allow spirv_to_nir callers to provide a float execution mode
authorJesse Natalie <jenatali@microsoft.com>
Fri, 13 Nov 2020 23:08:10 +0000 (15:08 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 18 Nov 2020 04:05:37 +0000 (04:05 +0000)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7565>

src/compiler/spirv/nir_spirv.h
src/compiler/spirv/spirv_to_nir.c

index 5964184..b7d2432 100644 (file)
@@ -69,6 +69,11 @@ struct spirv_to_nir_options {
    /* Create a nir library. */
    bool create_library;
 
+   /* Initial value for shader_info::float_controls_execution_mode,
+    * indicates hardware requirements rather than shader author intent
+    */
+   uint16_t float_controls_execution_mode;
+
    struct spirv_supported_capabilities caps;
 
    /* Address format for various kinds of pointers. */
index b8b6397..de3d12d 100644 (file)
@@ -4828,6 +4828,15 @@ vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
       }
 
       b->shader->info.float_controls_execution_mode |= execution_mode;
+
+      for (unsigned bit_size = 16; bit_size <= 64; bit_size *= 2) {
+         vtn_fail_if(nir_is_denorm_flush_to_zero(b->shader->info.float_controls_execution_mode, bit_size) &&
+                     nir_is_denorm_preserve(b->shader->info.float_controls_execution_mode, bit_size),
+                     "Cannot flush to zero and preserve denorms for the same bit size.");
+         vtn_fail_if(nir_is_rounding_mode_rtne(b->shader->info.float_controls_execution_mode, bit_size) &&
+                     nir_is_rounding_mode_rtz(b->shader->info.float_controls_execution_mode, bit_size),
+                     "Cannot set rounding mode to RTNE and RTZ for the same bit size.");
+      }
       break;
    }
 
@@ -5744,6 +5753,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
    words+= 5;
 
    b->shader = nir_shader_create(b, stage, nir_options, NULL);
+   b->shader->info.float_controls_execution_mode = options->float_controls_execution_mode;
 
    /* Handle all the preamble instructions */
    words = vtn_foreach_instruction(b, words, word_end,