Archived

This topic is now archived and is closed to further replies.

Axiverse

Partitioning Vertex Buffers

Recommended Posts

I want cre create a vertex buffer that can be easily partitioned and have a representitive class to represent the patitioned space. When it is first partitioned out, there is no problem (simply keep track of the upper bound of used areas). The problem is that i want partitioned areas to be able to "release" what they used for future use and the more it is released and created the more fragmented it becomes. Is there a simple way to keep fragmentation to a minimum?

Share this post


Link to post
Share on other sites
Fragmentation shouldn''t be an issue if you follow the advice nVidia gives for vertex buffers.

In dynamic buffers you just append to the end, until you''re about to overflow. You then discard and begin at the start of the buffer again.

In static buffers, you''re only supposed to Lock once, ever. I used to interpret this as a warning about Locking each frame being bad. Now, however, DX emits warnings about Locking a buffer a second time (again saying it may affect performance). According to a paper I saw, it claimed that some drivers may actually convert your VB to dynamic if you lock a second time. Now, that last part was a shock, and something everyone probably wants to avoid.

So, in essence, static buffers have the following suggested usage: Accumulate data, Create, Lock, Copy, UnLock... On modify, Destroy buffer, accumulate data, Create, Lock, Copy, UnLock... ie: Never a second lock on the buffer.

Now you need your code to be able to find all the source data to copy into new buffers when a new buffer is needed. You want to batch these copies as much as you can to reduce the number of times you do a destroy/create cycle. And finally, you need to be able to modify your structure that says which VB and offset to use for your objects.

Using this pattern can''t fragment, and is apparently the "official" usage pattern. Sure, it''s more of a pain, and will require reorganizing some code, but what''s the point of code that''s incorrect? It''ll just cause you trouble down the line, and more code will rely on the bad code causing the change required later to be massive.

Share this post


Link to post
Share on other sites