2021-07-05 17:18:16 +00:00
|
|
|
#include <metal_stdlib>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
struct Params {
|
|
|
|
/* 0x0000 */ uint filterDim;
|
|
|
|
/* 0x0004 */ uint blockDim;
|
|
|
|
};
|
2022-02-09 23:55:51 +00:00
|
|
|
|
2021-07-05 17:18:16 +00:00
|
|
|
struct Flip {
|
|
|
|
/* 0x0000 */ uint value;
|
|
|
|
};
|
2022-02-09 23:55:51 +00:00
|
|
|
|
2021-07-05 17:18:16 +00:00
|
|
|
struct tint_array_wrapper_1 {
|
|
|
|
float3 arr[256];
|
|
|
|
};
|
2022-02-09 23:55:51 +00:00
|
|
|
|
2021-07-05 17:18:16 +00:00
|
|
|
struct tint_array_wrapper {
|
|
|
|
tint_array_wrapper_1 arr[4];
|
|
|
|
};
|
|
|
|
|
2021-10-28 15:00:39 +00:00
|
|
|
void tint_symbol_inner(uint3 WorkGroupID, uint3 LocalInvocationID, uint local_invocation_index, threadgroup tint_array_wrapper* const tint_symbol_1, const constant Params* const tint_symbol_2, texture2d<float, access::sample> tint_symbol_3, const constant Flip* const tint_symbol_4, sampler tint_symbol_5, texture2d<float, access::write> tint_symbol_6) {
|
2021-07-30 14:08:06 +00:00
|
|
|
for(uint idx = local_invocation_index; (idx < 1024u); idx = (idx + 64u)) {
|
|
|
|
uint const i_1 = (idx / 256u);
|
|
|
|
uint const i_2 = (idx % 256u);
|
2021-08-04 22:15:28 +00:00
|
|
|
(*(tint_symbol_1)).arr[i_1].arr[i_2] = float3();
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
2021-10-28 15:00:39 +00:00
|
|
|
uint const filterOffset = (((*(tint_symbol_2)).filterDim - 1u) / 2u);
|
|
|
|
int2 const dims = int2(tint_symbol_3.get_width(0), tint_symbol_3.get_height(0));
|
|
|
|
int2 const baseIndex = as_type<int2>((as_type<uint2>(int2(((uint3(WorkGroupID).xy * uint2((*(tint_symbol_2)).blockDim, 4u)) + (uint3(LocalInvocationID).xy * uint2(4u, 1u))))) - as_type<uint2>(int2(int(filterOffset), 0))));
|
2021-07-08 21:23:33 +00:00
|
|
|
for(uint r = 0u; (r < 4u); r = (r + 1u)) {
|
|
|
|
for(uint c = 0u; (c < 4u); c = (c + 1u)) {
|
2021-07-30 18:59:06 +00:00
|
|
|
int2 loadIndex = as_type<int2>((as_type<uint2>(baseIndex) + as_type<uint2>(int2(int(c), int(r)))));
|
2021-10-28 15:00:39 +00:00
|
|
|
if (((*(tint_symbol_4)).value != 0u)) {
|
2021-10-20 16:12:33 +00:00
|
|
|
loadIndex = int2(loadIndex).yx;
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
2021-10-28 15:00:39 +00:00
|
|
|
(*(tint_symbol_1)).arr[r].arr[((4u * LocalInvocationID[0]) + c)] = float4(tint_symbol_3.sample(tint_symbol_5, ((float2(loadIndex) + float2(0.25f, 0.25f)) / float2(dims)), level(0.0f))).rgb;
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
threadgroup_barrier(mem_flags::mem_threadgroup);
|
2021-07-08 21:23:33 +00:00
|
|
|
for(uint r = 0u; (r < 4u); r = (r + 1u)) {
|
|
|
|
for(uint c = 0u; (c < 4u); c = (c + 1u)) {
|
2021-07-30 18:59:06 +00:00
|
|
|
int2 writeIndex = as_type<int2>((as_type<uint2>(baseIndex) + as_type<uint2>(int2(int(c), int(r)))));
|
2021-10-28 15:00:39 +00:00
|
|
|
if (((*(tint_symbol_4)).value != 0u)) {
|
2021-10-20 16:12:33 +00:00
|
|
|
writeIndex = int2(writeIndex).yx;
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
2021-10-20 16:12:33 +00:00
|
|
|
uint const center = ((4u * LocalInvocationID[0]) + c);
|
2021-07-08 21:23:33 +00:00
|
|
|
if ((((center >= filterOffset) && (center < (256u - filterOffset))) && all((writeIndex < dims)))) {
|
|
|
|
float3 acc = float3(0.0f, 0.0f, 0.0f);
|
2021-10-28 15:00:39 +00:00
|
|
|
for(uint f = 0u; (f < (*(tint_symbol_2)).filterDim); f = (f + 1u)) {
|
2021-07-08 21:23:33 +00:00
|
|
|
uint i = ((center + f) - filterOffset);
|
2021-10-28 15:00:39 +00:00
|
|
|
acc = (acc + ((1.0f / float((*(tint_symbol_2)).filterDim)) * (*(tint_symbol_1)).arr[r].arr[i]));
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
2021-10-28 15:00:39 +00:00
|
|
|
tint_symbol_6.write(float4(acc, 1.0f), uint2(writeIndex));
|
2021-07-05 17:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-04 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:00:39 +00:00
|
|
|
kernel void tint_symbol(const constant Params* tint_symbol_8 [[buffer(0)]], texture2d<float, access::sample> tint_symbol_9 [[texture(0)]], const constant Flip* tint_symbol_10 [[buffer(1)]], sampler tint_symbol_11 [[sampler(0)]], texture2d<float, access::write> tint_symbol_12 [[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_wrapper tint_symbol_7;
|
|
|
|
tint_symbol_inner(WorkGroupID, LocalInvocationID, local_invocation_index, &(tint_symbol_7), tint_symbol_8, tint_symbol_9, tint_symbol_10, tint_symbol_11, tint_symbol_12);
|
2021-07-05 17:18:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|