xref: /aosp_15_r20/external/skia/tests/sksl/shared/MatrixEquality.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    half2x2 testMatrix2x2;
11    half3x3 testMatrix3x3;
12};
13struct Inputs {
14};
15struct Outputs {
16    half4 sk_FragColor [[color(0)]];
17};
18
19thread bool operator==(const half2x2 left, const half2x2 right);
20thread bool operator!=(const half2x2 left, const half2x2 right);
21
22thread bool operator==(const half3x3 left, const half3x3 right);
23thread bool operator!=(const half3x3 left, const half3x3 right);
24
25thread bool operator==(const float2x2 left, const float2x2 right);
26thread bool operator!=(const float2x2 left, const float2x2 right);
27
28thread bool operator==(const float3x3 left, const float3x3 right);
29thread bool operator!=(const float3x3 left, const float3x3 right);
30thread bool operator==(const half2x2 left, const half2x2 right) {
31    return all(left[0] == right[0]) &&
32           all(left[1] == right[1]);
33}
34thread bool operator!=(const half2x2 left, const half2x2 right) {
35    return !(left == right);
36}
37thread bool operator==(const half3x3 left, const half3x3 right) {
38    return all(left[0] == right[0]) &&
39           all(left[1] == right[1]) &&
40           all(left[2] == right[2]);
41}
42thread bool operator!=(const half3x3 left, const half3x3 right) {
43    return !(left == right);
44}
45thread bool operator==(const float2x2 left, const float2x2 right) {
46    return all(left[0] == right[0]) &&
47           all(left[1] == right[1]);
48}
49thread bool operator!=(const float2x2 left, const float2x2 right) {
50    return !(left == right);
51}
52thread bool operator==(const float3x3 left, const float3x3 right) {
53    return all(left[0] == right[0]) &&
54           all(left[1] == right[1]) &&
55           all(left[2] == right[2]);
56}
57thread bool operator!=(const float3x3 left, const float3x3 right) {
58    return !(left == right);
59}
60float3x3 float3x3_from_float2x2(float2x2 x0) {
61    return float3x3(float3(x0[0].xy, 0.0), float3(x0[1].xy, 0.0), float3(0.0, 0.0, 1.0));
62}
63float2x2 float2x2_from_float3x3(float3x3 x0) {
64    return float2x2(float2(x0[0].xy), float2(x0[1].xy));
65}
66
67half4 half4_from_half2x2(half2x2 x) {
68    return half4(x[0].xy, x[1].xy);
69}
70fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
71    Outputs _out;
72    (void)_out;
73    bool _0_ok = true;
74    _0_ok = _0_ok && _uniforms.testMatrix2x2 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
75    _0_ok = _0_ok && _uniforms.testMatrix3x3 == half3x3(half3(1.0h, 2.0h, 3.0h), half3(4.0h, 5.0h, 6.0h), half3(7.0h, 8.0h, 9.0h));
76    _0_ok = _0_ok && _uniforms.testMatrix2x2 != half2x2(100.0h);
77    _0_ok = _0_ok && _uniforms.testMatrix3x3 != half3x3(half3(9.0h, 8.0h, 7.0h), half3(6.0h, 5.0h, 4.0h), half3(3.0h, 2.0h, 1.0h));
78    float _1_zero = float(_uniforms.colorGreen.x);
79    float _2_one = float(_uniforms.colorGreen.y);
80    float _3_two = 2.0 * _2_one;
81    float _4_nine = 9.0 * _2_one;
82    _0_ok = _0_ok && float2x2(float2(_2_one, _1_zero), float2(_1_zero, _2_one)) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0));
83    _0_ok = _0_ok && float2x2(float2(_2_one, _1_zero), float2(_2_one)) != float2x2(float2(1.0, 0.0), float2(0.0, 1.0));
84    _0_ok = _0_ok && float2x2(_2_one) == float2x2(1.0);
85    _0_ok = _0_ok && float2x2(_2_one) != float2x2(0.0);
86    _0_ok = _0_ok && float2x2(-_2_one) == float2x2(-1.0);
87    _0_ok = _0_ok && float2x2(_1_zero) == float2x2(-0.0);
88    _0_ok = _0_ok && (-1.0 * float2x2(-_2_one)) == float2x2(1.0);
89    _0_ok = _0_ok && (-1.0 * float2x2(_1_zero)) == float2x2(-0.0);
90    _0_ok = _0_ok && float2x2(_2_one) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0));
91    _0_ok = _0_ok && float2x2(_3_two) != float2x2(float2(1.0, 0.0), float2(0.0, 1.0));
92    _0_ok = _0_ok && float2x2(_2_one) == float2x2(1.0);
93    _0_ok = _0_ok && float2x2(_2_one) != float2x2(0.0);
94    _0_ok = _0_ok && float3x3(float3(_2_one, _1_zero, _1_zero), float3(_1_zero, _2_one, _1_zero), float3(_1_zero, _1_zero, _2_one)) == float3x3_from_float2x2(float2x2(1.0));
95    _0_ok = _0_ok && float3x3(float3(_4_nine, _1_zero, _1_zero), float3(_1_zero, _4_nine, _1_zero), float3(_1_zero, _1_zero, _2_one)) == float3x3_from_float2x2(float2x2(9.0));
96    _0_ok = _0_ok && float3x3(_2_one) == float3x3_from_float2x2(float2x2(1.0));
97    _0_ok = _0_ok && float3x3(float3(_4_nine, 0.0, 0.0), float3(0.0, _4_nine, 0.0), float3(0.0, 0.0, _2_one)) == float3x3_from_float2x2(float2x2(9.0));
98    _0_ok = _0_ok && float2x2_from_float3x3(float3x3(_2_one)) == float2x2(1.0);
99    _0_ok = _0_ok && float2x2_from_float3x3(float3x3(_2_one)) == float2x2(1.0);
100    _0_ok = _0_ok && float2x2(float2(_2_one, _1_zero), float2(_1_zero, _2_one)) == float2x2(1.0);
101    _0_ok = _0_ok && float2x2(float2(_2_one, _1_zero), float2(_1_zero, _2_one)) == float2x2(1.0);
102    _0_ok = _0_ok && float2x2(float2(_2_one, _1_zero), float2(_1_zero, _2_one)) == float2x2(1.0);
103    _0_ok = _0_ok && all(float4(half4_from_half2x2(_uniforms.testMatrix2x2)) * float4(_2_one) == float4(1.0, 2.0, 3.0, 4.0));
104    _0_ok = _0_ok && all(float4(half4_from_half2x2(_uniforms.testMatrix2x2)) * float4(_2_one) == float4(half4_from_half2x2(_uniforms.testMatrix2x2)));
105    _0_ok = _0_ok && all(float4(half4_from_half2x2(_uniforms.testMatrix2x2)) * float4(_1_zero) == float4(0.0));
106    float3x3 _5_m = float3x3(float3(_2_one, _3_two, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, _4_nine));
107    _0_ok = _0_ok && all(_5_m[0] == float3(1.0, 2.0, 3.0));
108    _0_ok = _0_ok && all(_5_m[1] == float3(4.0, 5.0, 6.0));
109    _0_ok = _0_ok && all(_5_m[2] == float3(7.0, 8.0, 9.0));
110    _0_ok = _0_ok && _5_m[0].x == 1.0;
111    _0_ok = _0_ok && _5_m[0].y == 2.0;
112    _0_ok = _0_ok && _5_m[0].z == 3.0;
113    _0_ok = _0_ok && _5_m[1].x == 4.0;
114    _0_ok = _0_ok && _5_m[1].y == 5.0;
115    _0_ok = _0_ok && _5_m[1].z == 6.0;
116    _0_ok = _0_ok && _5_m[2].x == 7.0;
117    _0_ok = _0_ok && _5_m[2].y == 8.0;
118    _0_ok = _0_ok && _5_m[2].z == 9.0;
119    _out.sk_FragColor = _0_ok ? _uniforms.colorGreen : _uniforms.colorRed;
120    return _out;
121}
122