st/oxr: Check that VkPhysicalDevice in graphics binding matches suggested device

XR_KHR_vulkan_enable2:
physicalDevice VkPhysicalDevice must match the device specified by xrGetVulkanGraphicsDevice2KHR

XR_KHR_vulkan_enable:
physicalDevice VkPhysicalDevice must match the device specified by xrGetVulkanGraphicsDeviceKHR

XR_KHR_vulkan_enable:
Add a trivial check that xrGetVulkanGraphicsDeviceKHR is called before xrCreateSession.
(our cached suggested device will be XR_NULL_HANDLE if it has not been called).
The XR_KHR_vulkan_enable2 code path already contains this check.
This commit is contained in:
Christoph Haag 2021-05-07 00:34:47 +02:00
parent 35beaeead4
commit d384c90104
5 changed files with 25 additions and 5 deletions

View file

@ -403,10 +403,10 @@ oxr_xrCreateVulkanDeviceKHR(XrInstance instance,
// VK_NULL_HANDLE is 0
OXR_VERIFY_ARG_NOT_NULL(&log, createInfo->vulkanPhysicalDevice);
OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_physical_device);
OXR_VERIFY_ARG_NOT_NULL(&log, sys->suggested_vulkan_physical_device);
OXR_VERIFY_ARG_NOT_NULL(&log, sys->vulkan_enable2_instance);
if (sys->vulkan_enable2_physical_device != createInfo->vulkanPhysicalDevice) {
if (sys->suggested_vulkan_physical_device != createInfo->vulkanPhysicalDevice) {
return oxr_error(&log, XR_ERROR_HANDLE_INVALID,
"createInfo->vulkanPhysicalDevice must be the device "
"returned by xrGetVulkanGraphicsDeviceKHR");

View file

@ -1095,7 +1095,9 @@ struct oxr_system
#ifdef XR_USE_GRAPHICS_API_VULKAN
//! The instance/device we create when vulkan_enable2 is used
VkInstance vulkan_enable2_instance;
VkPhysicalDevice vulkan_enable2_physical_device;
//! The device returned with the last xrGetVulkanGraphicsDeviceKHR or xrGetVulkanGraphicsDevice2KHR call.
//! XR_NULL_HANDLE if neither has been called.
VkPhysicalDevice suggested_vulkan_physical_device;
#endif
};

View file

@ -2048,6 +2048,21 @@ oxr_session_create_impl(struct oxr_logger *log,
"xrGetVulkanGraphicsRequirementsKHR");
}
if (sys->suggested_vulkan_physical_device == VK_NULL_HANDLE) {
char *fn = sys->inst->extensions.KHR_vulkan_enable ? "xrGetVulkanGraphicsDeviceKHR"
: "xrGetVulkanGraphicsDevice2KHR";
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "Has not called %s", fn);
}
if (sys->suggested_vulkan_physical_device != vulkan->physicalDevice) {
char *fn = sys->inst->extensions.KHR_vulkan_enable ? "xrGetVulkanGraphicsDeviceKHR"
: "xrGetVulkanGraphicsDevice2KHR";
return oxr_error(
log, XR_ERROR_VALIDATION_FAILURE,
"XrGraphicsBindingVulkanKHR::physicalDevice %p must match device %p specified by %s",
(void *)vulkan->physicalDevice, (void *)sys->suggested_vulkan_physical_device, fn);
}
OXR_SESSION_ALLOCATE(log, sys, *out_session);
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
return oxr_session_populate_vk(log, sys, vulkan, *out_session);

View file

@ -101,7 +101,7 @@ oxr_system_fill_in(struct oxr_logger *log, struct oxr_instance *inst, XrSystemId
#ifdef XR_USE_GRAPHICS_API_VULKAN
sys->vulkan_enable2_instance = VK_NULL_HANDLE;
sys->vulkan_enable2_physical_device = VK_NULL_HANDLE;
sys->suggested_vulkan_physical_device = VK_NULL_HANDLE;
#endif
// Headless.

View file

@ -369,7 +369,10 @@ 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;
}
sys->suggested_vulkan_physical_device = *vkPhysicalDevice;
if (ll <= U_LOGGING_DEBUG) {
oxr_log(log, "Suggesting vulkan physical device %p", (void *)*vkPhysicalDevice);
}
free(phys);