user1157885
user1157885

Reputation: 2069

Multiple buffers vs single buffer?

I'm drawing simple 3D shapes and I was wondering in the long run is it better to only use 1 buffer to store all the data of your vertices?

Right now I have arrays of vertex data (positions and colors, per vertex) and I am pushing them to their own separate buffers.

But if I use stride and offset, I could join them into one array but that would become messier and harder to manage.

What is the "traditional" way of doing this?

It feels much cleaner and organized to have separate buffers for each piece of data, but I would imagine it's less efficient.

Is the efficiency increase worth putting it all into a single buffer?

Upvotes: 6

Views: 3451

Answers (1)

user3995702
user3995702

Reputation:

The answer to this is highly usage-dependent.

If all your vertex attributes are highly volatile or highly static, you would probably benefit from interleaving and keeping them all together, as mentioned in the comments.

However, separating the data can yield better performance if one attribute is far more volatile than others. For example, if you have a mesh where you're often changing the vertex positions, but never the texture coordinates, you might benefit from keeping them separate: you would only need to re-upload the positions to the video card, instead of the whole set of attributes. An example of this might be a CPU-driven cloth simulation.

It is also hardware and implementation dependent. Interleaving isn't helpful everywhere, but I've never heard of it having a negative impact. If you can use it, you probably should.

However, since you can't properly interleave if you split the attributes, you're essentially comparing the performance impacts of two unknowns. Will interleaving help on your target hardware/drivers? Will your data benefit from being split? The first there's no real answer to. The second is between you and your data.

Personally, I would suggest just using interleaved single blocks of vertex attributes unless you have a highly specialized need. It cuts the complexity, as opposed to needing to have potentially different systems mixed together in the same back end.

On the other hand, setting up interleaving is a rather complex task as far as memory addressing goes in C++. If you're not designing an entire graphics engine from scratch, I really doubt it's worth the effort for you. But again, that's up to you and your application.

In theory, though, merely grouping together the data you were going to upload to the video card regardless should have little impact. It might be slightly more efficient to group all the attributes together due to reducing the number of calls, but that's again going to be highly driver-dependent.

Unfortunately, I think the simple answer to your question boils down to: "it depends" and "no one really knows".

Upvotes: 9

Related Questions