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}; 16thread bool operator==(const half2x2 left, const half2x2 right);thread bool operator!=(const half2x2 left, const half2x2 right);thread bool operator==(const half3x3 left, const half3x3 right);thread bool operator!=(const half3x3 left, const half3x3 right);thread bool operator==(const half4x4 left, const half4x4 right);thread bool operator!=(const half4x4 left, const half4x4 right);thread bool operator==(const float2x2 left, const float2x2 right);thread bool operator!=(const float2x2 left, const float2x2 right);thread bool operator==(const float4x4 left, const float4x4 right);thread bool operator!=(const float4x4 left, const float4x4 right);thread bool operator==(const half2x2 left, const half2x2 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const half2x2 left, const half2x2 right) {return !(left == right);}thread half2x2& operator*=(thread half2x2& left, thread const half2x2& right) { 17 left = left * right; 18 return left; 19} 20thread bool operator==(const half3x3 left, const half3x3 right) {return all(left[0] == right[0]) && all(left[1] == right[1]) && all(left[2] == right[2]);}thread bool operator!=(const half3x3 left, const half3x3 right) {return !(left == right);}thread bool operator==(const half4x4 left, const half4x4 right) {return all(left[0] == right[0]) && all(left[1] == right[1]) && all(left[2] == right[2]) && all(left[3] == right[3]);}thread bool operator!=(const half4x4 left, const half4x4 right) {return !(left == right);}thread bool operator==(const float2x2 left, const float2x2 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const float2x2 left, const float2x2 right) {return !(left == right);}thread float2x2& operator*=(thread float2x2& left, thread const float2x2& right) { 21 left = left * right; 22 return left; 23} 24thread bool operator==(const float4x4 left, const float4x4 right) {return all(left[0] == right[0]) && all(left[1] == right[1]) && all(left[2] == right[2]) && all(left[3] == right[3]);}thread bool operator!=(const float4x4 left, const float4x4 right) {return !(left == right);}bool test_half_b() { 25 bool ok = true; 26 half2x2 m1 = half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h)); 27 ok = ok && m1 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h)); 28 half2x2 m3 = m1; 29 ok = ok && m3 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h)); 30 half2x2 m4 = half2x2(6.0h); 31 ok = ok && m4 == half2x2(half2(6.0h, 0.0h), half2(0.0h, 6.0h)); 32 m3 *= m4; 33 ok = ok && m3 == half2x2(half2(6.0h, 12.0h), half2(18.0h, 24.0h)); 34 half2x2 m5 = half2x2(m1[1].y); 35 ok = ok && m5 == half2x2(half2(4.0h, 0.0h), half2(0.0h, 4.0h)); 36 m1 += m5; 37 ok = ok && m1 == half2x2(half2(5.0h, 2.0h), half2(3.0h, 8.0h)); 38 half2x2 m7 = half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h)); 39 ok = ok && m7 == half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h)); 40 half3x3 m9 = half3x3(9.0h); 41 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)); 42 half4x4 m10 = half4x4(11.0h); 43 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)); 44 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)); 45 m11 -= m10; 46 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)); 47 return ok; 48} 49bool test_comma_b() { 50 float2x2 x; 51 float2x2 y; 52 return ((x = float2x2(float2(1.0, 2.0), float2(3.0, 4.0)), y = float2x2(float2(1.0, 2.0), float2(3.0, 4.0))), x == y); 53} 54fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 55 Outputs _out; 56 (void)_out; 57 bool _0_ok = true; 58 float2x2 _1_m1 = float2x2(float2(1.0, 2.0), float2(3.0, 4.0)); 59 _0_ok = _0_ok && _1_m1 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0)); 60 float2x2 _2_m3 = _1_m1; 61 _0_ok = _0_ok && _2_m3 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0)); 62 const float2x2 _3_m4 = float2x2(6.0); 63 _2_m3 *= _3_m4; 64 _0_ok = _0_ok && _2_m3 == float2x2(float2(6.0, 12.0), float2(18.0, 24.0)); 65 float2x2 _4_m5 = float2x2(_1_m1[1].y); 66 _0_ok = _0_ok && _4_m5 == float2x2(float2(4.0, 0.0), float2(0.0, 4.0)); 67 _1_m1 += _4_m5; 68 _0_ok = _0_ok && _1_m1 == float2x2(float2(5.0, 2.0), float2(3.0, 8.0)); 69 const float4x4 _7_m10 = float4x4(11.0); 70 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)); 71 _8_m11 -= _7_m10; 72 _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)); 73 _out.sk_FragColor = (_0_ok && test_half_b()) && test_comma_b() ? _uniforms.colorGreen : _uniforms.colorRed; 74 return _out; 75} 76