st/oxr: Validate XrReferenceSpaceType in common code

Also deal with the different types of error code returns that the CTS expects.
This commit is contained in:
Jakob Bornecrantz 2023-11-06 23:20:01 +00:00
parent 6cb275803c
commit 2fbe588f66
5 changed files with 77 additions and 55 deletions

View file

@ -16,6 +16,7 @@
#include "oxr_objects.h"
#include "oxr_logger.h"
#include "oxr_conversions.h"
#include "oxr_two_call.h"
#include "oxr_api_funcs.h"
@ -33,6 +34,23 @@
*
*/
static XrResult
is_reference_space_type_valid(struct oxr_logger *log,
struct oxr_system *sys,
const char *field_name,
XrReferenceSpaceType referenceSpaceType)
{
switch (referenceSpaceType) {
case XR_REFERENCE_SPACE_TYPE_VIEW:
case XR_REFERENCE_SPACE_TYPE_LOCAL:
case XR_REFERENCE_SPACE_TYPE_STAGE: return XR_SUCCESS;
default: break;
}
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "(%s == 0x%08x) is not a valid XrReferenceSpaceType",
field_name, referenceSpaceType);
}
static XrResult
is_reference_space_type_supported(struct oxr_logger *log,
struct oxr_system *sys,
@ -45,8 +63,13 @@ is_reference_space_type_supported(struct oxr_logger *log,
}
}
/*
* This function assumes that the referenceSpaceType has
* been validated with is_reference_space_type_valid first.
*/
return oxr_error(log, XR_ERROR_REFERENCE_SPACE_UNSUPPORTED,
"(%s == 0x%08x) is not a supported XrReferenceSpaceType", field_name, referenceSpaceType);
"(%s == %s) is not a supported XrReferenceSpaceType", field_name,
xr_ref_space_to_string(referenceSpaceType));
}
@ -114,16 +137,9 @@ oxr_xrGetReferenceSpaceBoundsRect(XrSession session, XrReferenceSpaceType refere
OXR_VERIFY_SESSION_AND_INIT_LOG(&log, session, sess, "xrGetReferenceSpaceBoundsRect");
OXR_VERIFY_ARG_NOT_NULL(&log, bounds);
switch (referenceSpaceType) {
case XR_REFERENCE_SPACE_TYPE_VIEW:
case XR_REFERENCE_SPACE_TYPE_LOCAL:
case XR_REFERENCE_SPACE_TYPE_STAGE: break;
default:
return oxr_error(&log, XR_ERROR_VALIDATION_FAILURE,
"(referenceSpaceType == 0x%08x) is not a "
"valid XrReferenceSpaceType",
referenceSpaceType);
ret = is_reference_space_type_valid(&log, sess->sys, "referenceSpaceType", referenceSpaceType);
if (ret != XR_SUCCESS) {
return ret;
}
ret = is_reference_space_type_supported(&log, sess->sys, "referenceSpaceType", referenceSpaceType);
@ -152,6 +168,18 @@ oxr_xrCreateReferenceSpace(XrSession session, const XrReferenceSpaceCreateInfo *
OXR_VERIFY_ARG_TYPE_AND_NOT_NULL(&log, createInfo, XR_TYPE_REFERENCE_SPACE_CREATE_INFO);
OXR_VERIFY_POSE(&log, createInfo->poseInReferenceSpace);
ret = is_reference_space_type_valid(&log, sess->sys, "createInfo->referenceSpaceType",
createInfo->referenceSpaceType);
if (ret != XR_SUCCESS) {
// The CTS currently requiers us to return XR_ERROR_REFERENCE_SPACE_UNSUPPORTED.
if (sess->sys->inst->quirks.no_validation_error_in_create_ref_space &&
ret == XR_ERROR_VALIDATION_FAILURE) {
return XR_ERROR_REFERENCE_SPACE_UNSUPPORTED;
} else {
return ret;
}
}
ret = is_reference_space_type_supported(&log, sess->sys, "createInfo->referenceSpaceType",
createInfo->referenceSpaceType);
if (ret != XR_SUCCESS) {

View file

@ -84,3 +84,18 @@ xr_ref_space_to_oxr(XrReferenceSpaceType space_type)
// wrap around or negative depending on enum data type, invalid value either way.
return (enum oxr_space_type) - 1;
}
static inline const char *
xr_ref_space_to_string(XrReferenceSpaceType space_type)
{
switch (space_type) {
case XR_REFERENCE_SPACE_TYPE_VIEW: return "XR_REFERENCE_SPACE_TYPE_VIEW";
case XR_REFERENCE_SPACE_TYPE_LOCAL: return "XR_REFERENCE_SPACE_TYPE_LOCAL";
case XR_REFERENCE_SPACE_TYPE_LOCAL_FLOOR_EXT: return "XR_REFERENCE_SPACE_TYPE_LOCAL_FLOOR_EXT";
case XR_REFERENCE_SPACE_TYPE_STAGE: return "XR_REFERENCE_SPACE_TYPE_STAGE";
case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT: return "XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT";
case XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO: return "XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO";
case XR_REFERENCE_SPACE_TYPE_MAX_ENUM: return "XR_REFERENCE_SPACE_TYPE_MAX_ENUM";
default: return "UNKNOWN REFERENCE SPACE";
}
}

View file

@ -169,14 +169,19 @@ detect_engine(struct oxr_logger *log, struct oxr_instance *inst, const XrInstanc
static void
apply_quirks(struct oxr_logger *log, struct oxr_instance *inst)
{
// Reset.
inst->quirks.skip_end_session = false;
inst->quirks.disable_vulkan_format_depth_stencil = false;
inst->quirks.no_validation_error_in_create_ref_space = false;
if (starts_with("UnrealEngine", inst->appinfo.detected.engine.name) && //
inst->appinfo.detected.engine.major == 4 && //
inst->appinfo.detected.engine.minor <= 27) {
inst->quirks.skip_end_session = true;
}
// Currently always true.
inst->quirks.no_validation_error_in_create_ref_space = true;
}
XrResult
@ -365,16 +370,18 @@ oxr_instance_create(struct oxr_logger *log,
"\tcreateInfo->applicationInfo.engineVersion: %i\n"
"\tappinfo.detected.engine.name: %s\n"
"\tappinfo.detected.engine.version: %i.%i.%i\n"
"\tquirks.disable_vulkan_format_depth_stencil: %s",
createInfo->applicationInfo.applicationName, //
createInfo->applicationInfo.applicationVersion, //
createInfo->applicationInfo.engineName, //
createInfo->applicationInfo.engineVersion, //
inst->appinfo.detected.engine.name, //
inst->appinfo.detected.engine.major, //
inst->appinfo.detected.engine.minor, //
inst->appinfo.detected.engine.patch, //
inst->quirks.disable_vulkan_format_depth_stencil ? "true" : "false"); //
"\tquirks.disable_vulkan_format_depth_stencil: %s"
"\tquirks.no_validation_error_in_create_ref_space: %s",
createInfo->applicationInfo.applicationName, //
createInfo->applicationInfo.applicationVersion, //
createInfo->applicationInfo.engineName, //
createInfo->applicationInfo.engineVersion, //
inst->appinfo.detected.engine.name, //
inst->appinfo.detected.engine.major, //
inst->appinfo.detected.engine.minor, //
inst->appinfo.detected.engine.patch, //
inst->quirks.disable_vulkan_format_depth_stencil ? "true" : "false", //
inst->quirks.no_validation_error_in_create_ref_space ? "true" : "false"); //
debug_print_devices(log, sys);

View file

@ -1459,6 +1459,12 @@ struct oxr_instance
bool disable_vulkan_format_depth_stencil;
//! Unreal 4 has a bug calling xrEndSession; the function should just exit
bool skip_end_session;
/*!
* Return XR_ERROR_REFERENCE_SPACE_UNSUPPORTED instead of
* XR_ERROR_VALIDATION_FAILURE in xrCreateReferenceSpace.
*/
bool no_validation_error_in_create_ref_space;
} quirks;
//! Debug messengers

View file

@ -29,33 +29,6 @@
#include <string.h>
/*
*
* Helper functions.
*
*/
static XrResult
check_reference_space_type(struct oxr_logger *log, XrReferenceSpaceType type)
{
switch (type) {
case XR_REFERENCE_SPACE_TYPE_VIEW: return XR_SUCCESS;
case XR_REFERENCE_SPACE_TYPE_LOCAL: return XR_SUCCESS;
case XR_REFERENCE_SPACE_TYPE_STAGE:
// For now stage space is always supported.
if (true) {
return XR_SUCCESS;
}
return oxr_error(log, XR_ERROR_REFERENCE_SPACE_UNSUPPORTED,
"(createInfo->referenceSpaceType == XR_REFERENCE_SPACE_TYPE_STAGE)"
" Stage space is unsupported on this device.");
default:
return oxr_error(log, XR_ERROR_REFERENCE_SPACE_UNSUPPORTED,
"(createInfo->referenceSpaceType == 0x%08x)", type);
}
}
/*
*
* To xrt_space functions.
@ -187,13 +160,6 @@ oxr_space_reference_create(struct oxr_logger *log,
const XrReferenceSpaceCreateInfo *createInfo,
struct oxr_space **out_space)
{
XrResult ret;
ret = check_reference_space_type(log, createInfo->referenceSpaceType);
if (ret != XR_SUCCESS) {
return ret;
}
if (!math_pose_validate((struct xrt_pose *)&createInfo->poseInReferenceSpace)) {
return oxr_error(log, XR_ERROR_POSE_INVALID, "(createInfo->poseInReferenceSpace)");
}