xref: /aosp_15_r20/external/skia/resources/sksl/intrinsics/MatrixCompMultES2.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorGreen, colorRed;
2uniform float2x2 testMatrix2x2;
3uniform half3x3 testMatrix3x3;
4
5half4 main(float2 coords) {
6    // This multiplication does not overflow and can be evaluated at compile time.
7    const half2x2 smallM22 = half2x2(1000, 1000, 1000, 1000);
8    half2x2 h22 = matrixCompMult(smallM22, smallM22);
9
10    // This multiplication would overflow the maximum float value, so we don't evaluate it at
11    // compile time. We don't care what the result is, since ES2 doesn't guarantee infinities, but
12    // we should be able to compile it safely.
13    const half2x2 hugeM22 = half2x2(1e30, 1e30, 1e30, 1e30);
14    h22 = matrixCompMult(hugeM22, hugeM22);
15
16    h22 = matrixCompMult(half2x2(5, 5, 5, 5), half2x2(0, 1, 2, 3));
17    const half4x4 h44 = matrixCompMult(half4x4(0.5), half4x4(1, 2, 3, 4,
18                                                             5, 6, 7, 8,
19                                                             9, 10,11,12,
20                                                             13,14,15,16));
21    float2x2 f22 = matrixCompMult(testMatrix2x2, float2x2(1));
22    half3x3 h33 = matrixCompMult(testMatrix3x3, half3x3(2,2,2,2,2,2,2,2,2));
23    return (h22 == half2x2(0, 5, 10, 15) &&
24            f22 == float2x2(1, 0, 0, 4) &&
25            h33 == half3x3(2, 4, 6, 8, 10, 12, 14, 16, 18) &&
26            h44 == half4x4(0.5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5.5, 0, 0, 0, 0, 8))
27                ? colorGreen : colorRed;
28}
29