0
$\begingroup$

I would like to change/add/remove some mesh vertices in existing VBO's (while deforming and remeshing 3D objects) . With OpenGL I would have to reload whole vertex VBO's. I suppose with Vulkan there could be a way to directly access VBO's to only change/add/remove the changed vertex data. Is there some sample code out there demonstrating how this can be achieved? Many thanks for any help.

$\endgroup$
0
$\begingroup$

With OpenGL I would have to reload whole vertex VBO's.

No you wouldn't. You can use glBufferSubData

I suppose with Vulkan there could be a way to directly access VBO's to only change/add/remove the changed vertex data

If you know the memory layout of the vertex buffer, you can find the offset of the contents you want to change, populate a transfer buffer with the new data and then uss vkCmdCopyBuffer to copy the data. The VkBufferCopy parameter lets you specify the size as well as the source and destination offsets. In other words, every call to vkCmdCopyBuffer is basically the equivalent of N calls to glBufferSubData

To clarify, updating a vertex buffer on Vulkan is almost the same as populating it. If you're on a desktop architecture where device local memory is typically not mappable, then you have to create a transfer buffer that is host visible. You can populate that buffer with a memcpy (or whatever), and then use vkCmdCopyBuffer to transfer it to the device local memory backed buffer. If you're on a mobile architecture with unified memory, then device local memory is typically also host visible and so you can just map it directly and update it with your memcpy (or whatever)

$\endgroup$
  • 2
    $\begingroup$ "If you're on a desktop architecture where device local memory is typically not mappable, then you have to create a transfer buffer that is host visible." Even implementations that offer split memory may allow you to use host-visible memory for vertex data. In cases where you're frequently uploading data (like a GUI), this would be a good thing to use. $\endgroup$ – Nicol Bolas May 30 at 4:55
  • 1
    $\begingroup$ Also, synchronization is really important when updating memory. $\endgroup$ – Nicol Bolas May 30 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.