st/oxr: Add naive xrLocateSpaces[KHR,]

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2194>
This commit is contained in:
Christoph Haag 2024-02-23 13:39:06 +01:00 committed by Marge Bot
parent bff72f6c23
commit 0bd463c2af
5 changed files with 126 additions and 0 deletions

View file

@ -47,6 +47,7 @@ EXTENSIONS = (
['XR_KHR_D3D12_enable', 'XR_USE_GRAPHICS_API_D3D12'], ['XR_KHR_D3D12_enable', 'XR_USE_GRAPHICS_API_D3D12'],
['XR_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'], ['XR_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'],
['XR_KHR_loader_init_android', 'OXR_HAVE_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_enable', 'XR_USE_GRAPHICS_API_OPENGL'],
['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'], ['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'],
['XR_KHR_swapchain_usage_input_attachment_bit'], ['XR_KHR_swapchain_usage_input_attachment_bit'],

View file

@ -571,6 +571,15 @@ oxr_xrGetDisplayRefreshRateFB(XrSession session, float *displayRefreshRate);
XRAPI_ATTR XrResult XRAPI_CALL XRAPI_ATTR XrResult XRAPI_CALL
oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate); 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 * oxr_api_passthrough.c

View file

@ -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); ENTRY_IF_EXT(xrCreateXDevSpaceMNDX, MNDX_xdev_space);
#endif // OXR_HAVE_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 * Not logging here because there's no need to loudly advertise
* which extensions the loader knows about (it calls this on * which extensions the loader knows about (it calls this on

View file

@ -7,6 +7,9 @@
* @ingroup oxr_api * @ingroup oxr_api
*/ */
#include "openxr/openxr.h"
#include "oxr_chain.h"
#include "util/u_misc.h"
#include "xrt/xrt_compiler.h" #include "xrt/xrt_compiler.h"
#include "util/u_debug.h" #include "util/u_debug.h"
@ -244,3 +247,98 @@ oxr_xrDestroySpace(XrSpace space)
return oxr_handle_destroy(&log, &spc->handle); 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);
}

View file

@ -179,6 +179,17 @@
#endif #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 * XR_KHR_opengl_enable
*/ */
@ -671,6 +682,7 @@
OXR_EXTENSION_SUPPORT_KHR_D3D12_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_D3D12_enable(_) \
OXR_EXTENSION_SUPPORT_KHR_loader_init(_) \ OXR_EXTENSION_SUPPORT_KHR_loader_init(_) \
OXR_EXTENSION_SUPPORT_KHR_loader_init_android(_) \ OXR_EXTENSION_SUPPORT_KHR_loader_init_android(_) \
OXR_EXTENSION_SUPPORT_KHR_locate_spaces(_) \
OXR_EXTENSION_SUPPORT_KHR_opengl_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_enable(_) \
OXR_EXTENSION_SUPPORT_KHR_opengl_es_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_es_enable(_) \
OXR_EXTENSION_SUPPORT_KHR_swapchain_usage_input_attachment_bit(_) \ OXR_EXTENSION_SUPPORT_KHR_swapchain_usage_input_attachment_bit(_) \