Can I extend a vertex buffer in place (DX12)?

Started by
4 comments, last by lubbe75 6 years ago

Can I extend a vertex buffer in DirectX 12 (actually SharpDX with DX12)? 

I am already set up and happily rendering along when I suddenly realise I need more vertices to render.

  • I could of course scrap the vertex buffer and create a new, larger one, but the problem is that I have already discarded my vertex data on the CPU side, to save memory.
  • So... I could create another vertex buffer instead and make sure to use both, one after the other, when rendering my frames. That would be OK, but what if I need to do this extension 1000 times? I would end up with 1001 vertex buffers, and I guess that would really kill performance.
  • What if I could simply extend my vertex buffer? Is there a way? Let me guess the answer here. I'm guessing there isn't. But maybe there is a way to copy the older vertex buffer into a new larger one? I have already used an upload buffer and copied it to my vertex buffer. Can I simply use the same technique for copying my old vertex buffer into a new one? Does anyone have an example code where this is being done? Well, if I can't extend my vertex buffer in place, I guess this is what I will try instead.

Have a great weekend!

Advertisement

Hi,

 

I will let someone else answer your main question (Best way to copy from a vertex buffer to another). However this information should be very relevant for you.

 

I've read in many place that it is common practice to create your dynamic vertex buffers with extra space at the end to avoid recreating the whole buffer on every byte that you want to add. Let's say you always create your vertex buffer with 1.5x the original size, you wont have to do all this until your vertex data almost double in size. I may be wrong on the next one but I believe i've also read somewhere that DX11 was actually doing that for us under the hood with dynamic buffers. So that's one thing you can do to reduce the number of buffer creation.

buffers as far as I know are immutable wrt to size...The overhead of the driver managing the growth or shrinkage of buffers outways the gain. You as the application developer have to manage resources. If its the case that 'suddenly you realize you need to render more vertices' then you have the conditions that you could use to figure out the high water mark for your buffer size. If you don't want to waste memory, then you can also create multiple fix sized buffer, but this may require you to submit multiple draw calls. In the end I think you have to consider your use case and plan your buffer creation accordingly under the assumption that you cannot resize buffers directly..

The one thing you could do is use a very large reserved vertex buffer, and map additional heaps into it as you need more memory. As long as you don't directly need CPU access to the buffer you're talking about growing, that seems like a pretty good solution.

Excellent... Adding a bit of extra space at the end sounds like a good idea. And also extending when necessary by first copying the existing buffer. Thanks!

Now I just need to write code that works :P

This topic is closed to new replies.

Advertisement