xref: /aosp_15_r20/external/skia/tests/sksl/shared/MatricesNonsquare.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 colorGreen;
9    half4 colorRed;
10};
11struct Inputs {
12};
13struct Outputs {
14    half4 sk_FragColor [[color(0)]];
15};
16
17thread bool operator==(const half2x3 left, const half2x3 right);
18thread bool operator!=(const half2x3 left, const half2x3 right);
19
20thread bool operator==(const half2x4 left, const half2x4 right);
21thread bool operator!=(const half2x4 left, const half2x4 right);
22
23thread bool operator==(const half3x2 left, const half3x2 right);
24thread bool operator!=(const half3x2 left, const half3x2 right);
25
26thread bool operator==(const half3x4 left, const half3x4 right);
27thread bool operator!=(const half3x4 left, const half3x4 right);
28
29thread bool operator==(const half4x2 left, const half4x2 right);
30thread bool operator!=(const half4x2 left, const half4x2 right);
31
32thread bool operator==(const half4x3 left, const half4x3 right);
33thread bool operator!=(const half4x3 left, const half4x3 right);
34
35thread bool operator==(const half2x2 left, const half2x2 right);
36thread bool operator!=(const half2x2 left, const half2x2 right);
37
38thread bool operator==(const half3x3 left, const half3x3 right);
39thread bool operator!=(const half3x3 left, const half3x3 right);
40
41thread bool operator==(const float2x3 left, const float2x3 right);
42thread bool operator!=(const float2x3 left, const float2x3 right);
43
44thread bool operator==(const float2x4 left, const float2x4 right);
45thread bool operator!=(const float2x4 left, const float2x4 right);
46
47thread bool operator==(const float3x2 left, const float3x2 right);
48thread bool operator!=(const float3x2 left, const float3x2 right);
49
50thread bool operator==(const float2x2 left, const float2x2 right);
51thread bool operator!=(const float2x2 left, const float2x2 right);
52thread bool operator==(const half2x3 left, const half2x3 right) {
53    return all(left[0] == right[0]) &&
54           all(left[1] == right[1]);
55}
56thread bool operator!=(const half2x3 left, const half2x3 right) {
57    return !(left == right);
58}
59thread bool operator==(const half2x4 left, const half2x4 right) {
60    return all(left[0] == right[0]) &&
61           all(left[1] == right[1]);
62}
63thread bool operator!=(const half2x4 left, const half2x4 right) {
64    return !(left == right);
65}
66thread bool operator==(const half3x2 left, const half3x2 right) {
67    return all(left[0] == right[0]) &&
68           all(left[1] == right[1]) &&
69           all(left[2] == right[2]);
70}
71thread bool operator!=(const half3x2 left, const half3x2 right) {
72    return !(left == right);
73}
74thread bool operator==(const half3x4 left, const half3x4 right) {
75    return all(left[0] == right[0]) &&
76           all(left[1] == right[1]) &&
77           all(left[2] == right[2]);
78}
79thread bool operator!=(const half3x4 left, const half3x4 right) {
80    return !(left == right);
81}
82thread bool operator==(const half4x2 left, const half4x2 right) {
83    return all(left[0] == right[0]) &&
84           all(left[1] == right[1]) &&
85           all(left[2] == right[2]) &&
86           all(left[3] == right[3]);
87}
88thread bool operator!=(const half4x2 left, const half4x2 right) {
89    return !(left == right);
90}
91thread bool operator==(const half4x3 left, const half4x3 right) {
92    return all(left[0] == right[0]) &&
93           all(left[1] == right[1]) &&
94           all(left[2] == right[2]) &&
95           all(left[3] == right[3]);
96}
97thread bool operator!=(const half4x3 left, const half4x3 right) {
98    return !(left == right);
99}
100thread bool operator==(const half2x2 left, const half2x2 right) {
101    return all(left[0] == right[0]) &&
102           all(left[1] == right[1]);
103}
104thread bool operator!=(const half2x2 left, const half2x2 right) {
105    return !(left == right);
106}
107thread bool operator==(const half3x3 left, const half3x3 right) {
108    return all(left[0] == right[0]) &&
109           all(left[1] == right[1]) &&
110           all(left[2] == right[2]);
111}
112thread bool operator!=(const half3x3 left, const half3x3 right) {
113    return !(left == right);
114}
115thread bool operator==(const float2x3 left, const float2x3 right) {
116    return all(left[0] == right[0]) &&
117           all(left[1] == right[1]);
118}
119thread bool operator!=(const float2x3 left, const float2x3 right) {
120    return !(left == right);
121}
122thread bool operator==(const float2x4 left, const float2x4 right) {
123    return all(left[0] == right[0]) &&
124           all(left[1] == right[1]);
125}
126thread bool operator!=(const float2x4 left, const float2x4 right) {
127    return !(left == right);
128}
129thread bool operator==(const float3x2 left, const float3x2 right) {
130    return all(left[0] == right[0]) &&
131           all(left[1] == right[1]) &&
132           all(left[2] == right[2]);
133}
134thread bool operator!=(const float3x2 left, const float3x2 right) {
135    return !(left == right);
136}
137thread bool operator==(const float2x2 left, const float2x2 right) {
138    return all(left[0] == right[0]) &&
139           all(left[1] == right[1]);
140}
141thread bool operator!=(const float2x2 left, const float2x2 right) {
142    return !(left == right);
143}
144bool test_half_b() {
145    bool ok = true;
146    half2x3 m23 = half2x3(2.0h);
147    ok = ok && m23 == half2x3(half3(2.0h, 0.0h, 0.0h), half3(0.0h, 2.0h, 0.0h));
148    half2x4 m24 = half2x4(3.0h);
149    ok = ok && m24 == half2x4(half4(3.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 3.0h, 0.0h, 0.0h));
150    half3x2 m32 = half3x2(4.0h);
151    ok = ok && m32 == half3x2(half2(4.0h, 0.0h), half2(0.0h, 4.0h), half2(0.0h, 0.0h));
152    half3x4 m34 = half3x4(5.0h);
153    ok = ok && m34 == half3x4(half4(5.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 5.0h, 0.0h, 0.0h), half4(0.0h, 0.0h, 5.0h, 0.0h));
154    half4x2 m42 = half4x2(6.0h);
155    ok = ok && m42 == half4x2(half2(6.0h, 0.0h), half2(0.0h, 6.0h), half2(0.0h, 0.0h), half2(0.0h, 0.0h));
156    half4x3 m43 = half4x3(7.0h);
157    ok = ok && m43 == half4x3(half3(7.0h, 0.0h, 0.0h), half3(0.0h, 7.0h, 0.0h), half3(0.0h, 0.0h, 7.0h), half3(0.0h, 0.0h, 0.0h));
158    half2x2 m22 = m32 * m23;
159    ok = ok && m22 == half2x2(8.0h);
160    half3x3 m33 = m43 * m34;
161    ok = ok && m33 == half3x3(35.0h);
162    m23 += (half2x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 1.0h);
163    ok = ok && m23 == half2x3(half3(3.0h, 1.0h, 1.0h), half3(1.0h, 3.0h, 1.0h));
164    m32 -= (half3x2(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 2.0h);
165    ok = ok && m32 == half3x2(half2(2.0h, -2.0h), half2(-2.0h, 2.0h), half2(-2.0h, -2.0h));
166    m24 *= 0.25h;
167    ok = ok && m24 == half2x4(half4(0.75h, 0.0h, 0.0h, 0.0h), half4(0.0h, 0.75h, 0.0h, 0.0h));
168    return ok;
169}
170fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
171    Outputs _out;
172    (void)_out;
173    bool _0_ok = true;
174    float2x3 _1_m23 = float2x3(2.0);
175    _0_ok = _0_ok && _1_m23 == float2x3(float3(2.0, 0.0, 0.0), float3(0.0, 2.0, 0.0));
176    float2x4 _2_m24 = float2x4(3.0);
177    _0_ok = _0_ok && _2_m24 == float2x4(float4(3.0, 0.0, 0.0, 0.0), float4(0.0, 3.0, 0.0, 0.0));
178    float3x2 _3_m32 = float3x2(4.0);
179    _0_ok = _0_ok && _3_m32 == float3x2(float2(4.0, 0.0), float2(0.0, 4.0), float2(0.0, 0.0));
180    float2x2 _7_m22 = _3_m32 * _1_m23;
181    _0_ok = _0_ok && _7_m22 == float2x2(8.0);
182    _1_m23 += (float2x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 1.0);
183    _0_ok = _0_ok && _1_m23 == float2x3(float3(3.0, 1.0, 1.0), float3(1.0, 3.0, 1.0));
184    _3_m32 -= (float3x2(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 2.0);
185    _0_ok = _0_ok && _3_m32 == float3x2(float2(2.0, -2.0), float2(-2.0, 2.0), float2(-2.0, -2.0));
186    _2_m24 *= 0.25;
187    _0_ok = _0_ok && _2_m24 == float2x4(float4(0.75, 0.0, 0.0, 0.0), float4(0.0, 0.75, 0.0, 0.0));
188    _out.sk_FragColor = _0_ok && test_half_b() ? _uniforms.colorGreen : _uniforms.colorRed;
189    return _out;
190}
191