• 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 half3x3 left, const half3x3 right);
15thread bool operator!=(const half3x3 left, const half3x3 right);
16
17thread bool operator==(const half2x2 left, const half2x2 right);
18thread bool operator!=(const half2x2 left, const half2x2 right);
19
20thread bool operator==(const float3x3 left, const float3x3 right);
21thread bool operator!=(const float3x3 left, const float3x3 right);
22
23thread bool operator==(const float2x2 left, const float2x2 right);
24thread bool operator!=(const float2x2 left, const float2x2 right);
25thread bool operator==(const half3x3 left, const half3x3 right) {
26    return all(left[0] == right[0]) &&
27           all(left[1] == right[1]) &&
28           all(left[2] == right[2]);
29}
30thread bool operator!=(const half3x3 left, const half3x3 right) {
31    return !(left == right);
32}
33thread half3x3 operator/(const half3x3 left, const half3x3 right) {
34    return half3x3(left[0] / right[0], left[1] / right[1], left[2] / right[2]);
35}
36thread half3x3& operator/=(thread half3x3& left, thread const half3x3& right) {
37    left = left / right;
38    return left;
39}
40thread bool operator==(const half2x2 left, const half2x2 right) {
41    return all(left[0] == right[0]) &&
42           all(left[1] == right[1]);
43}
44thread bool operator!=(const half2x2 left, const half2x2 right) {
45    return !(left == right);
46}
47thread half2x2 operator/(const half2x2 left, const half2x2 right) {
48    return half2x2(left[0] / right[0], left[1] / right[1]);
49}
50thread half2x2& operator/=(thread half2x2& left, thread const half2x2& right) {
51    left = left / right;
52    return left;
53}
54thread bool operator==(const float3x3 left, const float3x3 right) {
55    return all(left[0] == right[0]) &&
56           all(left[1] == right[1]) &&
57           all(left[2] == right[2]);
58}
59thread bool operator!=(const float3x3 left, const float3x3 right) {
60    return !(left == right);
61}
62thread float3x3 operator/(const float3x3 left, const float3x3 right) {
63    return float3x3(left[0] / right[0], left[1] / right[1], left[2] / right[2]);
64}
65thread float3x3& operator/=(thread float3x3& left, thread const float3x3& right) {
66    left = left / right;
67    return left;
68}
69thread bool operator==(const float2x2 left, const float2x2 right) {
70    return all(left[0] == right[0]) &&
71           all(left[1] == right[1]);
72}
73thread bool operator!=(const float2x2 left, const float2x2 right) {
74    return !(left == right);
75}
76thread float2x2 operator/(const float2x2 left, const float2x2 right) {
77    return float2x2(left[0] / right[0], left[1] / right[1]);
78}
79thread float2x2& operator/=(thread float2x2& left, thread const float2x2& right) {
80    left = left / right;
81    return left;
82}
83bool test_half_b() {
84    bool ok = true;
85    ok = ok && half3x3(2.0h) + (half3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h) == half3x3(half3(6.0h, 4.0h, 4.0h), half3(4.0h, 6.0h, 4.0h), half3(4.0h, 4.0h, 6.0h));
86    ok = ok && half3x3(2.0h) - (half3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h) == half3x3(half3(-2.0h, -4.0h, -4.0h), half3(-4.0h, -2.0h, -4.0h), half3(-4.0h, -4.0h, -2.0h));
87    ok = ok && half3x3(2.0h) * 4.0h == half3x3(8.0h);
88    ok = ok && half3x3(2.0h) / (half3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h) == half3x3(0.5h);
89    ok = ok && (half3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h) + half3x3(2.0h) == half3x3(half3(6.0h, 4.0h, 4.0h), half3(4.0h, 6.0h, 4.0h), half3(4.0h, 4.0h, 6.0h));
90    ok = ok && (half3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h) - half3x3(2.0h) == half3x3(half3(2.0h, 4.0h, 4.0h), half3(4.0h, 2.0h, 4.0h), half3(4.0h, 4.0h, 2.0h));
91    ok = ok && 4.0h * half3x3(2.0h) == half3x3(8.0h);
92    ok = ok && (half2x2(1.0, 1.0, 1.0, 1.0) * 4.0h) / half2x2(half2(2.0h, 2.0h), half2(2.0h, 2.0h)) == half2x2(half2(2.0h, 2.0h), half2(2.0h, 2.0h));
93    return ok;
94}
95fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
96    Outputs _out;
97    (void)_out;
98    bool _0_ok = true;
99    _0_ok = _0_ok && float3x3(2.0) + (float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0) == float3x3(float3(6.0, 4.0, 4.0), float3(4.0, 6.0, 4.0), float3(4.0, 4.0, 6.0));
100    _0_ok = _0_ok && float3x3(2.0) - (float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0) == float3x3(float3(-2.0, -4.0, -4.0), float3(-4.0, -2.0, -4.0), float3(-4.0, -4.0, -2.0));
101    _0_ok = _0_ok && float3x3(2.0) * 4.0 == float3x3(8.0);
102    _0_ok = _0_ok && float3x3(2.0) / (float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0) == float3x3(0.5);
103    _0_ok = _0_ok && (float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0) + float3x3(2.0) == float3x3(float3(6.0, 4.0, 4.0), float3(4.0, 6.0, 4.0), float3(4.0, 4.0, 6.0));
104    _0_ok = _0_ok && (float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0) - float3x3(2.0) == float3x3(float3(2.0, 4.0, 4.0), float3(4.0, 2.0, 4.0), float3(4.0, 4.0, 2.0));
105    _0_ok = _0_ok && 4.0 * float3x3(2.0) == float3x3(8.0);
106    _0_ok = _0_ok && (float2x2(1.0, 1.0, 1.0, 1.0) * 4.0) / float2x2(float2(2.0, 2.0), float2(2.0, 2.0)) == float2x2(float2(2.0, 2.0), float2(2.0, 2.0));
107    _out.sk_FragColor = _0_ok && test_half_b() ? _uniforms.colorGreen : _uniforms.colorRed;
108    return _out;
109}
110