| 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 |
struct Sub |
| 48 |
{ |
| 49 |
float4 f[2]; |
| 50 |
float4 f2[2]; |
| 51 |
float3 f3[2]; |
| 52 |
float4 f4[2]; |
| 53 |
}; |
| 54 |
|
| 55 |
struct SSBO |
| 56 |
{ |
| 57 |
Sub sub[2]; |
| 58 |
}; |
| 59 |
|
| 60 |
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u); |
| 61 |
|
| 62 |
kernel void main0(device SSBO& _27 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]]) |
| 63 |
{ |
| 64 |
spvUnsafeArray<float, 2> _155; |
| 65 |
_155[0] = _27.sub[gl_WorkGroupID.x].f[0].x; |
| 66 |
_155[1] = _27.sub[gl_WorkGroupID.x].f[1].x; |
| 67 |
spvUnsafeArray<float2, 2> _156; |
| 68 |
_156[0] = _27.sub[gl_WorkGroupID.x].f2[0].xy; |
| 69 |
_156[1] = _27.sub[gl_WorkGroupID.x].f2[1].xy; |
| 70 |
spvUnsafeArray<float3, 2> _157; |
| 71 |
_157[0] = _27.sub[gl_WorkGroupID.x].f3[0]; |
| 72 |
_157[1] = _27.sub[gl_WorkGroupID.x].f3[1]; |
| 73 |
spvUnsafeArray<float4, 2> _158; |
| 74 |
_158[0] = _27.sub[gl_WorkGroupID.x].f4[0]; |
| 75 |
_158[1] = _27.sub[gl_WorkGroupID.x].f4[1]; |
| 76 |
_155[gl_GlobalInvocationID.x] += 1.0; |
| 77 |
_156[gl_GlobalInvocationID.x] += float2(2.0); |
| 78 |
_157[gl_GlobalInvocationID.x] += float3(3.0); |
| 79 |
_158[gl_GlobalInvocationID.x] += float4(4.0); |
| 80 |
(device float&)_27.sub[gl_WorkGroupID.x].f[0] = _155[0]; |
| 81 |
(device float&)_27.sub[gl_WorkGroupID.x].f[1] = _155[1]; |
| 82 |
(device float2&)_27.sub[gl_WorkGroupID.x].f2[0] = _156[0]; |
| 83 |
(device float2&)_27.sub[gl_WorkGroupID.x].f2[1] = _156[1]; |
| 84 |
_27.sub[gl_WorkGroupID.x].f3[0] = _157[0]; |
| 85 |
_27.sub[gl_WorkGroupID.x].f3[1] = _157[1]; |
| 86 |
_27.sub[gl_WorkGroupID.x].f4[0] = _158[0]; |
| 87 |
_27.sub[gl_WorkGroupID.x].f4[1] = _158[1]; |
| 88 |
(device float&)_27.sub[0].f[0] = _27.sub[0].f[0].x + 5.0; |
| 89 |
(device float2&)_27.sub[0].f2[1] = _27.sub[0].f2[1].xy + float2(5.0); |
| 90 |
} |
| 91 |
|