Staging buffers can be used not only to transfer data between buffers, but also to and from an image. Here, we will show how to map a buffer's memory and copy its contents to a desired image.
Using a staging buffer to update an image with a device-local memory bound
How to do it...
- Create a staging buffer big enough to hold the entire data to be transferred. Specify a VK_BUFFER_USAGE_TRANSFER_SRC_BIT usage for the buffer and store its handle in a variable of type VkBuffer named staging_buffer. Allocate a memory object that supports the VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT property and bind it to the staging buffer. Store the memory object's handle in a variable of type VkDeviceMemory named memory_object. Map the memory and update its contents with the data...