4f1593eaee
Not a big deal necessarily, but considering using this logic in GLSL as well, and I'm less confident that your average GLSL ES driver will optimize away the separate array loads. Change-Id: I6a9f0d18c0fac138f64ad6426670f615e17f3492 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/449099 Commit-Queue: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
70 lines
2.9 KiB
Metal
70 lines
2.9 KiB
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Uniforms {
|
|
float4 colorGreen;
|
|
float4 colorRed;
|
|
float2x2 testMatrix2x2;
|
|
};
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
|
|
thread bool operator==(const float2x2 left, const float2x2 right);
|
|
thread bool operator!=(const float2x2 left, const float2x2 right);
|
|
|
|
thread bool operator==(const float3x3 left, const float3x3 right);
|
|
thread bool operator!=(const float3x3 left, const float3x3 right);
|
|
|
|
thread bool operator==(const float4x4 left, const float4x4 right);
|
|
thread bool operator!=(const float4x4 left, const float4x4 right);
|
|
|
|
float4 float4_from_float2x2(float2x2 x) {
|
|
return float4(x[0].xy, x[1].xy);
|
|
}
|
|
thread bool operator==(const float2x2 left, const float2x2 right) {
|
|
return all(left[0] == right[0]) &&
|
|
all(left[1] == right[1]);
|
|
}
|
|
thread bool operator!=(const float2x2 left, const float2x2 right) {
|
|
return !(left == right);
|
|
}
|
|
float2x2 float2x2_from_float3_float(float3 x0, float x1) {
|
|
return float2x2(float2(x0.xy), float2(x0.z, x1));
|
|
}
|
|
thread bool operator==(const float3x3 left, const float3x3 right) {
|
|
return all(left[0] == right[0]) &&
|
|
all(left[1] == right[1]) &&
|
|
all(left[2] == right[2]);
|
|
}
|
|
thread bool operator!=(const float3x3 left, const float3x3 right) {
|
|
return !(left == right);
|
|
}
|
|
float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) {
|
|
return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3));
|
|
}
|
|
thread bool operator==(const float4x4 left, const float4x4 right) {
|
|
return all(left[0] == right[0]) &&
|
|
all(left[1] == right[1]) &&
|
|
all(left[2] == right[2]) &&
|
|
all(left[3] == right[3]);
|
|
}
|
|
thread bool operator!=(const float4x4 left, const float4x4 right) {
|
|
return !(left == right);
|
|
}
|
|
float4x4 float4x4_from_float2_float4_float3_float2_float4_float(float2 x0, float4 x1, float3 x2, float2 x3, float4 x4, float x5) {
|
|
return float4x4(float4(x0.xy, x1.xy), float4(x1.zw, x2.xy), float4(x2.z, x3.xy, x4.x), float4(x4.yzw, x5));
|
|
}
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Outputs _out;
|
|
(void)_out;
|
|
float4 f4 = float4_from_float2x2(_uniforms.testMatrix2x2);
|
|
bool ok = float2x2_from_float3_float(f4.xyz, 4.0) == float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
|
|
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));
|
|
ok = ok && float4x4_from_float2_float4_float3_float2_float4_float(f4.xy, f4.zwxy, f4.zwx, f4.yz, f4.wxyz, f4.w) == 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));
|
|
_out.sk_FragColor = ok ? _uniforms.colorGreen : _uniforms.colorRed;
|
|
return _out;
|
|
}
|