The NVIDIA Direct Compute programming guide lists some best practices for memory management on the GPU. One tip they give on page 8 ("Structured Buffers") is to use a 'structure of arrays' (SOA) layout rather than the typical 'array of structures' (AOS) one:

struct Particle {     
    float4 position;    
    float4 velocity;
RWStructuredBuffer<Particle> particles;


struct Particles {     
    RWStructuredBuffer<float4> position;    
    RWStructuredBuffer<float4> velocity;
Particles particles;

(At least, as far as I understand)

AOS layout seems to be the most popular (maybe even only) way to manage lists of stuff in the compute shader.

I haven't found a way to implement SOA from the CPU side, Unity's ComputeShader.cs doesn't have a set struct function or similar. Does Unity expose a way to set SOA structs from the CPU side at all?



You must log in to answer this question.

Browse other questions tagged .