| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
|
| 3 |
#include <metal_stdlib> |
| 4 |
#include <simd/simd.h> |
| 5 |
|
| 6 |
using namespace metal; |
| 7 |
|
| 8 |
struct Block |
| 9 |
{ |
| 10 |
uint2 _m0[2]; |
| 11 |
uint2 _m1[2]; |
| 12 |
}; |
| 13 |
|
| 14 |
struct SSBO |
| 15 |
{ |
| 16 |
Block _m0[3]; |
| 17 |
}; |
| 18 |
|
| 19 |
template<typename T, uint A> |
| 20 |
inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) |
| 21 |
{ |
| 22 |
for (uint i = 0; i < A; i++) |
| 23 |
{ |
| 24 |
dst[i] = src[i]; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
template<typename T, uint A> |
| 29 |
inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) |
| 30 |
{ |
| 31 |
for (uint i = 0; i < A; i++) |
| 32 |
{ |
| 33 |
dst[i] = src[i]; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
template<typename T, uint A> |
| 38 |
inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) |
| 39 |
{ |
| 40 |
for (uint i = 0; i < A; i++) |
| 41 |
{ |
| 42 |
dst[i] = src[i]; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
template<typename T, uint A> |
| 47 |
inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) |
| 48 |
{ |
| 49 |
for (uint i = 0; i < A; i++) |
| 50 |
{ |
| 51 |
dst[i] = src[i]; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
template<typename T, uint A> |
| 56 |
inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) |
| 57 |
{ |
| 58 |
for (uint i = 0; i < A; i++) |
| 59 |
{ |
| 60 |
dst[i] = src[i]; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
template<typename T, uint A> |
| 65 |
inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) |
| 66 |
{ |
| 67 |
for (uint i = 0; i < A; i++) |
| 68 |
{ |
| 69 |
dst[i] = src[i]; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
template<typename T, uint A> |
| 74 |
inline void spvArrayCopyFromDeviceToDevice1(device T (&dst)[A], device const T (&src)[A]) |
| 75 |
{ |
| 76 |
for (uint i = 0; i < A; i++) |
| 77 |
{ |
| 78 |
dst[i] = src[i]; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
template<typename T, uint A> |
| 83 |
inline void spvArrayCopyFromConstantToDevice1(device T (&dst)[A], constant T (&src)[A]) |
| 84 |
{ |
| 85 |
for (uint i = 0; i < A; i++) |
| 86 |
{ |
| 87 |
dst[i] = src[i]; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
template<typename T, uint A> |
| 92 |
inline void spvArrayCopyFromStackToDevice1(device T (&dst)[A], thread const T (&src)[A]) |
| 93 |
{ |
| 94 |
for (uint i = 0; i < A; i++) |
| 95 |
{ |
| 96 |
dst[i] = src[i]; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
template<typename T, uint A> |
| 101 |
inline void spvArrayCopyFromThreadGroupToDevice1(device T (&dst)[A], threadgroup const T (&src)[A]) |
| 102 |
{ |
| 103 |
for (uint i = 0; i < A; i++) |
| 104 |
{ |
| 105 |
dst[i] = src[i]; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
template<typename T, uint A> |
| 110 |
inline void spvArrayCopyFromDeviceToStack1(thread T (&dst)[A], device const T (&src)[A]) |
| 111 |
{ |
| 112 |
for (uint i = 0; i < A; i++) |
| 113 |
{ |
| 114 |
dst[i] = src[i]; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
template<typename T, uint A> |
| 119 |
inline void spvArrayCopyFromDeviceToThreadGroup1(threadgroup T (&dst)[A], device const T (&src)[A]) |
| 120 |
{ |
| 121 |
for (uint i = 0; i < A; i++) |
| 122 |
{ |
| 123 |
dst[i] = src[i]; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
kernel void main0(device SSBO& ssbo [[buffer(0)]], constant SSBO& ubo [[buffer(1)]]) |
| 128 |
{ |
| 129 |
threadgroup uint2 _18[2]; |
| 130 |
spvArrayCopyFromDeviceToDevice1(ssbo._m0[0u]._m0, ssbo._m0[0u]._m1); |
| 131 |
spvArrayCopyFromConstantToDevice1(ssbo._m0[0u]._m0, ubo._m0[0u]._m1); |
| 132 |
uint2 _24[2]; |
| 133 |
spvArrayCopyFromStackToDevice1(ssbo._m0[0u]._m0, _24); |
| 134 |
spvArrayCopyFromThreadGroupToDevice1(ssbo._m0[0u]._m0, _18); |
| 135 |
spvArrayCopyFromDeviceToThreadGroup1(_18, ssbo._m0[0u]._m1); |
| 136 |
spvArrayCopyFromDeviceToStack1(_24, ssbo._m0[0u]._m1); |
| 137 |
spvArrayCopyFromConstantToThreadGroup1(_18, ubo._m0[0u]._m1); |
| 138 |
spvArrayCopyFromConstantToStack1(_24, ubo._m0[0u]._m1); |
| 139 |
} |
| 140 |
|