From 0ef39d11d8b2cd56cf70731ae67e3cfe0ba8726d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 6 Nov 2022 15:37:58 +0100 Subject: [PATCH] Add a dynamic loader for OpenXR so the VR code can link. Make it all build on Windows. --- CMakeLists.txt | 2 + Common/Common.vcxproj | 4 +- Common/Common.vcxproj.filters | 8 +- Common/VR/OpenXRLoader.cpp | 160 ++++++++++++++++++++++++++++++++++ Common/VR/OpenXRLoader.h | 109 +++++++++++++++++++++++ Common/VR/PPSSPPVR.cpp | 18 ++-- Common/VR/PPSSPPVR.h | 33 ------- Common/VR/VRBase.cpp | 20 +++-- Common/VR/VRBase.h | 32 +------ Common/VR/VRRenderer.cpp | 1 + android/jni/Android.mk | 1 + libretro/Makefile.common | 1 + 12 files changed, 312 insertions(+), 77 deletions(-) create mode 100644 Common/VR/OpenXRLoader.cpp create mode 100644 Common/VR/OpenXRLoader.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b9084bea3a..12c75eaff3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -507,6 +507,8 @@ if(WIN32) endif() set(CommonVR + Common/VR/OpenXRLoader.cpp + Common/VR/OpenXRLoader.h Common/VR/PPSSPPVR.cpp Common/VR/PPSSPPVR.h Common/VR/VRBase.cpp diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 5c085bd0ed..39e804db79 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -557,6 +557,7 @@ + @@ -995,6 +996,7 @@ + @@ -1015,4 +1017,4 @@ - + \ No newline at end of file diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 5c58a6453f..33468b43d8 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -443,6 +443,9 @@ VR + + VR + @@ -839,6 +842,9 @@ VR + + VR + @@ -952,4 +958,4 @@ ext\libpng17 - + \ No newline at end of file diff --git a/Common/VR/OpenXRLoader.cpp b/Common/VR/OpenXRLoader.cpp new file mode 100644 index 0000000000..57b39f85f1 --- /dev/null +++ b/Common/VR/OpenXRLoader.cpp @@ -0,0 +1,160 @@ +#include "Common/VR/OpenXRLoader.h" +#ifdef _WIN32 +#include "Common/CommonWindows.h" +#endif + +#ifdef XR_NO_PROTOTYPES + +PFN_xrGetInstanceProcAddr xrGetInstanceProcAddr; +PFN_xrEnumerateApiLayerProperties xrEnumerateApiLayerProperties; +PFN_xrEnumerateInstanceExtensionProperties xrEnumerateInstanceExtensionProperties; +PFN_xrCreateInstance xrCreateInstance; +PFN_xrDestroyInstance xrDestroyInstance; +PFN_xrGetInstanceProperties xrGetInstanceProperties; +PFN_xrPollEvent xrPollEvent; +PFN_xrResultToString xrResultToString; +PFN_xrStructureTypeToString xrStructureTypeToString; +PFN_xrGetSystem xrGetSystem; +PFN_xrGetSystemProperties xrGetSystemProperties; +PFN_xrEnumerateEnvironmentBlendModes xrEnumerateEnvironmentBlendModes; +PFN_xrCreateSession xrCreateSession; +PFN_xrDestroySession xrDestroySession; +PFN_xrEnumerateReferenceSpaces xrEnumerateReferenceSpaces; +PFN_xrCreateReferenceSpace xrCreateReferenceSpace; +PFN_xrGetReferenceSpaceBoundsRect xrGetReferenceSpaceBoundsRect; +PFN_xrCreateActionSpace xrCreateActionSpace; +PFN_xrLocateSpace xrLocateSpace; +PFN_xrDestroySpace xrDestroySpace; +PFN_xrEnumerateViewConfigurations xrEnumerateViewConfigurations; +PFN_xrGetViewConfigurationProperties xrGetViewConfigurationProperties; +PFN_xrEnumerateViewConfigurationViews xrEnumerateViewConfigurationViews; +PFN_xrEnumerateSwapchainFormats xrEnumerateSwapchainFormats; +PFN_xrCreateSwapchain xrCreateSwapchain; +PFN_xrDestroySwapchain xrDestroySwapchain; +PFN_xrEnumerateSwapchainImages xrEnumerateSwapchainImages; +PFN_xrAcquireSwapchainImage xrAcquireSwapchainImage; +PFN_xrWaitSwapchainImage xrWaitSwapchainImage; +PFN_xrReleaseSwapchainImage xrReleaseSwapchainImage; +PFN_xrBeginSession xrBeginSession; +PFN_xrEndSession xrEndSession; +PFN_xrRequestExitSession xrRequestExitSession; +PFN_xrWaitFrame xrWaitFrame; +PFN_xrBeginFrame xrBeginFrame; +PFN_xrEndFrame xrEndFrame; +PFN_xrLocateViews xrLocateViews; +PFN_xrStringToPath xrStringToPath; +PFN_xrPathToString xrPathToString; +PFN_xrCreateActionSet xrCreateActionSet; +PFN_xrDestroyActionSet xrDestroyActionSet; +PFN_xrCreateAction xrCreateAction; +PFN_xrDestroyAction xrDestroyAction; +PFN_xrSuggestInteractionProfileBindings xrSuggestInteractionProfileBindings; +PFN_xrAttachSessionActionSets xrAttachSessionActionSets; +PFN_xrGetCurrentInteractionProfile xrGetCurrentInteractionProfile; +PFN_xrGetActionStateBoolean xrGetActionStateBoolean; +PFN_xrGetActionStateFloat xrGetActionStateFloat; +PFN_xrGetActionStateVector2f xrGetActionStateVector2f; +PFN_xrGetActionStatePose xrGetActionStatePose; +PFN_xrSyncActions xrSyncActions; +PFN_xrEnumerateBoundSourcesForAction xrEnumerateBoundSourcesForAction; +PFN_xrGetInputSourceLocalizedName xrGetInputSourceLocalizedName; +PFN_xrApplyHapticFeedback xrApplyHapticFeedback; +PFN_xrStopHapticFeedback xrStopHapticFeedback; + +#ifdef _WIN32 +#define dlsym(x, y) GetProcAddress(x, y) +static HMODULE g_xrLibrary; +#else +#define dlsym(x, y) nullptr +void *xrLibrary; +#endif + +#define LOAD_INSTANCE_FUNC(name) (PFN_ ## name)xrGetInstanceProcAddr(instance, #name, (PFN_xrVoidFunction *)(&name)) + + +bool XRLoad() { + if (g_xrLibrary) { + // Already loaded. That's OK. + return true; + } + +#ifdef _WIN32 + g_xrLibrary = LoadLibrary(L"openxr_loader.dll"); + if (!g_xrLibrary) { + return false; + } +#else + void *library = nullptr; +#endif + + // Load the three basic functions. + xrGetInstanceProcAddr = (PFN_xrGetInstanceProcAddr)dlsym(g_xrLibrary, "xrGetInstanceProcAddr"); + xrEnumerateApiLayerProperties = (PFN_xrEnumerateApiLayerProperties)dlsym(g_xrLibrary, "xrEnumerateApiLayerProperties"); + xrEnumerateInstanceExtensionProperties = (PFN_xrEnumerateInstanceExtensionProperties)dlsym(g_xrLibrary, "xrEnumerateInstanceExtensionProperties"); + + // Load the rest. + return true; +} + +void XRLoadInstanceFunctions(XrInstance instance) { + LOAD_INSTANCE_FUNC(xrCreateInstance); + LOAD_INSTANCE_FUNC(xrGetInstanceProcAddr); + LOAD_INSTANCE_FUNC(xrEnumerateApiLayerProperties); + LOAD_INSTANCE_FUNC(xrEnumerateInstanceExtensionProperties); + LOAD_INSTANCE_FUNC(xrCreateInstance); + LOAD_INSTANCE_FUNC(xrDestroyInstance); + LOAD_INSTANCE_FUNC(xrGetInstanceProperties); + LOAD_INSTANCE_FUNC(xrPollEvent); + LOAD_INSTANCE_FUNC(xrResultToString); + LOAD_INSTANCE_FUNC(xrStructureTypeToString); + LOAD_INSTANCE_FUNC(xrGetSystem); + LOAD_INSTANCE_FUNC(xrGetSystemProperties); + LOAD_INSTANCE_FUNC(xrEnumerateEnvironmentBlendModes); + LOAD_INSTANCE_FUNC(xrCreateSession); + LOAD_INSTANCE_FUNC(xrDestroySession); + LOAD_INSTANCE_FUNC(xrEnumerateReferenceSpaces); + LOAD_INSTANCE_FUNC(xrCreateReferenceSpace); + LOAD_INSTANCE_FUNC(xrGetReferenceSpaceBoundsRect); + LOAD_INSTANCE_FUNC(xrCreateActionSpace); + LOAD_INSTANCE_FUNC(xrLocateSpace); + LOAD_INSTANCE_FUNC(xrDestroySpace); + LOAD_INSTANCE_FUNC(xrEnumerateViewConfigurations); + LOAD_INSTANCE_FUNC(xrGetViewConfigurationProperties); + LOAD_INSTANCE_FUNC(xrEnumerateViewConfigurationViews); + LOAD_INSTANCE_FUNC(xrEnumerateSwapchainFormats); + LOAD_INSTANCE_FUNC(xrCreateSwapchain); + LOAD_INSTANCE_FUNC(xrDestroySwapchain); + LOAD_INSTANCE_FUNC(xrEnumerateSwapchainImages); + LOAD_INSTANCE_FUNC(xrAcquireSwapchainImage); + LOAD_INSTANCE_FUNC(xrWaitSwapchainImage); + LOAD_INSTANCE_FUNC(xrReleaseSwapchainImage); + LOAD_INSTANCE_FUNC(xrBeginSession); + LOAD_INSTANCE_FUNC(xrEndSession); + LOAD_INSTANCE_FUNC(xrRequestExitSession); + LOAD_INSTANCE_FUNC(xrWaitFrame); + LOAD_INSTANCE_FUNC(xrBeginFrame); + LOAD_INSTANCE_FUNC(xrEndFrame); + LOAD_INSTANCE_FUNC(xrLocateViews); + LOAD_INSTANCE_FUNC(xrStringToPath); + LOAD_INSTANCE_FUNC(xrPathToString); + LOAD_INSTANCE_FUNC(xrCreateActionSet); + LOAD_INSTANCE_FUNC(xrDestroyActionSet); + LOAD_INSTANCE_FUNC(xrCreateAction); + LOAD_INSTANCE_FUNC(xrDestroyAction); + LOAD_INSTANCE_FUNC(xrSuggestInteractionProfileBindings); + LOAD_INSTANCE_FUNC(xrAttachSessionActionSets); + LOAD_INSTANCE_FUNC(xrGetCurrentInteractionProfile); + LOAD_INSTANCE_FUNC(xrGetActionStateBoolean); + LOAD_INSTANCE_FUNC(xrGetActionStateFloat); + LOAD_INSTANCE_FUNC(xrGetActionStateVector2f); + LOAD_INSTANCE_FUNC(xrGetActionStatePose); + LOAD_INSTANCE_FUNC(xrSyncActions); + LOAD_INSTANCE_FUNC(xrEnumerateBoundSourcesForAction); + LOAD_INSTANCE_FUNC(xrGetInputSourceLocalizedName); + LOAD_INSTANCE_FUNC(xrApplyHapticFeedback); + LOAD_INSTANCE_FUNC(xrStopHapticFeedback); + + // TODO: Load any extensions we need, too. +} + +#endif diff --git a/Common/VR/OpenXRLoader.h b/Common/VR/OpenXRLoader.h new file mode 100644 index 0000000000..e8b4822d86 --- /dev/null +++ b/Common/VR/OpenXRLoader.h @@ -0,0 +1,109 @@ +#pragma once + +//Vulkan +#ifdef VK_USE_NATIVE_LIB +#include +#else +#include "Common/GPU/Vulkan/VulkanLoader.h" +using namespace PPSSPP_VK; +#endif + +#ifdef ANDROID +//OpenXR +#define XR_USE_PLATFORM_ANDROID 1 +#define XR_USE_GRAPHICS_API_OPENGL_ES 1 +#define XR_USE_GRAPHICS_API_VULKAN 1 +#include +#include +#include +#elif defined(_WIN32) +#include "Common/CommonWindows.h" +#include "Common/GPU/OpenGL/GLCommon.h" +#include "Common/VR/OpenXRLoader.h" +#include +#define XR_USE_PLATFORM_WIN32 1 +#define XR_USE_GRAPHICS_API_OPENGL 1 +#define XR_USE_GRAPHICS_API_VULKAN 1 +#define XR_NO_PROTOTYPES 1 +#else +#define XR_USE_GRAPHICS_API_VULKAN 1 +#define XR_NO_PROTOTYPES 1 +#endif + +#include +#include + +#ifdef XR_NO_PROTOTYPES + +extern PFN_xrGetInstanceProcAddr xrGetInstanceProcAddr; +extern PFN_xrEnumerateApiLayerProperties xrEnumerateApiLayerProperties; +extern PFN_xrEnumerateInstanceExtensionProperties xrEnumerateInstanceExtensionProperties; +extern PFN_xrCreateInstance xrCreateInstance; +extern PFN_xrDestroyInstance xrDestroyInstance; +extern PFN_xrGetInstanceProperties xrGetInstanceProperties; +extern PFN_xrPollEvent xrPollEvent; +extern PFN_xrResultToString xrResultToString; +extern PFN_xrStructureTypeToString xrStructureTypeToString; +extern PFN_xrGetSystem xrGetSystem; +extern PFN_xrGetSystemProperties xrGetSystemProperties; +extern PFN_xrEnumerateEnvironmentBlendModes xrEnumerateEnvironmentBlendModes; +extern PFN_xrCreateSession xrCreateSession; +extern PFN_xrDestroySession xrDestroySession; +extern PFN_xrEnumerateReferenceSpaces xrEnumerateReferenceSpaces; +extern PFN_xrCreateReferenceSpace xrCreateReferenceSpace; +extern PFN_xrGetReferenceSpaceBoundsRect xrGetReferenceSpaceBoundsRect; +extern PFN_xrCreateActionSpace xrCreateActionSpace; +extern PFN_xrLocateSpace xrLocateSpace; +extern PFN_xrDestroySpace xrDestroySpace; +extern PFN_xrEnumerateViewConfigurations xrEnumerateViewConfigurations; +extern PFN_xrGetViewConfigurationProperties xrGetViewConfigurationProperties; +extern PFN_xrEnumerateViewConfigurationViews xrEnumerateViewConfigurationViews; +extern PFN_xrEnumerateSwapchainFormats xrEnumerateSwapchainFormats; +extern PFN_xrCreateSwapchain xrCreateSwapchain; +extern PFN_xrDestroySwapchain xrDestroySwapchain; +extern PFN_xrEnumerateSwapchainImages xrEnumerateSwapchainImages; +extern PFN_xrAcquireSwapchainImage xrAcquireSwapchainImage; +extern PFN_xrWaitSwapchainImage xrWaitSwapchainImage; +extern PFN_xrReleaseSwapchainImage xrReleaseSwapchainImage; +extern PFN_xrBeginSession xrBeginSession; +extern PFN_xrEndSession xrEndSession; +extern PFN_xrRequestExitSession xrRequestExitSession; +extern PFN_xrWaitFrame xrWaitFrame; +extern PFN_xrBeginFrame xrBeginFrame; +extern PFN_xrEndFrame xrEndFrame; +extern PFN_xrLocateViews xrLocateViews; +extern PFN_xrStringToPath xrStringToPath; +extern PFN_xrPathToString xrPathToString; +extern PFN_xrCreateActionSet xrCreateActionSet; +extern PFN_xrDestroyActionSet xrDestroyActionSet; +extern PFN_xrCreateAction xrCreateAction; +extern PFN_xrDestroyAction xrDestroyAction; +extern PFN_xrSuggestInteractionProfileBindings xrSuggestInteractionProfileBindings; +extern PFN_xrAttachSessionActionSets xrAttachSessionActionSets; +extern PFN_xrGetCurrentInteractionProfile xrGetCurrentInteractionProfile; +extern PFN_xrGetActionStateBoolean xrGetActionStateBoolean; +extern PFN_xrGetActionStateFloat xrGetActionStateFloat; +extern PFN_xrGetActionStateVector2f xrGetActionStateVector2f; +extern PFN_xrGetActionStatePose xrGetActionStatePose; +extern PFN_xrSyncActions xrSyncActions; +extern PFN_xrEnumerateBoundSourcesForAction xrEnumerateBoundSourcesForAction; +extern PFN_xrGetInputSourceLocalizedName xrGetInputSourceLocalizedName; +extern PFN_xrApplyHapticFeedback xrApplyHapticFeedback; +extern PFN_xrStopHapticFeedback xrStopHapticFeedback; + +// Dynamic loader for OpenXR on desktop platforms. +// On Quest/Pico, we use statically linked loaders provided by the platform owners. +// On Windows (and Linux etc), we're not so lucky - we could link to static libraries, but we really +// don't want to as we still want to function when one is not present. +// +// Similar to our dynamic Vulkan loader. + +bool XRLoad(); +void XRLoadInstanceFunctions(XrInstance instance); + +#else + +inline bool XRLoad() { return true; } +inline void XRLoadInstanceFunctions(XrInstance instance) {} + +#endif diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index e133ebd277..4cec7c42c9 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -1,5 +1,3 @@ -#ifdef OPENXR - #include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/GPU/Vulkan/VulkanContext.h" @@ -396,6 +394,12 @@ void* BindVRFramebuffer() { return VR_BindFramebuffer(VR_GetEngine()); } +inline float clampFloat(float x, float minValue, float maxValue) { + if (x < minValue) return minValue; + if (x > maxValue) return maxValue; + return x; +} + bool StartVRRender() { if (!VR_GetConfig(VR_CONFIG_VIEWPORT_VALID)) { VR_InitRenderer(VR_GetEngine(), IsMultiviewSupported()); @@ -430,8 +434,8 @@ bool StartVRRender() { height = 0; side = 0; } - g_Config.fCameraHeight = std::clamp(height, -10.0f, 10.0f); - g_Config.fCameraSide = std::clamp(side, -10.0f, 10.0f); + g_Config.fCameraHeight = clampFloat(height, -10.0f, 10.0f); + g_Config.fCameraSide = clampFloat(side, -10.0f, 10.0f); //right joystick controls distance and fov float dst = g_Config.fCameraDistance; @@ -445,8 +449,8 @@ bool StartVRRender() { fov = 100; dst = 0; } - g_Config.fCameraDistance = std::clamp(dst, -10.0f, 10.0f); - g_Config.fFieldOfViewPercentage = std::clamp(fov, 100.0f, 200.0f); + g_Config.fCameraDistance = clampFloat(dst, -10.0f, 10.0f); + g_Config.fFieldOfViewPercentage = clampFloat(fov, 100.0f, 200.0f); } // Set customizations @@ -599,5 +603,3 @@ void UpdateVRView(float* leftEye, float* rightEye) { memcpy(dst[index], renderView.M, 16 * sizeof(float)); } } - -#endif diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index dfb38471b1..2dd2d1c11f 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -17,8 +17,6 @@ enum VRCompatFlag { VR_COMPAT_MAX }; -#ifdef OPENXR - // VR app flow integration bool IsVREnabled(); void InitVROnAndroid(void* vm, void* activity, const char* system, int version, const char* name); @@ -45,34 +43,3 @@ bool Is2DVRObject(float* projMatrix, bool ortho); void UpdateVRParams(float* projMatrix); void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye); void UpdateVRView(float* leftEye, float* rightEye); - -#else //dummy integration - -// VR app flow integration -inline bool IsVREnabled() { return false; } -inline void InitVROnAndroid(void* vm, void* activity, const char* system, int version, const char* name) {} -inline void EnterVR(bool firstTime, void* vulkanContext) {} -inline void GetVRResolutionPerEye(int* width, int* height) {} -inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale) {} -inline void UpdateVRSpecialKeys(const KeyInput &key) {} - -// VR games compatibility -inline void PreprocessStepVR(void* step) {} -inline void SetVRCompat(VRCompatFlag flag, long value) {} - -// VR rendering integration -inline void* BindVRFramebuffer() { return nullptr; } -inline bool StartVRRender() { return false; } -inline void FinishVRRender() {} -inline void PreVRFrameRender(int fboIndex) {} -inline void PostVRFrameRender() {} -inline int GetVRFBOIndex() { return 0; } -inline int GetVRPassesCount() { return 1; } -inline bool IsMultiviewSupported() { return false; } -inline bool IsFlatVRScene() { return true; } -inline bool Is2DVRObject(float* projMatrix, bool ortho) { return false; } -inline void UpdateVRParams(float* projMatrix) {} -inline void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye) {} -inline void UpdateVRView(float* leftEye, float* rightEye) {} - -#endif diff --git a/Common/VR/VRBase.cpp b/Common/VR/VRBase.cpp index ec4a44c703..d6ff987fc4 100644 --- a/Common/VR/VRBase.cpp +++ b/Common/VR/VRBase.cpp @@ -41,12 +41,14 @@ static bool vr_platform[VR_PLATFORM_MAX]; static engine_t vr_engine; int vr_initialized = 0; -#if defined(OPENXR) - void VR_Init( void* system, const char* name, int version ) { if (vr_initialized) return; + if (!XRLoad()) { + return; + } + ovrApp_Clear(&vr_engine.appState); #ifdef ANDROID @@ -68,9 +70,12 @@ void VR_Init( void* system, const char* name, int version ) { if (VR_GetPlatformFlag(VR_PLATFORM_RENDERER_VULKAN)) { extensions.push_back(XR_KHR_VULKAN_ENABLE_EXTENSION_NAME); } else { +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES extensions.push_back(XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME); +#endif } extensions.push_back(XR_KHR_COMPOSITION_LAYER_CYLINDER_EXTENSION_NAME); +#ifdef ANDROID if (VR_GetPlatformFlag(VR_PLATFORM_PERFORMANCE_EXT)) { extensions.push_back(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME); extensions.push_back(XR_KHR_ANDROID_THREAD_SETTINGS_EXTENSION_NAME); @@ -83,6 +88,7 @@ void VR_Init( void* system, const char* name, int version ) { extensions.push_back("XR_PICO_configs_ext"); extensions.push_back("XR_PICO_reset_sensor"); } +#endif // Create the OpenXR instance. XrApplicationInfo appInfo; @@ -101,7 +107,7 @@ void VR_Init( void* system, const char* name, int version ) { instanceCreateInfo.applicationInfo = appInfo; instanceCreateInfo.enabledApiLayerCount = 0; instanceCreateInfo.enabledApiLayerNames = NULL; - instanceCreateInfo.enabledExtensionCount = extensions.size(); + instanceCreateInfo.enabledExtensionCount = (uint32_t)extensions.size(); instanceCreateInfo.enabledExtensionNames = extensions.data(); #ifdef ANDROID @@ -121,6 +127,8 @@ void VR_Init( void* system, const char* name, int version ) { exit(1); } + XRLoadInstanceFunctions(vr_engine.appState.Instance); + if (VR_GetPlatformFlag(VR_PLATFORM_PICO_INIT)) { xrGetInstanceProcAddr(vr_engine.appState.Instance, "xrSetEngineVersionPico", (PFN_xrVoidFunction*)(&pfnXrSetEngineVersionPico)); xrGetInstanceProcAddr(vr_engine.appState.Instance, "xrStartCVControllerThreadPico", (PFN_xrVoidFunction*)(&pfnXrStartCVControllerThreadPico)); @@ -166,6 +174,7 @@ void VR_Init( void* system, const char* name, int version ) { graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR; OXR(pfnGetVulkanGraphicsRequirementsKHR(vr_engine.appState.Instance, systemId, &graphicsRequirements)); } else { +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES PFN_xrGetOpenGLESGraphicsRequirementsKHR pfnGetOpenGLESGraphicsRequirementsKHR = NULL; OXR(xrGetInstanceProcAddr( vr_engine.appState.Instance, @@ -175,15 +184,16 @@ void VR_Init( void* system, const char* name, int version ) { XrGraphicsRequirementsOpenGLESKHR graphicsRequirements = {}; graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_ES_KHR; OXR(pfnGetOpenGLESGraphicsRequirementsKHR(vr_engine.appState.Instance, systemId, &graphicsRequirements)); +#endif } +#ifdef ANDROID vr_engine.appState.MainThreadTid = gettid(); +#endif vr_engine.appState.SystemId = systemId; vr_initialized = 1; } -#endif - void VR_Destroy( engine_t* engine ) { if (engine == &vr_engine) { if (VR_GetPlatformFlag(VR_PLATFORM_PICO_INIT)) { diff --git a/Common/VR/VRBase.h b/Common/VR/VRBase.h index 0893ac7f84..34e52908d4 100644 --- a/Common/VR/VRBase.h +++ b/Common/VR/VRBase.h @@ -10,36 +10,10 @@ #define ALOGV(...) printf(__VA_ARGS__) #endif -//Vulkan -#ifdef VK_USE_NATIVE_LIB -#include -#else -#include "Common/GPU/Vulkan/VulkanLoader.h" -using namespace PPSSPP_VK; -#endif +#include "Common/VR/OpenXRLoader.h" -#ifdef ANDROID -//OpenXR -#define XR_USE_PLATFORM_ANDROID 1 -#define XR_USE_GRAPHICS_API_OPENGL_ES 1 -#define XR_USE_GRAPHICS_API_VULKAN 1 -#include -#include -#include -#elif defined(_WIN32) -#include "Common/CommonWindows.h" -#include "Common/GPU/OpenGL/GLCommon.h" -#include -#define XR_USE_PLATFORM_WIN32 1 -#define XR_USE_GRAPHICS_API_OPENGL 1 -#define XR_USE_GRAPHICS_API_VULKAN 1 -#else -#define XR_USE_GRAPHICS_API_VULKAN 1 -#endif - -#include -#include -#include +#define _USE_MATH_DEFINES +#include #ifdef ANDROID diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index 6895ad024f..e67d4ecd62 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -4,6 +4,7 @@ #include "VRBase.h" #include "VRInput.h" #include "VRRenderer.h" +#include "OpenXRLoader.h" #include #include diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 8913f641e5..2f3887c3e2 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -72,6 +72,7 @@ SPIRV_CROSS_FILES := \ $(SRC)/ext/SPIRV-Cross/spirv_cross_parsed_ir.cpp VR_FILES := \ + $(SRC)/Common/VR/OpenXRLoader.cpp \ $(SRC)/Common/VR/PPSSPPVR.cpp \ $(SRC)/Common/VR/VRBase.cpp \ $(SRC)/Common/VR/VRFramebuffer.cpp \ diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 7d858e0129..27540dc86f 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -314,6 +314,7 @@ SOURCES_CXX += \ $(COMMONDIR)/TimeUtil.cpp SOURCES_CXX += \ + $(COMMONDIR)/VR/OpenXRLoader.cpp \ $(COMMONDIR)/VR/PPSSPPVR.cpp \ $(COMMONDIR)/VR/VRBase.cpp \ $(COMMONDIR)/VR/VRMath.cpp \