1#include <metal_stdlib> 2#include <simd/simd.h> 3using namespace metal; 4struct Uniforms { 5 half4 colorGreen; 6 half4 colorRed; 7 float2x2 testMatrix2x2; 8}; 9struct Inputs { 10}; 11struct Outputs { 12 half4 sk_FragColor [[color(0)]]; 13}; 14 15thread bool operator==(const float2x3 left, const float2x3 right); 16thread bool operator!=(const float2x3 left, const float2x3 right); 17 18thread bool operator==(const float2x4 left, const float2x4 right); 19thread bool operator!=(const float2x4 left, const float2x4 right); 20 21thread bool operator==(const float3x3 left, const float3x3 right); 22thread bool operator!=(const float3x3 left, const float3x3 right); 23 24thread bool operator==(const float4x2 left, const float4x2 right); 25thread bool operator!=(const float4x2 left, const float4x2 right); 26 27thread bool operator==(const float4x3 left, const float4x3 right); 28thread bool operator!=(const float4x3 left, const float4x3 right); 29 30float4 float4_from_float2x2(float2x2 x) { 31 return float4(x[0].xy, x[1].xy); 32} 33thread bool operator==(const float2x3 left, const float2x3 right) { 34 return all(left[0] == right[0]) && 35 all(left[1] == right[1]); 36} 37thread bool operator!=(const float2x3 left, const float2x3 right) { 38 return !(left == right); 39} 40float2x3 float2x3_from_float4_float2(float4 x0, float2 x1) { 41 return float2x3(float3(x0.xyz), float3(x0.w, x1.xy)); 42} 43thread bool operator==(const float2x4 left, const float2x4 right) { 44 return all(left[0] == right[0]) && 45 all(left[1] == right[1]); 46} 47thread bool operator!=(const float2x4 left, const float2x4 right) { 48 return !(left == right); 49} 50float2x4 float2x4_from_float3_float4_float(float3 x0, float4 x1, float x2) { 51 return float2x4(float4(x0.xyz, x1.x), float4(x1.yzw, x2)); 52} 53thread bool operator==(const float3x3 left, const float3x3 right) { 54 return all(left[0] == right[0]) && 55 all(left[1] == right[1]) && 56 all(left[2] == right[2]); 57} 58thread bool operator!=(const float3x3 left, const float3x3 right) { 59 return !(left == right); 60} 61float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) { 62 return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3)); 63} 64thread bool operator==(const float4x2 left, const float4x2 right) { 65 return all(left[0] == right[0]) && 66 all(left[1] == right[1]) && 67 all(left[2] == right[2]) && 68 all(left[3] == right[3]); 69} 70thread bool operator!=(const float4x2 left, const float4x2 right) { 71 return !(left == right); 72} 73float4x2 float4x2_from_float3_float4_float(float3 x0, float4 x1, float x2) { 74 return float4x2(float2(x0.xy), float2(x0.z, x1.x), float2(x1.yz), float2(x1.w, x2)); 75} 76thread bool operator==(const float4x3 left, const float4x3 right) { 77 return all(left[0] == right[0]) && 78 all(left[1] == right[1]) && 79 all(left[2] == right[2]) && 80 all(left[3] == right[3]); 81} 82thread bool operator!=(const float4x3 left, const float4x3 right) { 83 return !(left == right); 84} 85float4x3 float4x3_from_float_float4_float4_float3(float x0, float4 x1, float4 x2, float3 x3) { 86 return float4x3(float3(x0, x1.xy), float3(x1.zw, x2.x), float3(x2.yzw), float3(x3.xyz)); 87} 88fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 89 Outputs _out; 90 (void)_out; 91 float4 f4 = float4_from_float2x2(_uniforms.testMatrix2x2); 92 bool ok = float2x3_from_float4_float2(f4, f4.xy) == float2x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0)); 93 ok = ok && float2x4_from_float3_float4_float(f4.xyz, f4.wxyz, f4.w) == float2x4(float4(1.0, 2.0, 3.0, 4.0), float4(1.0, 2.0, 3.0, 4.0)); 94 ok = ok && float3x3_from_float2_float2_float4_float(f4.xy, f4.zw, f4, f4.x) == float3x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0), float3(3.0, 4.0, 1.0)); 95 ok = ok && float4x2_from_float3_float4_float(f4.xyz, f4.wxyz, f4.w) == float4x2(float2(1.0, 2.0), float2(3.0, 4.0), float2(1.0, 2.0), float2(3.0, 4.0)); 96 ok = ok && float4x3_from_float_float4_float4_float3(f4.x, f4.yzwx, f4.yzwx, f4.yzw) == float4x3(float3(1.0, 2.0, 3.0), float3(4.0, 1.0, 2.0), float3(3.0, 4.0, 1.0), float3(2.0, 3.0, 4.0)); 97 _out.sk_FragColor = ok ? _uniforms.colorGreen : _uniforms.colorRed; 98 return _out; 99} 100