xref: /aosp_15_r20/external/skia/tests/sksl/shared/SwizzleIndexLookup.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    half4 colorGreen;
9    half4 colorRed;
10    float3x3 testMatrix3x3;
11    float4x4 testMatrix4x4;
12};
13struct Inputs {
14};
15struct Outputs {
16    half4 sk_FragColor [[color(0)]];
17};
18bool test3x3_b(Uniforms _uniforms) {
19    float3 expected = float3(3.0, 2.0, 1.0);
20    for (int c = 0;c < 3; ++c) {
21        float3 vec = _uniforms.testMatrix3x3[c];
22        for (int r = 0;r < 3; ++r) {
23            if (vec[uint3(2, 1, 0)[r]] != expected[r]) {
24                return false;
25            }
26        }
27        expected += 3.0;
28    }
29    return true;
30}
31bool test4x4_b(Uniforms _uniforms) {
32    float4 expected = float4(4.0, 3.0, 2.0, 1.0);
33    for (int c = 0;c < 4; ++c) {
34        float4 vec = _uniforms.testMatrix4x4[c];
35        for (int r = 0;r < 4; ++r) {
36            if (vec[uint4(3, 2, 1, 0)[r]] != expected[r]) {
37                return false;
38            }
39        }
40        expected += 4.0;
41    }
42    return true;
43}
44fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
45    Outputs _out;
46    (void)_out;
47    _out.sk_FragColor = test3x3_b(_uniforms) && test4x4_b(_uniforms) ? _uniforms.colorGreen : _uniforms.colorRed;
48    return _out;
49}
50