#pragma clang diagnostic ignored "-Wmissing-prototypes"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

// Returns 2D texture coords corresponding to 1D texel buffer coords
static inline __attribute__((always_inline))
uint2 spvTexelBufferCoord(uint tc)
{
    return uint2(tc % 4096, tc / 4096);
}

struct cb5_struct
{
    float4 _m0[5];
};

kernel void main0(constant cb5_struct& cb0_5 [[buffer(0)]], texture2d<uint, access::write> u0 [[texture(0)]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
{
    uint _41 = uint(int(gl_LocalInvocationID.x) << 4) >> 2u;
    uint4 _50 = as_type<uint4>(cb0_5._m0[uint(int(gl_LocalInvocationID.x)) + 1u]);
    u0.write(_50.xxxx, spvTexelBufferCoord(_41));
    u0.write(_50.yyyy, spvTexelBufferCoord((_41 + 1u)));
    u0.write(_50.zzzz, spvTexelBufferCoord((_41 + 2u)));
    u0.write(_50.wwww, spvTexelBufferCoord((_41 + 3u)));
}

