Copying data between buffers
In Vulkan, to upload data to a buffer, we are not limited only to the memory mapping technique. It is possible to copy data between buffers, even if the memory objects bound to them were allocated from different memory types.
How to do it...
- Take the handle of a command buffer. Store it in a variable of type
VkCommandBuffer
namedcommand_buffer
. Make sure the command buffer is in the recording state (refer to the Beginning a command buffer recording operation recipe from Chapter 3, Command Buffers and Synchronization).
- Take the buffer from which data will be copied. Represent this buffer with a variable of type
VkBuffer
namedsource_buffer
. - Take the buffer to which data will be uploaded. Represent this buffer using a variable of type
VkBuffer
nameddestination_buffer
. - Create a variable of type
std::vector<VkBufferCopy>
namedregions
. For each memory region from which data should be copied, add an element to theregions
vector. In each element, specify the memory...