xref: /aosp_15_r20/external/skia/resources/sksl/intrinsics/Sqrt.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform float2x2 testMatrix2x2;  // = {1, 2, 3, 4}
2uniform half4 colorGreen, colorRed;
3
4half4 main(float2 coords) {
5    // We should not attempt to constant-fold `sqrt(negative values)`. This sqrt call should remain
6    // in the generated code as-is.
7    const float4 negativeVal = half4(-1, -4, -16, -64);
8    coords.xy = sqrt(negativeVal).xy;
9
10    float4       inputVal = float4(testMatrix2x2) + half4(0, 2, 6, 12); // = {1, 4, 9, 16}
11    const float4 constVal = float4(1, 4, 9, 16);
12    const float4 expected = float4(1, 2, 3, 4);
13    const float4 allowedDelta = float4(0.05);
14
15    return (   (        (abs(sqrt(inputVal.x)       - expected.x)   < allowedDelta.x))     &&
16            all(lessThan(abs(sqrt(inputVal.xy)      - expected.xy),   allowedDelta.xy))    &&
17            all(lessThan(abs(sqrt(inputVal.xyz)     - expected.xyz),  allowedDelta.xyz))   &&
18            all(lessThan(abs(sqrt(inputVal.xyzw)    - expected.xyzw), allowedDelta.xyzw))  &&
19               (        (abs(sqrt(constVal.x)       - expected.x)   < allowedDelta.x))     &&
20            all(lessThan(abs(sqrt(constVal.xy)      - expected.xy),   allowedDelta.xy))    &&
21            all(lessThan(abs(sqrt(constVal.xyz)     - expected.xyz),  allowedDelta.xyz))   &&
22            all(lessThan(abs(sqrt(constVal.xyzw)    - expected.xyzw), allowedDelta.xyzw)))
23                ? colorGreen : colorRed;
24}
25