Module: Mesa
Branch: main
Commit: 7e4aac46ad41c7b928061552d4f48bc67c931f4b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7e4aac46ad41c7b928061552d4f48bc67c931f4b

Author: Qiang Yu <yuq...@gmail.com>
Date:   Wed Nov  8 10:44:22 2023 +0800

nir: add force_f2f16_rtz option to lower f2f16 to f2f16_rtz

Used by OpenGL driver like radeonsi which has undefined rounding mode.

Reviewed-by: Marek Olšák <marek.ol...@amd.com>
Signed-off-by: Qiang Yu <yuq...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25990>

---

 src/compiler/nir/nir.h                | 3 +++
 src/compiler/nir/nir_opt_algebraic.py | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index b44dad7e836..9273286691e 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4016,6 +4016,9 @@ typedef struct nir_shader_compiler_options {
 
    /** lowers fquantize2f16 to alu ops. */
    bool lower_fquantize2f16;
+
+   /** Lower f2f16 to f2f16_rtz when execution mode is not rtne. */
+   bool force_f2f16_rtz;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader {
diff --git a/src/compiler/nir/nir_opt_algebraic.py 
b/src/compiler/nir/nir_opt_algebraic.py
index 8a7cb3617fa..8e531b1e5b2 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -3281,6 +3281,8 @@ late_optimizations += [
   (('u2fmp', a), ('u2f16', a), "!options->preserve_mediump"),
   (('fisfinite', a), ('flt', ('fabs', a), float("inf"))),
 
+  (('f2f16', a), ('f2f16_rtz', a), "options->force_f2f16_rtz && 
!nir_is_rounding_mode_rtne(info->float_controls_execution_mode, 16)"),
+
   (('fcsel', ('slt', 0, a), b, c), ('fcsel_gt', a, b, c), 
"options->has_fused_comp_and_csel"),
   (('fcsel', ('slt', a, 0), b, c), ('fcsel_gt', ('fneg', a), b, c), 
"options->has_fused_comp_and_csel"),
   (('fcsel', ('sge', a, 0), b, c), ('fcsel_ge', a, b, c), 
"options->has_fused_comp_and_csel"),

Reply via email to