xref: /aosp_15_r20/external/skia/tests/sksl/shared/UniformMatrixResize.metal (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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    float3x3 testMatrix3x3;
9    half4 colorGreen;
10    half4 colorRed;
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);
23float2x2 float2x2_from_float3x3(float3x3 x0) {
24    return float2x2(float2(x0[0].xy), float2(x0[1].xy));
25}
26thread bool operator==(const float2x2 left, const float2x2 right) {
27    return all(left[0] == right[0]) &&
28           all(left[1] == right[1]);
29}
30thread bool operator!=(const float2x2 left, const float2x2 right) {
31    return !(left == right);
32}
33thread bool operator==(const float3x3 left, const float3x3 right) {
34    return all(left[0] == right[0]) &&
35           all(left[1] == right[1]) &&
36           all(left[2] == right[2]);
37}
38thread bool operator!=(const float3x3 left, const float3x3 right) {
39    return !(left == right);
40}
41float3x3 float3x3_from_float2x2(float2x2 x0) {
42    return float3x3(float3(x0[0].xy, 0.0), float3(x0[1].xy, 0.0), float3(0.0, 0.0, 1.0));
43}
44float2x2 resizeMatrix_f22(Uniforms _uniforms) {
45    return float2x2_from_float3x3(_uniforms.testMatrix3x3);
46}
47fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
48    Outputs _out;
49    (void)_out;
50    _out.sk_FragColor = resizeMatrix_f22(_uniforms) == float2x2(float2(1.0, 2.0), float2(4.0, 5.0)) && float3x3_from_float2x2(resizeMatrix_f22(_uniforms)) == float3x3(float3(1.0, 2.0, 0.0), float3(4.0, 5.0, 0.0), float3(0.0, 0.0, 1.0)) ? _uniforms.colorGreen : _uniforms.colorRed;
51    return _out;
52}
53