skia2/resources/sksl/intrinsics/Sqrt.sksl
John Stiles 443fa19832 Implement compile-time optimization for sqrt(constant).
Change-Id: I3427fbaf57787c3051db95ec5882c9292d7985cf
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411312
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-05-25 04:43:10 +00:00

20 lines
924 B
Plaintext

uniform half4 input, expected;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const half4 constVal = half4(1, 4, 16, 64);
const half4 negativeVal = half4(-1, -4, -16, -64); // should not optimize away
return (sqrt(input.x) == expected.x &&
sqrt(input.xy) == expected.xy &&
sqrt(input.xyz) == expected.xyz &&
sqrt(input.xyzw) == expected.xyzw &&
sqrt(constVal.x) == expected.x &&
sqrt(constVal.xy) == expected.xy &&
sqrt(constVal.xyz) == expected.xyz &&
sqrt(constVal.xyzw) == expected.xyzw &&
sqrt(negativeVal.x) == expected.x &&
sqrt(negativeVal.xy) == expected.xy &&
sqrt(negativeVal.xyz) == expected.xyz &&
sqrt(negativeVal.xyzw) == expected.xyzw) ? colorGreen : colorRed;
}