diff --git a/scripts/generate_oxr_ext_support.py b/scripts/generate_oxr_ext_support.py index 80c40712c..705e98603 100755 --- a/scripts/generate_oxr_ext_support.py +++ b/scripts/generate_oxr_ext_support.py @@ -47,6 +47,7 @@ EXTENSIONS = ( ['XR_KHR_D3D12_enable', 'XR_USE_GRAPHICS_API_D3D12'], ['XR_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'], ['XR_KHR_loader_init_android', 'OXR_HAVE_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'], + ['XR_KHR_locate_spaces'], ['XR_KHR_opengl_enable', 'XR_USE_GRAPHICS_API_OPENGL'], ['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'], ['XR_KHR_swapchain_usage_input_attachment_bit'], diff --git a/src/xrt/state_trackers/oxr/oxr_api_funcs.h b/src/xrt/state_trackers/oxr/oxr_api_funcs.h index 73be08655..0b00ce855 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_funcs.h +++ b/src/xrt/state_trackers/oxr/oxr_api_funcs.h @@ -571,6 +571,15 @@ oxr_xrGetDisplayRefreshRateFB(XrSession session, float *displayRefreshRate); XRAPI_ATTR XrResult XRAPI_CALL oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate); + +//! OpenXR API function @ep{xrLocateSpacesKHR} +XRAPI_ATTR XrResult XRAPI_CALL +oxr_xrLocateSpacesKHR(XrSession session, const XrSpacesLocateInfoKHR *locateInfo, XrSpaceLocationsKHR *spaceLocations); + +//! OpenXR API function @ep{xrLocateSpaces} +XRAPI_ATTR XrResult XRAPI_CALL +oxr_xrLocateSpaces(XrSession session, const XrSpacesLocateInfo *locateInfo, XrSpaceLocations *spaceLocations); + /* * * oxr_api_passthrough.c diff --git a/src/xrt/state_trackers/oxr/oxr_api_negotiate.c b/src/xrt/state_trackers/oxr/oxr_api_negotiate.c index 80c6caece..12adbb9d1 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_negotiate.c +++ b/src/xrt/state_trackers/oxr/oxr_api_negotiate.c @@ -341,6 +341,12 @@ handle_non_null(struct oxr_instance *inst, struct oxr_logger *log, const char *n ENTRY_IF_EXT(xrCreateXDevSpaceMNDX, MNDX_xdev_space); #endif // OXR_HAVE_MNDX_xdev_space +#ifdef OXR_HAVE_KHR_locate_spaces + ENTRY_IF_EXT(xrLocateSpacesKHR, KHR_locate_spaces); +#endif + + ENTRY_IF_VERSION_AT_LEAST(xrLocateSpaces, 1, 1); + /* * Not logging here because there's no need to loudly advertise * which extensions the loader knows about (it calls this on diff --git a/src/xrt/state_trackers/oxr/oxr_api_space.c b/src/xrt/state_trackers/oxr/oxr_api_space.c index 51c5d309c..5846f5d96 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_space.c +++ b/src/xrt/state_trackers/oxr/oxr_api_space.c @@ -7,6 +7,9 @@ * @ingroup oxr_api */ +#include "openxr/openxr.h" +#include "oxr_chain.h" +#include "util/u_misc.h" #include "xrt/xrt_compiler.h" #include "util/u_debug.h" @@ -244,3 +247,98 @@ oxr_xrDestroySpace(XrSpace space) return oxr_handle_destroy(&log, &spc->handle); } + +static XrResult +locate_spaces(XrSession session, const XrSpacesLocateInfo *locateInfo, XrSpaceLocations *spaceLocations) +{ + struct oxr_space *spc; + struct oxr_space *baseSpc; + struct oxr_logger log; + OXR_VERIFY_SPACE_AND_INIT_LOG(&log, locateInfo->baseSpace, spc, "xrLocateSpacesKHR"); + OXR_VERIFY_SESSION_NOT_LOST(&log, spc->sess); + OXR_VERIFY_ARG_TYPE_AND_NOT_NULL(&log, locateInfo, XR_TYPE_SPACES_LOCATE_INFO_KHR); + OXR_VERIFY_ARG_TYPE_AND_NOT_NULL(&log, spaceLocations, XR_TYPE_SPACE_LOCATIONS_KHR); + OXR_VERIFY_SPACE_NOT_NULL(&log, locateInfo->baseSpace, baseSpc); + + OXR_VERIFY_ARG_NOT_ZERO(&log, locateInfo->spaceCount); + OXR_VERIFY_ARG_NOT_ZERO(&log, spaceLocations->locationCount); + + if (locateInfo->spaceCount != spaceLocations->locationCount) { + return oxr_error(&log, XR_ERROR_VALIDATION_FAILURE, + "(locateInfo->spaceCount == %d) must equal (spaceLocations->locationCount == %d)", + locateInfo->spaceCount, spaceLocations->locationCount); + } + + + if (locateInfo->time <= (XrTime)0) { + return oxr_error(&log, XR_ERROR_TIME_INVALID, "(time == %" PRIi64 ") is not a valid time.", + locateInfo->time); + } + + XrSpaceVelocitiesKHR *velocities = + OXR_GET_OUTPUT_FROM_CHAIN((void *)spaceLocations->next, XR_TYPE_SPACE_VELOCITIES_KHR, XrSpaceVelocitiesKHR); + if (velocities) { + if (velocities->velocityCount != locateInfo->spaceCount) { + return oxr_error(&log, XR_ERROR_VALIDATION_FAILURE, + "(next->velocityCount == %d) must equal (locateInfo->spaceCount == %d)", + velocities->velocityCount, locateInfo->spaceCount); + } + } + + + for (uint32_t i = 0; i < locateInfo->spaceCount; i++) { + struct oxr_space *s; + OXR_VERIFY_SPACE_NOT_NULL(&log, locateInfo->spaces[i], s); + + XrSpaceVelocity v = { + .type = XR_TYPE_SPACE_VELOCITY, + .next = NULL, + }; + + void *next = NULL; + if (velocities) { + next = &v; + } + + XrSpaceLocation l = { + .type = XR_TYPE_SPACE_LOCATION, + .next = next, + }; + + XrResult result = oxr_space_locate(&log, s, baseSpc, locateInfo->time, &l); + + if (result == XR_SUCCESS) { + spaceLocations->locations[i].locationFlags = l.locationFlags; + spaceLocations->locations[i].pose = l.pose; + + if (velocities) { + velocities->velocities[i].angularVelocity = v.angularVelocity; + velocities->velocities[i].linearVelocity = v.linearVelocity; + velocities->velocities[i].velocityFlags = v.velocityFlags; + } + + } else { + return result; + } + } + + return XR_SUCCESS; +} + +#ifdef OXR_HAVE_KHR_locate_spaces +XRAPI_ATTR XrResult XRAPI_CALL +oxr_xrLocateSpacesKHR(XrSession session, const XrSpacesLocateInfoKHR *locateInfo, XrSpaceLocationsKHR *spaceLocations) +{ + OXR_TRACE_MARKER(); + + return locate_spaces(session, locateInfo, spaceLocations); +} +#endif + +XRAPI_ATTR XrResult XRAPI_CALL +oxr_xrLocateSpaces(XrSession session, const XrSpacesLocateInfo *locateInfo, XrSpaceLocations *spaceLocations) +{ + OXR_TRACE_MARKER(); + + return locate_spaces(session, locateInfo, spaceLocations); +} diff --git a/src/xrt/state_trackers/oxr/oxr_extension_support.h b/src/xrt/state_trackers/oxr/oxr_extension_support.h index 336157762..a93172ca7 100644 --- a/src/xrt/state_trackers/oxr/oxr_extension_support.h +++ b/src/xrt/state_trackers/oxr/oxr_extension_support.h @@ -179,6 +179,17 @@ #endif +/* + * XR_KHR_locate_spaces + */ +#if defined(XR_KHR_locate_spaces) +#define OXR_HAVE_KHR_locate_spaces +#define OXR_EXTENSION_SUPPORT_KHR_locate_spaces(_) _(KHR_locate_spaces, KHR_LOCATE_SPACES) +#else +#define OXR_EXTENSION_SUPPORT_KHR_locate_spaces(_) +#endif + + /* * XR_KHR_opengl_enable */ @@ -671,6 +682,7 @@ OXR_EXTENSION_SUPPORT_KHR_D3D12_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_loader_init(_) \ OXR_EXTENSION_SUPPORT_KHR_loader_init_android(_) \ + OXR_EXTENSION_SUPPORT_KHR_locate_spaces(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_es_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_swapchain_usage_input_attachment_bit(_) \