From 723d641771e37d2576b162efc1c9f8e51f532da7 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 27 Aug 2022 12:23:03 +0200 Subject: [PATCH] OpenXR - Enable performance mode --- Common/VR/VRBase.cpp | 4 ++++ Common/VR/VRBase.h | 2 ++ Common/VR/VRFramebuffer.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/Common/VR/VRBase.cpp b/Common/VR/VRBase.cpp index 56745116e7..9932d09553 100644 --- a/Common/VR/VRBase.cpp +++ b/Common/VR/VRBase.cpp @@ -10,6 +10,10 @@ int vr_initialized = 0; const char* const requiredExtensionNames[] = { XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME, +#ifdef OPENXR_HAS_PERFORMANCE_EXTENSION + XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME, + XR_KHR_ANDROID_THREAD_SETTINGS_EXTENSION_NAME, +#endif XR_KHR_COMPOSITION_LAYER_CYLINDER_EXTENSION_NAME}; const uint32_t numRequiredExtensions = sizeof(requiredExtensionNames) / sizeof(requiredExtensionNames[0]); diff --git a/Common/VR/VRBase.h b/Common/VR/VRBase.h index ae7fb7fcd3..482c541a91 100644 --- a/Common/VR/VRBase.h +++ b/Common/VR/VRBase.h @@ -73,6 +73,8 @@ static void OXR_CheckErrors(XrInstance instance, XrResult result, const char* fu #define OXR(func) func; #endif +#define OPENXR_HAS_PERFORMANCE_EXTENSION + enum { ovrMaxLayerCount = 1 }; enum { ovrMaxNumEyes = 2 }; diff --git a/Common/VR/VRFramebuffer.cpp b/Common/VR/VRFramebuffer.cpp index 81e40ec3d8..cda680908d 100644 --- a/Common/VR/VRFramebuffer.cpp +++ b/Common/VR/VRFramebuffer.cpp @@ -273,6 +273,32 @@ void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) { OXR(result = xrBeginSession(app->Session, &sessionBeginInfo)); app->SessionActive = (result == XR_SUCCESS); + + // Set session state once we have entered VR mode and have a valid session object. +#ifdef OPENXR_HAS_PERFORMANCE_EXTENSION + if (app->SessionActive) { + XrPerfSettingsLevelEXT cpuPerfLevel = XR_PERF_SETTINGS_LEVEL_BOOST_EXT; + XrPerfSettingsLevelEXT gpuPerfLevel = XR_PERF_SETTINGS_LEVEL_BOOST_EXT; + + PFN_xrPerfSettingsSetPerformanceLevelEXT pfnPerfSettingsSetPerformanceLevelEXT = NULL; + OXR(xrGetInstanceProcAddr( + app->Instance, + "xrPerfSettingsSetPerformanceLevelEXT", + (PFN_xrVoidFunction*)(&pfnPerfSettingsSetPerformanceLevelEXT))); + + OXR(pfnPerfSettingsSetPerformanceLevelEXT(app->Session, XR_PERF_SETTINGS_DOMAIN_CPU_EXT, cpuPerfLevel)); + OXR(pfnPerfSettingsSetPerformanceLevelEXT(app->Session, XR_PERF_SETTINGS_DOMAIN_GPU_EXT, gpuPerfLevel)); + + PFN_xrSetAndroidApplicationThreadKHR pfnSetAndroidApplicationThreadKHR = NULL; + OXR(xrGetInstanceProcAddr( + app->Instance, + "xrSetAndroidApplicationThreadKHR", + (PFN_xrVoidFunction*)(&pfnSetAndroidApplicationThreadKHR))); + + OXR(pfnSetAndroidApplicationThreadKHR(app->Session, XR_ANDROID_THREAD_TYPE_APPLICATION_MAIN_KHR, app->MainThreadTid)); + OXR(pfnSetAndroidApplicationThreadKHR(app->Session, XR_ANDROID_THREAD_TYPE_RENDERER_MAIN_KHR, app->RenderThreadTid)); + } +#endif } else if (state == XR_SESSION_STATE_STOPPING) { assert(app->SessionActive);