Sign in to follow this  
Christoph

locking vertex buffers

Recommended Posts

Christoph    122
Hi, one tiny question concerning vertex buffers: Is it faster to lock and update a whole big dynamic buffer than to lock only the valuable regions? For example, I create a 32x32-Vertex-Buffer and need to update the first three columns... is it better to lock the entire buffer than rather column 1-3? thX, Chris

Share this post


Link to post
Share on other sites
It's best to lock the smallest region possible. Once you unlock, the new data needs to be uploaded to the card. If you lock the entire buffer, and only modify a small part of it, you'll be transfering lots of unnecessary data.

Unlike a static buffer, data doesn't usually go into a dynamic buffer at particular offsets. You append data as you need it. If you need to use 32x3. Lock and write it, unlock, and draw. If you need a new 32x3 block, Lock a new section of the buffer, write it, unlock, and draw. If you attempt to relock the same 32x3 block, you're either a) Ignoring the NOOVERWRITE flag, or b) Ignoring the DISCARD flag. A dynamic lock requires one flag or the other. NOOVERWRITE means you're not locking data you've already written to. DISCARD will throw away the whole buffer, allowing you to start at vertex 0 of the buffer again.

If you're only updating a 32x3 block, but rendering the whole 32x32 block, you'll need to lock a 32x32 chunk, write it all, unlock, and render. If you need to update it again, either lock with NOOVERWRITE to a second 32x32 block in the same dynamic VB, or lock with DISCARD, and overwrite the entire buffer.

If try to render a second time and you lock a region you've already used with NOOVERWRITE, you may get visual artifacts. You may be changing data as the GPU is trying to access it. You've promised to leave the data alone, but changed it anyway.

Share this post


Link to post
Share on other sites
Christoph    122
Quote:
Original post by Namethatnobodyelsetook
If you're only updating a 32x3 block, but rendering the whole 32x32 block, you'll need to lock a 32x32 chunk, write it all, unlock, and render..


I definitely have to render the entire buffer.
So, as I understand you, I must lock the whole 32x32 chunk... Or is there a way to only change the 32x3 block, but render the whole buffer?

thanks again

Share this post


Link to post
Share on other sites
You can make a 32x32 static buffer, and locking will stall the CPU until the GPU is idle.

Or, you can make a dynamic buffer, update your vertices in a system memory copy, lock the 32x32 section, memcpy the whole chunk at once (to get AGP fast writes), unlock, then draw.

The second way is better, as it doesn't stall.

If the data only occasionally changes, you could keep two static VBs. When a change is required, switch which one is active, lock it, store the new data, and unlock it. As long as you have 3 or 4 frames between updates this should be smooth, as one VB will fall out of use by D3D by the time you ask to lock it again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this