Interleaving VBOs

Hey , i have a Question regarding interleaving VBO’s . Currently i am using glMap to map the buffer and copy the data into the buffer. At the moment i have a struct called VertexData looking something along the lines:


struct VertexData
{
   vec3 position;
   vec3 normal;
   vec2 uv;
   .....
}


Here is the possible alternate variant of the vertexdata structure


struct VertexData
{
  vector<vec3> positions;
  vector<vec3> normals;
  vector<vec2> uvs;
  .....
}

So the VBO layout is something like VertexData[0],VertexData[1],VertexData[n]. My Question is if i am going to notice (or will be there) any significant performance boost if the data layout is something like VertexPositions[0-n],VertexNormals[0-n],VertexUV[0-n] … etc. As i understand both methods are type of interleaving the data in the buffer. Does it matter which layout i use ?
Thanks in advance

The first method is going to be faster because the GPU will be able to fetch an entire vertex from a contiguous region of memory.

So the one i am using now


struct VertexData
{
   vec3 position;
   vec3 normal;
   vec2 uv;
   .....
}

Yes, the one you are using now. Please see http://http.developer.nvidia.com/GPUGems/gpugems_ch28.html for more info:

Access vertex data in a relatively sequential manner. Modern GPUs cache memory accesses when fetching vertices. As in any memory hierarchy, spatial locality of reference helps maximize hits in the cache, thus reducing bandwidth requirements.

All this is assuming that vertex fetching is actually a measurable bottleneck in your program, of course, but as a general rule the way you are doing it now is preferred.

A counterpoint is that if the vertex data isn’t static, interleaved attributes may increase the cost of uploads, as you’ll effectively have to upload all of the attributes even if only some of them were modified.

A related issue is that manipulating vertex data on the CPU will typically have worse locality with interleaved attributes because iterating over the vertices will end up reading and caching all of the attributes, not just the ones which are actually used.

But for static data, interleaved attributes will typically be better (and at least no worse) than using a separate region for each attribute.