|
| 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 _3 |
| 48 | +{ |
| 49 | + float _m0[4]; |
| 50 | +}; |
| 51 | + |
| 52 | +template<typename T, uint A> |
| 53 | +inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) |
| 54 | +{ |
| 55 | + for (uint i = 0; i < A; i++) |
| 56 | + { |
| 57 | + dst[i] = src[i]; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +template<typename T, uint A> |
| 62 | +inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) |
| 63 | +{ |
| 64 | + for (uint i = 0; i < A; i++) |
| 65 | + { |
| 66 | + dst[i] = src[i]; |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +template<typename T, uint A> |
| 71 | +inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) |
| 72 | +{ |
| 73 | + for (uint i = 0; i < A; i++) |
| 74 | + { |
| 75 | + dst[i] = src[i]; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +template<typename T, uint A> |
| 80 | +inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) |
| 81 | +{ |
| 82 | + for (uint i = 0; i < A; i++) |
| 83 | + { |
| 84 | + dst[i] = src[i]; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +template<typename T, uint A> |
| 89 | +inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) |
| 90 | +{ |
| 91 | + for (uint i = 0; i < A; i++) |
| 92 | + { |
| 93 | + dst[i] = src[i]; |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +template<typename T, uint A> |
| 98 | +inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) |
| 99 | +{ |
| 100 | + for (uint i = 0; i < A; i++) |
| 101 | + { |
| 102 | + dst[i] = src[i]; |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +template<typename T, uint A> |
| 107 | +inline void spvArrayCopyFromDeviceToDevice1(device T (&dst)[A], device const T (&src)[A]) |
| 108 | +{ |
| 109 | + for (uint i = 0; i < A; i++) |
| 110 | + { |
| 111 | + dst[i] = src[i]; |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +template<typename T, uint A> |
| 116 | +inline void spvArrayCopyFromConstantToDevice1(device T (&dst)[A], constant T (&src)[A]) |
| 117 | +{ |
| 118 | + for (uint i = 0; i < A; i++) |
| 119 | + { |
| 120 | + dst[i] = src[i]; |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +template<typename T, uint A> |
| 125 | +inline void spvArrayCopyFromStackToDevice1(device T (&dst)[A], thread const T (&src)[A]) |
| 126 | +{ |
| 127 | + for (uint i = 0; i < A; i++) |
| 128 | + { |
| 129 | + dst[i] = src[i]; |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +template<typename T, uint A> |
| 134 | +inline void spvArrayCopyFromThreadGroupToDevice1(device T (&dst)[A], threadgroup const T (&src)[A]) |
| 135 | +{ |
| 136 | + for (uint i = 0; i < A; i++) |
| 137 | + { |
| 138 | + dst[i] = src[i]; |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +template<typename T, uint A> |
| 143 | +inline void spvArrayCopyFromDeviceToStack1(thread T (&dst)[A], device const T (&src)[A]) |
| 144 | +{ |
| 145 | + for (uint i = 0; i < A; i++) |
| 146 | + { |
| 147 | + dst[i] = src[i]; |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +template<typename T, uint A> |
| 152 | +inline void spvArrayCopyFromDeviceToThreadGroup1(threadgroup T (&dst)[A], device const T (&src)[A]) |
| 153 | +{ |
| 154 | + for (uint i = 0; i < A; i++) |
| 155 | + { |
| 156 | + dst[i] = src[i]; |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +fragment void main0() |
| 161 | +{ |
| 162 | + spvUnsafeArray<float, 4> _20; |
| 163 | + _20[0u] = 0.0; |
| 164 | + _20[1u] = 0.0; |
| 165 | + _20[2u] = 0.0; |
| 166 | + _20[3u] = 0.0; |
| 167 | + _3 _19; |
| 168 | + spvArrayCopyFromStackToStack1(_19._m0, _20.elements); |
| 169 | +} |
| 170 | + |
0 commit comments