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 19template <size_t N> 20array<int, N> array_of_int_from_short(thread const array<short, N>& x) { 21 array<int, N> result; 22 for (int i = 0; i < N; ++i) { 23 result[i] = int(x[i]); 24 } 25 return result; 26} 27 28template <size_t N> 29array<short, N> array_of_short_from_int(thread const array<int, N>& x) { 30 array<short, N> result; 31 for (int i = 0; i < N; ++i) { 32 result[i] = short(x[i]); 33 } 34 return result; 35} 36 37template <size_t N> 38array<float, N> array_of_float_from_half(thread const array<half, N>& x) { 39 array<float, N> result; 40 for (int i = 0; i < N; ++i) { 41 result[i] = float(x[i]); 42 } 43 return result; 44} 45 46template <size_t N> 47array<half, N> array_of_half_from_float(thread const array<float, N>& x) { 48 array<half, N> result; 49 for (int i = 0; i < N; ++i) { 50 result[i] = half(x[i]); 51 } 52 return result; 53} 54 55template <typename T1, typename T2, size_t N> 56bool operator==(thread const array<T1, N>& left, thread const array<T2, N>& right) { 57 for (size_t index = 0; index < N; ++index) { 58 if (!all(left[index] == right[index])) { 59 return false; 60 } 61 } 62 return true; 63} 64 65template <typename T1, typename T2, size_t N> 66bool operator!=(thread const array<T1, N>& left, thread const array<T2, N>& right) { 67 return !(left == right); 68} 69fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 70 Outputs _out; 71 (void)_out; 72 array<int, 2> i2 = array<int, 2>{1, 2}; 73 array<short, 2> s2 = array<short, 2>{1, 2}; 74 array<float, 2> f2 = array<float, 2>{1.0, 2.0}; 75 array<half, 2> h2 = array<half, 2>{1.0h, 2.0h}; 76 i2 = array_of_int_from_short(s2); 77 s2 = array_of_short_from_int(i2); 78 f2 = array_of_float_from_half(h2); 79 h2 = array_of_half_from_float(f2); 80 const array<float, 2> cf2 = array<float, 2>{1.0, 2.0}; 81 _out.sk_FragColor = ((i2 == array_of_int_from_short(s2) && f2 == array_of_float_from_half(h2)) && i2 == array<int, 2>{1, 2}) && array_of_float_from_half(h2) == cf2 ? _uniforms.colorGreen : _uniforms.colorRed; 82 return _out; 83} 84