Hello community,
I have GPU programming experience (HIP and Cuda), but am new to compute shaders in unity.
The following datastructure on my CPU will create an array of structs. This data structure is mostly good for CPU cash efficiency when all values in the struct are needed simulatiously.
public struct DataStruct
{
public int state;
public float intensity;
public float rho;
public Vector2 u;
}
DataStruct data = new DataStruct[1024]
However on my GPU i would prefer a struct of arrays (warning, c++ styled pseudo code),
template<int N>
struct DataStruct
{
int* state = new int[N];
float* intensity = new float[N];
float* rho = new float[N];
Vector2* u = new Vector2[N];
}
DataStruct data[1024];
How does unity actually interpret my DataStruct in the compute shader? Will it just copy my CPU DataStruct and thus create an array of structs. Or does it convert it to a struct of arrays for coalescent data access?
If it remains an array of struct, what is the best way to create a struct of arrays? As far as i can tell you can’t create structs with arrays in them with dynamic length in c#. The only solution I came up with would be to create one compute buffer for each array.
@ : Why isn’t there a ‘compute shader’ or ‘compute buffer’ tag?