Vulkan & The SteamVR compositor

Already in December, Valve has updated OpenVR to include support for Vulkan.

When using Vulkan instead of OpenGL with OpenVR/SteamVR, there are two additional steps to take:

  1. To work at all, you need to create your Vulkan instance and Vulkan device with the extensions supplied by the IVRCompositor::GetVulkanInstanceExtensionsRequired() and IVRCompositor::GetVulkanDeviceExtensionsRequired() functions. On Nvidia cards, the first function will return the VK_NV_external_memory_capabilities extension, which enables sharing of Vulkan memory with other applications. I have not tested this yet on AMD.
  2. In contrast to OpenGL, the where the handle of Texture_t points to a texture handle, in the Vulkan case, it must point to an instance of VRVulkanTextureData_t. This struct contains the instance, physical device, device, queue and, most importantly, the texture format. Here, the compositor seems to be a wee bit picky, with VK_FORMAT_R8G8B8A8_UNORM and VK_FORMAT_R8G8B8A8_SRGB working best. As the images you submit will usually be swapchain images, so this shouldn't be much of a problem.

Update 2017-01-29: I just realized that Valve actually has a wiki page on Vulkan & OpenVR, listing more compatible image formats, and stating two more crucial points:

  • The image has to be in VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL state when being sent off to the compositor.
  • The queue referenced in VRVulkanTexture_t must not be accessed by any other thread of the application, until submission is finished.

A mostly complete usage example can be found in Johan Gardell's vulkan-cpp-library.

As usual — your mileage may vary, but I hope this is useful information!

Happy hacking!