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 colorRed; 9 half4 colorGreen; 10}; 11struct Inputs { 12}; 13struct Outputs { 14 half4 sk_FragColor [[color(0)]]; 15}; 16thread bool operator==(const half3x2 left, const half3x2 right);thread bool operator!=(const half3x2 left, const half3x2 right);thread bool operator==(const half2x3 left, const half2x3 right);thread bool operator!=(const half2x3 left, const half2x3 right);thread bool operator==(const half4x3 left, const half4x3 right);thread bool operator!=(const half4x3 left, const half4x3 right);thread bool operator==(const half4x2 left, const half4x2 right);thread bool operator!=(const half4x2 left, const half4x2 right);thread bool operator==(const half2x4 left, const half2x4 right);thread bool operator!=(const half2x4 left, const half2x4 right);thread bool operator==(const float3x2 left, const float3x2 right);thread bool operator!=(const float3x2 left, const float3x2 right);thread bool operator==(const float2x3 left, const float2x3 right);thread bool operator!=(const float2x3 left, const float2x3 right);thread bool operator==(const float4x3 left, const float4x3 right);thread bool operator!=(const float4x3 left, const float4x3 right);thread bool operator==(const float4x2 left, const float4x2 right);thread bool operator!=(const float4x2 left, const float4x2 right);thread bool operator==(const float2x4 left, const float2x4 right);thread bool operator!=(const float2x4 left, const float2x4 right);thread bool operator==(const half3x2 left, const half3x2 right) {return all(left[0] == right[0]) && all(left[1] == right[1]) && all(left[2] == right[2]);}thread bool operator!=(const half3x2 left, const half3x2 right) {return !(left == right);}thread half3x2 operator/(const half3x2 left, const half3x2 right) { 17 return half3x2(left[0] / right[0], left[1] / right[1], left[2] / right[2]); 18} 19thread half3x2& operator/=(thread half3x2& left, thread const half3x2& right) { 20 left = left / right; 21 return left; 22} 23thread bool operator==(const half2x3 left, const half2x3 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const half2x3 left, const half2x3 right) {return !(left == right);}thread half2x3 operator/(const half2x3 left, const half2x3 right) { 24 return half2x3(left[0] / right[0], left[1] / right[1]); 25} 26thread half2x3& operator/=(thread half2x3& left, thread const half2x3& right) { 27 left = left / right; 28 return left; 29} 30thread bool operator==(const half4x3 left, const half4x3 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 half4x3 left, const half4x3 right) {return !(left == right);}thread bool operator==(const half4x2 left, const half4x2 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 half4x2 left, const half4x2 right) {return !(left == right);}thread half2x4 operator/(const half2x4 left, const half2x4 right) { 31 return half2x4(left[0] / right[0], left[1] / right[1]); 32} 33thread half2x4& operator/=(thread half2x4& left, thread const half2x4& right) { 34 left = left / right; 35 return left; 36} 37thread bool operator==(const half2x4 left, const half2x4 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const half2x4 left, const half2x4 right) {return !(left == right);}thread half2x3& operator*=(thread half2x3& left, thread const half2x2& right) { 38 left = left * right; 39 return left; 40} 41thread bool operator==(const float3x2 left, const float3x2 right) {return all(left[0] == right[0]) && all(left[1] == right[1]) && all(left[2] == right[2]);}thread bool operator!=(const float3x2 left, const float3x2 right) {return !(left == right);}thread float3x2 operator/(const float3x2 left, const float3x2 right) { 42 return float3x2(left[0] / right[0], left[1] / right[1], left[2] / right[2]); 43} 44thread float3x2& operator/=(thread float3x2& left, thread const float3x2& right) { 45 left = left / right; 46 return left; 47} 48thread bool operator==(const float2x3 left, const float2x3 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const float2x3 left, const float2x3 right) {return !(left == right);}thread float2x3 operator/(const float2x3 left, const float2x3 right) { 49 return float2x3(left[0] / right[0], left[1] / right[1]); 50} 51thread float2x3& operator/=(thread float2x3& left, thread const float2x3& right) { 52 left = left / right; 53 return left; 54} 55thread bool operator==(const float4x3 left, const float4x3 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 float4x3 left, const float4x3 right) {return !(left == right);}thread bool operator==(const float4x2 left, const float4x2 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 float4x2 left, const float4x2 right) {return !(left == right);}thread float2x4 operator/(const float2x4 left, const float2x4 right) { 56 return float2x4(left[0] / right[0], left[1] / right[1]); 57} 58thread float2x4& operator/=(thread float2x4& left, thread const float2x4& right) { 59 left = left / right; 60 return left; 61} 62thread bool operator==(const float2x4 left, const float2x4 right) {return all(left[0] == right[0]) && all(left[1] == right[1]);}thread bool operator!=(const float2x4 left, const float2x4 right) {return !(left == right);}thread float2x3& operator*=(thread float2x3& left, thread const float2x2& right) { 63 left = left * right; 64 return left; 65} 66bool test_matrix_op_matrix_half_b() { 67 bool ok = true; 68 { 69 const half3x2 splat_4 = half3x2(half2(4.0h, 4.0h), half2(4.0h, 4.0h), half2(4.0h, 4.0h)); 70 half3x2 m = half3x2(2.0h); 71 m += splat_4; 72 ok = ok && m == half3x2(half2(6.0h, 4.0h), half2(4.0h, 6.0h), half2(4.0h, 4.0h)); 73 m = half3x2(2.0h); 74 m -= splat_4; 75 ok = ok && m == half3x2(half2(-2.0h, -4.0h), half2(-4.0h, -2.0h), half2(-4.0h, -4.0h)); 76 m = half3x2(2.0h); 77 m /= splat_4; 78 ok = ok && m == half3x2(0.5h); 79 } 80 { 81 const half2x3 splat_4 = half2x3(half3(4.0h, 4.0h, 4.0h), half3(4.0h, 4.0h, 4.0h)); 82 half2x3 m = splat_4; 83 m += half2x3(2.0h); 84 ok = ok && m == half2x3(half3(6.0h, 4.0h, 4.0h), half3(4.0h, 6.0h, 4.0h)); 85 m = splat_4; 86 m -= half2x3(2.0h); 87 ok = ok && m == half2x3(half3(2.0h, 4.0h, 4.0h), half3(4.0h, 2.0h, 4.0h)); 88 m = splat_4; 89 m /= half2x3(half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h)); 90 ok = ok && m == half2x3(half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h)); 91 } 92 { 93 half4x3 m = half4x3(half3(1.0h, 2.0h, 3.0h), half3(4.0h, 5.0h, 6.0h), half3(7.0h, 8.0h, 9.0h), half3(10.0h, 11.0h, 12.0h)); 94 m += half4x3(half3(16.0h, 15.0h, 14.0h), half3(13.0h, 12.0h, 11.0h), half3(10.0h, 9.0h, 8.0h), half3(7.0h, 6.0h, 5.0h)); 95 ok = ok && m == half4x3(half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h), half3(17.0h, 17.0h, 17.0h)); 96 } 97 { 98 half4x2 m = half4x2(half2(10.0h, 20.0h), half2(30.0h, 40.0h), half2(50.0h, 60.0h), half2(70.0h, 80.0h)); 99 m -= half4x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h), half2(5.0h, 6.0h), half2(7.0h, 8.0h)); 100 ok = ok && m == half4x2(half2(9.0h, 18.0h), half2(27.0h, 36.0h), half2(45.0h, 54.0h), half2(63.0h, 72.0h)); 101 } 102 { 103 half2x4 m = half2x4(half4(10.0h, 20.0h, 30.0h, 40.0h), half4(10.0h, 20.0h, 30.0h, 40.0h)); 104 m /= half2x4(half4(10.0h, 10.0h, 10.0h, 10.0h), half4(5.0h, 5.0h, 5.0h, 5.0h)); 105 ok = ok && m == half2x4(half4(1.0h, 2.0h, 3.0h, 4.0h), half4(2.0h, 4.0h, 6.0h, 8.0h)); 106 } 107 { 108 half2x3 m = half2x3(half3(7.0h, 9.0h, 11.0h), half3(8.0h, 10.0h, 12.0h)); 109 m *= half2x2(half2(1.0h, 4.0h), half2(2.0h, 5.0h)); 110 ok = ok && m == half2x3(half3(39.0h, 49.0h, 59.0h), half3(54.0h, 68.0h, 82.0h)); 111 } 112 return ok; 113} 114fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 115 Outputs _out; 116 (void)_out; 117 bool _0_ok = true; 118 { 119 const float3x2 _1_splat_4 = float3x2(float2(4.0, 4.0), float2(4.0, 4.0), float2(4.0, 4.0)); 120 float3x2 _2_m = float3x2(2.0); 121 _2_m += _1_splat_4; 122 _0_ok = _0_ok && _2_m == float3x2(float2(6.0, 4.0), float2(4.0, 6.0), float2(4.0, 4.0)); 123 _2_m = float3x2(2.0); 124 _2_m -= _1_splat_4; 125 _0_ok = _0_ok && _2_m == float3x2(float2(-2.0, -4.0), float2(-4.0, -2.0), float2(-4.0, -4.0)); 126 _2_m = float3x2(2.0); 127 _2_m /= _1_splat_4; 128 _0_ok = _0_ok && _2_m == float3x2(0.5); 129 } 130 { 131 const float2x3 _3_splat_4 = float2x3(float3(4.0, 4.0, 4.0), float3(4.0, 4.0, 4.0)); 132 float2x3 _4_m = _3_splat_4; 133 _4_m += float2x3(2.0); 134 _0_ok = _0_ok && _4_m == float2x3(float3(6.0, 4.0, 4.0), float3(4.0, 6.0, 4.0)); 135 _4_m = _3_splat_4; 136 _4_m -= float2x3(2.0); 137 _0_ok = _0_ok && _4_m == float2x3(float3(2.0, 4.0, 4.0), float3(4.0, 2.0, 4.0)); 138 _4_m = _3_splat_4; 139 _4_m /= float2x3(float3(2.0, 2.0, 2.0), float3(2.0, 2.0, 2.0)); 140 _0_ok = _0_ok && _4_m == float2x3(float3(2.0, 2.0, 2.0), float3(2.0, 2.0, 2.0)); 141 } 142 { 143 float4x3 _5_m = float4x3(float3(1.0, 2.0, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, 9.0), float3(10.0, 11.0, 12.0)); 144 _5_m += float4x3(float3(16.0, 15.0, 14.0), float3(13.0, 12.0, 11.0), float3(10.0, 9.0, 8.0), float3(7.0, 6.0, 5.0)); 145 _0_ok = _0_ok && _5_m == float4x3(float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0), float3(17.0, 17.0, 17.0)); 146 } 147 { 148 float4x2 _6_m = float4x2(float2(10.0, 20.0), float2(30.0, 40.0), float2(50.0, 60.0), float2(70.0, 80.0)); 149 _6_m -= float4x2(float2(1.0, 2.0), float2(3.0, 4.0), float2(5.0, 6.0), float2(7.0, 8.0)); 150 _0_ok = _0_ok && _6_m == float4x2(float2(9.0, 18.0), float2(27.0, 36.0), float2(45.0, 54.0), float2(63.0, 72.0)); 151 } 152 { 153 float2x4 _7_m = float2x4(float4(10.0, 20.0, 30.0, 40.0), float4(10.0, 20.0, 30.0, 40.0)); 154 _7_m /= float2x4(float4(10.0, 10.0, 10.0, 10.0), float4(5.0, 5.0, 5.0, 5.0)); 155 _0_ok = _0_ok && _7_m == float2x4(float4(1.0, 2.0, 3.0, 4.0), float4(2.0, 4.0, 6.0, 8.0)); 156 } 157 { 158 float2x3 _8_m = float2x3(float3(7.0, 9.0, 11.0), float3(8.0, 10.0, 12.0)); 159 _8_m *= float2x2(float2(1.0, 4.0), float2(2.0, 5.0)); 160 _0_ok = _0_ok && _8_m == float2x3(float3(39.0, 49.0, 59.0), float3(54.0, 68.0, 82.0)); 161 } 162 _out.sk_FragColor = _0_ok && test_matrix_op_matrix_half_b() ? _uniforms.colorGreen : _uniforms.colorRed; 163 return _out; 164} 165