The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/oxr: cache VkInstance in xrGetVulkanGraphicsDeviceKHR

The problem:
* xrCreateVulkanDeviceKHR is passed a VkPhysicalDevice, but not a VkInstance.
* xrGetVulkanGraphicsDevice2KHR is passed a VkInstance and returns a VkPhysicalDevice
that is a child of that instance.
* xrCreateVulkanDeviceKHR must verify that the xrGetVulkanGraphicsDevice2KHR
has been called and that the passed VkPhysicalDevice matches the one returned
by xrGetVulkanGraphicsDevice2KHR.

We have to consider:
* xrCreateVulkanDeviceKHR has to work on the "correct" VkInstance, which the passed
VkPhysicalDevice is a child of.

The reqirement

> If the vulkanPhysicalDevice parameter does not match the output of
> xrGetVulkanGraphicsDeviceKHR, then the runtime must return XR_ERROR_HANDLE_INVALID.

is not 100% clear whether calling xrCreateVulkanInstance multiple times is allowed
and how a second call to xrGetVulkanGraphicsDevice2KHR with a dfferent VkInstance
should be handled.

For this implementation xrCreateVulkanDeviceKHR will only consider the most recent call
to xrGetVulkanGraphicsDevice2KHR and the VkInstance that was used for this call.
This enforces at least that VkPhysicalDevice is a child of the cached VkInstance when
xrCreateVulkanDeviceKHR is called, because using a different VkPhysicalDevice would be
an error.

+2 -3
+1 -1
src/xrt/state_trackers/oxr/oxr_api_system.c
··· 369 369 // VK_NULL_HANDLE is 0 370 370 OXR_VERIFY_ARG_NOT_NULL(&log, createInfo->vulkanPhysicalDevice); 371 371 372 - //! @todo require xrCreateVulkanInstanceKHR to be called in the spec 372 + OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_physical_device); 373 373 OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_instance); 374 374 375 375 if (sys->vulkan_enable2_physical_device != createInfo->vulkanPhysicalDevice) {
+1 -2
src/xrt/state_trackers/oxr/oxr_vulkan.c
··· 250 250 free((void *)modified_info.ppEnabledExtensionNames); 251 251 } 252 252 253 - sys->vulkan_enable2_instance = *vulkanInstance; 254 - 255 253 return XR_SUCCESS; 256 254 } 257 255 ··· 370 368 371 369 // vulkan_enable2 needs the physical device in xrCreateVulkanDeviceKHR 372 370 if (inst->extensions.KHR_vulkan_enable2) { 371 + sys->vulkan_enable2_instance = vkInstance; 373 372 sys->vulkan_enable2_physical_device = *vkPhysicalDevice; 374 373 } 375 374