-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBurstFunction.cs
308 lines (270 loc) · 10.9 KB
/
BurstFunction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
using Unity.Burst;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
namespace Vella.Common
{
public interface IBurstOperation
{
}
public interface IBurstFunction<T1, T2, T3, T4, T5, TResult> : IBurstOperation
{
TResult Execute(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
}
public interface IBurstFunction<T1, T2, T3, T4, TResult> : IBurstOperation
{
TResult Execute(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
}
public interface IBurstFunction<T1, T2, T3, TResult> : IBurstOperation
{
TResult Execute(T1 arg1, T2 arg2, T3 arg3);
}
public interface IBurstFunction<T1, T2, TResult> : IBurstOperation
{
TResult Execute(T1 arg1, T2 arg2);
}
public interface IBurstFunction<T1, TResult> : IBurstOperation
{
TResult Execute(T1 arg1);
}
public interface IBurstFunction<TResult> : IBurstOperation
{
TResult Execute();
}
[BurstCompile]
public struct BurstFunction<TFunc, T1, T2, T3, T4, T5, TResult> : IJob
where TFunc : struct, IBurstFunction<T1, T2, T3, T4, T5, TResult>
where T1 : struct
where T2 : struct
where T3 : struct
where T4 : struct
where T5 : struct
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument1Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument2Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument3Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument4Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument5Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
UnsafeUtility.CopyPtrToStructure(Argument1Ptr, out T1 arg1);
UnsafeUtility.CopyPtrToStructure(Argument2Ptr, out T2 arg2);
UnsafeUtility.CopyPtrToStructure(Argument3Ptr, out T3 arg3);
UnsafeUtility.CopyPtrToStructure(Argument4Ptr, out T4 arg4);
UnsafeUtility.CopyPtrToStructure(Argument5Ptr, out T5 arg5);
result = func.Execute(arg1, arg2, arg3, arg4, arg5);
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
{
TResult result = default;
new BurstFunction<TFunc, T1, T2, T3, T4, T5, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
Argument1Ptr = UnsafeUtility.AddressOf(ref arg1),
Argument2Ptr = UnsafeUtility.AddressOf(ref arg2),
Argument3Ptr = UnsafeUtility.AddressOf(ref arg3),
Argument4Ptr = UnsafeUtility.AddressOf(ref arg4),
Argument5Ptr = UnsafeUtility.AddressOf(ref arg5),
}.Run();
return result;
}
}
[BurstCompile]
public struct BurstFunction<TFunc, T1, T2, T3, T4, TResult> : IJob
where TFunc : struct, IBurstFunction<T1, T2, T3, T4, TResult>
where T1 : struct
where T2 : struct
where T3 : struct
where T4 : struct
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument1Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument2Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument3Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument4Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
UnsafeUtility.CopyPtrToStructure(Argument1Ptr, out T1 arg1);
UnsafeUtility.CopyPtrToStructure(Argument2Ptr, out T2 arg2);
UnsafeUtility.CopyPtrToStructure(Argument3Ptr, out T3 arg3);
UnsafeUtility.CopyPtrToStructure(Argument4Ptr, out T4 arg4);
result = func.Execute(arg1, arg2, arg3, arg4);
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
TResult result = default;
new BurstFunction<TFunc, T1, T2, T3, T4, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
Argument1Ptr = UnsafeUtility.AddressOf(ref arg1),
Argument2Ptr = UnsafeUtility.AddressOf(ref arg2),
Argument3Ptr = UnsafeUtility.AddressOf(ref arg3),
Argument4Ptr = UnsafeUtility.AddressOf(ref arg4),
}.Run();
return result;
}
}
[BurstCompile]
public struct BurstFunction<TFunc, T1, T2, T3, TResult> : IJob
where TFunc : struct, IBurstFunction<T1, T2, T3, TResult>
where T1 : struct
where T2 : struct
where T3 : struct
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument1Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument2Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument3Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
UnsafeUtility.CopyPtrToStructure(Argument1Ptr, out T1 arg1);
UnsafeUtility.CopyPtrToStructure(Argument2Ptr, out T2 arg2);
UnsafeUtility.CopyPtrToStructure(Argument3Ptr, out T3 arg3);
result = func.Execute(arg1, arg2, arg3);
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func, T1 arg1, T2 arg2, T3 arg3)
{
TResult result = default;
new BurstFunction<TFunc, T1, T2, T3, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
Argument1Ptr = UnsafeUtility.AddressOf(ref arg1),
Argument2Ptr = UnsafeUtility.AddressOf(ref arg2),
Argument3Ptr = UnsafeUtility.AddressOf(ref arg3),
}.Run();
return result;
}
}
[BurstCompile]
public struct BurstFunction<TFunc, T1, T2, TResult> : IJob
where TFunc : struct, IBurstFunction<T1, T2, TResult>
where T1 : struct
where T2 : struct
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument1Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument2Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
UnsafeUtility.CopyPtrToStructure(Argument1Ptr, out T1 arg1);
UnsafeUtility.CopyPtrToStructure(Argument2Ptr, out T2 arg2);
result = func.Execute(arg1, arg2);
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func, T1 arg1, T2 arg2)
{
TResult result = default;
new BurstFunction<TFunc, T1, T2, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
Argument1Ptr = UnsafeUtility.AddressOf(ref arg1),
Argument2Ptr = UnsafeUtility.AddressOf(ref arg2),
}.Run();
return result;
}
}
[BurstCompile]
public struct BurstFunction<TFunc, T1, TResult> : IJob
where TFunc : struct, IBurstFunction<T1, TResult>
where T1 : struct
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* Argument1Ptr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
UnsafeUtility.CopyPtrToStructure(Argument1Ptr, out T1 arg1);
result = func.Execute(arg1);
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func, T1 arg1)
{
TResult result = default;
new BurstFunction<TFunc, T1, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
Argument1Ptr = UnsafeUtility.AddressOf(ref arg1),
}.Run();
return result;
}
}
[BurstCompile]
public struct BurstFunction<TFunc, TResult> : IJob
where TFunc : struct, IBurstFunction<TResult>
where TResult : struct
{
[NativeDisableUnsafePtrRestriction]
public unsafe void* FunctionPtr;
[NativeDisableUnsafePtrRestriction]
public unsafe void* ResultPtr;
public unsafe void Execute()
{
UnsafeUtility.CopyPtrToStructure(ResultPtr, out TResult result);
UnsafeUtility.CopyPtrToStructure(FunctionPtr, out TFunc func);
result = func.Execute();
UnsafeUtility.CopyStructureToPtr(ref result, ResultPtr);
}
public static unsafe TResult Run(TFunc func)
{
TResult result = default;
new BurstFunction<TFunc, TResult>
{
ResultPtr = UnsafeUtility.AddressOf(ref result),
FunctionPtr = UnsafeUtility.AddressOf(ref func),
}.Run();
return result;
}
}
}