Copying data from an image to a buffer
In Vulkan, we can not only transfer data from a buffer to an image, but also the other way--we can copy data from an image to the buffer. It doesn't matter what the properties of memory objects bound to them are. But, the data copy operation is the only way to update a device-local memory which cannot be mapped.
How to do it...
- Take the handle of a command buffer and store it in a variable of type
VkCommandBuffer
namedcommand_buffer
. Make sure the command buffer is already in a recording state (refer to the Beginning a command buffer recording operation recipe from Chapter 3, Command Buffers and Synchronization). - Take an image from which data will be copied. Store its handle in a variable of type
VkImage
namedsource_image
. - Take the source image's current memory layout and use it to initialize a variable of type
VkImageLayout
namedimage_layout
. - Take the buffer to which data will be copied. Prepare its handle in a variable of type
VkBuffer
nameddestination_buffer...