xref: /aosp_15_r20/external/skia/tests/sksl/compute/DesaturateFunction.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 Inputs {
8    uint3 sk_GlobalInvocationID;
9};
10struct Globals {
11    texture2d<half, access::read> src;
12    texture2d<half, access::write> dest;
13};
14void desaturate_vTT(Inputs _in, texture2d<half, access::read> src, texture2d<half, access::write> dest) {
15    half4 color = src.read(_in.sk_GlobalInvocationID.xy);
16    color.xyz = half3(dot(color.xyz, half3(0.22h, 0.67h, 0.11h)));
17    dest.write(color, _in.sk_GlobalInvocationID.xy);
18}
19kernel void computeMain(uint3 sk_GlobalInvocationID [[thread_position_in_grid]], texture2d<half, access::read> src [[texture(0)]], texture2d<half, access::write> dest [[texture(1)]]) {
20    Globals _globals{src, dest};
21    (void)_globals;
22    Inputs _in = { sk_GlobalInvocationID };
23    if (_in.sk_GlobalInvocationID.x < _globals.src.get_width() && _in.sk_GlobalInvocationID.y < _globals.src.get_height()) {
24        desaturate_vTT(_in, _globals.src, _globals.dest);
25    }
26    return;
27}
28