skia2/resources/sksl/intrinsics/PackUnorm2x16.sksl
John Stiles 8d0dd0d1c1 Add support for pack/unpackUnorm2x16 to public SkSL.
This includes compile-time optimization and tests.

The unit test is disabled in a followup CL
(http://review.skia.org/447057) because it exposes a Radeon 5300M bug
in OpenGL.

Change-Id: I8b2f0411358aeb68c4edfeb0bd7a2814c4be1f40
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/447056
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-09-09 18:59:15 +00:00

19 lines
888 B
Plaintext

uniform half4 colorGreen, colorRed;
uniform float4 testInputs; // equals (-1.25, 0, 0.75, 2.25)
half4 main(float2 coords) {
const float4 constVal = float4(-1.25, 0, 0.75, 2.25);
const float4 expected = clamp(constVal, 0, 1);
const uint constXY = packUnorm2x16(constVal.xy);
const uint constZW = packUnorm2x16(constVal.zw);
uint xy = packUnorm2x16(testInputs.xy);
uint zw = packUnorm2x16(testInputs.zw);
const float2 tolerance = float2(0.015625);
return (all(lessThan(abs(unpackUnorm2x16(xy) - float2(expected.xy)), tolerance)) &&
all(lessThan(abs(unpackUnorm2x16(zw) - float2(expected.zw)), tolerance)) &&
all(lessThan(abs(unpackUnorm2x16(constXY) - float2(expected.xy)), tolerance)) &&
all(lessThan(abs(unpackUnorm2x16(constZW) - float2(expected.zw)), tolerance)))
? colorGreen : colorRed;
}