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 Workerstruct Uniforms { 8*c8dee2aaSAndroid Build Coastguard Worker half4 colorGreen; 9*c8dee2aaSAndroid Build Coastguard Worker half4 colorRed; 10*c8dee2aaSAndroid Build Coastguard Worker float2x2 testMatrix2x2; 11*c8dee2aaSAndroid Build Coastguard Worker half3x3 testMatrix3x3; 12*c8dee2aaSAndroid Build Coastguard Worker}; 13*c8dee2aaSAndroid Build Coastguard Workerstruct Inputs { 14*c8dee2aaSAndroid Build Coastguard Worker}; 15*c8dee2aaSAndroid Build Coastguard Workerstruct Outputs { 16*c8dee2aaSAndroid Build Coastguard Worker half4 sk_FragColor [[color(0)]]; 17*c8dee2aaSAndroid Build Coastguard Worker}; 18*c8dee2aaSAndroid Build Coastguard Worker 19*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half2x2 left, const half2x2 right); 20*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half2x2 left, const half2x2 right); 21*c8dee2aaSAndroid Build Coastguard Worker 22*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const float2x2 left, const float2x2 right); 23*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const float2x2 left, const float2x2 right); 24*c8dee2aaSAndroid Build Coastguard Worker 25*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half3x3 left, const half3x3 right); 26*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half3x3 left, const half3x3 right); 27*c8dee2aaSAndroid Build Coastguard Worker 28*c8dee2aaSAndroid Build Coastguard Workertemplate <typename T, int C, int R> 29*c8dee2aaSAndroid Build Coastguard Workermatrix<T, C, R> matrixCompMult(matrix<T, C, R> a, const matrix<T, C, R> b) { 30*c8dee2aaSAndroid Build Coastguard Worker for (int c = 0; c < C; ++c) { a[c] *= b[c]; } 31*c8dee2aaSAndroid Build Coastguard Worker return a; 32*c8dee2aaSAndroid Build Coastguard Worker} 33*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half2x2 left, const half2x2 right) { 34*c8dee2aaSAndroid Build Coastguard Worker return all(left[0] == right[0]) && 35*c8dee2aaSAndroid Build Coastguard Worker all(left[1] == right[1]); 36*c8dee2aaSAndroid Build Coastguard Worker} 37*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half2x2 left, const half2x2 right) { 38*c8dee2aaSAndroid Build Coastguard Worker return !(left == right); 39*c8dee2aaSAndroid Build Coastguard Worker} 40*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const float2x2 left, const float2x2 right) { 41*c8dee2aaSAndroid Build Coastguard Worker return all(left[0] == right[0]) && 42*c8dee2aaSAndroid Build Coastguard Worker all(left[1] == right[1]); 43*c8dee2aaSAndroid Build Coastguard Worker} 44*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const float2x2 left, const float2x2 right) { 45*c8dee2aaSAndroid Build Coastguard Worker return !(left == right); 46*c8dee2aaSAndroid Build Coastguard Worker} 47*c8dee2aaSAndroid Build Coastguard Workerthread bool operator==(const half3x3 left, const half3x3 right) { 48*c8dee2aaSAndroid Build Coastguard Worker return all(left[0] == right[0]) && 49*c8dee2aaSAndroid Build Coastguard Worker all(left[1] == right[1]) && 50*c8dee2aaSAndroid Build Coastguard Worker all(left[2] == right[2]); 51*c8dee2aaSAndroid Build Coastguard Worker} 52*c8dee2aaSAndroid Build Coastguard Workerthread bool operator!=(const half3x3 left, const half3x3 right) { 53*c8dee2aaSAndroid Build Coastguard Worker return !(left == right); 54*c8dee2aaSAndroid Build Coastguard Worker} 55*c8dee2aaSAndroid Build Coastguard Workerfragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 56*c8dee2aaSAndroid Build Coastguard Worker Outputs _out; 57*c8dee2aaSAndroid Build Coastguard Worker (void)_out; 58*c8dee2aaSAndroid Build Coastguard Worker half2x2 h22 = half2x2(half2(1000000.0h, 1000000.0h), half2(1000000.0h, 1000000.0h)); 59*c8dee2aaSAndroid Build Coastguard Worker const half2x2 hugeM22 = half2x2(half2(1e+30h, 1e+30h), half2(1e+30h, 1e+30h)); 60*c8dee2aaSAndroid Build Coastguard Worker h22 = matrixCompMult(hugeM22, hugeM22); 61*c8dee2aaSAndroid Build Coastguard Worker h22 = half2x2(half2(0.0h, 5.0h), half2(10.0h, 15.0h)); 62*c8dee2aaSAndroid Build Coastguard Worker float2x2 f22 = matrixCompMult(_uniforms.testMatrix2x2, float2x2(1.0)); 63*c8dee2aaSAndroid Build Coastguard Worker half3x3 h33 = matrixCompMult(_uniforms.testMatrix3x3, half3x3(half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h), half3(2.0h, 2.0h, 2.0h))); 64*c8dee2aaSAndroid Build Coastguard Worker _out.sk_FragColor = (h22 == half2x2(half2(0.0h, 5.0h), half2(10.0h, 15.0h)) && f22 == float2x2(float2(1.0, 0.0), float2(0.0, 4.0))) && h33 == half3x3(half3(2.0h, 4.0h, 6.0h), half3(8.0h, 10.0h, 12.0h), half3(14.0h, 16.0h, 18.0h)) ? _uniforms.colorGreen : _uniforms.colorRed; 65*c8dee2aaSAndroid Build Coastguard Worker return _out; 66*c8dee2aaSAndroid Build Coastguard Worker} 67