Do I need to memory map/unmap a buffer every time the content of the buffer changes?

Viewed 999

I'm doing a Vulkan project that renders into an outgoing stream instead of presenting it (no swapchain et al): the rendered image is copied to another image (vkCmdCopyImage) then that later image is memory mapped (vkMapMemory), data is copied somewhere else then it is unmapped (vkUnmapMemory). This is happing at every frame. Is there a way to map the (second) image once, enter the main loop (render a frame at each cycle) then unmap it as part of the application clean-up ? I tried this but it looks like whenever something is copied to the image, the earlier mapping doesn't work and it has to be unmapped and mapped again.

1 Answers

It is never necessary in Vulkan to unmap memory you have mapped. Even deleting the memory implicitly unmaps it.

However, it is necessary to synchronize access to that memory properly. For modifying an image on the GPU, using execution&memory dependencies to ensure the availability and visibility of the GPU modifications to the host, events that the CPU can wait on/test to ensure that the modification is visible, and if the memory is not host-coherent you will need to invoke vkInvalidateMappedMemoryRanges to ensure visibility of such changes to the host.

Related