# The most performant way to organize vertex data on modern GPUs

Say I have a model made up of vertices, each with position, normal, tangent, and texcoord attributes, where triangles are specified by index triples.

If we just focus on the vertex attributes, I'm aware of two broad strategies: the structure of arrays, and the array of structures. I've also heard that the array of structures is preferred because it increases the memory locality (and therefore cache locality) of the attributes for a given vertex.

Is it really the case that this improves performance? The main way I could think that this would come about is by vertex indices that require the rasterizer to acquire vertex data that has long since been evicted from cache. If vertex data access is random like this, then keeping all the attributes for a vertex on the same cache line would certainly make things faster, but is this not an issue that could be mostly mitigated by optimizing the order of triangle specification?

Furthermore, it's my understanding that modern GPUs may be better at unpacking long vectors of the same type, than vectors of structures of many types. Would it then be possible for a structure-of-arrays layout to consistently outperform an array-of-structures layout of the same vertex data, if the index order is optimized?

• Couldn't you simply try it out and see which is fastest for your case? – user1118321 Mar 19 '18 at 2:20
• I would have thought for indexed meshes that array-of-structures would be more efficient as the vertex shader will be fed all vertex attributes so having them grouped together in memory is going to be cache friendlier. – PaulHK Jan 11 at 7:33
• Depending on the data types in structure, vec4s and floats pack together nicely, other types not so well – PaulHK Jan 11 at 7:41
• @user1118321 While individual benchmarking experiments are a commendable practice, there certainly is more long-term value in a broader theoretical discussion and maybe resulting establishment of general practices based on how vertex pulling hardware works. – Christian Rau Feb 26 at 9:31