| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
#pragma clang diagnostic ignored "-Wmissing-braces" |
| 3 |
|
| 4 |
#include <metal_stdlib> |
| 5 |
#include <simd/simd.h> |
| 6 |
|
| 7 |
using namespace metal; |
| 8 |
|
| 9 |
template<typename T, size_t Num> |
| 10 |
struct spvUnsafeArray |
| 11 |
{ |
| 12 |
T elements[Num ? Num : 1]; |
| 13 |
|
| 14 |
thread T& operator [] (size_t pos) thread |
| 15 |
{ |
| 16 |
return elements[pos]; |
| 17 |
} |
| 18 |
constexpr const thread T& operator [] (size_t pos) const thread |
| 19 |
{ |
| 20 |
return elements[pos]; |
| 21 |
} |
| 22 |
|
| 23 |
device T& operator [] (size_t pos) device |
| 24 |
{ |
| 25 |
return elements[pos]; |
| 26 |
} |
| 27 |
constexpr const device T& operator [] (size_t pos) const device |
| 28 |
{ |
| 29 |
return elements[pos]; |
| 30 |
} |
| 31 |
|
| 32 |
constexpr const constant T& operator [] (size_t pos) const constant |
| 33 |
{ |
| 34 |
return elements[pos]; |
| 35 |
} |
| 36 |
|
| 37 |
threadgroup T& operator [] (size_t pos) threadgroup |
| 38 |
{ |
| 39 |
return elements[pos]; |
| 40 |
} |
| 41 |
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup |
| 42 |
{ |
| 43 |
return elements[pos]; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
constant spvUnsafeArray<float4, 2> _20 = spvUnsafeArray<float4, 2>({ float4(10.0), float4(20.0) }); |
| 48 |
|
| 49 |
struct main0_out |
| 50 |
{ |
| 51 |
float4 gl_Position [[position]]; |
| 52 |
}; |
| 53 |
|
| 54 |
struct main0_in |
| 55 |
{ |
| 56 |
float4 vInput0 [[attribute(0)]]; |
| 57 |
float4 vInput1 [[attribute(1)]]; |
| 58 |
}; |
| 59 |
|
| 60 |
static inline __attribute__((always_inline)) |
| 61 |
spvUnsafeArray<float4, 2> test() |
| 62 |
{ |
| 63 |
return _20; |
| 64 |
} |
| 65 |
|
| 66 |
static inline __attribute__((always_inline)) |
| 67 |
spvUnsafeArray<float4, 2> test2(thread float4& vInput0, thread float4& vInput1) |
| 68 |
{ |
| 69 |
spvUnsafeArray<float4, 2> foobar; |
| 70 |
foobar[0] = vInput0; |
| 71 |
foobar[1] = vInput1; |
| 72 |
return foobar; |
| 73 |
} |
| 74 |
|
| 75 |
vertex main0_out main0(main0_in in [[stage_in]]) |
| 76 |
{ |
| 77 |
main0_out out = {}; |
| 78 |
out.gl_Position = test()[0] + test2(in.vInput0, in.vInput1)[1]; |
| 79 |
return out; |
| 80 |
} |
| 81 |
|