• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#include <metal_stdlib>
2#include <simd/simd.h>
3using namespace metal;
4struct Uniforms {
5    half4 colorGreen;
6    half4 colorRed;
7};
8struct Inputs {
9};
10struct Outputs {
11    half4 sk_FragColor [[color(0)]];
12};
13
14thread bool operator==(const half2x2 left, const half2x2 right);
15thread bool operator!=(const half2x2 left, const half2x2 right);
16
17thread bool operator==(const half3x3 left, const half3x3 right);
18thread bool operator!=(const half3x3 left, const half3x3 right);
19
20thread bool operator==(const half4x4 left, const half4x4 right);
21thread bool operator!=(const half4x4 left, const half4x4 right);
22
23thread bool operator==(const float2x2 left, const float2x2 right);
24thread bool operator!=(const float2x2 left, const float2x2 right);
25
26thread bool operator==(const float3x3 left, const float3x3 right);
27thread bool operator!=(const float3x3 left, const float3x3 right);
28
29thread bool operator==(const float4x4 left, const float4x4 right);
30thread bool operator!=(const float4x4 left, const float4x4 right);
31thread bool operator==(const half2x2 left, const half2x2 right) {
32    return all(left[0] == right[0]) &&
33           all(left[1] == right[1]);
34}
35thread bool operator!=(const half2x2 left, const half2x2 right) {
36    return !(left == right);
37}
38thread half2x2& operator*=(thread half2x2& left, thread const half2x2& right) {
39    left = left * right;
40    return left;
41}
42thread bool operator==(const half3x3 left, const half3x3 right) {
43    return all(left[0] == right[0]) &&
44           all(left[1] == right[1]) &&
45           all(left[2] == right[2]);
46}
47thread bool operator!=(const half3x3 left, const half3x3 right) {
48    return !(left == right);
49}
50thread bool operator==(const half4x4 left, const half4x4 right) {
51    return all(left[0] == right[0]) &&
52           all(left[1] == right[1]) &&
53           all(left[2] == right[2]) &&
54           all(left[3] == right[3]);
55}
56thread bool operator!=(const half4x4 left, const half4x4 right) {
57    return !(left == right);
58}
59thread bool operator==(const float2x2 left, const float2x2 right) {
60    return all(left[0] == right[0]) &&
61           all(left[1] == right[1]);
62}
63thread bool operator!=(const float2x2 left, const float2x2 right) {
64    return !(left == right);
65}
66thread float2x2& operator*=(thread float2x2& left, thread const float2x2& right) {
67    left = left * right;
68    return left;
69}
70thread bool operator==(const float3x3 left, const float3x3 right) {
71    return all(left[0] == right[0]) &&
72           all(left[1] == right[1]) &&
73           all(left[2] == right[2]);
74}
75thread bool operator!=(const float3x3 left, const float3x3 right) {
76    return !(left == right);
77}
78thread bool operator==(const float4x4 left, const float4x4 right) {
79    return all(left[0] == right[0]) &&
80           all(left[1] == right[1]) &&
81           all(left[2] == right[2]) &&
82           all(left[3] == right[3]);
83}
84thread bool operator!=(const float4x4 left, const float4x4 right) {
85    return !(left == right);
86}
87bool test_half_b() {
88    bool ok = true;
89    half2x2 m1 = half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
90    ok = ok && m1 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
91    half2x2 m3 = m1;
92    ok = ok && m3 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
93    half2x2 m4 = half2x2(6.0h);
94    ok = ok && m4 == half2x2(half2(6.0h, 0.0h), half2(0.0h, 6.0h));
95    m3 *= m4;
96    ok = ok && m3 == half2x2(half2(6.0h, 12.0h), half2(18.0h, 24.0h));
97    half2x2 m5 = half2x2(m1[1].y);
98    ok = ok && m5 == half2x2(half2(4.0h, 0.0h), half2(0.0h, 4.0h));
99    m1 += m5;
100    ok = ok && m1 == half2x2(half2(5.0h, 2.0h), half2(3.0h, 8.0h));
101    half2x2 m7 = half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h));
102    ok = ok && m7 == half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h));
103    half3x3 m9 = half3x3(9.0h);
104    ok = ok && m9 == half3x3(half3(9.0h, 0.0h, 0.0h), half3(0.0h, 9.0h, 0.0h), half3(0.0h, 0.0h, 9.0h));
105    half4x4 m10 = half4x4(11.0h);
106    ok = ok && m10 == half4x4(half4(11.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 11.0h, 0.0h, 0.0h), half4(0.0h, 0.0h, 11.0h, 0.0h), half4(0.0h, 0.0h, 0.0h, 11.0h));
107    half4x4 m11 = half4x4(half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h));
108    m11 -= m10;
109    ok = ok && m11 == half4x4(half4(9.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 9.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 9.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 9.0h));
110    return ok;
111}
112bool test_comma_b() {
113    float2x2 x;
114    float2x2 y;
115    return ((x = float2x2(float2(1.0, 2.0), float2(3.0, 4.0)) , y = 0.5 * float2x2(float2(2.0, 4.0), float2(6.0, 8.0))) , x == y);
116}
117fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
118    Outputs _out;
119    (void)_out;
120    bool _0_ok = true;
121    float2x2 _1_m1 = float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
122    _0_ok = _0_ok && _1_m1 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
123    float2x2 _2_m3 = _1_m1;
124    _0_ok = _0_ok && _2_m3 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
125    float2x2 _3_m4 = float2x2(6.0);
126    _0_ok = _0_ok && _3_m4 == float2x2(float2(6.0, 0.0), float2(0.0, 6.0));
127    _2_m3 *= _3_m4;
128    _0_ok = _0_ok && _2_m3 == float2x2(float2(6.0, 12.0), float2(18.0, 24.0));
129    float2x2 _4_m5 = float2x2(_1_m1[1].y);
130    _0_ok = _0_ok && _4_m5 == float2x2(float2(4.0, 0.0), float2(0.0, 4.0));
131    _1_m1 += _4_m5;
132    _0_ok = _0_ok && _1_m1 == float2x2(float2(5.0, 2.0), float2(3.0, 8.0));
133    float2x2 _5_m7 = float2x2(float2(5.0, 6.0), float2(7.0, 8.0));
134    _0_ok = _0_ok && _5_m7 == float2x2(float2(5.0, 6.0), float2(7.0, 8.0));
135    float3x3 _6_m9 = float3x3(9.0);
136    _0_ok = _0_ok && _6_m9 == float3x3(float3(9.0, 0.0, 0.0), float3(0.0, 9.0, 0.0), float3(0.0, 0.0, 9.0));
137    float4x4 _7_m10 = float4x4(11.0);
138    _0_ok = _0_ok && _7_m10 == float4x4(float4(11.0, 0.0, 0.0, 0.0), float4(0.0, 11.0, 0.0, 0.0), float4(0.0, 0.0, 11.0, 0.0), float4(0.0, 0.0, 0.0, 11.0));
139    float4x4 _8_m11 = float4x4(float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0));
140    _8_m11 -= _7_m10;
141    _0_ok = _0_ok && _8_m11 == float4x4(float4(9.0, 20.0, 20.0, 20.0), float4(20.0, 9.0, 20.0, 20.0), float4(20.0, 20.0, 9.0, 20.0), float4(20.0, 20.0, 20.0, 9.0));
142    _out.sk_FragColor = (_0_ok && test_half_b()) && test_comma_b() ? _uniforms.colorGreen : _uniforms.colorRed;
143    return _out;
144}
145