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 half2x3 left, const half2x3 right); 15thread bool operator!=(const half2x3 left, const half2x3 right); 16 17thread bool operator==(const half2x4 left, const half2x4 right); 18thread bool operator!=(const half2x4 left, const half2x4 right); 19 20thread bool operator==(const half3x2 left, const half3x2 right); 21thread bool operator!=(const half3x2 left, const half3x2 right); 22 23thread bool operator==(const half3x4 left, const half3x4 right); 24thread bool operator!=(const half3x4 left, const half3x4 right); 25 26thread bool operator==(const half4x2 left, const half4x2 right); 27thread bool operator!=(const half4x2 left, const half4x2 right); 28 29thread bool operator==(const half4x3 left, const half4x3 right); 30thread bool operator!=(const half4x3 left, const half4x3 right); 31 32thread bool operator==(const half2x2 left, const half2x2 right); 33thread bool operator!=(const half2x2 left, const half2x2 right); 34 35thread bool operator==(const half3x3 left, const half3x3 right); 36thread bool operator!=(const half3x3 left, const half3x3 right); 37 38thread bool operator==(const float2x3 left, const float2x3 right); 39thread bool operator!=(const float2x3 left, const float2x3 right); 40 41thread bool operator==(const float2x4 left, const float2x4 right); 42thread bool operator!=(const float2x4 left, const float2x4 right); 43 44thread bool operator==(const float3x2 left, const float3x2 right); 45thread bool operator!=(const float3x2 left, const float3x2 right); 46 47thread bool operator==(const float3x4 left, const float3x4 right); 48thread bool operator!=(const float3x4 left, const float3x4 right); 49 50thread bool operator==(const float4x2 left, const float4x2 right); 51thread bool operator!=(const float4x2 left, const float4x2 right); 52 53thread bool operator==(const float4x3 left, const float4x3 right); 54thread bool operator!=(const float4x3 left, const float4x3 right); 55 56thread bool operator==(const float2x2 left, const float2x2 right); 57thread bool operator!=(const float2x2 left, const float2x2 right); 58 59thread bool operator==(const float3x3 left, const float3x3 right); 60thread bool operator!=(const float3x3 left, const float3x3 right); 61thread bool operator==(const half2x3 left, const half2x3 right) { 62 return all(left[0] == right[0]) && 63 all(left[1] == right[1]); 64} 65thread bool operator!=(const half2x3 left, const half2x3 right) { 66 return !(left == right); 67} 68thread bool operator==(const half2x4 left, const half2x4 right) { 69 return all(left[0] == right[0]) && 70 all(left[1] == right[1]); 71} 72thread bool operator!=(const half2x4 left, const half2x4 right) { 73 return !(left == right); 74} 75thread bool operator==(const half3x2 left, const half3x2 right) { 76 return all(left[0] == right[0]) && 77 all(left[1] == right[1]) && 78 all(left[2] == right[2]); 79} 80thread bool operator!=(const half3x2 left, const half3x2 right) { 81 return !(left == right); 82} 83thread bool operator==(const half3x4 left, const half3x4 right) { 84 return all(left[0] == right[0]) && 85 all(left[1] == right[1]) && 86 all(left[2] == right[2]); 87} 88thread bool operator!=(const half3x4 left, const half3x4 right) { 89 return !(left == right); 90} 91thread bool operator==(const half4x2 left, const half4x2 right) { 92 return all(left[0] == right[0]) && 93 all(left[1] == right[1]) && 94 all(left[2] == right[2]) && 95 all(left[3] == right[3]); 96} 97thread bool operator!=(const half4x2 left, const half4x2 right) { 98 return !(left == right); 99} 100thread bool operator==(const half4x3 left, const half4x3 right) { 101 return all(left[0] == right[0]) && 102 all(left[1] == right[1]) && 103 all(left[2] == right[2]) && 104 all(left[3] == right[3]); 105} 106thread bool operator!=(const half4x3 left, const half4x3 right) { 107 return !(left == right); 108} 109thread bool operator==(const half2x2 left, const half2x2 right) { 110 return all(left[0] == right[0]) && 111 all(left[1] == right[1]); 112} 113thread bool operator!=(const half2x2 left, const half2x2 right) { 114 return !(left == right); 115} 116thread bool operator==(const half3x3 left, const half3x3 right) { 117 return all(left[0] == right[0]) && 118 all(left[1] == right[1]) && 119 all(left[2] == right[2]); 120} 121thread bool operator!=(const half3x3 left, const half3x3 right) { 122 return !(left == right); 123} 124thread half2x4 operator/(const half2x4 left, const half2x4 right) { 125 return half2x4(left[0] / right[0], left[1] / right[1]); 126} 127thread half2x4& operator/=(thread half2x4& left, thread const half2x4& right) { 128 left = left / right; 129 return left; 130} 131thread bool operator==(const float2x3 left, const float2x3 right) { 132 return all(left[0] == right[0]) && 133 all(left[1] == right[1]); 134} 135thread bool operator!=(const float2x3 left, const float2x3 right) { 136 return !(left == right); 137} 138thread bool operator==(const float2x4 left, const float2x4 right) { 139 return all(left[0] == right[0]) && 140 all(left[1] == right[1]); 141} 142thread bool operator!=(const float2x4 left, const float2x4 right) { 143 return !(left == right); 144} 145thread bool operator==(const float3x2 left, const float3x2 right) { 146 return all(left[0] == right[0]) && 147 all(left[1] == right[1]) && 148 all(left[2] == right[2]); 149} 150thread bool operator!=(const float3x2 left, const float3x2 right) { 151 return !(left == right); 152} 153thread bool operator==(const float3x4 left, const float3x4 right) { 154 return all(left[0] == right[0]) && 155 all(left[1] == right[1]) && 156 all(left[2] == right[2]); 157} 158thread bool operator!=(const float3x4 left, const float3x4 right) { 159 return !(left == right); 160} 161thread bool operator==(const float4x2 left, const float4x2 right) { 162 return all(left[0] == right[0]) && 163 all(left[1] == right[1]) && 164 all(left[2] == right[2]) && 165 all(left[3] == right[3]); 166} 167thread bool operator!=(const float4x2 left, const float4x2 right) { 168 return !(left == right); 169} 170thread bool operator==(const float4x3 left, const float4x3 right) { 171 return all(left[0] == right[0]) && 172 all(left[1] == right[1]) && 173 all(left[2] == right[2]) && 174 all(left[3] == right[3]); 175} 176thread bool operator!=(const float4x3 left, const float4x3 right) { 177 return !(left == right); 178} 179thread bool operator==(const float2x2 left, const float2x2 right) { 180 return all(left[0] == right[0]) && 181 all(left[1] == right[1]); 182} 183thread bool operator!=(const float2x2 left, const float2x2 right) { 184 return !(left == right); 185} 186thread bool operator==(const float3x3 left, const float3x3 right) { 187 return all(left[0] == right[0]) && 188 all(left[1] == right[1]) && 189 all(left[2] == right[2]); 190} 191thread bool operator!=(const float3x3 left, const float3x3 right) { 192 return !(left == right); 193} 194thread float2x4 operator/(const float2x4 left, const float2x4 right) { 195 return float2x4(left[0] / right[0], left[1] / right[1]); 196} 197thread float2x4& operator/=(thread float2x4& left, thread const float2x4& right) { 198 left = left / right; 199 return left; 200} 201bool test_half_b() { 202 bool ok = true; 203 half2x3 m23 = half2x3(2.0h); 204 ok = ok && m23 == half2x3(half3(2.0h, 0.0h, 0.0h), half3(0.0h, 2.0h, 0.0h)); 205 half2x4 m24 = half2x4(3.0h); 206 ok = ok && m24 == half2x4(half4(3.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 3.0h, 0.0h, 0.0h)); 207 half3x2 m32 = half3x2(4.0h); 208 ok = ok && m32 == half3x2(half2(4.0h, 0.0h), half2(0.0h, 4.0h), half2(0.0h, 0.0h)); 209 half3x4 m34 = half3x4(5.0h); 210 ok = ok && m34 == half3x4(half4(5.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 5.0h, 0.0h, 0.0h), half4(0.0h, 0.0h, 5.0h, 0.0h)); 211 half4x2 m42 = half4x2(6.0h); 212 ok = ok && m42 == half4x2(half2(6.0h, 0.0h), half2(0.0h, 6.0h), half2(0.0h, 0.0h), half2(0.0h, 0.0h)); 213 half4x3 m43 = half4x3(7.0h); 214 ok = ok && m43 == half4x3(half3(7.0h, 0.0h, 0.0h), half3(0.0h, 7.0h, 0.0h), half3(0.0h, 0.0h, 7.0h), half3(0.0h, 0.0h, 0.0h)); 215 half2x2 m22 = m32 * m23; 216 ok = ok && m22 == half2x2(8.0h); 217 half3x3 m33 = m43 * m34; 218 ok = ok && m33 == half3x3(35.0h); 219 m23 += (half2x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 1.0h); 220 ok = ok && m23 == half2x3(half3(3.0h, 1.0h, 1.0h), half3(1.0h, 3.0h, 1.0h)); 221 m32 -= (half3x2(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 2.0h); 222 ok = ok && m32 == half3x2(half2(2.0h, -2.0h), half2(-2.0h, 2.0h), half2(-2.0h, -2.0h)); 223 m24 /= (half2x4(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0h); 224 ok = ok && m24 == half2x4(half4(0.75h, 0.0h, 0.0h, 0.0h), half4(0.0h, 0.75h, 0.0h, 0.0h)); 225 return ok; 226} 227fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 228 Outputs _out; 229 (void)_out; 230 bool _0_ok = true; 231 float2x3 _1_m23 = float2x3(2.0); 232 _0_ok = _0_ok && _1_m23 == float2x3(float3(2.0, 0.0, 0.0), float3(0.0, 2.0, 0.0)); 233 float2x4 _2_m24 = float2x4(3.0); 234 _0_ok = _0_ok && _2_m24 == float2x4(float4(3.0, 0.0, 0.0, 0.0), float4(0.0, 3.0, 0.0, 0.0)); 235 float3x2 _3_m32 = float3x2(4.0); 236 _0_ok = _0_ok && _3_m32 == float3x2(float2(4.0, 0.0), float2(0.0, 4.0), float2(0.0, 0.0)); 237 float3x4 _4_m34 = float3x4(5.0); 238 _0_ok = _0_ok && _4_m34 == float3x4(float4(5.0, 0.0, 0.0, 0.0), float4(0.0, 5.0, 0.0, 0.0), float4(0.0, 0.0, 5.0, 0.0)); 239 float4x2 _5_m42 = float4x2(6.0); 240 _0_ok = _0_ok && _5_m42 == float4x2(float2(6.0, 0.0), float2(0.0, 6.0), float2(0.0, 0.0), float2(0.0, 0.0)); 241 float4x3 _6_m43 = float4x3(7.0); 242 _0_ok = _0_ok && _6_m43 == float4x3(float3(7.0, 0.0, 0.0), float3(0.0, 7.0, 0.0), float3(0.0, 0.0, 7.0), float3(0.0, 0.0, 0.0)); 243 float2x2 _7_m22 = _3_m32 * _1_m23; 244 _0_ok = _0_ok && _7_m22 == float2x2(8.0); 245 float3x3 _8_m33 = _6_m43 * _4_m34; 246 _0_ok = _0_ok && _8_m33 == float3x3(35.0); 247 _1_m23 += (float2x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 1.0); 248 _0_ok = _0_ok && _1_m23 == float2x3(float3(3.0, 1.0, 1.0), float3(1.0, 3.0, 1.0)); 249 _3_m32 -= (float3x2(1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 2.0); 250 _0_ok = _0_ok && _3_m32 == float3x2(float2(2.0, -2.0), float2(-2.0, 2.0), float2(-2.0, -2.0)); 251 _2_m24 /= (float2x4(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) * 4.0); 252 _0_ok = _0_ok && _2_m24 == float2x4(float4(0.75, 0.0, 0.0, 0.0), float4(0.0, 0.75, 0.0, 0.0)); 253 _out.sk_FragColor = _0_ok && test_half_b() ? _uniforms.colorGreen : _uniforms.colorRed; 254 return _out; 255} 256