Skip to main content

Copying Images on the Host in Vulkan

The Vulkan Working Group has released the VK_EXT_host_image_copy extension, allowing copies to and from images to be done on the host rather than the device.

Vulkan already provides functions to copy between buffers and images through vkCmdCopyBufferToImage, vkCmdCopyImageToBuffer, and vkCmdCopyImage (later made extensible in VK_KHR_copy_commands2 and Vulkan 1.3). These functions are essential as the physical layout of an image (otherwise known as memory swizzling) created with VK_IMAGE_TILING_OPTIMAL is opaque to the application, so it cannot meaningfully copy to and from such an image by mapping its device memory on the host. What’s more, its device memory may not be host-mappable to begin with. However, the Vulkan implementation is capable of copying to and from these types of images with hardware-accelerated swizzling.

These functions work well when the image data is available or needed in device memory and it is desirable to do the copy on the device timeline. There are, however, common scenarios where that is not true. Additionally, whenever the data is available or needed in host memory, a buffer↔image copy can incur penalties. The recently released VK_EXT_host_image_copy extension aims to address these inefficiencies.