skia2/resources/sksl/intrinsics/Mod.sksl
John Stiles e5240a2498 Implement compile-time optimization for mod().
$genType mod($genType x, float y);
$genType mod($genType x, $genType y);
$genHType mod($genHType x, half y);
$genHType mod($genHType x, $genHType y);

Change-Id: I406eafbe824d7aa55012196521e6f10cac50ed19
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/412376
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-05-25 22:07:53 +00:00

26 lines
1.5 KiB
Plaintext

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