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 14template <typename T1, typename T2, size_t N> 15bool operator==(thread const array<T1, N>& left, thread const array<T2, N>& right); 16template <typename T1, typename T2, size_t N> 17bool operator!=(thread const array<T1, N>& left, thread const array<T2, N>& right); 18 19thread bool operator==(const float2x2 left, const float2x2 right); 20thread bool operator!=(const float2x2 left, const float2x2 right); 21 22template <size_t N> 23array<half, N> array_of_half_from_float(thread const array<float, N>& x) { 24 array<half, N> result; 25 for (int i = 0; i < N; ++i) { 26 result[i] = half(x[i]); 27 } 28 return result; 29} 30 31template <size_t N> 32array<float, N> array_of_float_from_half(thread const array<half, N>& x) { 33 array<float, N> result; 34 for (int i = 0; i < N; ++i) { 35 result[i] = float(x[i]); 36 } 37 return result; 38} 39 40template <size_t N> 41array<short3, N> array_of_short3_from_int3(thread const array<int3, N>& x) { 42 array<short3, N> result; 43 for (int i = 0; i < N; ++i) { 44 result[i] = short3(x[i]); 45 } 46 return result; 47} 48 49template <size_t N> 50array<int3, N> array_of_int3_from_short3(thread const array<short3, N>& x) { 51 array<int3, N> result; 52 for (int i = 0; i < N; ++i) { 53 result[i] = int3(x[i]); 54 } 55 return result; 56} 57 58template <size_t N> 59array<float2x2, N> array_of_float2x2_from_half2x2(thread const array<half2x2, N>& x) { 60 array<float2x2, N> result; 61 for (int i = 0; i < N; ++i) { 62 result[i] = float2x2(x[i]); 63 } 64 return result; 65} 66 67template <size_t N> 68array<half2x2, N> array_of_half2x2_from_float2x2(thread const array<float2x2, N>& x) { 69 array<half2x2, N> result; 70 for (int i = 0; i < N; ++i) { 71 result[i] = half2x2(x[i]); 72 } 73 return result; 74} 75 76template <typename T1, typename T2, size_t N> 77bool operator==(thread const array<T1, N>& left, thread const array<T2, N>& right) { 78 for (size_t index = 0; index < N; ++index) { 79 if (!all(left[index] == right[index])) { 80 return false; 81 } 82 } 83 return true; 84} 85 86template <typename T1, typename T2, size_t N> 87bool operator!=(thread const array<T1, N>& left, thread const array<T2, N>& right) { 88 return !(left == right); 89} 90thread bool operator==(const float2x2 left, const float2x2 right) { 91 return all(left[0] == right[0]) && 92 all(left[1] == right[1]); 93} 94thread bool operator!=(const float2x2 left, const float2x2 right) { 95 return !(left == right); 96} 97fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 98 Outputs _out; 99 (void)_out; 100 array<float, 4> f = array<float, 4>{1.0, 2.0, 3.0, 4.0}; 101 array<half, 4> h = array_of_half_from_float(f); 102 f = array_of_float_from_half(h); 103 h = array_of_half_from_float(f); 104 array<int3, 3> i3 = array<int3, 3>{int3(1), int3(2), int3(3)}; 105 array<short3, 3> s3 = array_of_short3_from_int3(i3); 106 i3 = array_of_int3_from_short3(s3); 107 s3 = array_of_short3_from_int3(i3); 108 array<half2x2, 2> h2x2 = array<half2x2, 2>{half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h)), half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h))}; 109 array<float2x2, 2> f2x2 = array_of_float2x2_from_half2x2(h2x2); 110 f2x2 = array_of_float2x2_from_half2x2(h2x2); 111 h2x2 = array_of_half2x2_from_float2x2(f2x2); 112 _out.sk_FragColor = (f == array_of_float_from_half(h) && i3 == array_of_int3_from_short3(s3)) && f2x2 == array_of_float2x2_from_half2x2(h2x2) ? _uniforms.colorGreen : _uniforms.colorRed; 113 return _out; 114} 115