1#include <metal_stdlib> 2#include <simd/simd.h> 3#ifdef __clang__ 4#pragma clang diagnostic ignored "-Wall" 5#endif 6using namespace metal; 7struct Uniforms { 8 half4 colorGreen; 9 half4 colorRed; 10 float2x2 testMatrix2x2; 11}; 12struct Inputs { 13}; 14struct Outputs { 15 half4 sk_FragColor [[color(0)]]; 16}; 17 18thread bool operator==(const float2x2 left, const float2x2 right); 19thread bool operator!=(const float2x2 left, const float2x2 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 float4x4 left, const float4x4 right); 25thread bool operator!=(const float4x4 left, const float4x4 right); 26 27float4 float4_from_float2x2(float2x2 x) { 28 return float4(x[0].xy, x[1].xy); 29} 30thread bool operator==(const float2x2 left, const float2x2 right) { 31 return all(left[0] == right[0]) && 32 all(left[1] == right[1]); 33} 34thread bool operator!=(const float2x2 left, const float2x2 right) { 35 return !(left == right); 36} 37float2x2 float2x2_from_float3_float(float3 x0, float x1) { 38 return float2x2(float2(x0.xy), float2(x0.z, x1)); 39} 40thread bool operator==(const float3x3 left, const float3x3 right) { 41 return all(left[0] == right[0]) && 42 all(left[1] == right[1]) && 43 all(left[2] == right[2]); 44} 45thread bool operator!=(const float3x3 left, const float3x3 right) { 46 return !(left == right); 47} 48float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) { 49 return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3)); 50} 51thread bool operator==(const float4x4 left, const float4x4 right) { 52 return all(left[0] == right[0]) && 53 all(left[1] == right[1]) && 54 all(left[2] == right[2]) && 55 all(left[3] == right[3]); 56} 57thread bool operator!=(const float4x4 left, const float4x4 right) { 58 return !(left == right); 59} 60float4x4 float4x4_from_float3_float3_float4_float2_float4(float3 x0, float3 x1, float4 x2, float2 x3, float4 x4) { 61 return float4x4(float4(x0.xyz, x1.x), float4(x1.yz, x2.xy), float4(x2.zw, x3.xy), float4(x4.xyzw)); 62} 63fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { 64 Outputs _out; 65 (void)_out; 66 float4 f4 = float4_from_float2x2(_uniforms.testMatrix2x2); 67 bool ok = float2x2_from_float3_float(f4.xyz, 4.0) == float2x2(float2(1.0, 2.0), float2(3.0, 4.0)); 68 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)); 69 ok = ok && float4x4_from_float3_float3_float4_float2_float4(f4.xyz, f4.wxy, f4.zwxy, f4.zw, f4) == float4x4(float4(1.0, 2.0, 3.0, 4.0), float4(1.0, 2.0, 3.0, 4.0), float4(1.0, 2.0, 3.0, 4.0), float4(1.0, 2.0, 3.0, 4.0)); 70 _out.sk_FragColor = ok ? _uniforms.colorGreen : _uniforms.colorRed; 71 return _out; 72} 73