1cb93a386Sopenharmony_ci#include <metal_stdlib> 2cb93a386Sopenharmony_ci#include <simd/simd.h> 3cb93a386Sopenharmony_ciusing namespace metal; 4cb93a386Sopenharmony_cistruct Uniforms { 5cb93a386Sopenharmony_ci half4 colorGreen; 6cb93a386Sopenharmony_ci half4 colorRed; 7cb93a386Sopenharmony_ci float2x2 testMatrix2x2; 8cb93a386Sopenharmony_ci float3x3 testMatrix3x3; 9cb93a386Sopenharmony_ci half4 testInputs; 10cb93a386Sopenharmony_ci}; 11cb93a386Sopenharmony_cistruct Inputs { 12cb93a386Sopenharmony_ci}; 13cb93a386Sopenharmony_cistruct Outputs { 14cb93a386Sopenharmony_ci half4 sk_FragColor [[color(0)]]; 15cb93a386Sopenharmony_ci}; 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_cithread bool operator==(const float2x2 left, const float2x2 right); 18cb93a386Sopenharmony_cithread bool operator!=(const float2x2 left, const float2x2 right); 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_cithread bool operator==(const float3x3 left, const float3x3 right); 21cb93a386Sopenharmony_cithread bool operator!=(const float3x3 left, const float3x3 right); 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_cithread bool operator==(const float3x2 left, const float3x2 right); 24cb93a386Sopenharmony_cithread bool operator!=(const float3x2 left, const float3x2 right); 25cb93a386Sopenharmony_ci 26cb93a386Sopenharmony_cithread bool operator==(const float4x4 left, const float4x4 right); 27cb93a386Sopenharmony_cithread bool operator!=(const float4x4 left, const float4x4 right); 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_cithread bool operator==(const float2x4 left, const float2x4 right); 30cb93a386Sopenharmony_cithread bool operator!=(const float2x4 left, const float2x4 right); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_cithread bool operator==(const float4x2 left, const float4x2 right); 33cb93a386Sopenharmony_cithread bool operator!=(const float4x2 left, const float4x2 right); 34cb93a386Sopenharmony_cithread bool operator==(const float2x2 left, const float2x2 right) { 35cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 36cb93a386Sopenharmony_ci all(left[1] == right[1]); 37cb93a386Sopenharmony_ci} 38cb93a386Sopenharmony_cithread bool operator!=(const float2x2 left, const float2x2 right) { 39cb93a386Sopenharmony_ci return !(left == right); 40cb93a386Sopenharmony_ci} 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_citemplate <typename T, int C, int R> 43cb93a386Sopenharmony_cimatrix<T, C, R> outerProduct(const vec<T, R> a, const vec<T, C> b) { 44cb93a386Sopenharmony_ci matrix<T, C, R> result; 45cb93a386Sopenharmony_ci for (int c = 0; c < C; ++c) { 46cb93a386Sopenharmony_ci result[c] = a * b[c]; 47cb93a386Sopenharmony_ci } 48cb93a386Sopenharmony_ci return result; 49cb93a386Sopenharmony_ci} 50cb93a386Sopenharmony_cithread bool operator==(const float3x3 left, const float3x3 right) { 51cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 52cb93a386Sopenharmony_ci all(left[1] == right[1]) && 53cb93a386Sopenharmony_ci all(left[2] == right[2]); 54cb93a386Sopenharmony_ci} 55cb93a386Sopenharmony_cithread bool operator!=(const float3x3 left, const float3x3 right) { 56cb93a386Sopenharmony_ci return !(left == right); 57cb93a386Sopenharmony_ci} 58cb93a386Sopenharmony_cithread bool operator==(const float3x2 left, const float3x2 right) { 59cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 60cb93a386Sopenharmony_ci all(left[1] == right[1]) && 61cb93a386Sopenharmony_ci all(left[2] == right[2]); 62cb93a386Sopenharmony_ci} 63cb93a386Sopenharmony_cithread bool operator!=(const float3x2 left, const float3x2 right) { 64cb93a386Sopenharmony_ci return !(left == right); 65cb93a386Sopenharmony_ci} 66cb93a386Sopenharmony_cithread bool operator==(const float4x4 left, const float4x4 right) { 67cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 68cb93a386Sopenharmony_ci all(left[1] == right[1]) && 69cb93a386Sopenharmony_ci all(left[2] == right[2]) && 70cb93a386Sopenharmony_ci all(left[3] == right[3]); 71cb93a386Sopenharmony_ci} 72cb93a386Sopenharmony_cithread bool operator!=(const float4x4 left, const float4x4 right) { 73cb93a386Sopenharmony_ci return !(left == right); 74cb93a386Sopenharmony_ci} 75cb93a386Sopenharmony_cithread bool operator==(const float2x4 left, const float2x4 right) { 76cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 77cb93a386Sopenharmony_ci all(left[1] == right[1]); 78cb93a386Sopenharmony_ci} 79cb93a386Sopenharmony_cithread bool operator!=(const float2x4 left, const float2x4 right) { 80cb93a386Sopenharmony_ci return !(left == right); 81cb93a386Sopenharmony_ci} 82cb93a386Sopenharmony_cithread bool operator==(const float4x2 left, const float4x2 right) { 83cb93a386Sopenharmony_ci return all(left[0] == right[0]) && 84cb93a386Sopenharmony_ci all(left[1] == right[1]) && 85cb93a386Sopenharmony_ci all(left[2] == right[2]) && 86cb93a386Sopenharmony_ci all(left[3] == right[3]); 87cb93a386Sopenharmony_ci} 88cb93a386Sopenharmony_cithread bool operator!=(const float4x2 left, const float4x2 right) { 89cb93a386Sopenharmony_ci return !(left == right); 90cb93a386Sopenharmony_ci} 91cb93a386Sopenharmony_cifragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 92cb93a386Sopenharmony_ci Outputs _out; 93cb93a386Sopenharmony_ci (void)_out; 94cb93a386Sopenharmony_ci const float2 c12 = float2(1.0, 2.0); 95cb93a386Sopenharmony_ci _out.sk_FragColor = ((((outerProduct(_uniforms.testMatrix2x2[0], _uniforms.testMatrix2x2[1]) == float2x2(float2(3.0, 6.0), float2(4.0, 8.0)) && outerProduct(_uniforms.testMatrix3x3[0], _uniforms.testMatrix3x3[1]) == float3x3(float3(4.0, 8.0, 12.0), float3(5.0, 10.0, 15.0), float3(6.0, 12.0, 18.0))) && outerProduct(_uniforms.testMatrix2x2[0], _uniforms.testMatrix3x3[1]) == float3x2(float2(4.0, 8.0), float2(5.0, 10.0), float2(6.0, 12.0))) && float4x4(outerProduct(_uniforms.testInputs, half4(1.0h, 0.0h, 0.0h, 2.0h))) == float4x4(float4(-1.25, 0.0, 0.75, 2.25), float4(0.0, 0.0, 0.0, 0.0), float4(0.0, 0.0, 0.0, 0.0), float4(-2.5, 0.0, 1.5, 4.5))) && outerProduct(float4(_uniforms.testInputs), c12) == float2x4(float4(-1.25, 0.0, 0.75, 2.25), float4(-2.5, 0.0, 1.5, 4.5))) && outerProduct(c12, float4(_uniforms.testInputs)) == float4x2(float2(-1.25, -2.5), float2(0.0, 0.0), float2(0.75, 1.5), float2(2.25, 4.5)) ? _uniforms.colorGreen : _uniforms.colorRed; 96cb93a386Sopenharmony_ci return _out; 97cb93a386Sopenharmony_ci} 98