xref: /aosp_15_r20/external/skia/resources/sksl/folding/MatrixNoOpFolding.rts (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform float2x2 testMatrix2x2;
2uniform float3x3 testMatrix3x3;
3uniform float4 testInputs;
4uniform half4 colorRed, colorGreen;
5uniform half unknownInput;
6
7bool test_mat2_mat2() {
8    float2x2 m, mm;
9    const float2x2 i = float2x2(1.0);
10    const float2x2 z = float2x2(0.0);
11    const float2x2 s = float2x2(float4(1.0));
12
13    m = testMatrix2x2 * i;
14    m = i * testMatrix2x2;
15
16    m = m * i;
17    m = i * m;
18    m *= i;
19
20    m = m / s;
21    m /= s;
22
23    m = m + z;
24    m = z + m;
25    m += z;
26
27    m = m - z;
28    m = z - m;  // negates
29    m -= z;
30
31    mm = m * z;
32    mm = z * m;
33
34    return m == -testMatrix2x2 && mm == z;
35}
36
37bool test_mat3_mat3() {
38    float3x3 m, mm;
39    const float3x3 i = float3x3(1.0);
40    const float3x3 z = float3x3(0.0);
41    const float3x3 s = float3x3(float3(1.0), float3(1.0), float3(1.0));
42
43    m = testMatrix3x3 * i;
44    m = i * testMatrix3x3;
45
46    m = m * i;
47    m = i * m;
48    m *= i;
49
50    m = m / s;
51    m /= s;
52
53    m = m + z;
54    m = z + m;
55    m += z;
56
57    m = m - z;
58    m = z - m;  // negates
59    m -= z;
60
61    mm = m * z;
62    mm = z * m;
63
64    return m == -testMatrix3x3 && mm == z;
65}
66
67bool test_mat4_mat4() {
68    float4x4 testMatrix4x4 = float4x4(testInputs, testInputs, testInputs, testInputs);
69
70    float4x4 m, mm;
71    const float4x4 i = float4x4(1.0);
72    const float4x4 z = float4x4(0.0);
73    const float4x4 s = float4x4(float4(1.0), float4(1.0), float4(1.0), float4(1.0));
74
75    m = testMatrix4x4 * i;
76    m = i * testMatrix4x4;
77
78    m = m * i;
79    m = i * m;
80    m *= i;
81
82    m = m / s;
83    m /= s;
84
85    m = m + z;
86    m = z + m;
87    m += z;
88
89    m = m - z;
90    m = z - m;  // negates
91    m -= z;
92
93    mm = m * z;
94    mm = z * m;
95
96    return m == -testMatrix4x4 && mm == z;
97}
98
99half4 main(float2 coords) {
100    return test_mat2_mat2() &&
101           test_mat3_mat3() &&
102           test_mat4_mat4() ? colorGreen : colorRed;
103}
104