| 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 Data |
| 9 |
{ |
| 10 |
float a; |
| 11 |
float b; |
| 12 |
}; |
| 13 |
|
| 14 |
constant float X_tmp [[function_constant(0)]]; |
| 15 |
constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; |
| 16 |
|
| 17 |
struct Data_1 |
| 18 |
{ |
| 19 |
float a; |
| 20 |
float b; |
| 21 |
}; |
| 22 |
|
| 23 |
struct SSBO |
| 24 |
{ |
| 25 |
Data_1 outdata[1]; |
| 26 |
}; |
| 27 |
|
| 28 |
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u); |
| 29 |
|
| 30 |
template<typename T, uint A> |
| 31 |
inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) |
| 32 |
{ |
| 33 |
for (uint i = 0; i < A; i++) |
| 34 |
{ |
| 35 |
dst[i] = src[i]; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
template<typename T, uint A> |
| 40 |
inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) |
| 41 |
{ |
| 42 |
for (uint i = 0; i < A; i++) |
| 43 |
{ |
| 44 |
dst[i] = src[i]; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
template<typename T, uint A> |
| 49 |
inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) |
| 50 |
{ |
| 51 |
for (uint i = 0; i < A; i++) |
| 52 |
{ |
| 53 |
dst[i] = src[i]; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
template<typename T, uint A> |
| 58 |
inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) |
| 59 |
{ |
| 60 |
for (uint i = 0; i < A; i++) |
| 61 |
{ |
| 62 |
dst[i] = src[i]; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
template<typename T, uint A> |
| 67 |
inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) |
| 68 |
{ |
| 69 |
for (uint i = 0; i < A; i++) |
| 70 |
{ |
| 71 |
dst[i] = src[i]; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
template<typename T, uint A> |
| 76 |
inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) |
| 77 |
{ |
| 78 |
for (uint i = 0; i < A; i++) |
| 79 |
{ |
| 80 |
dst[i] = src[i]; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
template<typename T, uint A> |
| 85 |
inline void spvArrayCopyFromDeviceToDevice1(device T (&dst)[A], device const T (&src)[A]) |
| 86 |
{ |
| 87 |
for (uint i = 0; i < A; i++) |
| 88 |
{ |
| 89 |
dst[i] = src[i]; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
template<typename T, uint A> |
| 94 |
inline void spvArrayCopyFromConstantToDevice1(device T (&dst)[A], constant T (&src)[A]) |
| 95 |
{ |
| 96 |
for (uint i = 0; i < A; i++) |
| 97 |
{ |
| 98 |
dst[i] = src[i]; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
template<typename T, uint A> |
| 103 |
inline void spvArrayCopyFromStackToDevice1(device T (&dst)[A], thread const T (&src)[A]) |
| 104 |
{ |
| 105 |
for (uint i = 0; i < A; i++) |
| 106 |
{ |
| 107 |
dst[i] = src[i]; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
template<typename T, uint A> |
| 112 |
inline void spvArrayCopyFromThreadGroupToDevice1(device T (&dst)[A], threadgroup const T (&src)[A]) |
| 113 |
{ |
| 114 |
for (uint i = 0; i < A; i++) |
| 115 |
{ |
| 116 |
dst[i] = src[i]; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
template<typename T, uint A> |
| 121 |
inline void spvArrayCopyFromDeviceToStack1(thread T (&dst)[A], device const T (&src)[A]) |
| 122 |
{ |
| 123 |
for (uint i = 0; i < A; i++) |
| 124 |
{ |
| 125 |
dst[i] = src[i]; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
template<typename T, uint A> |
| 130 |
inline void spvArrayCopyFromDeviceToThreadGroup1(threadgroup T (&dst)[A], device const T (&src)[A]) |
| 131 |
{ |
| 132 |
for (uint i = 0; i < A; i++) |
| 133 |
{ |
| 134 |
dst[i] = src[i]; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) |
| 139 |
{ |
| 140 |
Data _25[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; |
| 141 |
|
| 142 |
Data _31[2] = { Data{ X, 2.0 }, Data{ 3.0, 5.0 } }; |
| 143 |
Data data2[2]; |
| 144 |
spvArrayCopyFromStackToStack1(data2, _31); |
| 145 |
_53.outdata[gl_WorkGroupID.x].a = _25[gl_LocalInvocationID.x].a + data2[gl_LocalInvocationID.x].a; |
| 146 |
_53.outdata[gl_WorkGroupID.x].b = _25[gl_LocalInvocationID.x].b + data2[gl_LocalInvocationID.x].b; |
| 147 |
} |
| 148 |
|