- December 5, 2009 at 4:32 pm #30000
I went to Apple Tech Talk yesterday and the evangelist ( Allan Schaffer ) mentioned something very interesting about data alignment in interleaved array.
It seems vertices data need to 4 bytes aligned or else the driver will have to pad the incoming stream of vertices on drawArray or drawElements.
} vertex_t ;
But instead pre-pad like this:
} vertex_t ;
It doesn’t really make sense to me because whether you declare an array of size 4 with C, the strive you declare later with the GL vertex/norma/texture pointers will hide it from the GPU anyway. And as far as I know the GPU does copy the data anyway.
I though that maybe the GPU/driver can perform a batch memcpy if the data is properly aligned but then we increase the bandwidth consumption and the slight improvement is lost.
Can anyone elaborate on this recommendation ?
Is it still valid in a shader renderer if we upload the data with glVertexAttribPointer ?
nicolasbol 2009-12-05 16:35:35December 9, 2009 at 10:27 am #33583
Apple support the iPhone themselves so questions are better directed at them, but I believe this is a requirement for the iPhone drivers although it is not necessary for other MBX or SGX platforms that we directly support.
Unfortunately, on the iPhone reducing the size of your vertex data can be quite important for performance so padding seems undesirable, but is necessary. As I say, Apple support the platform themselves so it may be better to approach them.December 10, 2009 at 12:01 am #33584
If only they were as outstanding as you are answering questions it would be perfect ! No kidding I can get someone to look at my question within a day here but If I send it to Apple I’m not even sure they will open my email.
I’ll try anyway, thanks GordonDecember 10, 2009 at 4:38 pm #33585
I don’t think it is required to have your vertex data 4 bytes aligned on the iPhone …. it used to make no difference but I think they made some changes with 3.x releases and now it does matter in terms of performance.
The older iPhone (pre 3gs) for some reason always copies vertex data around regardless if you are using VBOs or not and thus what Gordon said about reducing the size of your vertex data is from my experience directly related to that copy being performed in the driver.
So switching to using shorts, minimizing vertex size etc â€¦ has nothing to do with the GPU itself ( in fact using shorts will slow things down a bit in terms of GPU processing) but all of it is done to minimize the cost of the CPU preprocessing step that is applied to all vertex streams.
Look here for some extended discussions regarding this very issue:December 10, 2009 at 5:40 pm #33586
I’ve seen posts on the oolong group complaining about crashes if POD data wasn’t aligned, although I haven’t seen it myself – I may be incorrect. Alignment options will be available in the next release of the SDK so it shouldn’t be a problem. Unaligned data does harm performance, like warmi says. As always, profiling both ways is probably wise.