How to update vertex buffer on every frame

Started by
3 comments, last by iedoc 7 years ago

I have a vertex buffer and i need to update it on almost every frame, it is a cloth. I have pool of upload heaps, so creating intermediate buffer isn't costly. But if i will wirte data to the same vertex buffer on every frame, then i will tie CPU and GPU together. Should i create several copies of the same vertex buffer? I that the case where i need to use ring buffer for all my buffers for deformables?

Advertisement

The main point is to avoid updating anything being used by the GPU (or scheduled to be used), and there are a few ways to do this.

The easiest is to store multiple separate vertex buffers and update them in order. This requires a bit more book-keeping for Direct3D 12 but is simple to implement.
The best way requires more effort on your part. Allocate a buffer 2 or 3 times larger than you need (depending on how many back buffers you have) and update/draw parts of it in order in a ring fashion.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

...

L. Spiro

Thank you for this valuable answer. could you please tell me two next things:

1. Do i need to implement one ring buffer for all my deformables or one ring buffer per every deformable? I believe you mean one for all of them, but just to be sure. And if one for all, which size approximately should i choose?

2. How it should correlate with number of back buffers?

---

Third question just came up. Do you mean ring buffer for upload or default heap? Because now i have linear allocator for upload heaps, which i use as intermediates to copy into my vertex buffers.

It does not really matter which option you choose.

1.One ring buffer of size = Number of meshes * Number of vertices per mesh * Number of back buffers or

2.Ring buffer per mesh 1 of size = Number of vertices per mesh * Number of back buffers

....

Ring buffer per mesh N of size = Number of vertices per mesh * Number of back buffers

If you read the data directly from upload heap this would suffice. In case you decide to copy the data to default heap from upload heap before reading, you would need to duplicate them in the default heap as well.

Unless you won't ever be adding or removing these objects from your scene (in which case either option is fine), you'll most likely want one ring buffer per object who's buffer changes per frame. If you think about it, with one giant buffer for all of them, its going to be a lot less efficient adding and removing objects from your scene. Every time you add a new object, you'll have to resize that buffer, which would include creating a new buffer of the correct size, copying all the stuff over from the previous buffer (might not have to do this if you know your updating each objects entire buffer every frame), then finally freeing the old buffer.

This topic is closed to new replies.

Advertisement