Hi,
Trying to implement something to use in a pipeline where inputs could be math types (mainly float-float4 in this test). Just your thoughts on what I could do here better? Basically I want a struct where [0] might refer to a float2, [1] might be a float3, using a 128 byte buffer. Also no idea when used in a separate op job, how burst will like it. No idea if this would be better using a NativeArray. Iโm no expert, but just looking to expand my knowledge from experts ![]()
public struct Floats
{
fixed byte store[128];
fixed int offset[32];
int remaining;
int pos;
int current;
public void Init()
{
remaining = 128;
pos = 0;
current = 0;
}
public void Set<T>(T someValue) where T : unmanaged
{
var size = sizeof(T);
if (size < remaining)
{
fixed(void* p = &store[current]) *(T*)p = someValue;
current += size;
offset[pos + 1] = offset[pos++] + size;
remaining -= size;
}
}
public T Get<T>(int i) where T : unmanaged
{
fixed (void* f = &store[offset[i]]) return *(T*)f;
}
}