Hi,
I need a vertex buffer that is updated every frame.
Currently I:
- Write CPU data to a host-visible staging buffer
- Copy to a device-local vertex buffer each frame
This works, but I’m wondering if there is a faster way.
Thanks!
Hi,
I need a vertex buffer that is updated every frame.
Currently I:
This works, but I’m wondering if there is a faster way.
Thanks!
In Sascha Willem’s “How to Vulkan” tutorial, check out at least this section:
The “About” section has a link to the associated source code:
(NOTE: I have no Vulkan dev experience, so I defer to anyone here that is.)
Fastest way would be storing your vertex data in a memory type that’s both host visible and device local. Nowadays you get such a type on pretty much any device incl. discrete GPUs (thanks to ReBAR/SAM).
That way you can skip the staging part.
But make sure that you don’t update from the CPU while the GPU still reads from it. E.g. by using one buffer per max. frames in flight and using a fence to defer updates until the GPU has finished.
Interesting, I haven’t tried using memory that is both device-local and host-visible. If that’s possible, it should be faster than the staging buffer approach. Are you familiar with Unity? In Unity, there’s a MarkDynamic method on the Mesh class, and I’m curious if Unity uses this technique for this.
You could maybe find this out with RenderDoc or a similar graphics debugging tool to inspect the resource details for the buffers backing a Unity mesh.
In general I would think at best they use it as an optional optimization for this case - for some insight into the reasoning that goes into which features to use/require for a game you can take a look at this blog post, specifically the " GPU Upload Heaps" (which AFAIK is the D3D12 feature to utilize ReBAR) section.