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

Author: Georg Lehmann <[email protected]>
Date:   Wed Mar  1 13:24:30 2023 +0100

nir/lower_mediump: don't use fp16 for constants if the result is denormal

Image stores are not required to preserve denorms.

Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Emma Anholt <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21622>

---

 src/compiler/nir/nir_lower_mediump.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_lower_mediump.c 
b/src/compiler/nir/nir_lower_mediump.c
index c1baabf27ed..2e7a40d2359 100644
--- a/src/compiler/nir/nir_lower_mediump.c
+++ b/src/compiler/nir/nir_lower_mediump.c
@@ -749,7 +749,9 @@ static bool
 const_is_f16(nir_ssa_scalar scalar)
 {
    double value = nir_ssa_scalar_as_float(scalar);
-   return value == _mesa_half_to_float(_mesa_float_to_half(value));
+   uint16_t fp16_val = _mesa_float_to_half(value);
+   bool is_denorm = (fp16_val & 0x7fff) != 0 && (fp16_val & 0x7fff) <= 0x3ff;
+   return value == _mesa_half_to_float(fp16_val) && !is_denorm;
 }
 
 static bool

Reply via email to