I work with OpenGL4.X .Recently I read this Apple OpenGLES2 doc where it is stated that using interleaved attribute arrays improves performance on IOS mobile devices and is the recommended way (instead of using blocks of attributes).
For those who didn't understand what I mean here is an example:
Block of attributes in a single attribute array:
float vertices[]{
//Triangle vertices:
v0x , v0y , v0z ,
v1x , v1y , v1z ,
v2x , v2y , v2z ,
//Triangle UVs:
uv0s , uv0t ,
uv1s , uv1t ,
uv2s , uv2t ,
//Triangle Normals:
n0x , n0y , n0z ,
n1x , n1y , n1z ,
n2x , n2y , n2z
}
Interleaved attribute array:
float vertices[]{
v0x , v0y , v0z ,
uv0s , uv0t , ////vertex 1 attributes
n0x , n0y , n0z ,
v1x , v1y , v1z ,
uv1s , uv1t , ///vertex 2 attributes
n1x , n1y , n1z ,
v2x , v2y , v2z ,
uv2s , uv2t , ///vertex 3 attributes
n2x , n2y , n2z
}
So my question is : Is it also true for OpenGL running on desktop GPUs ? If yes ,then how big the performance gain can theoretically be ?
Is it also true for OpenGL running on desktop GPUs ?
From Vertex specification wiki page :
As a general rule, you should use interleaved attributes wherever possible. Obviously if you need to change certain attributes and not others, then interleaving the ones that change with those that don't is not a good idea.
how big the performance gain can theoretically be ?
I can't really answer that, but I wouldn't expect huge improvement. The only sure way is to measure.
In order for any optimization to be a performance gain, it must first optimize something that is a performance bottleneck. Unless it is currently a bottleneck, then doing anything about it will not necessarily improve performance.
There is no way to answer your question because any performance gain first depends on whether you are bottlenecked on vertex transfer performance (ie: what this optimizes). Unless you are actually pushing your graphics card so hard that your vertex shader, fragment shader, and CPU issues don't become bottlenecks, this won't matter.
And there's no way to know how much of a gain it is, because different hardware will respond differently. Different situations will respond differently based on how tight the bottleneck is.
Just interleave your attributes. It costs you nothing, requires minimal time or effort, and may be of non-trivial value performance-wise.
The benefit of interleaved attribute arrays is memory locality. This means that all necessary vertex data is located next to each other and could be fetched more efficiently compared to data located in multiple buffers.
Having big number of vertices with many attributes might manifest the difference in performance. The values of big and many should be established by profiling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With