xref: /aosp_15_r20/external/skia/tests/sksl/shared/SwizzleOpt.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 colorRed;
9    half4 colorGreen;
10    half4 testInputs;
11};
12struct Inputs {
13};
14struct Outputs {
15    half4 sk_FragColor [[color(0)]];
16};
17half fn_hh4(half4 v) {
18    for (int x = 1;x <= 2; ++x) {
19        return v.x;
20    }
21}
22fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
23    Outputs _out;
24    (void)_out;
25    half4 v = _uniforms.testInputs;
26    v = half4(0.0h, v.zyx);
27    v = half4(0.0h, 0.0h, v.xw);
28    v = half4(1.0h, 1.0h, v.wx);
29    v = half4(v.zy, 1.0h, 1.0h);
30    v = half4(v.xx, 1.0h, 1.0h);
31    v = v.wzwz;
32    v = half3(fn_hh4(v), 123.0h, 456.0h).yyzz;
33    v = half3(fn_hh4(v), 123.0h, 456.0h).yyzz;
34    v = half4(123.0h, 456.0h, 456.0h, fn_hh4(v));
35    v = half4(123.0h, 456.0h, 456.0h, fn_hh4(v));
36    v = half3(fn_hh4(v), 123.0h, 456.0h).yxxz;
37    v = half3(fn_hh4(v), 123.0h, 456.0h).yxxz;
38    v = half4(1.0h, 1.0h, 2.0h, 3.0h);
39    v = half4(_uniforms.colorRed.xyz, 1.0h);
40    v = half4(_uniforms.colorRed.x, 1.0h, _uniforms.colorRed.yz);
41    v.wzyx = v;
42    v.xw = v.yz;
43    v.zyx = half3(v.ww, 1.0h);
44    _out.sk_FragColor = all(v == half4(1.0h)) ? _uniforms.colorGreen : _uniforms.colorRed;
45    return _out;
46}
47