skia2/resources/sksl/intrinsics/DFdy.sksl
John Stiles 4e2494870d Allow derivatives in Runtime Effects when ES3 restrictions are off.
We can now add functions to sksl_public.sksl with an $es3 prefix. These
will be allowed in a Runtime Effect when strict-ES2 mode is disabled.
Note that the CPU backend still doesn't have support for these calls,
and will fail ungracefully (assertion, nonsense result) if these
intrinsics are used.

The testing here is limited, due to an unrelated bug in SPIR-V
(skia:12340)

Change-Id: I9c911bc2b77f5051e80844607e7fd08ad386ee56
Bug: skia:12202, skia:12340
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439058
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-08-13 16:45:17 +00:00

17 lines
697 B
Plaintext

uniform half4 testInputs; // equals (-1.25, 0, 0.75, 2.25)
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
half4 expected = half4(0); // derivative of a constant is zero
return (dFdx(testInputs.x) == expected.x &&
dFdx(testInputs.xy) == expected.xy &&
dFdx(testInputs.xyz) == expected.xyz &&
dFdx(testInputs.xyzw) == expected.xyzw) ? colorGreen : colorRed;
/*
// TODO(skia:12340): This test triggers an RTFlip bug in the SPIR-V code generator
sign(dFdy(coords.xx)) == half2(0, 0) &&
sign(dFdy(coords.yy)) == half2(1, 1) &&
sign(dFdy(coords.xy)) == half2(0, 1)
*/
}