xref: /aosp_15_r20/external/skia/tests/sksl/shared/MatrixOpEqualsES3.metal (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1#include <metal_stdlib>
2#include <simd/simd.h>
3#ifdef __clang__
4#pragma clang diagnostic ignored "-Wall"
5#endif
6using namespace metal;
7struct Uniforms {
8    half4 colorRed;
9    half4 colorGreen;
10};
11struct Inputs {
12};
13struct Outputs {
14    half4 sk_FragColor [[color(0)]];
15};
16
17thread bool operator==(const half3x2 left, const half3x2 right);
18thread bool operator!=(const half3x2 left, const half3x2 right);
19
20thread bool operator==(const half2x3 left, const half2x3 right);
21thread bool operator!=(const half2x3 left, const half2x3 right);
22
23thread bool operator==(const half4x3 left, const half4x3 right);
24thread bool operator!=(const half4x3 left, const half4x3 right);
25
26thread bool operator==(const half4x2 left, const half4x2 right);
27thread bool operator!=(const half4x2 left, const half4x2 right);
28
29thread bool operator==(const half2x4 left, const half2x4 right);
30thread bool operator!=(const half2x4 left, const half2x4 right);
31
32thread bool operator==(const float3x2 left, const float3x2 right);
33thread bool operator!=(const float3x2 left, const float3x2 right);
34
35thread bool operator==(const float2x3 left, const float2x3 right);
36thread bool operator!=(const float2x3 left, const float2x3 right);
37
38thread bool operator==(const float4x3 left, const float4x3 right);
39thread bool operator!=(const float4x3 left, const float4x3 right);
40
41thread bool operator==(const float4x2 left, const float4x2 right);
42thread bool operator!=(const float4x2 left, const float4x2 right);
43
44thread bool operator==(const float2x4 left, const float2x4 right);
45thread bool operator!=(const float2x4 left, const float2x4 right);
46thread bool operator==(const half3x2 left, const half3x2 right) {
47    return all(left[0] == right[0]) &&
48           all(left[1] == right[1]) &&
49           all(left[2] == right[2]);
50}
51thread bool operator!=(const half3x2 left, const half3x2 right) {
52    return !(left == right);
53}
54thread half3x2 operator/(const half3x2 left, const half3x2 right) {
55    return half3x2(left[0] / right[0], left[1] / right[1], left[2] / right[2]);
56}
57thread half3x2& operator/=(thread half3x2& left, thread const half3x2& right) {
58    left = left / right;
59    return left;
60}
61thread bool operator==(const half2x3 left, const half2x3 right) {
62    return all(left[0] == right[0]) &&
63           all(left[1] == right[1]);
64}
65thread bool operator!=(const half2x3 left, const half2x3 right) {
66    return !(left == right);
67}
68thread half2x3 operator/(const half2x3 left, const half2x3 right) {
69    return half2x3(left[0] / right[0], left[1] / right[1]);
70}
71thread half2x3& operator/=(thread half2x3& left, thread const half2x3& right) {
72    left = left / right;
73    return left;
74}
75thread bool operator==(const half4x3 left, const half4x3 right) {
76    return all(left[0] == right[0]) &&
77           all(left[1] == right[1]) &&
78           all(left[2] == right[2]) &&
79           all(left[3] == right[3]);
80}
81thread bool operator!=(const half4x3 left, const half4x3 right) {
82    return !(left == right);
83}
84thread bool operator==(const half4x2 left, const half4x2 right) {
85    return all(left[0] == right[0]) &&
86           all(left[1] == right[1]) &&
87           all(left[2] == right[2]) &&
88           all(left[3] == right[3]);
89}
90thread bool operator!=(const half4x2 left, const half4x2 right) {
91    return !(left == right);
92}
93thread half2x4 operator/(const half2x4 left, const half2x4 right) {
94    return half2x4(left[0] / right[0], left[1] / right[1]);
95}
96thread half2x4& operator/=(thread half2x4& left, thread const half2x4& right) {
97    left = left / right;
98    return left;
99}
100thread bool operator==(const half2x4 left, const half2x4 right) {
101    return all(left[0] == right[0]) &&
102           all(left[1] == right[1]);
103}
104thread bool operator!=(const half2x4 left, const half2x4 right) {
105    return !(left == right);
106}
107thread half2x3& operator*=(thread half2x3& left, thread const half2x2& right) {
108    left = left * right;
109    return left;
110}
111thread bool operator==(const float3x2 left, const float3x2 right) {
112    return all(left[0] == right[0]) &&
113           all(left[1] == right[1]) &&
114           all(left[2] == right[2]);
115}
116thread bool operator!=(const float3x2 left, const float3x2 right) {
117    return !(left == right);
118}
119thread float3x2 operator/(const float3x2 left, const float3x2 right) {
120    return float3x2(left[0] / right[0], left[1] / right[1], left[2] / right[2]);
121}
122thread float3x2& operator/=(thread float3x2& left, thread const float3x2& right) {
123    left = left / right;
124    return left;
125}
126thread bool operator==(const float2x3 left, const float2x3 right) {
127    return all(left[0] == right[0]) &&
128           all(left[1] == right[1]);
129}
130thread bool operator!=(const float2x3 left, const float2x3 right) {
131    return !(left == right);
132}
133thread float2x3 operator/(const float2x3 left, const float2x3 right) {
134    return float2x3(left[0] / right[0], left[1] / right[1]);
135}
136thread float2x3& operator/=(thread float2x3& left, thread const float2x3& right) {
137    left = left / right;
138    return left;
139}
140thread bool operator==(const float4x3 left, const float4x3 right) {
141    return all(left[0] == right[0]) &&
142           all(left[1] == right[1]) &&
143           all(left[2] == right[2]) &&
144           all(left[3] == right[3]);
145}
146thread bool operator!=(const float4x3 left, const float4x3 right) {
147    return !(left == right);
148}
149thread bool operator==(const float4x2 left, const float4x2 right) {
150    return all(left[0] == right[0]) &&
151           all(left[1] == right[1]) &&
152           all(left[2] == right[2]) &&
153           all(left[3] == right[3]);
154}
155thread bool operator!=(const float4x2 left, const float4x2 right) {
156    return !(left == right);
157}
158thread float2x4 operator/(const float2x4 left, const float2x4 right) {
159    return float2x4(left[0] / right[0], left[1] / right[1]);
160}
161thread float2x4& operator/=(thread float2x4& left, thread const float2x4& right) {
162    left = left / right;
163    return left;
164}
165thread bool operator==(const float2x4 left, const float2x4 right) {
166    return all(left[0] == right[0]) &&
167           all(left[1] == right[1]);
168}
169thread bool operator!=(const float2x4 left, const float2x4 right) {
170    return !(left == right);
171}
172thread float2x3& operator*=(thread float2x3& left, thread const float2x2& right) {
173    left = left * right;
174    return left;
175}
176bool test_matrix_op_matrix_half_b() {
177    bool ok = true;
178    {
179        const half3x2 splat_4 = half3x2(half2(4.0h, 4.0h), half2(4.0h, 4.0h), half2(4.0h, 4.0h));
180        half3x2 m = half3x2(2.0h);
181        m += splat_4;
182        ok = ok && m == half3x2(half2(6.0h, 4.0h), half2(4.0h, 6.0h), half2(4.0h, 4.0h));
183        m = half3x2(2.0h);
184        m -= splat_4;
185        ok = ok && m == half3x2(half2(-2.0h, -4.0h), half2(-4.0h, -2.0h), half2(-4.0h, -4.0h));
186        m = half3x2(2.0h);
187        m /= splat_4;
188        ok = ok && m == half3x2(0.5h);
189    }
190    {
191        const half2x3 splat_4 = half2x3(half3(4.0h, 4.0h, 4.0h), half3(4.0h, 4.0h, 4.0h));
192        half2x3 m = splat_4;
193        m += half2x3(2.0h);
194        ok = ok && m == half2x3(half3(6.0h, 4.0h, 4.0h), half3(4.0h, 6.0h, 4.0h));
195        m = splat_4;
196        m -= half2x3(2.0h);
197        ok = ok && m == half2x3(half3(2.0h, 4.0h, 4.0h), half3(4.0h, 2.0h, 4.0h));
198        m = splat_4;
199        m /= half2x3(half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h));
200        ok = ok && m == half2x3(half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h));
201    }
202    {
203        half4x3 m = half4x3(half3(1.0h, 2.0h, 3.0h), half3(4.0h, 5.0h, 6.0h), half3(7.0h, 8.0h, 9.0h), half3(10.0h, 11.0h, 12.0h));
204        m += half4x3(half3(16.0h, 15.0h, 14.0h), half3(13.0h, 12.0h, 11.0h), half3(10.0h, 9.0h, 8.0h), half3(7.0h, 6.0h, 5.0h));
205        ok = ok && m == half4x3(half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h));
206    }
207    {
208        half4x2 m = half4x2(half2(10.0h, 20.0h), half2(30.0h, 40.0h), half2(50.0h, 60.0h), half2(70.0h, 80.0h));
209        m -= half4x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h), half2(5.0h, 6.0h), half2(7.0h, 8.0h));
210        ok = ok && m == half4x2(half2(9.0h, 18.0h), half2(27.0h, 36.0h), half2(45.0h, 54.0h), half2(63.0h, 72.0h));
211    }
212    {
213        half2x4 m = half2x4(half4(10.0h, 20.0h, 30.0h, 40.0h), half4(10.0h, 20.0h, 30.0h, 40.0h));
214        m /= half2x4(half4(10.0h, 10.0h, 10.0h, 10.0h), half4(5.0h, 5.0h, 5.0h, 5.0h));
215        ok = ok && m == half2x4(half4(1.0h, 2.0h, 3.0h, 4.0h), half4(2.0h, 4.0h, 6.0h, 8.0h));
216    }
217    {
218        half2x3 m = half2x3(half3(7.0h, 9.0h, 11.0h), half3(8.0h, 10.0h, 12.0h));
219        m *= half2x2(half2(1.0h, 4.0h), half2(2.0h, 5.0h));
220        ok = ok && m == half2x3(half3(39.0h, 49.0h, 59.0h), half3(54.0h, 68.0h, 82.0h));
221    }
222    return ok;
223}
224fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
225    Outputs _out;
226    (void)_out;
227    bool _0_ok = true;
228    {
229        const float3x2 _1_splat_4 = float3x2(float2(4.0, 4.0), float2(4.0, 4.0), float2(4.0, 4.0));
230        float3x2 _2_m = float3x2(2.0);
231        _2_m += _1_splat_4;
232        _0_ok = _0_ok && _2_m == float3x2(float2(6.0, 4.0), float2(4.0, 6.0), float2(4.0, 4.0));
233        _2_m = float3x2(2.0);
234        _2_m -= _1_splat_4;
235        _0_ok = _0_ok && _2_m == float3x2(float2(-2.0, -4.0), float2(-4.0, -2.0), float2(-4.0, -4.0));
236        _2_m = float3x2(2.0);
237        _2_m /= _1_splat_4;
238        _0_ok = _0_ok && _2_m == float3x2(0.5);
239    }
240    {
241        const float2x3 _3_splat_4 = float2x3(float3(4.0, 4.0, 4.0), float3(4.0, 4.0, 4.0));
242        float2x3 _4_m = _3_splat_4;
243        _4_m += float2x3(2.0);
244        _0_ok = _0_ok && _4_m == float2x3(float3(6.0, 4.0, 4.0), float3(4.0, 6.0, 4.0));
245        _4_m = _3_splat_4;
246        _4_m -= float2x3(2.0);
247        _0_ok = _0_ok && _4_m == float2x3(float3(2.0, 4.0, 4.0), float3(4.0, 2.0, 4.0));
248        _4_m = _3_splat_4;
249        _4_m /= float2x3(float3(2.0, 2.0, 2.0), float3(2.0, 2.0, 2.0));
250        _0_ok = _0_ok && _4_m == float2x3(float3(2.0, 2.0, 2.0), float3(2.0, 2.0, 2.0));
251    }
252    {
253        float4x3 _5_m = float4x3(float3(1.0, 2.0, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, 9.0), float3(10.0, 11.0, 12.0));
254        _5_m += float4x3(float3(16.0, 15.0, 14.0), float3(13.0, 12.0, 11.0), float3(10.0, 9.0, 8.0), float3(7.0, 6.0, 5.0));
255        _0_ok = _0_ok && _5_m == float4x3(float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0));
256    }
257    {
258        float4x2 _6_m = float4x2(float2(10.0, 20.0), float2(30.0, 40.0), float2(50.0, 60.0), float2(70.0, 80.0));
259        _6_m -= float4x2(float2(1.0, 2.0), float2(3.0, 4.0), float2(5.0, 6.0), float2(7.0, 8.0));
260        _0_ok = _0_ok && _6_m == float4x2(float2(9.0, 18.0), float2(27.0, 36.0), float2(45.0, 54.0), float2(63.0, 72.0));
261    }
262    {
263        float2x4 _7_m = float2x4(float4(10.0, 20.0, 30.0, 40.0), float4(10.0, 20.0, 30.0, 40.0));
264        _7_m /= float2x4(float4(10.0, 10.0, 10.0, 10.0), float4(5.0, 5.0, 5.0, 5.0));
265        _0_ok = _0_ok && _7_m == float2x4(float4(1.0, 2.0, 3.0, 4.0), float4(2.0, 4.0, 6.0, 8.0));
266    }
267    {
268        float2x3 _8_m = float2x3(float3(7.0, 9.0, 11.0), float3(8.0, 10.0, 12.0));
269        _8_m *= float2x2(float2(1.0, 4.0), float2(2.0, 5.0));
270        _0_ok = _0_ok && _8_m == float2x3(float3(39.0, 49.0, 59.0), float3(54.0, 68.0, 82.0));
271    }
272    _out.sk_FragColor = _0_ok && test_matrix_op_matrix_half_b() ? _uniforms.colorGreen : _uniforms.colorRed;
273    return _out;
274}
275