Copying data from a buffer to an image
For images, we can bind memory objects that are allocated from different memory types. Only host-visible memory can be mapped and updated directly from our application. When we want to update the memory of an image that uses a device-local memory, we need to copy data from a buffer.
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 a buffer from which data will be copied. Store its handle in a variable of type
VkBuffer
namedsource_buffer
.
- Take the image to which data will be copied. Represent this image with a variable of type
VkImage
nameddestination_image
. - Create a variable of type
VkImageLayout
namedimage_layout
, in which the image's current layout will be stored. - Create a variable of type...