skia2/resources/sksl/intrinsics/ClampUInt.sksl
John Stiles 107ea94139 Add support for clamp($genUType, ...) in SkSL.
We never used it internally, but the shaders used by Filament rely on
it. It doesn't exist in ES2 so this doesn't affect Runtime Effects.

Change-Id: Idb2afb15ff160b950ad02101bf6381a5d5c56468
Bug: skia:12635, skia:11209
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470156
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-11-11 18:43:42 +00:00

32 lines
1.9 KiB
Plaintext

uniform half4 testInputs;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
uint4 uintValues = uint4(testInputs * 100 + 200);
uint4 expectedA = uint4( 100, 200, 275, 300);
const uint4 clampLow = uint4( 100, 0, 0, 300);
const uint4 constVal = uint4( 75, 200, 275, 425);
uint4 expectedB = uint4( 100, 200, 250, 425);
const uint4 clampHigh = uint4( 300, 400, 250, 500);
return (clamp(uintValues.x, 100, 300) == expectedA.x &&
clamp(uintValues.xy, 100, 300) == expectedA.xy &&
clamp(uintValues.xyz, 100, 300) == expectedA.xyz &&
clamp(uintValues.xyzw, 100, 300) == expectedA.xyzw &&
clamp(constVal.x, 100, 300) == expectedA.x &&
clamp(constVal.xy, 100, 300) == expectedA.xy &&
clamp(constVal.xyz, 100, 300) == expectedA.xyz &&
clamp(constVal.xyzw, 100, 300) == expectedA.xyzw &&
clamp(uintValues.x, clampLow.x, clampHigh.x ) == expectedB.x &&
clamp(uintValues.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy &&
clamp(uintValues.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz &&
clamp(uintValues.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw &&
clamp(constVal.x, clampLow.x, clampHigh.x ) == expectedB.x &&
clamp(constVal.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy &&
clamp(constVal.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz &&
clamp(constVal.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen
: colorRed;
}