skia2/resources/sksl/intrinsics/AbsInt.sksl
John Stiles edac7716aa Evaluate single-argument generic intrinsics at compile time.
In particular, this optimizes abs() and sign() when all inputs are known
at compile time. This resolves a TODO on a test case in
`IllegalIndexing.rts`.

Change-Id: Ica310522a85b42dc7ae255bd25004a6629d04176
Bug: skia:10835
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405676
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-10 14:50:50 +00:00

16 lines
689 B
Plaintext

uniform half4 testInputs;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const half4 constVal = half4(-1.25, 0, 0.75, 2.25);
int4 expected = int4(1, 0, 0, 2);
return (abs(int4(testInputs).x) == expected.x &&
abs(int4(testInputs).xy) == expected.xy &&
abs(int4(testInputs).xyz) == expected.xyz &&
abs(int4(testInputs).xyzw) == expected.xyzw &&
abs(int4(constVal).x) == expected.x &&
abs(int4(constVal).xy) == expected.xy &&
abs(int4(constVal).xyz) == expected.xyz &&
abs(int4(constVal).xyzw) == expected.xyzw) ? colorGreen : colorRed;
}