Mesa (main): nir: Add Mali-specific derivative opcodes

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 6 01:10:37 UTC 2021


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

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Sat Oct  2 09:02:19 2021 -0400

nir: Add Mali-specific derivative opcodes

Add derivative opcodes fddx_must_abs_mali/fddy_must_abs_mali satisfying:

   fabs(fdd*_must_abs_mali(v)) = fabs(fdd*(v))

The sign of their result is undefined.

On Bifrost and Valhall, these unsigned derivatives can be implemented
more efficiently than the correctly-signed counterparts, since the sign
fixup requires extra ALU instructions. On backends where this is the
case, it is useful to optimize fabs(fdd*(v)) to
fabs(fdd*_must_abs_mali(v)). This pattern comes up with the GLSL builtin
`fwidth`.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Acked-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12332>

---

 src/compiler/nir/nir_opcodes.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py
index 95470b1255f..c16923b0ee8 100644
--- a/src/compiler/nir/nir_opcodes.py
+++ b/src/compiler/nir/nir_opcodes.py
@@ -1308,6 +1308,10 @@ for (int i = 0; i < 32; i += 8) {
 unop("fsat_signed_mali", tfloat, ("fmin(fmax(src0, -1.0), 1.0)"))
 unop("fclamp_pos_mali", tfloat, ("fmax(src0, 0.0)"))
 
+# Magnitude equal to fddx/y, sign undefined. Derivative of a constant is zero.
+unop("fddx_must_abs_mali", tfloat, "0.0")
+unop("fddy_must_abs_mali", tfloat, "0.0")
+
 # DXIL specific double [un]pack
 # DXIL doesn't support generic [un]pack instructions, so we want those
 # lowered to bit ops. HLSL doesn't support 64bit bitcasts to/from



More information about the mesa-commit mailing list