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

Mostly remove the use of the OPENXR ifdef #16344

Merged
merged 7 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 3 additions & 3 deletions Common/GPU/OpenGL/GLQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void GLQueueRunner::RunInitSteps(const std::vector<GLRInitStep> &steps, bool ski
_dbg_assert_(query.name);

int location = -1;
if (IsVRBuild() && IsMultiviewSupported()) {
if (IsVREnabled() && IsMultiviewSupported()) {
int index = GetStereoBufferIndex(query.name);
if (index >= 0) {
std::string layout = GetStereoBufferLayout(query.name);
Expand Down Expand Up @@ -707,7 +707,7 @@ void GLQueueRunner::RunSteps(const std::vector<GLRStep *> &steps, bool skipGLCal
switch (step.stepType) {
case GLRStepType::RENDER:
renderCount++;
if (IsVRBuild()) {
if (IsVREnabled()) {
GLRStep vrStep = step;
PreprocessStepVR(&vrStep);
PerformRenderPass(vrStep, renderCount == 1, renderCount == totalRenderCount);
Expand Down Expand Up @@ -1603,7 +1603,7 @@ void GLQueueRunner::PerformBindFramebufferAsRenderTarget(const GLRStep &pass) {
fbo_bind_fb_target(false, curFB_->handle);
} else {
fbo_unbind();
if (IsVRBuild()) {
if (IsVREnabled()) {
BindVRFramebuffer();
}
// Backbuffer is now bound.
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/OpenGL/GLRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void GLRenderManager::Run(int frame) {
}
}

if (IsVRBuild()) {
if (IsVREnabled()) {
int passes = GetVRPassesCount();
for (int i = 0; i < passes; i++) {
PreVRFrameRender(i);
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void VulkanSetAvailable(bool available) {

bool VulkanMayBeAvailable() {
// Unsupported in VR at the moment
if (IsVRBuild()) {
if (IsVREnabled()) {
return false;
}
Comment on lines 312 to 315
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although fine for now, I think it'll end up making sense to reverse this onto where VR is configured (until VR is available with Vulkan.)

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is just a minimal step, how configuration works will be redone later.


Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ VKRRenderPass *VulkanQueueRunner::PerformBindFramebufferAsRenderTarget(const VKR
};
renderPass = GetRenderPass(key);

if (IsVRBuild()) {
if (IsVREnabled()) {
framebuf = (VkFramebuffer)BindVRFramebuffer();
} else {
framebuf = backbuffer_;
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ void VulkanRenderManager::Run(VKRRenderThreadTask &task) {
if (task.steps.empty() && !frameData.hasAcquired)
frameData.skipSwap = true;
//queueRunner_.LogSteps(stepsOnThread, false);
if (IsVRBuild()) {
if (IsVREnabled()) {
int passes = GetVRPassesCount();
for (int i = 0; i < passes; i++) {
PreVRFrameRender(i);
Expand Down
8 changes: 7 additions & 1 deletion Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ VR app flow integration
================================================================================
*/

bool IsVRBuild() {
bool IsVREnabled() {
// For now, let the OPENXR build flag control enablement.
// This will change.
#ifdef OPENXR
return true;
#else
return false;
#endif
}

#if PPSSPP_PLATFORM(ANDROID)
Expand Down
4 changes: 2 additions & 2 deletions Common/VR/PPSSPPVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum VRCompatFlag {
#ifdef OPENXR

// VR app flow integration
bool IsVRBuild();
bool IsVREnabled();
void InitVROnAndroid(void* vm, void* activity, const char* system, int version, const char* name);
void EnterVR(bool firstStart, void* vulkanContext);
void GetVRResolutionPerEye(int* width, int* height);
Expand Down Expand Up @@ -49,7 +49,7 @@ void UpdateVRView(float* leftEye, float* rightEye);
#else //dummy integration

// VR app flow integration
inline bool IsVRBuild() { return false; }
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) {}
Expand Down
6 changes: 4 additions & 2 deletions Common/VR/VRBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <string.h>
#include <vector>

#if defined(OPENXR)

#ifndef _WIN32
#include <unistd.h>
#endif

enum ConfigsSetEXT {
UNREAL_VERSION = 0,
Expand Down Expand Up @@ -41,6 +41,8 @@ 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;
Expand Down
4 changes: 2 additions & 2 deletions Common/VR/VRBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ using namespace PPSSPP_VK;
#include <jni.h>
#elif defined(_WIN32)
#include "Common/CommonWindows.h"
#include "Common/GPU/OpenGL/GLCommon.h"
#include <unknwn.h>
#define XR_USE_PLATFORM_WIN32 1
#define XR_USE_GRAPHICS_API_OPENGL_ES 1
#define XR_USE_GRAPHICS_API_OPENGL 1
#define XR_USE_GRAPHICS_API_VULKAN 1
#else
#define XR_USE_GRAPHICS_API_OPENGL_ES 1
#define XR_USE_GRAPHICS_API_VULKAN 1
#endif

Expand Down
40 changes: 22 additions & 18 deletions Common/VR/VRFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void ovrFramebuffer_Clear(ovrFramebuffer* frameBuffer) {
frameBuffer->Acquired = false;
}

#ifdef OPENXR
#if XR_USE_GRAPHICS_API_OPENGL_ES

bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, bool multiview) {
static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, bool multiview) {

frameBuffer->Width = width;
frameBuffer->Height = height;
Expand All @@ -56,12 +56,11 @@ bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuffer, int
}

typedef void (*PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)(GLenum, GLenum, GLuint, GLint, GLint, GLsizei);
auto glFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)eglGetProcAddress ("glFramebufferTextureMultiviewOVR");
if (!glFramebufferTextureMultiviewOVR)
{
PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR glFramebufferTextureMultiviewOVR = nullptr;
glFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)eglGetProcAddress ("glFramebufferTextureMultiviewOVR");
if (!glFramebufferTextureMultiviewOVR) {
ALOGE("Can not get proc address for glFramebufferTextureMultiviewOVR.\n");
}

XrSwapchainCreateInfo swapChainCreateInfo;
memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo));
swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
Expand Down Expand Up @@ -136,8 +135,10 @@ bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuffer, int
return true;
}

bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int width, int height,
bool multiview, void* context) {
#endif

static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int width, int height,
bool multiview, void* context) {

frameBuffer->Width = width;
frameBuffer->Height = height;
Expand Down Expand Up @@ -241,7 +242,7 @@ bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int

void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) {
if (VR_GetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN)) {
for (int i = 0; i < frameBuffer->TextureSwapChainLength; i++) {
for (int i = 0; i < (int)frameBuffer->TextureSwapChainLength; i++) {
vkDestroyImageView(frameBuffer->VKContext->device, frameBuffer->VKColorImages[i], nullptr);
vkDestroyImageView(frameBuffer->VKContext->device, frameBuffer->VKDepthImages[i], nullptr);
vkDestroyFramebuffer(frameBuffer->VKContext->device, frameBuffer->VKFrameBuffers[i], nullptr);
Expand All @@ -250,7 +251,7 @@ void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) {
delete[] frameBuffer->VKDepthImages;
delete[] frameBuffer->VKFrameBuffers;
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->GLFrameBuffers));
free(frameBuffer->GLFrameBuffers);
#endif
Expand All @@ -267,7 +268,7 @@ void* ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer) {
if (VR_GetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN)) {
return (void *)frameBuffer->VKFrameBuffers[frameBuffer->TextureSwapChainIndex];
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->GLFrameBuffers[frameBuffer->TextureSwapChainIndex]));
#endif
return nullptr;
Expand Down Expand Up @@ -299,7 +300,7 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) {
if (VR_GetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN)) {
//TODO:implement
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
GL(glEnable( GL_SCISSOR_TEST ));
GL(glViewport( 0, 0, frameBuffer->Width, frameBuffer->Height ));
GL(glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ));
Expand All @@ -321,7 +322,7 @@ void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer) {
if (VR_GetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN)) {
//TODO:implement
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
GL(glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE));
GL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
GL(glClear(GL_COLOR_BUFFER_BIT));
Expand Down Expand Up @@ -352,8 +353,10 @@ void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int
if (vulkanContext) {
ovrFramebuffer_CreateVK(session, &renderer->FrameBuffer[i], width, height, multiview, vulkanContext);
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
ovrFramebuffer_CreateGL(session, &renderer->FrameBuffer[i], width, height, multiview);
#if XR_USE_GRAPHICS_API_OPENGL_ES
ovrFramebuffer_CreateGLES(session, &renderer->FrameBuffer[i], width, height, multiview);
#elif XR_USE_GRAPHICS_API_OPENGL
// TODO
#endif
}
}
Expand All @@ -370,7 +373,7 @@ void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int size) {
if (VR_GetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN)) {
//TODO:implement
} else {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
GL(glEnable(GL_SCISSOR_TEST));
GL(glScissor(x, y, size, size));
GL(glViewport(x, y, size, size));
Expand Down Expand Up @@ -414,6 +417,7 @@ void ovrApp_Destroy(ovrApp* app) {
ovrApp_Clear(app);
}


void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) {
if (state == XR_SESSION_STATE_READY) {
assert(app->SessionActive == false);
Expand All @@ -428,6 +432,7 @@ void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) {
OXR(result = xrBeginSession(app->Session, &sessionBeginInfo));
app->SessionActive = (result == XR_SUCCESS);

#ifdef ANDROID
if (app->SessionActive && VR_GetPlatformFLag(VR_PLATFORM_PERFORMANCE_EXT)) {
XrPerfSettingsLevelEXT cpuPerfLevel = XR_PERF_SETTINGS_LEVEL_BOOST_EXT;
XrPerfSettingsLevelEXT gpuPerfLevel = XR_PERF_SETTINGS_LEVEL_BOOST_EXT;
Expand All @@ -450,6 +455,7 @@ void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) {
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);

Expand Down Expand Up @@ -538,5 +544,3 @@ int ovrApp_HandleXrEvents(ovrApp* app) {
}
return recenter;
}

#endif
4 changes: 0 additions & 4 deletions Common/VR/VRInput.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "VRInput.h"
#include <cstring>

#ifdef OPENXR

//OpenXR
XrPath leftHandPath;
XrPath rightHandPath;
Expand Down Expand Up @@ -464,5 +462,3 @@ XrPosef IN_VRGetPose( int controllerIndex ) {
xrLocateSpace(aimSpace[controllerIndex], engine->appState.CurrentSpace, (XrTime)(engine->predictedDisplayTime), &loc);
return loc.pose;
}

#endif
4 changes: 0 additions & 4 deletions Common/VR/VRRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ float vrConfigFloat[VR_CONFIG_FLOAT_MAX] = {};
XrVector3f hmdorientation;
XrVector3f hmdposition;

#ifdef OPENXR

void VR_UpdateStageBounds(ovrApp* pappState) {
XrExtent2Df stageBounds = {};

Expand Down Expand Up @@ -554,5 +552,3 @@ void* VR_BindFramebuffer(engine_t *engine) {
ovrMatrix4f VR_GetMatrix( VRMatrix matrix ) {
return vrMatrix[matrix];
}

#endif
3 changes: 3 additions & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cstring>

#include "Common/Log.h"
#include "Common/Data/Format/IniFile.h"
#include "Common/StringUtils.h"
#include "Core/Compatibility.h"
Expand Down Expand Up @@ -122,6 +123,8 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) {
void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID) {
CheckSetting(iniFile, gameID, "Skyplane", &vrCompat_.Skyplane);
CheckSetting(iniFile, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter);

NOTICE_LOG(G3D, "UnitsPerMeter for %s: %f", gameID.c_str(), vrCompat_.UnitsPerMeter);
}

void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) {
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ const char * const vulkanDefaultBlacklist[] = {
};

static int DefaultGPUBackend() {
if (IsVRBuild()) {
if (IsVREnabled()) {
return (int)GPUBackend::OPENGL;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ void RestoreDefault() {
g_controllerMap.clear();
g_controllerMapGeneration++;

if (IsVRBuild()) {
if (IsVREnabled()) {
SetDefaultKeyMap(DEFAULT_MAPPING_VR_HEADSET, false);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void CenterDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &f

SmallDisplayZoom zoomType = (SmallDisplayZoom)g_Config.iSmallDisplayZoomType;

if (IsVRBuild()) {
if (IsVREnabled()) {
if (IsFlatVRScene()) {
zoomType = SmallDisplayZoom::AUTO;
} else {
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/GPU_GLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ u32 GPU_GLES::CheckGPUFeatures() const {
features |= GPU_USE_FRAGMENT_TEST_CACHE;
}

if (IsVRBuild()) {
if (IsVREnabled()) {
features |= GPU_USE_VIRTUAL_REALITY;
}
if (IsMultiviewSupported()) {
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
}
if (dirty & DIRTY_FOGCOLOR) {
SetColorUniform3(render_, &u_fogcolor, gstate.fogcolor);
if (IsVRBuild()) {
if (IsVREnabled()) {
SetVRCompat(VR_COMPAT_FOG_COLOR, gstate.fogcolor);
}
}
Expand Down
2 changes: 1 addition & 1 deletion UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ bool NativeTouch(const TouchInput &touch) {

bool NativeKey(const KeyInput &key) {
// Special key VR actions
if (IsVRBuild()) {
if (IsVREnabled()) {
UpdateVRSpecialKeys(key);
}

Expand Down
2 changes: 1 addition & 1 deletion android/jni/AndroidEGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool AndroidEGLGraphicsContext::InitFromRenderThread(ANativeWindow *wnd, int des
}
gl->MakeCurrent();
if (gl->GetMode() == GLInterfaceMode::MODE_OPENGL)
SetGLCoreContext(!IsVRBuild());
SetGLCoreContext(!IsVREnabled());
CheckGLExtensions();
draw_ = Draw::T3DCreateGLContext();
SetGPUBackend(GPUBackend::OPENGL);
Expand Down
Loading