From 3e8f5407530a4ddfd58e2c203efdb77b3589fd3f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 2 Oct 2021 09:02:19 -0400 Subject: [PATCH] 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 Acked-by: Jason Ekstrand Part-of: --- 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