st/oxr: Implementation of XR_KHR_android_thread_settings

This commit is contained in:
Jiali Zhang 2023-09-12 14:39:09 +08:00 committed by Jakob Bornecrantz
parent 54017f6b3e
commit baf6c7f78d
7 changed files with 100 additions and 0 deletions

View file

@ -34,6 +34,7 @@ def not_(s):
# Keep sorted, KHR, EXT, Vendor, experimental (same order).
EXTENSIONS = (
['XR_KHR_android_create_instance', 'XR_USE_PLATFORM_ANDROID'],
['XR_KHR_android_thread_settings', 'XR_USE_PLATFORM_ANDROID'],
['XR_KHR_binding_modification'],
['XR_KHR_composition_layer_cube', 'XRT_FEATURE_OPENXR_LAYER_CUBE'],
['XR_KHR_composition_layer_cylinder', 'XRT_FEATURE_OPENXR_LAYER_CYLINDER'],

View file

@ -311,6 +311,12 @@ oxr_xrGetVisibilityMaskKHR(XrSession session,
XrVisibilityMaskKHR *visibilityMask);
#endif // OXR_HAVE_KHR_visibility_mask
#ifdef OXR_HAVE_KHR_android_thread_settings
//! OpenXR API function @ep{xrSetAndroidApplicationThreadKHR}
XRAPI_ATTR XrResult XRAPI_CALL
oxr_xrSetAndroidApplicationThreadKHR(XrSession session, XrAndroidThreadTypeKHR threadType, uint32_t threadId);
#endif // OXR_HAVE_KHR_android_thread_settings
#ifdef OXR_HAVE_EXT_performance_settings
//! OpenXR API function @ep{xrPerfSettingsSetPerformanceLevelEXT}
XRAPI_ATTR XrResult XRAPI_CALL

View file

@ -218,6 +218,10 @@ handle_non_null(struct oxr_instance *inst, struct oxr_logger *log, const char *n
ENTRY_IF_EXT(xrConvertTimeToWin32PerformanceCounterKHR, KHR_win32_convert_performance_counter_time);
#endif // OXR_HAVE_KHR_win32_convert_performance_counter_time
#ifdef OXR_HAVE_KHR_android_thread_settings
ENTRY_IF_EXT(xrSetAndroidApplicationThreadKHR, KHR_android_thread_settings);
#endif // XR_HAVE_KHR_android_thread_settings
#ifdef OXR_HAVE_EXT_performance_settings
ENTRY_IF_EXT(xrPerfSettingsSetPerformanceLevelEXT, EXT_performance_settings);
#endif // OXR_HAVE_EXT_performance_settings

View file

@ -583,3 +583,35 @@ oxr_xrRequestDisplayRefreshRateFB(XrSession session, float displayRefreshRate)
}
#endif
/*
*
* XR_KHR_android_thread_settings
*
*/
#ifdef OXR_HAVE_KHR_android_thread_settings
XRAPI_ATTR XrResult XRAPI_CALL
oxr_xrSetAndroidApplicationThreadKHR(XrSession session, XrAndroidThreadTypeKHR threadType, uint32_t threadId)
{
OXR_TRACE_MARKER();
struct oxr_session *sess = NULL;
struct oxr_logger log;
OXR_VERIFY_SESSION_AND_INIT_LOG(&log, session, sess, "xrSetAndroidApplicationThreadKHR");
OXR_VERIFY_SESSION_NOT_LOST(&log, sess);
if (threadType != XR_ANDROID_THREAD_TYPE_APPLICATION_MAIN_KHR &&
threadType != XR_ANDROID_THREAD_TYPE_APPLICATION_WORKER_KHR &&
threadType != XR_ANDROID_THREAD_TYPE_RENDERER_MAIN_KHR &&
threadType != XR_ANDROID_THREAD_TYPE_RENDERER_WORKER_KHR) {
return oxr_error(&log, XR_ERROR_VALIDATION_FAILURE, "(threadType == %d) is invalid", threadType);
}
OXR_VERIFY_EXTENSION(&log, sess->sys->inst, KHR_android_thread_settings);
return oxr_session_android_thread_settings(&log, sess, threadType, threadId);
}
#endif

View file

@ -32,6 +32,17 @@
#endif
/*
* XR_KHR_android_thread_settings
*/
#if defined(XR_KHR_android_thread_settings) && defined(XR_USE_PLATFORM_ANDROID)
#define OXR_HAVE_KHR_android_thread_settings
#define OXR_EXTENSION_SUPPORT_KHR_android_thread_settings(_) _(KHR_android_thread_settings, KHR_ANDROID_THREAD_SETTINGS)
#else
#define OXR_EXTENSION_SUPPORT_KHR_android_thread_settings(_)
#endif
/*
* XR_KHR_binding_modification
*/
@ -485,6 +496,7 @@
// clang-format off
#define OXR_EXTENSION_SUPPORT_GENERATE(_) \
OXR_EXTENSION_SUPPORT_KHR_android_create_instance(_) \
OXR_EXTENSION_SUPPORT_KHR_android_thread_settings(_) \
OXR_EXTENSION_SUPPORT_KHR_binding_modification(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_cube(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_cylinder(_) \

View file

@ -737,6 +737,14 @@ oxr_session_apply_force_feedback(struct oxr_logger *log,
struct oxr_hand_tracker *hand_tracker,
const XrForceFeedbackCurlApplyLocationsMNDX *locations);
#ifdef OXR_HAVE_KHR_android_thread_settings
XrResult
oxr_session_android_thread_settings(struct oxr_logger *log,
struct oxr_session *sess,
XrAndroidThreadTypeKHR threadType,
uint32_t threadId);
#endif // OXR_HAVE_KHR_android_thread_settings
/*
*
* oxr_space.c

View file

@ -1120,3 +1120,40 @@ oxr_session_apply_force_feedback(struct oxr_logger *log,
return XR_SUCCESS;
}
#ifdef OXR_HAVE_KHR_android_thread_settings
static enum xrt_thread_hint
xr_thread_type_to_thread_hint(XrAndroidThreadTypeKHR type)
{
switch (type) {
case XR_ANDROID_THREAD_TYPE_APPLICATION_MAIN_KHR: return XRT_THREAD_HINT_APPLICATION_MAIN;
case XR_ANDROID_THREAD_TYPE_APPLICATION_WORKER_KHR: return XRT_THREAD_HINT_APPLICATION_WORKER;
case XR_ANDROID_THREAD_TYPE_RENDERER_MAIN_KHR: return XRT_THREAD_HINT_RENDERER_MAIN;
case XR_ANDROID_THREAD_TYPE_RENDERER_WORKER_KHR: return XRT_THREAD_HINT_RENDERER_WORKER;
default: assert(false); return 0;
}
}
XrResult
oxr_session_android_thread_settings(struct oxr_logger *log,
struct oxr_session *sess,
XrAndroidThreadTypeKHR threadType,
uint32_t threadId)
{
struct xrt_compositor *xc = &sess->xcn->base;
if (xc == NULL) {
return oxr_error(log, XR_ERROR_FUNCTION_UNSUPPORTED,
"Extension XR_KHR_android_thread_settings not be implemented");
}
// Convert.
enum xrt_thread_hint xhint = xr_thread_type_to_thread_hint(threadType);
// Do the call!
xrt_result_t xret = xrt_comp_set_thread_hint(xc, xhint, threadId);
OXR_CHECK_XRET(log, sess, xret, oxr_session_android_thread_settings);
return XR_SUCCESS;
}
#endif // OXR_HAVE_KHR_android_thread_settings