xref: /aosp_15_r20/external/skia/tests/sksl/shared/MatrixConstructorsES3.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    float2x2 testMatrix2x2;
11};
12struct Inputs {
13};
14struct Outputs {
15    half4 sk_FragColor [[color(0)]];
16};
17
18thread bool operator==(const float2x3 left, const float2x3 right);
19thread bool operator!=(const float2x3 left, const float2x3 right);
20
21thread bool operator==(const float2x4 left, const float2x4 right);
22thread bool operator!=(const float2x4 left, const float2x4 right);
23
24thread bool operator==(const float3x3 left, const float3x3 right);
25thread bool operator!=(const float3x3 left, const float3x3 right);
26
27thread bool operator==(const float4x2 left, const float4x2 right);
28thread bool operator!=(const float4x2 left, const float4x2 right);
29
30thread bool operator==(const float4x3 left, const float4x3 right);
31thread bool operator!=(const float4x3 left, const float4x3 right);
32
33float4 float4_from_float2x2(float2x2 x) {
34    return float4(x[0].xy, x[1].xy);
35}
36thread bool operator==(const float2x3 left, const float2x3 right) {
37    return all(left[0] == right[0]) &&
38           all(left[1] == right[1]);
39}
40thread bool operator!=(const float2x3 left, const float2x3 right) {
41    return !(left == right);
42}
43float2x3 float2x3_from_float4_float2(float4 x0, float2 x1) {
44    return float2x3(float3(x0.xyz), float3(x0.w, x1.xy));
45}
46thread bool operator==(const float2x4 left, const float2x4 right) {
47    return all(left[0] == right[0]) &&
48           all(left[1] == right[1]);
49}
50thread bool operator!=(const float2x4 left, const float2x4 right) {
51    return !(left == right);
52}
53float2x4 float2x4_from_float3_float4_float(float3 x0, float4 x1, float x2) {
54    return float2x4(float4(x0.xyz, x1.x), float4(x1.yzw, x2));
55}
56thread bool operator==(const float3x3 left, const float3x3 right) {
57    return all(left[0] == right[0]) &&
58           all(left[1] == right[1]) &&
59           all(left[2] == right[2]);
60}
61thread bool operator!=(const float3x3 left, const float3x3 right) {
62    return !(left == right);
63}
64float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) {
65    return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3));
66}
67thread bool operator==(const float4x2 left, const float4x2 right) {
68    return all(left[0] == right[0]) &&
69           all(left[1] == right[1]) &&
70           all(left[2] == right[2]) &&
71           all(left[3] == right[3]);
72}
73thread bool operator!=(const float4x2 left, const float4x2 right) {
74    return !(left == right);
75}
76float4x2 float4x2_from_float3_float4_float(float3 x0, float4 x1, float x2) {
77    return float4x2(float2(x0.xy), float2(x0.z, x1.x), float2(x1.yz), float2(x1.w, x2));
78}
79thread bool operator==(const float4x3 left, const float4x3 right) {
80    return all(left[0] == right[0]) &&
81           all(left[1] == right[1]) &&
82           all(left[2] == right[2]) &&
83           all(left[3] == right[3]);
84}
85thread bool operator!=(const float4x3 left, const float4x3 right) {
86    return !(left == right);
87}
88float4x3 float4x3_from_float_float4_float4_float3(float x0, float4 x1, float4 x2, float3 x3) {
89    return float4x3(float3(x0, x1.xy), float3(x1.zw, x2.x), float3(x2.yzw), float3(x3.xyz));
90}
91fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
92    Outputs _out;
93    (void)_out;
94    float4 f4 = float4_from_float2x2(_uniforms.testMatrix2x2);
95    bool ok = float2x3_from_float4_float2(f4, f4.xy) == float2x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0));
96    ok = ok && float2x4_from_float3_float4_float(f4.xyz, f4.wxyz, f4.w) == float2x4(float4(1.0, 2.0, 3.0, 4.0), float4(1.0, 2.0, 3.0, 4.0));
97    ok = ok && float3x3_from_float2_float2_float4_float(f4.xy, f4.zw, f4, f4.x) == float3x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0), float3(3.0, 4.0, 1.0));
98    ok = ok && float4x2_from_float3_float4_float(f4.xyz, f4.wxyz, f4.w) == float4x2(float2(1.0, 2.0), float2(3.0, 4.0), float2(1.0, 2.0), float2(3.0, 4.0));
99    ok = ok && float4x3_from_float_float4_float4_float3(f4.x, f4.yzwx, f4.yzwx, f4.yzw) == float4x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0), float3(3.0, 4.0, 1.0), float3(2.0, 3.0, 4.0));
100    _out.sk_FragColor = ok ? _uniforms.colorGreen : _uniforms.colorRed;
101    return _out;
102}
103