#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

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

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
    T elements[Num ? Num : 1];
    
    thread T& operator [] (size_t pos) thread
    {
        return elements[pos];
    }
    constexpr const thread T& operator [] (size_t pos) const thread
    {
        return elements[pos];
    }
    
    device T& operator [] (size_t pos) device
    {
        return elements[pos];
    }
    constexpr const device T& operator [] (size_t pos) const device
    {
        return elements[pos];
    }
    
    constexpr const constant T& operator [] (size_t pos) const constant
    {
        return elements[pos];
    }
    
    threadgroup T& operator [] (size_t pos) threadgroup
    {
        return elements[pos];
    }
    constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
    {
        return elements[pos];
    }
};

struct Foo0
{
    float a;
};

struct Foo1
{
    Foo0 a;
};

struct Foo2
{
    Foo1 a;
    float weight;
};

struct Foo0_1
{
    float a;
};

struct Foo1_1
{
    Foo0_1 a;
};

struct Foo2_1
{
    Foo1_1 a;
    float weight;
};

struct SSBO
{
    Foo2_1 outputs[1];
};

constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(8u, 8u, 1u);

kernel void main0(device SSBO& _53 [[buffer(0)]], uint gl_LocalInvocationIndex [[thread_index_in_threadgroup]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]])
{
    threadgroup spvUnsafeArray<Foo2, 64> coeffs;
    coeffs[gl_LocalInvocationIndex] = Foo2{ Foo1{ Foo0{ 0.0 } }, 0.0 };
    threadgroup_barrier(mem_flags::mem_threadgroup);
    if (gl_LocalInvocationIndex == 0u)
    {
        _53.outputs[gl_WorkGroupID.x].a.a.a = coeffs[0].a.a.a;
        _53.outputs[gl_WorkGroupID.x].weight = coeffs[0].weight;
    }
}

