mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-02 20:08:29 +00:00
st/oxr: Refactor extension parsing and verify extensions
This commit is contained in:
parent
fe9191a708
commit
ec537eb3aa
src/xrt/state_trackers/oxr
|
@ -92,17 +92,12 @@ oxr_xrInitializeLoaderKHR(const XrLoaderInitInfoBaseHeaderKHR *loaderInitInfo)
|
|||
|
||||
#ifdef XRT_OS_ANDROID
|
||||
static XrResult
|
||||
oxr_check_android_extensions(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo)
|
||||
oxr_check_android_extensions(struct oxr_logger *log,
|
||||
const XrInstanceCreateInfo *createInfo,
|
||||
const struct oxr_extension_status *extensions)
|
||||
{
|
||||
|
||||
bool foundAndroidExtension = false;
|
||||
for (uint32_t i = 0; i < createInfo->enabledExtensionCount; ++i) {
|
||||
if (strcmp(createInfo->enabledExtensionNames[i], XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME) == 0) {
|
||||
foundAndroidExtension = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundAndroidExtension) {
|
||||
// We need the XR_KHR_android_create_instance extension.
|
||||
if (!extensions->KHR_android_create_instance) {
|
||||
return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED,
|
||||
"(createInfo->enabledExtensionNames) "
|
||||
"Mandatory platform-specific extension " XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME
|
||||
|
@ -166,33 +161,43 @@ oxr_xrCreateInstance(const XrInstanceCreateInfo *createInfo, XrInstance *out_ins
|
|||
"Cannot satisfy request for version: too high");
|
||||
}
|
||||
|
||||
// To be passed into verify and instance creation.
|
||||
struct oxr_extension_status extensions;
|
||||
U_ZERO(&extensions);
|
||||
|
||||
/*
|
||||
* Check that all extension names are recognized, so oxr_instance_create
|
||||
* doesn't need to check for bad extension names.
|
||||
*
|
||||
* Also fill out the oxr_extension_status struct at the same time.
|
||||
*/
|
||||
#define CHECK_EXT_NAME(mixed_case, all_caps) \
|
||||
if (strcmp(createInfo->enabledExtensionNames[i], XR_##all_caps##_EXTENSION_NAME) == 0) { \
|
||||
extensions.mixed_case = true; \
|
||||
continue; \
|
||||
}
|
||||
for (uint32_t i = 0; i < createInfo->enabledExtensionCount; ++i) {
|
||||
OXR_EXTENSION_SUPPORT_GENERATE(CHECK_EXT_NAME)
|
||||
|
||||
return oxr_error(&log, XR_ERROR_EXTENSION_NOT_PRESENT,
|
||||
"(createInfo->enabledExtensionNames[%d]) "
|
||||
"Unrecognized extension name",
|
||||
i);
|
||||
"(createInfo->enabledExtensionNames[%d]) Unrecognized extension name '%s'", i,
|
||||
createInfo->enabledExtensionNames[i]);
|
||||
}
|
||||
|
||||
ret = oxr_verify_extensions(&log, &extensions);
|
||||
if (ret != XR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef XRT_OS_ANDROID
|
||||
ret = oxr_check_android_extensions(&log, createInfo);
|
||||
ret = oxr_check_android_extensions(&log, createInfo, &extensions);
|
||||
if (ret != XR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
struct oxr_instance *inst = NULL;
|
||||
|
||||
ret = oxr_instance_create(&log, createInfo, &inst);
|
||||
ret = oxr_instance_create(&log, createInfo, &extensions, &inst);
|
||||
if (ret != XR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -238,6 +238,9 @@ oxr_verify_subaction_path_get(struct oxr_logger *log,
|
|||
struct oxr_subaction_paths *out_subaction_paths,
|
||||
const char *variable);
|
||||
|
||||
XrResult
|
||||
oxr_verify_extensions(struct oxr_logger *log, const struct oxr_extension_status *extensions);
|
||||
|
||||
XrResult
|
||||
oxr_verify_view_config_type(struct oxr_logger *log,
|
||||
struct oxr_instance *inst,
|
||||
|
|
|
@ -186,7 +186,10 @@ apply_quirks(struct oxr_logger *log, struct oxr_instance *inst)
|
|||
}
|
||||
|
||||
XrResult
|
||||
oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo, struct oxr_instance **out_instance)
|
||||
oxr_instance_create(struct oxr_logger *log,
|
||||
const XrInstanceCreateInfo *createInfo,
|
||||
const struct oxr_extension_status *extensions,
|
||||
struct oxr_instance **out_instance)
|
||||
{
|
||||
struct oxr_instance *inst = NULL;
|
||||
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
||||
|
@ -354,20 +357,8 @@ oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createIn
|
|||
dev->hmd->views[1].fov.angle_down = down_override;
|
||||
}
|
||||
|
||||
|
||||
U_ZERO(&inst->extensions);
|
||||
for (uint32_t i = 0; i < createInfo->enabledExtensionCount; ++i) {
|
||||
|
||||
#define ENABLE_EXT(mixed_case, all_caps) \
|
||||
if (strcmp(createInfo->enabledExtensionNames[i], XR_##all_caps##_EXTENSION_NAME) == 0) { \
|
||||
inst->extensions.mixed_case = true; \
|
||||
continue; \
|
||||
}
|
||||
OXR_EXTENSION_SUPPORT_GENERATE(ENABLE_EXT)
|
||||
// assert(false &&
|
||||
// "Should not be reached - oxr_xrCreateInstance should "
|
||||
// "have failed on unrecognized extension.");
|
||||
}
|
||||
// Sets the enabled extensions, this is where we should do any extra validation.
|
||||
inst->extensions = *extensions;
|
||||
|
||||
// Create the compositor, if we are not headless.
|
||||
if (!inst->extensions.MND_headless) {
|
||||
|
|
|
@ -95,6 +95,7 @@ extern "C" {
|
|||
|
||||
struct xrt_instance;
|
||||
struct oxr_logger;
|
||||
struct oxr_extension_status;
|
||||
struct oxr_instance;
|
||||
struct oxr_system;
|
||||
struct oxr_session;
|
||||
|
@ -211,10 +212,20 @@ oxr_instance_to_openxr(struct oxr_instance *inst)
|
|||
}
|
||||
|
||||
/*!
|
||||
* Creates a instance, does minimal validation of @p createInfo.
|
||||
*
|
||||
* @param[in] log Logger
|
||||
* @param[in] createInfo OpenXR creation info.
|
||||
* @param[in] extensions Parsed extension list to be enabled.
|
||||
* @param[out] out_inst Pointer to pointer to a instance, returned instance.
|
||||
*
|
||||
* @public @static @memberof oxr_instance
|
||||
*/
|
||||
XrResult
|
||||
oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo, struct oxr_instance **out_inst);
|
||||
oxr_instance_create(struct oxr_logger *log,
|
||||
const XrInstanceCreateInfo *createInfo,
|
||||
const struct oxr_extension_status *extensions,
|
||||
struct oxr_instance **out_inst);
|
||||
|
||||
/*!
|
||||
* @public @memberof oxr_instance
|
||||
|
|
|
@ -405,6 +405,20 @@ oxr_verify_subaction_path_get(struct oxr_logger *log,
|
|||
*
|
||||
*/
|
||||
|
||||
XrResult
|
||||
oxr_verify_extensions(struct oxr_logger *log, const struct oxr_extension_status *extensions)
|
||||
{
|
||||
if ((extensions->KHR_swapchain_usage_input_attachment_bit ||
|
||||
extensions->MND_swapchain_usage_input_attachment_bit) &&
|
||||
!extensions->KHR_vulkan_enable2 && !extensions->KHR_vulkan_enable) {
|
||||
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
||||
"Using [KHR|MND]_swapchain_usage_input_attachment_bit doesn't make sense without "
|
||||
"KHR_vulkan_enable[2].");
|
||||
}
|
||||
|
||||
return XR_SUCCESS;
|
||||
}
|
||||
|
||||
XrResult
|
||||
oxr_verify_view_config_type(struct oxr_logger *log,
|
||||
struct oxr_instance *inst,
|
||||
|
|
Loading…
Reference in a new issue