1cb93a386Sopenharmony_ciuniform float2x2 testMatrix2x2;
2cb93a386Sopenharmony_ciuniform half4 colorRed, colorGreen;
3cb93a386Sopenharmony_ciuniform half unknownInput;
4cb93a386Sopenharmony_ci
5cb93a386Sopenharmony_cibool test() {
6cb93a386Sopenharmony_ci    bool ok = true;
7cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) ==
8cb93a386Sopenharmony_ci                 float2x2(float2(1.0, 0.0), float2(0.0, 1.0)));
9cb93a386Sopenharmony_ci    ok = ok && !(float2x2(float2(1.0, 0.0), float2(1.0, 1.0)) ==
10cb93a386Sopenharmony_ci                 float2x2(float2(1.0, 0.0), float2(0.0, 1.0)));
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci    ok = ok &&  ( float2x2(1)  == float2x2(1));
13cb93a386Sopenharmony_ci    ok = ok && !( float2x2(1)  == float2x2(0));
14cb93a386Sopenharmony_ci    ok = ok &&  ( float2x2(-1) == -float2x2(1));
15cb93a386Sopenharmony_ci    ok = ok &&  ( float2x2(0)  == -float2x2(0));
16cb93a386Sopenharmony_ci    ok = ok &&  (-float2x2(-1) ==  float2x2(1));
17cb93a386Sopenharmony_ci    ok = ok &&  (-float2x2(0)  == -float2x2(-0));
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(1) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)));
20cb93a386Sopenharmony_ci    ok = ok && !(float2x2(2) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0)));
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_ci    ok = ok && !(float2x2(1) != float2x2(1));
23cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(1) != float2x2(0));
24cb93a386Sopenharmony_ci    ok = ok &&  (float3x3(float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), float3(0.0, 0.0, 1.0)) ==
25cb93a386Sopenharmony_ci                 float3x3(float2x2(1.0)));
26cb93a386Sopenharmony_ci    ok = ok &&  (float3x3(float3(9.0, 0.0, 0.0), float3(0.0, 9.0, 0.0), float3(0.0, 0.0, 1.0)) ==
27cb93a386Sopenharmony_ci                 float3x3(float2x2(9.0)));
28cb93a386Sopenharmony_ci    ok = ok &&  (float3x3(unknownInput) == float3x3(float2x2(1.0)));
29cb93a386Sopenharmony_ci    ok = ok &&  (float3x3(float3(9).x00, float3(9).0x0, float3(unknownInput).00x) ==
30cb93a386Sopenharmony_ci                 float3x3(float2x2(9.0)));
31cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(float3x3(1.0)) == float2x2(1.0));
32cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(float3x3(1.0)) == float2x2(1.0));
33cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(float4(1.0, 0.0, 0.0, 1.0)) == float2x2(1.0));
34cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(1.0, 0.0, float2(0.0, 1.0)) == float2x2(1.0));
35cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(float2(1.0, 0.0), 0.0, 1.0) == float2x2(1.0));
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_ci    ok = ok &&  (float4(testMatrix2x2) * float4(1)) == float4(1, 2, 3, 4);
38cb93a386Sopenharmony_ci    ok = ok &&  (float4(testMatrix2x2) * float4(1)) == float4(testMatrix2x2);
39cb93a386Sopenharmony_ci    ok = ok &&  (float4(testMatrix2x2) * float4(0)) == float4(0);
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[0] == float2(5.0, 0.0));
42cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[1] == float2(0.0, 5.0));
43cb93a386Sopenharmony_ci
44cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[0][0] == 5.0);
45cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[0][1] == 0.0);
46cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[1][0] == 0.0);
47cb93a386Sopenharmony_ci    ok = ok &&  (float2x2(5.0)[1][1] == 5.0);
48cb93a386Sopenharmony_ci
49cb93a386Sopenharmony_ci    const float3x3 m = float3x3(1, 2, 3, 4, 5, 6, 7, 8, 9);
50cb93a386Sopenharmony_ci    ok = ok &&  (m[0] == float3(1, 2, 3));
51cb93a386Sopenharmony_ci    ok = ok &&  (m[1] == float3(4, 5, 6));
52cb93a386Sopenharmony_ci    ok = ok &&  (m[2] == float3(7, 8, 9));
53cb93a386Sopenharmony_ci
54cb93a386Sopenharmony_ci    ok = ok &&  (m[0][0] == 1);
55cb93a386Sopenharmony_ci    ok = ok &&  (m[0][1] == 2);
56cb93a386Sopenharmony_ci    ok = ok &&  (m[0][2] == 3);
57cb93a386Sopenharmony_ci    ok = ok &&  (m[1][0] == 4);
58cb93a386Sopenharmony_ci    ok = ok &&  (m[1][1] == 5);
59cb93a386Sopenharmony_ci    ok = ok &&  (m[1][2] == 6);
60cb93a386Sopenharmony_ci    ok = ok &&  (m[2][0] == 7);
61cb93a386Sopenharmony_ci    ok = ok &&  (m[2][1] == 8);
62cb93a386Sopenharmony_ci    ok = ok &&  (m[2][2] == 9);
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ci    {
65cb93a386Sopenharmony_ci        // This `five` is constant and should always fold.
66cb93a386Sopenharmony_ci        const float five = 5.0;
67cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[0] == float2(five, 0.0));
68cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[1] == float2(0.0, five));
69cb93a386Sopenharmony_ci
70cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[0][0] == five);
71cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[0][1] == 0.0);
72cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[1][0] == 0.0);
73cb93a386Sopenharmony_ci        ok = ok &&  (float2x2(five)[1][1] == five);
74cb93a386Sopenharmony_ci
75cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[0] == float3(1, 2, 3));
76cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[1] == float3(4, five, 6));
77cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[2] == float3(7, 8, 9));
78cb93a386Sopenharmony_ci    }
79cb93a386Sopenharmony_ci    {
80cb93a386Sopenharmony_ci        // This `five` cannot be folded, but the first and third columns should still be foldable.
81cb93a386Sopenharmony_ci        float five = 5.0;
82cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[0] == float3(1, 2, 3));
83cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[1] == float3(4, five, 6));
84cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[2] == float3(7, 8, 9));
85cb93a386Sopenharmony_ci    }
86cb93a386Sopenharmony_ci    {
87cb93a386Sopenharmony_ci        // Side-effecting expressions should never be folded away.
88cb93a386Sopenharmony_ci        float num = 6.0;
89cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, 5, num++, 7, 8, 9)[0] == float3(1, 2, 3));
90cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, 5, 6, num++, 8, 9)[1] == float3(4, 5, 6));
91cb93a386Sopenharmony_ci        ok = ok &&  (float3x3(1, 2, 3, 4, 5, 6, 7, num++, 9)[2] == float3(7, 8, 9));
92cb93a386Sopenharmony_ci    }
93cb93a386Sopenharmony_ci    {
94cb93a386Sopenharmony_ci        // The upper-left 2x2 of the matrix is unknown, but the bottom two rows are still foldable.
95cb93a386Sopenharmony_ci        ok = ok && float4x4(half3x3(testMatrix2x2))[0] == float4(1, 2, 0, 0);
96cb93a386Sopenharmony_ci        ok = ok && float4x4(half3x3(testMatrix2x2))[1] == float4(3, 4, 0, 0);
97cb93a386Sopenharmony_ci        ok = ok && float4x4(half3x3(testMatrix2x2))[2] == float4(0, 0, 1, 0);
98cb93a386Sopenharmony_ci        ok = ok && float4x4(half3x3(testMatrix2x2))[3] == float4(0, 0, 0, 1);
99cb93a386Sopenharmony_ci    }
100cb93a386Sopenharmony_ci
101cb93a386Sopenharmony_ci    return ok;
102cb93a386Sopenharmony_ci}
103cb93a386Sopenharmony_ci
104cb93a386Sopenharmony_cihalf4 main(float2 coords) {
105cb93a386Sopenharmony_ci    return test() ? colorGreen : colorRed;
106cb93a386Sopenharmony_ci}
107