blob: fa62439319554fb9f147803302fe611fc1e386be [file] [log] [blame]
#include <metal_stdlib>
using namespace metal;
template<typename T, size_t N>
struct tint_array {
const constant T& operator[](size_t i) const constant { return elements[i]; }
device T& operator[](size_t i) device { return elements[i]; }
const device T& operator[](size_t i) const device { return elements[i]; }
thread T& operator[](size_t i) thread { return elements[i]; }
const thread T& operator[](size_t i) const thread { return elements[i]; }
threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
T elements[N];
};
#define TINT_ISOLATE_UB(VOLATILE_NAME) \
volatile bool VOLATILE_NAME = true; \
if (VOLATILE_NAME)
void tint_zero_workgroup_memory(uint local_idx, threadgroup tint_array<tint_array<float3, 256>, 4>* const tint_symbol_1) {
TINT_ISOLATE_UB(tint_volatile_true) for(uint idx = local_idx; (idx < 1024u); idx = (idx + 64u)) {
uint const i_1 = (idx / 256u);
uint const i_2 = (idx % 256u);
(*(tint_symbol_1))[i_1][i_2] = float3(0.0f);
}
threadgroup_barrier(mem_flags::mem_threadgroup);
}
struct Params {
/* 0x0000 */ uint filterDim;
/* 0x0004 */ uint blockDim;
};
struct Flip {
/* 0x0000 */ uint value;
};
uint tint_div(uint lhs, uint rhs) {
return (lhs / select(rhs, 1u, (rhs == 0u)));
}
void tint_symbol_inner(uint3 WorkGroupID, uint3 LocalInvocationID, uint local_invocation_index, threadgroup tint_array<tint_array<float3, 256>, 4>* const tint_symbol_2, const constant Params* const tint_symbol_3, texture2d<float, access::sample> tint_symbol_4, const constant Flip* const tint_symbol_5, sampler tint_symbol_6, texture2d<float, access::write> tint_symbol_7) {
tint_zero_workgroup_memory(local_invocation_index, tint_symbol_2);
uint const filterOffset = tint_div(((*(tint_symbol_3)).filterDim - 1u), 2u);
uint2 const dims = uint2(tint_symbol_4.get_width(0), tint_symbol_4.get_height(0));
uint2 const baseIndex = (((WorkGroupID.xy * uint2((*(tint_symbol_3)).blockDim, 4u)) + (LocalInvocationID.xy * uint2(4u, 1u))) - uint2(filterOffset, 0u));
TINT_ISOLATE_UB(tint_volatile_true_1) for(uint r = 0u; (r < 4u); r = (r + 1u)) {
TINT_ISOLATE_UB(tint_volatile_true_2) for(uint c = 0u; (c < 4u); c = (c + 1u)) {
uint2 loadIndex = (baseIndex + uint2(c, r));
if (((*(tint_symbol_5)).value != 0u)) {
loadIndex = loadIndex.yx;
}
(*(tint_symbol_2))[r][((4u * LocalInvocationID[0]) + c)] = tint_symbol_4.sample(tint_symbol_6, ((float2(loadIndex) + float2(0.25f)) / float2(dims)), level(0.0f)).rgb;
}
}
threadgroup_barrier(mem_flags::mem_threadgroup);
TINT_ISOLATE_UB(tint_volatile_true_3) for(uint r = 0u; (r < 4u); r = (r + 1u)) {
TINT_ISOLATE_UB(tint_volatile_true_4) for(uint c = 0u; (c < 4u); c = (c + 1u)) {
uint2 writeIndex = (baseIndex + uint2(c, r));
if (((*(tint_symbol_5)).value != 0u)) {
writeIndex = writeIndex.yx;
}
uint const center = ((4u * LocalInvocationID[0]) + c);
if ((((center >= filterOffset) && (center < (256u - filterOffset))) && all((writeIndex < dims)))) {
float3 acc = float3(0.0f);
TINT_ISOLATE_UB(tint_volatile_true_5) for(uint f = 0u; (f < (*(tint_symbol_3)).filterDim); f = (f + 1u)) {
uint i = ((center + f) - filterOffset);
acc = (acc + ((1.0f / float((*(tint_symbol_3)).filterDim)) * (*(tint_symbol_2))[r][i]));
}
tint_symbol_7.write(float4(acc, 1.0f), uint2(writeIndex));
}
}
}
}
kernel void tint_symbol(const constant Params* tint_symbol_9 [[buffer(0)]], texture2d<float, access::sample> tint_symbol_10 [[texture(0)]], const constant Flip* tint_symbol_11 [[buffer(1)]], sampler tint_symbol_12 [[sampler(0)]], texture2d<float, access::write> tint_symbol_13 [[texture(1)]], uint3 WorkGroupID [[threadgroup_position_in_grid]], uint3 LocalInvocationID [[thread_position_in_threadgroup]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
threadgroup tint_array<tint_array<float3, 256>, 4> tint_symbol_8;
tint_symbol_inner(WorkGroupID, LocalInvocationID, local_invocation_index, &(tint_symbol_8), tint_symbol_9, tint_symbol_10, tint_symbol_11, tint_symbol_12, tint_symbol_13);
return;
}