Vertex Buffers, Interleaved or separate?

10ef9dd08646b01d3f27aadf9d33152d
0
Vereor 101 Dec 16, 2011 at 07:05 opengl performance pipeline shadows vertex

In my current OpenGL-based game I’m using the approach of having different vertex formats for different purposes, e.g, my TerrainVertex has Position,Position2,Normal,Data1,Data2 , my ModelVertex has Position,TexCoords,Normal.

However, more and more I see examples of people using independent buffers of data for the different attributes, eg, one buffer for Position, one buffer for TexCoord.

My question; is the reason why people choose multiple independent buffers a performance one, or an ease-of-use one?

I know that using only the Position buffer for geometry to be rendered from a lights perspective (for shadow mapping, no texcoords needed etc) can save on the amount of data that the GPU has to work with for that specific operation, but is there a performance hit for binding 5 independent buffers per object to be drawn?

I currently have up to around 600 VBO’s being drawn at one time (large scale chunk-based terrain) and I’m facing the task of rendering all that geometry again in order to generate a shadow map which will bring my frame rate below acceptable levels, so I’m trying to decide if splitting my VBO’s into one buffer per attribute will be better in the long run or not.

Thanks

5 Replies

Please log in or register to post a reply.

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 Dec 16, 2011 at 09:22

Traditionally people recommend using interleaved arrays. I know of one architecture where that would be the worst possible choice though, so if you care, you’ll just have to benchmark and see what works.

Personally I’ve always kept them separate, and I don’t think that causes a major performance hit.

6837d514b487de395be51432d9cdd078
0
TheNut 179 Dec 16, 2011 at 12:42

I personally separate my buffers as well, especially when I deal with dynamic VBOs. I do this mainly because I like the flexibility of this organizational structure, although I do work with interleaved arrays on the Windows Phone platform. Theoretically, there’s a slight performance gain with interleaved arrays because you call fewer functions per frame, but it’s negligible at best. Since VBOs reside in graphics memory regardless of how you organize them, you shouldn’t suffer any penalty for stuff you don’t use. What matters is your shader code. If your shader only operates on positional data and simple fragment colouring, then you’re not wasting GPU cycles elsewhere.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 16, 2011 at 22:36

TheNut, there can be a nontrivial cost involved in just fetching the vertex data from memory to the shader, even if the shader doesn’t use all of it. That’s why people sometimes split streams into e.g. attributes used by the shadow shader and those only used by the main shader (the main shader reads both streams). Since shadow-map rendering is typically vertex-bound, you actually can save time by slimming down the streams. I’d also guess that on the flip side, having too many streams can negatively impact GPU memory read performance due to losing some cache locality. But this will be very hardware-dependent; YMMV, and such.

10ef9dd08646b01d3f27aadf9d33152d
0
Vereor 101 Dec 22, 2011 at 07:07

Thanks guys,

I’ve managed to get multiple buffers up and working perfectly fine, with the added benefit of being able to use position data only when necessary.

Fe8a5d0ee91f9db7f5b82b8fd4a4e1e6
0
JarkkoL 102 Jan 01, 2012 at 20:49

It’s not generally a good idea to have separate buffers because the vertex data is fetched in cache lines. Having the data split into multiple buffers essentially multiplies the amount of data GPU has to fetch for processings a vertex.

Cheers, Jarkko