Skip to main content
GameDev.net gamedev.net
🔒 Locked

dynamic vertex buffers

Started by ELFanatic Aug 3, 2006 at 11:21 PM 3 replies 3.4k views
Original Post
ELFanatic
ELFanatic
I'm trying to understand dynamic vertex buffers. Correct me if I'm wrong, vertex buffers should be orginized by texture. I heard that instantiating vb could cost performance loss if done incorrectly, are there any tips for this? How is static vertex buffers different than dynamic vertex buffers? Also, I heard something about batching, what is this? Also, I heard about something index buffers, what are these?
deathkrush
deathkrush
"Static" and "dynamic" are just hints to the Direct3D driver so that it can place them in appropriate memory for maximum performance. Static buffers are uploaded to VRAM (for maximum speed) and never changed. Dynamic buffers can be uploaded into VRAM (slow to read from, but fast to render/write) or AGP ram (fast to read/write but slow to render). Direct3D can also keep two copies of dynamic vertex buffers (one in VRAM and another one in AGP memory). Unlike static buffers, dynamic buffers can be locked/unlocked and changed every frame.

You are right, you should sort the vertex buffers by texture to minimize texture switches because texture switches are most expensive to the GPU.

If by instantiating a vb you mean dynamically allocating a vertex buffer every frame, then yes, it sounds like a big performance hit. Instead, you should allocate a dynamic buffer with enough storage once and then use D3D's locking mechanism to update it every frame.

As far as I know, batching is used in multi-threaded applications. In a multi-threaded setup there is usually one render thread and multiple batch threads. The batch threads build up D3D command buffers and when it's time to draw everything the render thread executes all the recorded batch commands from each thread.

EDIT: I almost forgot, there is also another definition for batching. Batching is a method of optimizing the GPU's triangle throughtput. It's done by splitting up large vertex buffers into smaller batches or organizing smaller vertex buffers into one large batch.

Index buffers are used for drawing Indexed Primitives. An index buffer stores integer values that point to the individual vertices in the current vertex buffer. It's a way to separate geometry from topology: the vertex buffer contains vertices and the index buffer contains polygons.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
ELFanatic
ELFanatic
Thank you for all your help. Oh yes, I have heard of locking a lot too. what does locking do? Why would a person use it? I also wonder the same about index buffers, when are they useful?
ET3D
ET3D
ELFanatic, if you don't know what locking and index buffers are, I'd suggest doing at least the tutorials before asking more advanced questions like the difference between dynamic and static buffers.


Anyway, the usage differences between static and dynamic buffers:

Dynamic buffers support the D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE locking flags. This allows updating them with less stalling of the 3D pipeline.

Dynamic buffers can't be in the managed pool, and therefore must be released and recreated on device reset.
Agony
Agony
Quote:
Original post by ELFanatic
Thank you for all your help. Oh yes, I have heard of locking a lot too. what does locking do? Why would a person use it? I also wonder the same about index buffers, when are they useful?

Locking basically gives you certain guarantees that you can depend on while the buffer is locked. Which guarantees you get depend on which flags you use when locking. Also, it is generally the case that the more guarantees you get, the greater the cost is in terms of performance. So depending on what you need to do, you try to request the fewest guarantees possible.

For example, if you need to write to a buffer, but you don't care at all what values are currently in the buffer, then you use the flag D3DLOCK_DISCARD. This guarantees that everything you write to the buffer will make it to the graphics card, but it will not guarantee that any of the data in the buffer when you lock it is actually valid previous data. The way it manages this is by keeping the previous buffer for it's own use (the GPU might still be reading from it, and doesn't want to lose it's data, or wait while you write new data), and it allocates new space an lets you write to that new buffer. When you unlock the buffer, the GPU throws out the previous buffer as soon as it is done with it, and begins using your new data instead. So the GPU can work on old data at the same time that you provide it with new data for it to use in the near future.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.