So i am in having a little of a problem with burst that i still didn't find a solution. This is a simplified version of my current problem, the code have more stuff that is unrelated to the problem: In my burst i am using a NativeArray<MyStruct>: Code (CSharp): public struct MyStruct{ public enum Types{ UseMatrix1, UseMatrix2, UseMatrix3 } public Types myMatrix; } Inside the Job(Burst).Execute() there is a switch(myMatrix), in all cases it will use a array of length = 9. Here are my arrays: Code (CSharp): public static readonly float[] Matrix1= { -1, -1, -1, -1, 9, -1, -1, -1, -1 }; public static readonly float[] Matrix2= { -1, -1, -1, -1, 8, -1, -1, -1, -1 }; public static readonly float[] Matrix3= { .2f, .25f, .2f, .25f, 0, .25f, .2f, .125f, .2f}; If i call the matrix inside the burst, it works! But it feel wrong since i am using static variables. If inside of MyStruct is used a NativeArray<float> for the matrix, MyStruct becomes non blittable. And if set the array as fixed, i will need to set the struct as unsafe, so I prefer to not do this. The only other solution i could think of is creating a struct like: Code (CSharp): float a1, a2, a3; float b1, b2, b3; float c1, c2, c3; And creating functions to get the index, but this still look like a hack. Just wondering if I am missing something obvious for this simple problem?
I know this is old, but is there a way to do this for arrays of a compile-time constant length? For example, I'd like to precompute some values like this... Code (CSharp): const int TESSELATION = 25; private static readonly float2[] arcCosSin = computeArcCosSin(); private static float2[] computeArcCosSin() { float2[] result = new float2[TESSELATION]; for(int i = 0; i < TESSELATION; ++i) { math.sincos(i * 1f / (TESSELATION - 1) * math.PI/2, out float s, out float c); result[i] = new float2(c, s); } return result; } Then I can change the TESSELATION and the array will update. But the whole array is essentially a compile-time constant. (I guess I can use NativeArray with Allocator.Persistent and then make the caller know about this implementation detail, or I hardcode the values. Neither one is acceptable, IMO, especially if the use case is more advanced than just this).
Is something like this helpful? https://docs.unity.cn/Packages/com....Unity.Collections.AllocatorManager.Range.html I hope so, as you've been a HUGE help with your sermon on shader variants! Thank you!!!
I suspect they've created Blocks as a collection type that's pointer friendly for animation curves to be easily LUT'd... if/when they get around to making a DOTS animation system