From ee225e31c1311bac5e3b2d476ac8eea4006b1ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 8 Jul 2023 18:00:45 -0400 Subject: [PATCH] nir: fix constant evaluation of fddx/fddy sourcing Inf & NaN constant A derivative of NaN is NaN. Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir_opcodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index e4d87aa6126..a66c37b4c0d 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -332,12 +332,12 @@ unop_convert("frexp_sig", tfloat, tfloat, "int n; dst = frexp(src0, &n);") deriv_template = """ Calculate the screen-space partial derivative using {} derivatives of the input with respect to the {}-axis. The constant folding is trivial as the derivative -of a constant is 0. +of a constant is 0 if the constant is not Inf or NaN. """ for mode, suffix in [("either fine or coarse", ""), ("fine", "_fine"), ("coarse", "_coarse")]: for axis in ["x", "y"]: - unop(f"fdd{axis}{suffix}", tfloat, "0.0", + unop(f"fdd{axis}{suffix}", tfloat, "isfinite(src0) ? 0.0 : NAN", description = deriv_template.format(mode, axis.upper())) # Floating point pack and unpack operations.