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.
This commit is contained in:
Christoph Haag 2021-01-26 03:45:43 +01:00
parent 0673c2e375
commit cb352839e3
2 changed files with 2 additions and 3 deletions
src/xrt/state_trackers/oxr

View file

@ -369,7 +369,7 @@ oxr_xrCreateVulkanDeviceKHR(XrInstance instance,
// VK_NULL_HANDLE is 0
OXR_VERIFY_ARG_NOT_NULL(&log, createInfo->vulkanPhysicalDevice);
//! @todo require xrCreateVulkanInstanceKHR to be called in the spec
OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_physical_device);
OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_instance);
if (sys->vulkan_enable2_physical_device != createInfo->vulkanPhysicalDevice) {

View file

@ -250,8 +250,6 @@ oxr_vk_create_vulkan_instance(struct oxr_logger *log,
free((void *)modified_info.ppEnabledExtensionNames);
}
sys->vulkan_enable2_instance = *vulkanInstance;
return XR_SUCCESS;
}
@ -370,6 +368,7 @@ oxr_vk_get_physical_device(struct oxr_logger *log,
// vulkan_enable2 needs the physical device in xrCreateVulkanDeviceKHR
if (inst->extensions.KHR_vulkan_enable2) {
sys->vulkan_enable2_instance = vkInstance;
sys->vulkan_enable2_physical_device = *vkPhysicalDevice;
}