xref: /aosp_15_r20/external/skia/tests/sksl/shared/ComplexDelete.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;
7
8struct sampler2D {
9    texture2d<half> tex;
10    sampler smp;
11};
12half4 sample(sampler2D i, float2 p, float b=0) { return i.tex.sample(i.smp, p, bias(b)); }
13half4 sample(sampler2D i, float3 p, float b=0) { return i.tex.sample(i.smp, p.xy / p.z, bias(b)); }
14half4 sampleLod(sampler2D i, float2 p, float lod) { return i.tex.sample(i.smp, p, level(lod)); }
15half4 sampleLod(sampler2D i, float3 p, float lod) {
16    return i.tex.sample(i.smp, p.xy / p.z, level(lod));
17}
18half4 sampleGrad(sampler2D i, float2 p, float2 dPdx, float2 dPdy) {
19    return i.tex.sample(i.smp, p, gradient2d(dPdx, dPdy));
20}
21
22struct Uniforms {
23    float4x4 colorXform;
24};
25struct Inputs {
26};
27struct Outputs {
28    half4 sk_FragColor [[color(0)]];
29};
30struct Globals {
31    sampler2D s;
32};
33
34thread bool operator==(const float4x4 left, const float4x4 right);
35thread bool operator!=(const float4x4 left, const float4x4 right);
36thread bool operator==(const float4x4 left, const float4x4 right) {
37    return all(left[0] == right[0]) &&
38           all(left[1] == right[1]) &&
39           all(left[2] == right[2]) &&
40           all(left[3] == right[3]);
41}
42thread bool operator!=(const float4x4 left, const float4x4 right) {
43    return !(left == right);
44}
45fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], texture2d<half> s_Tex [[texture(0)]], sampler s_Smplr [[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
46    Globals _globals{{s_Tex, s_Smplr}};
47    (void)_globals;
48    Outputs _out;
49    (void)_out;
50    float4 tmpColor;
51    _out.sk_FragColor = (tmpColor = float4(sample(_globals.s, float2(1.0))), half4(_uniforms.colorXform != float4x4(1.0) ? float4(clamp((_uniforms.colorXform * float4(tmpColor.xyz, 1.0)).xyz, 0.0, tmpColor.w), tmpColor.w) : tmpColor));
52    return _out;
53}
54