Advertisement

Does it matter how many vertex buffers you have in a scene?

Started by January 03, 2025 01:38 AM
4 comments, last by JoeJ 1 day, 19 hours ago

Additional information, if that helps: I have experience with Unity and Godot. I started my main game using Unity, but switched to Godot after the announcement of Unity’s runtime fee. I then left Godot due to running into its limitations as an engine, and now I’m trying to create a custom game engine to power my game. I’m using C++ and DirectX 11, but knowledge from any graphics API is welcome. My goals for my engine are for it to be simple, optimized, lightweight and cost-effective.

Does it matter how many vertex/index buffers you have in a scene? I’m thinking of going with “one vertex and index buffer per model” as that makes the most sense and fits best with my game engine goals (to me anyways) but I’m not sure if this is the “default” approach related to vertex buffers.

Yeah, it can matter, but it depends on how you manage them. Too many buffers can hurt performance if you're constantly switching between them, especially with a lot of draw calls. Combining similar meshes into one buffer can help, but don't over-optimize and make things unreadable. Your one-buffer-per-model idea sounds fine for now, but maybe test it and see if it fits your engine goals?

Advertisement

Another aspect, you might even want more than 1 buffer per model, regardless of whether you combine or not.

When you have all vertex-attributes (pos, tex, norm/tan/bin), then every shader will have to at least skip over all elements, even if only pos is used. This makes geometry-only passes like shadows or depth-prepass much more expensive. So for those, you‘ll want to put positions into a separate buffer from everything else. Then, for shadows, you only bind the position-buffer, making the stride that needs to be processed only 12/16 bytes, instead of 32-64. All graphics-APIs allow you to do that.

One per model is fine. Long ago when speeds were slower, you wanted to lessen every single draw/setup call for a GPU. The biggest optimization in rendering is making sure to use instanced rendering.

NBA2K, Madden, Maneater, Killing Floor, Sims

dpadam450 said:
Long ago when speeds were slower, you wanted to lessen every single draw/setup call for a GPU. The biggest optimization in rendering is making sure to use instanced rendering.

I would say this statement itself is already outdated. (not so much for DX 11 maybe)
The bigger optimization is GPU driven rendering to eliminate those draw calls compeltely.
To have that working, large vertex buffers containing multiple or even all models are necessary in practice.
Seperating geometry data (positions) and shading data (normals…) to help with shadows or depth prepass is still possible ofc.

Advertisement