1*c8dee2aaSAndroid Build Coastguard Worker#include <metal_stdlib> 2*c8dee2aaSAndroid Build Coastguard Worker#include <simd/simd.h> 3*c8dee2aaSAndroid Build Coastguard Worker#ifdef __clang__ 4*c8dee2aaSAndroid Build Coastguard Worker#pragma clang diagnostic ignored "-Wall" 5*c8dee2aaSAndroid Build Coastguard Worker#endif 6*c8dee2aaSAndroid Build Coastguard Workerusing namespace metal; 7*c8dee2aaSAndroid Build Coastguard Workerstruct Inputs { 8*c8dee2aaSAndroid Build Coastguard Worker uint3 sk_GlobalInvocationID; 9*c8dee2aaSAndroid Build Coastguard Worker}; 10*c8dee2aaSAndroid Build Coastguard Workerstruct Globals { 11*c8dee2aaSAndroid Build Coastguard Worker texture2d<half, access::read> src; 12*c8dee2aaSAndroid Build Coastguard Worker texture2d<half, access::write> dest; 13*c8dee2aaSAndroid Build Coastguard Worker}; 14*c8dee2aaSAndroid Build Coastguard Workervoid desaturate_vTT(Inputs _in, texture2d<half, access::read> src, texture2d<half, access::write> dest) { 15*c8dee2aaSAndroid Build Coastguard Worker half4 color = src.read(_in.sk_GlobalInvocationID.xy); 16*c8dee2aaSAndroid Build Coastguard Worker color.xyz = half3(dot(color.xyz, half3(0.22h, 0.67h, 0.11h))); 17*c8dee2aaSAndroid Build Coastguard Worker dest.write(color, _in.sk_GlobalInvocationID.xy); 18*c8dee2aaSAndroid Build Coastguard Worker} 19*c8dee2aaSAndroid Build Coastguard Workerkernel void computeMain(uint3 sk_GlobalInvocationID [[thread_position_in_grid]], texture2d<half, access::read> src [[texture(0)]], texture2d<half, access::write> dest [[texture(1)]]) { 20*c8dee2aaSAndroid Build Coastguard Worker Globals _globals{src, dest}; 21*c8dee2aaSAndroid Build Coastguard Worker (void)_globals; 22*c8dee2aaSAndroid Build Coastguard Worker Inputs _in = { sk_GlobalInvocationID }; 23*c8dee2aaSAndroid Build Coastguard Worker if (_in.sk_GlobalInvocationID.x < _globals.src.get_width() && _in.sk_GlobalInvocationID.y < _globals.src.get_height()) { 24*c8dee2aaSAndroid Build Coastguard Worker desaturate_vTT(_in, _globals.src, _globals.dest); 25*c8dee2aaSAndroid Build Coastguard Worker } 26*c8dee2aaSAndroid Build Coastguard Worker return; 27*c8dee2aaSAndroid Build Coastguard Worker} 28