Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oculus Quest native support #15659

Merged
merged 32 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
71da6a9
OpenXR - Quest target into Android Studio project added
lvonasek Jul 6, 2022
99a4a06
OpenXR - SDK added
lvonasek Jul 7, 2022
8ba87bf
OpenXR - Hide options which are not relevant for VR
lvonasek Jul 7, 2022
dc977a2
OpenXR - VR framebuffer class added
lvonasek Jul 7, 2022
9893e5c
OpenXR - VR mode initialization added
lvonasek Jul 8, 2022
f693850
OpenXR - Initial version of VR renderer added
lvonasek Jul 12, 2022
d109e7c
Merge branch 'master' into feature_openxr_quest
lvonasek Jul 12, 2022
08e01c9
OpenXR - Dummy rendering working
lvonasek Jul 15, 2022
553363a
OpenXR - Rendering into VR framebuffer works
lvonasek Jul 15, 2022
48cd392
OpenXR - Rendering UI fixed
lvonasek Jul 15, 2022
0d41691
OpenXR - Input class added
lvonasek Jul 17, 2022
a08325e
OpenXR - UI scale/resolution fixed
lvonasek Jul 17, 2022
29ff6af
OpenXR - UI controls integrated
lvonasek Jul 17, 2022
cc833fa
OpenXR - Hacky mapping to make the games playable
lvonasek Jul 17, 2022
67821ca
OpenXR - Controller mapping better
lvonasek Jul 22, 2022
28d598b
OpenXR - Button repeating implemented
lvonasek Jul 22, 2022
9dade20
OpenXR - Code formatting {
lvonasek Jul 23, 2022
7d9260e
OpenXR - Code formatting global variables
lvonasek Jul 23, 2022
18ad9ea
OpenXR - Code formatting header removal
lvonasek Jul 23, 2022
9fe7bbd
OpenXR - Pragma once instead of ifdefs
lvonasek Jul 24, 2022
8daba0d
OpenXR - Finalize VR renderer interface
lvonasek Jul 24, 2022
13221ed
OpenXR - VR code formatting fixed
lvonasek Jul 24, 2022
8c9fd58
OpenXR - Hide unsupported menus
lvonasek Jul 24, 2022
8f2904e
OpenXR - Default device config added
lvonasek Jul 24, 2022
eb2b305
OpenXR - Disable HW scaler on VR headsets
lvonasek Jul 24, 2022
b1e3d8b
OpenXR - Code formatting fixed
lvonasek Jul 24, 2022
c543c8f
Merge branch 'master' into feature_openxr_quest
lvonasek Jul 26, 2022
19ebbb6
OpenXR - Integrate SYSPROP_HAS_FILE_BROWSER
lvonasek Jul 26, 2022
b2509ad
OpenXR - Version info refactor
lvonasek Jul 26, 2022
ab9a48d
OpenXR - Static added to global variables
lvonasek Jul 26, 2022
89f5038
OpenXR - Move VR folder under Common
lvonasek Jul 26, 2022
4691b37
OpenXR - Use a build variant instead of a module
lvonasek Jul 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ include(GNUInstallDirs)

add_definitions(-DASSETS_DIR="${CMAKE_INSTALL_FULL_DATADIR}/ppsspp/assets/")

if(OPENXR)
add_definitions(-DOPENXR)
add_library(openxr SHARED IMPORTED)
include_directories(ext/openxr)
set_property(TARGET openxr PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/ext/openxr/libs/arm64-v8a/libopenxr_loader.so")
message("OpenXR enabled")
endif()

if(GOLD)
add_definitions(-DGOLD)
message("Gold Build")
Expand Down Expand Up @@ -1056,6 +1064,20 @@ if(ANDROID)
android/jni/OpenSLContext.cpp
android/jni/OpenSLContext.h
)

if (OPENXR)
set(nativeExtra ${nativeExtra}
VR/VRBase.cpp
VR/VRBase.h
VR/VRFramebuffer.cpp
VR/VRFramebuffer.h
VR/VRInput.cpp
VR/VRInput.h
VR/VRRenderer.cpp
VR/VRRenderer.h
)
set(nativeExtraLibs ${nativeExtraLibs} openxr)
endif()
# No target
elseif(IOS)
set(nativeExtra ${nativeExtra}
Expand Down
9 changes: 9 additions & 0 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static constexpr int TEXCACHE_NAME_CACHE_SIZE = 16;
extern void bindDefaultFBO();
#endif

#ifdef OPENXR
#include "VR/VRBase.h"
#include "VR/VRRenderer.h"
#endif

// Workaround for Retroarch. Simply declare
// extern GLuint g_defaultFBO;
// and set is as appropriate. Can adjust the variables in ext/native/base/display.h as
Expand Down Expand Up @@ -1653,6 +1658,10 @@ void GLQueueRunner::fbo_unbind() {
bindDefaultFBO();
#endif

#ifdef OPENXR
VR_BindFramebuffer(VR_GetEngine(), 0);
#endif

currentDrawHandle_ = 0;
currentReadHandle_ = 0;
CHECK_GL_ERROR_IF_DEBUG();
Expand Down
12 changes: 12 additions & 0 deletions Common/GPU/OpenGL/GLRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include "Common/MemoryUtil.h"
#include "Common/Math/math_util.h"

#ifdef OPENXR
#include "VR/VRBase.h"
#include "VR/VRRenderer.h"
#endif

#if 0 // def _DEBUG
#define VLOG(...) INFO_LOG(G3D, __VA_ARGS__)
#else
Expand Down Expand Up @@ -202,6 +207,9 @@ bool GLRenderManager::ThreadFrame() {
std::unique_lock<std::mutex> lock(mutex_);
if (!run_)
return false;
#ifdef OPENXR
VR_BeginFrame(VR_GetEngine());
#endif

// In case of syncs or other partial completion, we keep going until we complete a frame.
do {
Expand Down Expand Up @@ -240,6 +248,9 @@ bool GLRenderManager::ThreadFrame() {
Run(threadFrame_);
VLOG("PULL: Finished frame %d", threadFrame_);
} while (!nextFrame);
#ifdef OPENXR
VR_EndFrame(VR_GetEngine());
#endif
return true;
}

Expand Down Expand Up @@ -300,6 +311,7 @@ void GLRenderManager::BindFramebufferAsRenderTarget(GLRFramebuffer *fb, GLRRende
#ifdef _DEBUG
curProgram_ = nullptr;
#endif

// Eliminate dupes.
if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == GLRStepType::RENDER) {
if (color != GLRRenderPassAction::CLEAR && depth != GLRRenderPassAction::CLEAR && stencil != GLRRenderPassAction::CLEAR) {
Expand Down
6 changes: 6 additions & 0 deletions Common/GPU/Vulkan/VulkanLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ void VulkanSetAvailable(bool available) {
}

bool VulkanMayBeAvailable() {

#ifdef OPENXR
//unsupported at the moment
return false;
#endif

if (g_vulkanAvailabilityChecked) {
return g_vulkanMayBeAvailable;
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Input/InputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const char *GetDeviceName(int deviceId) {
case DEVICE_ID_XINPUT_3: return "x360_4";
case DEVICE_ID_ACCELEROMETER: return "accelerometer";
case DEVICE_ID_MOUSE: return "mouse";
case DEVICE_ID_XR_CONTROLLER_LEFT: return "xr_l";
case DEVICE_ID_XR_CONTROLLER_RIGHT: return "xr_r";
default:
return "unknown";
}
Expand Down
2 changes: 2 additions & 0 deletions Common/Input/InputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ enum {
DEVICE_ID_XINPUT_2 = 22,
DEVICE_ID_XINPUT_3 = 23,
DEVICE_ID_ACCELEROMETER = 30,
DEVICE_ID_XR_CONTROLLER_LEFT = 40,
DEVICE_ID_XR_CONTROLLER_RIGHT = 41,
};

//number of contiguous generic joypad IDs
Expand Down
1 change: 1 addition & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum SystemDeviceType {
DEVICE_TYPE_MOBILE = 0, // phones and pads
DEVICE_TYPE_TV = 1, // Android TV and similar
DEVICE_TYPE_DESKTOP = 2, // Desktop computer
DEVICE_TYPE_VR = 3, // VR headset
};

enum SystemKeyboardLayout {
Expand Down
9 changes: 9 additions & 0 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include "Common/Log.h"
#include "Common/StringUtils.h"

#ifdef OPENXR
#include "VR/VRBase.h"
#include "VR/VRRenderer.h"
#endif

static const bool ClickDebug = false;

UIScreen::UIScreen()
Expand Down Expand Up @@ -88,6 +93,10 @@ void UIScreen::preRender() {
draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, 0xFF000000 }, "UI");
screenManager()->getUIContext()->BeginFrame();

#ifdef OPENXR
VR_BindFramebuffer(VR_GetEngine(), 0);
#endif

Draw::Viewport viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
Expand Down
8 changes: 8 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ const char * const vulkanDefaultBlacklist[] = {
};

static int DefaultGPUBackend() {
#ifdef OPENXR
return (int)GPUBackend::OPENGL;
#endif

#if PPSSPP_PLATFORM(WINDOWS)
// If no Vulkan, use Direct3D 11 on Windows 8+ (most importantly 10.)
if (DoesVersionMatchWindows(6, 2, 0, 0, true)) {
Expand Down Expand Up @@ -956,6 +960,8 @@ static bool DefaultShowTouchControls() {
return false;
} else if (deviceType == DEVICE_TYPE_DESKTOP) {
return false;
} else if (deviceType == DEVICE_TYPE_VR) {
return false;
} else {
return false;
}
Expand Down Expand Up @@ -993,7 +999,9 @@ static ConfigSetting controlSettings[] = {
#if defined(USING_WIN_UI)
ConfigSetting("IgnoreWindowsKey", &g_Config.bIgnoreWindowsKey, false, true, true),
#endif

ConfigSetting("ShowTouchControls", &g_Config.bShowTouchControls, &DefaultShowTouchControls, true, true),

// ConfigSetting("KeyMapping", &g_Config.iMappingMap, 0),

#ifdef MOBILE_DEVICE
Expand Down
5 changes: 5 additions & 0 deletions Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool repla
void RestoreDefault() {
g_controllerMap.clear();
g_controllerMapGeneration++;
#ifdef OPENXR
SetDefaultKeyMap(DEFAULT_MAPPING_VR_HEADSET, false);
return;
#endif

#if PPSSPP_PLATFORM(WINDOWS)
SetDefaultKeyMap(DEFAULT_MAPPING_KEYBOARD, true);
SetDefaultKeyMap(DEFAULT_MAPPING_XINPUT, false);
Expand Down
26 changes: 26 additions & 0 deletions Core/KeyMapDefaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,28 @@ static const DefMappingStruct defaultXperiaPlay[] = {
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1},
};

static const DefMappingStruct defaultVRLeftController[] = {
{CTRL_UP , NKCODE_DPAD_UP},
{CTRL_DOWN , NKCODE_DPAD_DOWN},
{CTRL_LEFT , NKCODE_DPAD_LEFT},
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
{CTRL_SELECT , NKCODE_BUTTON_THUMBL},
{CTRL_LTRIGGER , NKCODE_BUTTON_X},
{CTRL_RTRIGGER , NKCODE_BUTTON_Y},
};

static const DefMappingStruct defaultVRRightController[] = {
{CTRL_CIRCLE , NKCODE_ALT_RIGHT},
{CTRL_CROSS , NKCODE_ENTER},
{CTRL_SQUARE , NKCODE_BUTTON_B},
{CTRL_TRIANGLE , NKCODE_BUTTON_A},
{CTRL_START , NKCODE_BUTTON_THUMBR},
{VIRTKEY_AXIS_Y_MAX, NKCODE_DPAD_UP},
{VIRTKEY_AXIS_Y_MIN, NKCODE_DPAD_DOWN},
{VIRTKEY_AXIS_X_MIN, NKCODE_DPAD_LEFT},
{VIRTKEY_AXIS_X_MAX, NKCODE_DPAD_RIGHT},
};

static void SetDefaultKeyMap(int deviceId, const DefMappingStruct *array, size_t count, bool replace) {
for (size_t i = 0; i < count; i++) {
if (array[i].direction == 0)
Expand Down Expand Up @@ -365,6 +387,10 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
case DEFAULT_MAPPING_RETRO_STATION_CONTROLLER:
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultRetroStationControllerMap, ARRAY_SIZE(defaultRetroStationControllerMap), replace);
break;
case DEFAULT_MAPPING_VR_HEADSET:
SetDefaultKeyMap(DEVICE_ID_XR_CONTROLLER_LEFT, defaultVRLeftController, ARRAY_SIZE(defaultVRLeftController), replace);
SetDefaultKeyMap(DEVICE_ID_XR_CONTROLLER_RIGHT, defaultVRRightController, ARRAY_SIZE(defaultVRRightController), replace);
break;
}

UpdateNativeMenuKeys();
Expand Down
1 change: 1 addition & 0 deletions Core/KeyMapDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum DefaultMaps {
DEFAULT_MAPPING_XPERIA_PLAY,
DEFAULT_MAPPING_MOQI_I7S,
DEFAULT_MAPPING_RETRO_STATION_CONTROLLER,
DEFAULT_MAPPING_VR_HEADSET,
};

void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
Expand Down
11 changes: 9 additions & 2 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ void GameSettingsScreen::CreateViews() {
}
}

#ifndef OPENXR
graphicsSettings->Add(new ItemHeader(gr->T("Screen layout")));
#if !defined(MOBILE_DEVICE)
graphicsSettings->Add(new CheckBox(&g_Config.bFullScreen, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenChange);
Expand Down Expand Up @@ -420,6 +421,7 @@ void GameSettingsScreen::CreateViews() {
// Let's reuse the Fullscreen translation string from desktop.
graphicsSettings->Add(new CheckBox(&g_Config.bImmersiveMode, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &GameSettingsScreen::OnImmersiveModeChange);
}
#endif
#endif

graphicsSettings->Add(new ItemHeader(gr->T("Performance")));
Expand All @@ -431,7 +433,8 @@ void GameSettingsScreen::CreateViews() {
});

#if PPSSPP_PLATFORM(ANDROID)
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_TV) {
int deviceType = System_GetPropertyInt(SYSPROP_DEVICE_TYPE);
if ((deviceType != DEVICE_TYPE_TV) && (deviceType != DEVICE_TYPE_VR)) {
static const char *deviceResolutions[] = { "Native device resolution", "Auto (same as Rendering)", "1x PSP", "2x PSP", "3x PSP", "4x PSP", "5x PSP" };
int max_res_temp = std::max(System_GetPropertyInt(SYSPROP_DISPLAY_XRES), System_GetPropertyInt(SYSPROP_DISPLAY_YRES)) / 480 + 2;
if (max_res_temp == 3)
Expand Down Expand Up @@ -585,7 +588,9 @@ void GameSettingsScreen::CreateViews() {
static const char *bufFilters[] = { "Linear", "Nearest", };
graphicsSettings->Add(new PopupMultiChoice(&g_Config.iBufFilter, gr->T("Screen Scaling Filter"), bufFilters, 1, ARRAY_SIZE(bufFilters), gr->GetName(), screenManager()));

#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
#ifdef OPENXR
bool showCardboardSettings = false;
#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
bool showCardboardSettings = true;
#else
// If you enabled it through the ini, you can see this. Useful for testing.
Expand Down Expand Up @@ -714,6 +719,7 @@ void GameSettingsScreen::CreateViews() {
});
}

#ifndef OPENXR
// TVs don't have touch control, at least not yet.
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_TV) {
controlsSettings->Add(new ItemHeader(co->T("OnScreen", "On-Screen Touch Controls")));
Expand Down Expand Up @@ -784,6 +790,7 @@ void GameSettingsScreen::CreateViews() {
controlsSettings->Add(new CheckBox(&g_Config.bMouseConfine, co->T("Confine Mouse", "Trap mouse within window/display area")))->SetEnabledPtr(&g_Config.bMouseControl);
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSensitivity, 0.01f, 1.0f, co->T("Mouse sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bMouseControl);
controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fMouseSmoothing, 0.0f, 0.95f, co->T("Mouse smoothing"), 0.05f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bMouseControl);
#endif
#endif

LinearLayout *networkingSettings = AddTab("GameSettingsNetworking", ms->T("Networking"));
Expand Down
4 changes: 4 additions & 0 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,17 +1121,21 @@ void MainScreen::CreateViews() {
ver->SetSmall(true);
ver->SetClip(false);

#ifndef OPENXR
lvonasek marked this conversation as resolved.
Show resolved Hide resolved
if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) {
rightColumnItems->Add(new Choice(mm->T("Load", "Load...")))->OnClick.Handle(this, &MainScreen::OnLoadFile);
}
#endif
rightColumnItems->Add(new Choice(mm->T("Game Settings", "Settings")))->OnClick.Handle(this, &MainScreen::OnGameSettings);
rightColumnItems->Add(new Choice(mm->T("Credits")))->OnClick.Handle(this, &MainScreen::OnCredits);
rightColumnItems->Add(new Choice(mm->T("www.ppsspp.org")))->OnClick.Handle(this, &MainScreen::OnPPSSPPOrg);
#ifndef OPENXR
if (!System_GetPropertyBool(SYSPROP_APP_GOLD)) {
Choice *gold = rightColumnItems->Add(new Choice(mm->T("Buy PPSSPP Gold")));
gold->OnClick.Handle(this, &MainScreen::OnSupport);
gold->SetIcon(ImageID("I_ICONGOLD"), 0.5f);
}
#endif

#if !PPSSPP_PLATFORM(UWP)
// Having an exit button is against UWP guidelines.
Expand Down
Loading