skia2/resources/sksl/intrinsics/Step.sksl
John Stiles 017ffd7e05 Implement compile-time optimization for step().
$genType step($genType edge, $genType x);
$genType step(float edge, $genType x);
$genHType step($genHType edge, $genHType x);
$genHType step(half edge, $genHType x);

Change-Id: If52634d7a247772e922cb3fd2e3e8a7c36c275f6
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411842
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-25 16:59:22 +00:00

27 lines
1.4 KiB
Plaintext

uniform half4 testInputs;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const half4 constVal = half4(-1.25, 0, 0.75, 2.25);
const half4 constGreen = half4(0, 1, 0, 1);
half4 expectedA = half4(0, 0, 1, 1);
half4 expectedB = half4(1, 1, 0, 0);
return (step(0.5, testInputs.x) == expectedA.x &&
step(0.5, testInputs.xy) == expectedA.xy &&
step(0.5, testInputs.xyz) == expectedA.xyz &&
step(0.5, testInputs.xyzw) == expectedA.xyzw &&
step(0.5, constVal.x) == expectedA.x &&
step(0.5, constVal.xy) == expectedA.xy &&
step(0.5, constVal.xyz) == expectedA.xyz &&
step(0.5, constVal.xyzw) == expectedA.xyzw &&
step(testInputs.x, constGreen.x) == expectedB.x &&
step(testInputs.xy, constGreen.xy) == expectedB.xy &&
step(testInputs.xyz, constGreen.xyz) == expectedB.xyz &&
step(testInputs.xyzw, constGreen.xyzw) == expectedB.xyzw &&
step(constVal.x, constGreen.x) == expectedB.x &&
step(constVal.xy, constGreen.xy) == expectedB.xy &&
step(constVal.xyz, constGreen.xyz) == expectedB.xyz &&
step(constVal.xyzw, constGreen.xyzw) == expectedB.xyzw) ? colorGreen : colorRed;
}