SPIRV-Cross/reference/shaders-msl-no-opt/asm/comp/variable-pointers.asm.comp
2019-09-24 14:35:25 -04:00

114 lines
2.4 KiB
Plaintext

#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 foo
{
spvUnsafeArray<int, 128> a;
uint b;
float2 c;
};
struct bar
{
int d;
};
struct baz
{
spvUnsafeArray<int, 128> e;
};
static inline __attribute__((always_inline))
device int* select_buffer(device foo& buf, device baz& buf2, constant bar& cb)
{
return (cb.d != 0) ? &buf.a[0u] : &buf2.e[0u];
}
static inline __attribute__((always_inline))
device int* select_buffer_null(device foo& buf, constant bar& cb)
{
return (cb.d != 0) ? &buf.a[0u] : nullptr;
}
static inline __attribute__((always_inline))
threadgroup int* select_tgsm(constant bar& cb, threadgroup int (&tgsm)[128])
{
return (cb.d != 0) ? &tgsm[0u] : nullptr;
}
kernel void main0(device foo& buf [[buffer(0)]], constant bar& cb [[buffer(1)]], device baz& buf2 [[buffer(2)]])
{
threadgroup int tgsm[128];
device int* sbuf = select_buffer(buf, buf2, cb);
device int* sbuf2 = select_buffer_null(buf, cb);
threadgroup int* stgsm = select_tgsm(cb, tgsm);
threadgroup int* cur = stgsm;
device int* _73;
_73 = &buf.a[0u];
threadgroup int* _76;
int _77;
for (;;)
{
_76 = cur;
_77 = *_73;
if (_77 != 0)
{
int _81 = *_76;
int _82 = _77 + _81;
*_73 = _82;
*_76 = _82;
cur = &_76[1u];
_73 = &_73[1u];
continue;
}
else
{
break;
}
}
}