1*c8dee2aaSAndroid Build Coastguard Worker#include <metal_stdlib> 2*c8dee2aaSAndroid Build Coastguard Worker#include <simd/simd.h> 3*c8dee2aaSAndroid Build Coastguard Worker#ifdef __clang__ 4*c8dee2aaSAndroid Build Coastguard Worker#pragma clang diagnostic ignored "-Wall" 5*c8dee2aaSAndroid Build Coastguard Worker#endif 6*c8dee2aaSAndroid Build Coastguard Workerusing namespace metal; 7*c8dee2aaSAndroid Build Coastguard Workerconstant const array<half, 5> globalArray = array<half, 5>{1.0h, 1.0h, 1.0h, 1.0h, 1.0h}; 8*c8dee2aaSAndroid Build Coastguard Workerconstant const half2 globalVector = half2(1.0h); 9*c8dee2aaSAndroid Build Coastguard Workerconstant const half2x2 globalMatrix = half2x2(half2(1.0h, 1.0h), half2(1.0h, 1.0h)); 10*c8dee2aaSAndroid Build Coastguard Workerstruct Uniforms { 11*c8dee2aaSAndroid Build Coastguard Worker half4 colorRed; 12*c8dee2aaSAndroid Build Coastguard Worker half2x2 testMatrix2x2; 13*c8dee2aaSAndroid Build Coastguard Worker array<half, 5> testArray; 14*c8dee2aaSAndroid Build Coastguard Worker}; 15*c8dee2aaSAndroid Build Coastguard Workerstruct Inputs { 16*c8dee2aaSAndroid Build Coastguard Worker}; 17*c8dee2aaSAndroid Build Coastguard Workerstruct Outputs { 18*c8dee2aaSAndroid Build Coastguard Worker half4 sk_FragColor [[color(0)]]; 19*c8dee2aaSAndroid Build Coastguard Worker}; 20*c8dee2aaSAndroid Build Coastguard Worker 21*c8dee2aaSAndroid Build Coastguard Workertemplate <typename T1, typename T2> 22*c8dee2aaSAndroid Build Coastguard Workerbool operator==(const array_ref<T1> left, const array_ref<T2> right); 23*c8dee2aaSAndroid Build Coastguard Workertemplate <typename T1, typename T2> 24*c8dee2aaSAndroid Build Coastguard Workerbool operator!=(const array_ref<T1> left, const array_ref<T2> right); 25*c8dee2aaSAndroid Build Coastguard Worker 26*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half2x2 left, const half2x2 right); 27*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half2x2 left, const half2x2 right); 28*c8dee2aaSAndroid Build Coastguard Worker 29*c8dee2aaSAndroid Build Coastguard Workertemplate <typename T1, typename T2> 30*c8dee2aaSAndroid Build Coastguard Workerbool operator==(const array_ref<T1> left, const array_ref<T2> right) { 31*c8dee2aaSAndroid Build Coastguard Worker if (left.size() != right.size()) { 32*c8dee2aaSAndroid Build Coastguard Worker return false; 33*c8dee2aaSAndroid Build Coastguard Worker } 34*c8dee2aaSAndroid Build Coastguard Worker for (size_t index = 0; index < left.size(); ++index) { 35*c8dee2aaSAndroid Build Coastguard Worker if (!all(left[index] == right[index])) { 36*c8dee2aaSAndroid Build Coastguard Worker return false; 37*c8dee2aaSAndroid Build Coastguard Worker } 38*c8dee2aaSAndroid Build Coastguard Worker } 39*c8dee2aaSAndroid Build Coastguard Worker return true; 40*c8dee2aaSAndroid Build Coastguard Worker} 41*c8dee2aaSAndroid Build Coastguard Worker 42*c8dee2aaSAndroid Build Coastguard Workertemplate <typename T1, typename T2> 43*c8dee2aaSAndroid Build Coastguard Workerbool operator!=(const array_ref<T1> left, const array_ref<T2> right) { 44*c8dee2aaSAndroid Build Coastguard Worker return !(left == right); 45*c8dee2aaSAndroid Build Coastguard Worker} 46*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half2x2 left, const half2x2 right) { 47*c8dee2aaSAndroid Build Coastguard Worker return all(left[0] == right[0]) && 48*c8dee2aaSAndroid Build Coastguard Worker all(left[1] == right[1]); 49*c8dee2aaSAndroid Build Coastguard Worker} 50*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half2x2 left, const half2x2 right) { 51*c8dee2aaSAndroid Build Coastguard Worker return !(left == right); 52*c8dee2aaSAndroid Build Coastguard Worker} 53*c8dee2aaSAndroid Build Coastguard Workerfragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 54*c8dee2aaSAndroid Build Coastguard Worker Outputs _out; 55*c8dee2aaSAndroid Build Coastguard Worker (void)_out; 56*c8dee2aaSAndroid Build Coastguard Worker const array<half, 5> localArray = array<half, 5>{0.0h, 1.0h, 2.0h, 3.0h, 4.0h}; 57*c8dee2aaSAndroid Build Coastguard Worker const half2 localVector = half2(1.0h); 58*c8dee2aaSAndroid Build Coastguard Worker const half2x2 localMatrix = half2x2(half2(0.0h, 1.0h), half2(2.0h, 3.0h)); 59*c8dee2aaSAndroid Build Coastguard Worker if (((((make_array_ref(globalArray) == make_array_ref(_uniforms.testArray) || all(globalVector == _uniforms.colorRed.xy)) || globalMatrix == _uniforms.testMatrix2x2) || make_array_ref(localArray) == make_array_ref(_uniforms.testArray)) || all(localVector == _uniforms.colorRed.xy)) || localMatrix == _uniforms.testMatrix2x2) { 60*c8dee2aaSAndroid Build Coastguard Worker _out.sk_FragColor = _uniforms.colorRed; 61*c8dee2aaSAndroid Build Coastguard Worker return _out; 62*c8dee2aaSAndroid Build Coastguard Worker } 63*c8dee2aaSAndroid Build Coastguard Worker _out.sk_FragColor = half4(0.0h, 1.0h, 0.0h, 1.0h); 64*c8dee2aaSAndroid Build Coastguard Worker return _out; 65*c8dee2aaSAndroid Build Coastguard Worker} 66