From 30a3cb622aed2e870fecc6300b2a17c24e76cf15 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 30 Aug 2022 21:09:12 +0200 Subject: [PATCH 01/12] Force clearing framebuffer for GTA games --- Common/GPU/OpenGL/GLQueueRunner.cpp | 8 ++++++++ Core/Compatibility.cpp | 1 + Core/Compatibility.h | 1 + assets/compat.ini | 17 +++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index f29ffbe2cd..986167903d 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -14,6 +14,7 @@ #include "Common/Data/Convert/SmallDataConvert.h" #include "Core/Reporting.h" +#include "Core/System.h" #include "GLQueueRunner.h" #include "GLRenderManager.h" #include "DataFormatGL.h" @@ -768,6 +769,13 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last PerformBindFramebufferAsRenderTarget(step); + if (IsVRBuild() && PSP_CoreParameter().compat.flags().VRClearFramebuffer) { + if ((strcmp(step.tag, "FramebufferSwitch") == 0) && (step.commands.size() > 50)) { + glClearColor(0.5f, 0.75f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + } + } + if (first) { glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index 84d42df284..4487c3f203 100644 --- a/Core/Compatibility.cpp +++ b/Core/Compatibility.cpp @@ -97,6 +97,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) { CheckSetting(iniFile, gameID, "AllowLargeFBTextureOffsets", &flags_.AllowLargeFBTextureOffsets); CheckSetting(iniFile, gameID, "AtracLoopHack", &flags_.AtracLoopHack); CheckSetting(iniFile, gameID, "DeswizzleDepth", &flags_.DeswizzleDepth); + CheckSetting(iniFile, gameID, "VRClearFramebuffer", &flags_.VRClearFramebuffer); } void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) { diff --git a/Core/Compatibility.h b/Core/Compatibility.h index dc22c45e0f..941844bd85 100644 --- a/Core/Compatibility.h +++ b/Core/Compatibility.h @@ -87,6 +87,7 @@ struct CompatFlags { bool AllowLargeFBTextureOffsets; bool AtracLoopHack; bool DeswizzleDepth; + bool VRClearFramebuffer; }; class IniFile; diff --git a/assets/compat.ini b/assets/compat.ini index 27b8fd571b..692173597f 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1263,3 +1263,20 @@ UCKS45048 = true UCJS18030 = true UCJS18047 = true NPJG00015 = true + +[VRClearFramebuffer] +#Grand Theft Auto: Liberty City Stories +ULUS10041 = true +ULES00151 = true +ULJM05255 = true +ULJM05359 = true +ULJM05885 = true +NPJH50825 = true + +#Grand Theft Auto: Vice City Stories +ULES00502 = true +ULUS10160 = true +ULJM05297 = true +ULJM05395 = true +ULJM05884 = true +NPJH50827 = true From 4b129bb9c3afefe9d71d2850ea975631023544bd Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 7 Sep 2022 15:52:50 +0200 Subject: [PATCH 02/12] OpenXR - Refactor VR compat integration --- Common/GPU/OpenGL/GLQueueRunner.cpp | 8 ++------ Common/VR/PPSSPPVR.cpp | 30 +++++++++++++++++++++++++++++ Common/VR/PPSSPPVR.h | 19 ++++++++++++++++++ Core/Compatibility.cpp | 2 +- Core/Compatibility.h | 2 +- assets/compat.ini | 2 +- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index f6ca57725c..253df013fe 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -14,7 +14,6 @@ #include "Common/Data/Convert/SmallDataConvert.h" #include "Core/Reporting.h" -#include "Core/System.h" #include "GLQueueRunner.h" #include "GLRenderManager.h" #include "DataFormatGL.h" @@ -771,11 +770,8 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last PerformBindFramebufferAsRenderTarget(step); - if (IsVRBuild() && PSP_CoreParameter().compat.flags().VRClearFramebuffer) { - if ((strcmp(step.tag, "FramebufferSwitch") == 0) && (step.commands.size() > 50)) { - glClearColor(0.5f, 0.75f, 1.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - } + if (IsVRBuild()) { + PreGLRenderPass(step); } if (first) { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 16b170e1fb..23f4c2d550 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -8,7 +8,9 @@ #include "Core/HLE/sceDisplay.h" #include "Core/Config.h" #include "Core/KeyMap.h" +#include "Core/System.h" +static long vrCompat[VR_COMPAT_MAX]; /* ================================================================================ @@ -210,6 +212,31 @@ void UpdateVRScreenKey(const KeyInput &key) { /* ================================================================================ +// VR games compatibility + +================================================================================ +*/ + +void PreGLRenderPass(const GLRStep& step) { + if (vrCompat[VR_COMPAT_SKYPLANE]) { + if (strcmp(step.tag, "FramebufferSwitch") == 0) { + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + } + } +} + +long GetVRCompat(VRCompat flag) { + return vrCompat[flag]; +} + +void SetVRCompat(VRCompat flag, long value) { + vrCompat[flag] = value; +} + +/* +================================================================================ + VR rendering integration ================================================================================ @@ -235,6 +262,9 @@ bool PreVRRender() { } VR_SetConfig(VR_CONFIG_3D_GEOMETRY_COUNT, VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) / 2); + // Set compatibility + vrCompat[VR_COMPAT_SKYPLANE] = PSP_CoreParameter().compat.flags().VRSkyplane; + // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.iCanvasDistance); diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index b41b69f1be..8ce9ca26b0 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -2,6 +2,15 @@ #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" +#include "GPU/OpenGL/GLQueueRunner.h" + +enum VRCompat { + //compatibility tweaks + VR_COMPAT_SKYPLANE, + + //end + VR_COMPAT_MAX +}; #ifdef OPENXR @@ -13,6 +22,11 @@ void GetVRResolutionPerEye(int* width, int* height); void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); void UpdateVRScreenKey(const KeyInput &key); +// VR games compatibility +void PreGLRenderPass(const GLRStep& step); +long GetVRCompat(VRCompat flag); +void SetVRCompat(VRCompat flag, long value); + // VR rendering integration void BindVRFramebuffer(); bool PreVRRender(); @@ -36,6 +50,11 @@ 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 UpdateVRScreenKey(const KeyInput &key) {} +// VR games compatibility +inline void PreGLRenderPass(const GLRStep& step) {} +inline long GetVRCompat(VRCompat flag) { return 0; } +inline void SetVRCompat(VRCompat flag, long value) {} + // VR rendering integration inline void BindVRFramebuffer() {} inline bool PreVRRender() { return false; } diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index 00608ceb7c..d46a93e850 100644 --- a/Core/Compatibility.cpp +++ b/Core/Compatibility.cpp @@ -98,7 +98,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) { CheckSetting(iniFile, gameID, "DeswizzleDepth", &flags_.DeswizzleDepth); CheckSetting(iniFile, gameID, "SplitFramebufferMargin", &flags_.SplitFramebufferMargin); CheckSetting(iniFile, gameID, "ForceLowerResolutionForEffectsOn", &flags_.ForceLowerResolutionForEffectsOn); - CheckSetting(iniFile, gameID, "VRClearFramebuffer", &flags_.VRClearFramebuffer); + CheckSetting(iniFile, gameID, "VRSkyplane", &flags_.VRSkyplane); } void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) { diff --git a/Core/Compatibility.h b/Core/Compatibility.h index f5e3dc0c31..07a2b99be0 100644 --- a/Core/Compatibility.h +++ b/Core/Compatibility.h @@ -88,7 +88,7 @@ struct CompatFlags { bool DeswizzleDepth; bool SplitFramebufferMargin; bool ForceLowerResolutionForEffectsOn; - bool VRClearFramebuffer; + bool VRSkyplane; }; class IniFile; diff --git a/assets/compat.ini b/assets/compat.ini index 2c2d430dc6..3c10463505 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1295,7 +1295,7 @@ ULES00262 = true ULUS10064 = true ULKS46087 = true -[VRClearFramebuffer] +[VRSkyplane] # Grand Theft Auto: Liberty City Stories ULUS10041 = true ULES00151 = true From 52af230210ba33dd7925c1e3bead9e9689898462 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 7 Sep 2022 19:57:26 +0200 Subject: [PATCH 03/12] OpenXR - Use fog color to replace the sky --- Common/GPU/OpenGL/GLQueueRunner.cpp | 6 ++++ Common/VR/PPSSPPVR.cpp | 48 ++++++++++++++++++++++++++--- Common/VR/PPSSPPVR.h | 7 +++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 253df013fe..6603255077 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -821,6 +821,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last CHECK_GL_ERROR_IF_DEBUG(); auto &commands = step.commands; for (const auto &c : commands) { + if (IsVRBuild()) { + PreGLCommand(c); + } switch (c.cmd) { case GLRRenderCommand::DEPTH: if (c.depth.enabled) { @@ -1328,6 +1331,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last Crash(); break; } + if (IsVRBuild()) { + PostGLCommand(c); + } } for (int i = 0; i < 7; i++) { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 23f4c2d550..28cf89a701 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -10,6 +10,9 @@ #include "Core/KeyMap.h" #include "Core/System.h" +#include "GPU/OpenGL/GLRenderManager.h" +#include "GPU/GPUState.h" + static long vrCompat[VR_COMPAT_MAX]; /* @@ -217,11 +220,48 @@ void UpdateVRScreenKey(const KeyInput &key) { ================================================================================ */ +bool IsSkyPlane(const GLRRenderData& data) { + if ((data.drawIndexed.count <= 60) && !vrCompat[VR_USE_CLIP]) { + //TODO:fix HUD items + return true; + } + return false; +} + void PreGLRenderPass(const GLRStep& step) { - if (vrCompat[VR_COMPAT_SKYPLANE]) { - if (strcmp(step.tag, "FramebufferSwitch") == 0) { - glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT); + if (IsFlatVRScene()) { + return; + } + vrCompat[VR_COMPAT_GEOMETRY] = strcmp(step.tag, "FramebufferSwitch") == 0; + + // Clear the screen with fog color, only for passes containing geometry (and no lens flares) + if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY] && (step.commands.size() > 50)) { + float color[4]; + Uint8x3ToFloat4(color, gstate.fogcolor); + glClearColor(color[0], color[1], color[2], 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + glClearColor(0, 0, 0, 1); + } +} + +void PreGLCommand(const GLRRenderData& data) { + if (IsFlatVRScene()) { + return; + } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { + if (data.cmd == GLRRenderCommand::BINDPROGRAM) { + vrCompat[VR_USE_CLIP] = data.program.program->use_clip_distance0; + } else if ((data.cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(data)) { + glColorMask(false, false, false, false); + } + } +} + +void PostGLCommand(const GLRRenderData& data) { + if (IsFlatVRScene()) { + return; + } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { + if ((data.cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(data)) { + glColorMask(true, true, true, true); } } } diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 8ce9ca26b0..4ec33406b9 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -8,6 +8,9 @@ enum VRCompat { //compatibility tweaks VR_COMPAT_SKYPLANE, + //render state + VR_COMPAT_GEOMETRY, VR_USE_CLIP, + //end VR_COMPAT_MAX }; @@ -24,6 +27,8 @@ void UpdateVRScreenKey(const KeyInput &key); // VR games compatibility void PreGLRenderPass(const GLRStep& step); +void PreGLCommand(const GLRRenderData& data); +void PostGLCommand(const GLRRenderData& data); long GetVRCompat(VRCompat flag); void SetVRCompat(VRCompat flag, long value); @@ -52,6 +57,8 @@ inline void UpdateVRScreenKey(const KeyInput &key) {} // VR games compatibility inline void PreGLRenderPass(const GLRStep& step) {} +inline void PreGLCommand(const GLRRenderData& data) {} +inline void PostGLCommand(const GLRRenderData& data) {} inline long GetVRCompat(VRCompat flag) { return 0; } inline void SetVRCompat(VRCompat flag, long value) {} From 6e4849b910e354c4590e38970821f06eb8a55ef7 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 8 Sep 2022 18:05:12 +0200 Subject: [PATCH 04/12] OpenXR - Refactor --- Common/GPU/OpenGL/GLQueueRunner.cpp | 13 ++++--------- Common/VR/PPSSPPVR.cpp | 20 +++++++++++--------- Common/VR/PPSSPPVR.h | 17 +---------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 6603255077..5646fa16b4 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -770,9 +770,8 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last PerformBindFramebufferAsRenderTarget(step); - if (IsVRBuild()) { - PreGLRenderPass(step); - } + bool isVR = IsVRBuild(); + if (isVR) PreGLRenderPass(step); if (first) { glDisable(GL_DEPTH_TEST); @@ -821,9 +820,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last CHECK_GL_ERROR_IF_DEBUG(); auto &commands = step.commands; for (const auto &c : commands) { - if (IsVRBuild()) { - PreGLCommand(c); - } + if (isVR) PreGLCommand(c); switch (c.cmd) { case GLRRenderCommand::DEPTH: if (c.depth.enabled) { @@ -1331,9 +1328,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last Crash(); break; } - if (IsVRBuild()) { - PostGLCommand(c); - } + if (isVR) PostGLCommand(c); } for (int i = 0; i < 7; i++) { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 28cf89a701..2a3f9e5fc2 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -10,9 +10,19 @@ #include "Core/KeyMap.h" #include "Core/System.h" -#include "GPU/OpenGL/GLRenderManager.h" #include "GPU/GPUState.h" +enum VRCompat { + //compatibility tweaks + VR_COMPAT_SKYPLANE, + + //render state + VR_COMPAT_GEOMETRY, VR_USE_CLIP, + + //end + VR_COMPAT_MAX +}; + static long vrCompat[VR_COMPAT_MAX]; /* @@ -266,14 +276,6 @@ void PostGLCommand(const GLRRenderData& data) { } } -long GetVRCompat(VRCompat flag) { - return vrCompat[flag]; -} - -void SetVRCompat(VRCompat flag, long value) { - vrCompat[flag] = value; -} - /* ================================================================================ diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 4ec33406b9..d177e3455a 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -1,19 +1,8 @@ #pragma once +#include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" -#include "GPU/OpenGL/GLQueueRunner.h" - -enum VRCompat { - //compatibility tweaks - VR_COMPAT_SKYPLANE, - - //render state - VR_COMPAT_GEOMETRY, VR_USE_CLIP, - - //end - VR_COMPAT_MAX -}; #ifdef OPENXR @@ -29,8 +18,6 @@ void UpdateVRScreenKey(const KeyInput &key); void PreGLRenderPass(const GLRStep& step); void PreGLCommand(const GLRRenderData& data); void PostGLCommand(const GLRRenderData& data); -long GetVRCompat(VRCompat flag); -void SetVRCompat(VRCompat flag, long value); // VR rendering integration void BindVRFramebuffer(); @@ -59,8 +46,6 @@ inline void UpdateVRScreenKey(const KeyInput &key) {} inline void PreGLRenderPass(const GLRStep& step) {} inline void PreGLCommand(const GLRRenderData& data) {} inline void PostGLCommand(const GLRRenderData& data) {} -inline long GetVRCompat(VRCompat flag) { return 0; } -inline void SetVRCompat(VRCompat flag, long value) {} // VR rendering integration inline void BindVRFramebuffer() {} From c9f08a85c66a2e91042e215763136e83deccecb0 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 8 Sep 2022 18:25:10 +0200 Subject: [PATCH 05/12] OpenXR - Do not mashup Common/GPU --- Common/VR/PPSSPPVR.cpp | 19 +++++-------------- Common/VR/PPSSPPVR.h | 16 ++++++++++++++++ GPU/GLES/ShaderManagerGLES.cpp | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 2a3f9e5fc2..1ff55eaceb 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -10,19 +10,6 @@ #include "Core/KeyMap.h" #include "Core/System.h" -#include "GPU/GPUState.h" - -enum VRCompat { - //compatibility tweaks - VR_COMPAT_SKYPLANE, - - //render state - VR_COMPAT_GEOMETRY, VR_USE_CLIP, - - //end - VR_COMPAT_MAX -}; - static long vrCompat[VR_COMPAT_MAX]; /* @@ -247,7 +234,7 @@ void PreGLRenderPass(const GLRStep& step) { // Clear the screen with fog color, only for passes containing geometry (and no lens flares) if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY] && (step.commands.size() > 50)) { float color[4]; - Uint8x3ToFloat4(color, gstate.fogcolor); + Uint8x3ToFloat4(color, vrCompat[VR_COMPAT_FOG_COLOR]); glClearColor(color[0], color[1], color[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT); glClearColor(0, 0, 0, 1); @@ -276,6 +263,10 @@ void PostGLCommand(const GLRRenderData& data) { } } +void SetVRCompat(VRCompat flag, long value) { + vrCompat[flag] = value; +} + /* ================================================================================ diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index d177e3455a..5a7bc4ac9c 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -4,6 +4,20 @@ #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" +enum VRCompat { + //compatibility tweaks + VR_COMPAT_SKYPLANE, + + //render state + VR_COMPAT_GEOMETRY, VR_USE_CLIP, + + //uniforms + VR_COMPAT_FOG_COLOR, + + //end + VR_COMPAT_MAX +}; + #ifdef OPENXR // VR app flow integration @@ -18,6 +32,7 @@ void UpdateVRScreenKey(const KeyInput &key); void PreGLRenderPass(const GLRStep& step); void PreGLCommand(const GLRRenderData& data); void PostGLCommand(const GLRRenderData& data); +void SetVRCompat(VRCompat flag, long value); // VR rendering integration void BindVRFramebuffer(); @@ -46,6 +61,7 @@ inline void UpdateVRScreenKey(const KeyInput &key) {} inline void PreGLRenderPass(const GLRStep& step) {} inline void PreGLCommand(const GLRRenderData& data) {} inline void PostGLCommand(const GLRRenderData& data) {} +inline void SetVRCompat(VRCompat flag, long value) {} // VR rendering integration inline void BindVRFramebuffer() {} diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index a1ae7edb61..8b0abb8b37 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -354,6 +354,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu if (IsVRBuild()) { dirty |= DIRTY_VIEWMATRIX; + SetVRCompat(VR_COMPAT_FOG_COLOR, gstate.fogcolor); } if (!dirty) return; From 214a5572c33c4d4f63c363791cdad832b4157b35 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 8 Sep 2022 19:00:41 +0200 Subject: [PATCH 06/12] OpenXR - Compile fix --- Common/GPU/OpenGL/GLQueueRunner.cpp | 8 ++++---- Common/VR/PPSSPPVR.cpp | 27 ++++++++++++++++----------- Common/VR/PPSSPPVR.h | 13 ++++++------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 5646fa16b4..79b3efa0b6 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -770,8 +770,8 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last PerformBindFramebufferAsRenderTarget(step); - bool isVR = IsVRBuild(); - if (isVR) PreGLRenderPass(step); + const bool isVR = IsVRBuild(); + if (isVR) PreGLRenderPass(&step); if (first) { glDisable(GL_DEPTH_TEST); @@ -820,7 +820,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last CHECK_GL_ERROR_IF_DEBUG(); auto &commands = step.commands; for (const auto &c : commands) { - if (isVR) PreGLCommand(c); + if (isVR) PreGLCommand(&c); switch (c.cmd) { case GLRRenderCommand::DEPTH: if (c.depth.enabled) { @@ -1328,7 +1328,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last Crash(); break; } - if (isVR) PostGLCommand(c); + if (isVR) PostGLCommand(&c); } for (int i = 0; i < 7; i++) { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 1ff55eaceb..af828ebe18 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -1,3 +1,5 @@ +#include "Common/GPU/OpenGL/GLRenderManager.h" + #include "Common/VR/PPSSPPVR.h" #include "Common/VR/VRBase.h" #include "Common/VR/VRInput.h" @@ -217,22 +219,23 @@ void UpdateVRScreenKey(const KeyInput &key) { ================================================================================ */ -bool IsSkyPlane(const GLRRenderData& data) { - if ((data.drawIndexed.count <= 60) && !vrCompat[VR_USE_CLIP]) { +bool IsSkyPlane(const GLRRenderData* data) { + if ((data->drawIndexed.count <= 60) && !vrCompat[VR_USE_CLIP]) { //TODO:fix HUD items return true; } return false; } -void PreGLRenderPass(const GLRStep& step) { +void PreGLRenderPass(const void* step) { if (IsFlatVRScene()) { return; } - vrCompat[VR_COMPAT_GEOMETRY] = strcmp(step.tag, "FramebufferSwitch") == 0; + const auto* glrStep = (const GLRStep*)step; + vrCompat[VR_COMPAT_GEOMETRY] = strcmp(glrStep->tag, "FramebufferSwitch") == 0; // Clear the screen with fog color, only for passes containing geometry (and no lens flares) - if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY] && (step.commands.size() > 50)) { + if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY] && (glrStep->commands.size() > 50)) { float color[4]; Uint8x3ToFloat4(color, vrCompat[VR_COMPAT_FOG_COLOR]); glClearColor(color[0], color[1], color[2], 1.0f); @@ -241,23 +244,25 @@ void PreGLRenderPass(const GLRStep& step) { } } -void PreGLCommand(const GLRRenderData& data) { +void PreGLCommand(const void* data) { if (IsFlatVRScene()) { return; } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { - if (data.cmd == GLRRenderCommand::BINDPROGRAM) { - vrCompat[VR_USE_CLIP] = data.program.program->use_clip_distance0; - } else if ((data.cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(data)) { + const auto* glrData = (const GLRRenderData*)data; + if (glrData->cmd == GLRRenderCommand::BINDPROGRAM) { + vrCompat[VR_USE_CLIP] = glrData->program.program->use_clip_distance0; + } else if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(glrData)) { glColorMask(false, false, false, false); } } } -void PostGLCommand(const GLRRenderData& data) { +void PostGLCommand(const void* data) { if (IsFlatVRScene()) { return; } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { - if ((data.cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(data)) { + const auto* glrData = (const GLRRenderData*)data; + if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(glrData)) { glColorMask(true, true, true, true); } } diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 5a7bc4ac9c..5a944419a9 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -1,6 +1,5 @@ #pragma once -#include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" @@ -29,9 +28,9 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con void UpdateVRScreenKey(const KeyInput &key); // VR games compatibility -void PreGLRenderPass(const GLRStep& step); -void PreGLCommand(const GLRRenderData& data); -void PostGLCommand(const GLRRenderData& data); +void PreGLRenderPass(const void* step); +void PreGLCommand(const void* data); +void PostGLCommand(const void* data); void SetVRCompat(VRCompat flag, long value); // VR rendering integration @@ -58,9 +57,9 @@ inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTou inline void UpdateVRScreenKey(const KeyInput &key) {} // VR games compatibility -inline void PreGLRenderPass(const GLRStep& step) {} -inline void PreGLCommand(const GLRRenderData& data) {} -inline void PostGLCommand(const GLRRenderData& data) {} +inline void PreGLRenderPass(const void* step) {} +inline void PreGLCommand(const void* data) {} +inline void PostGLCommand(const void* data) {} inline void SetVRCompat(VRCompat flag, long value) {} // VR rendering integration From 9ede9bd82232947861fa46255e6181e3c346a2e4 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 12 Sep 2022 23:01:44 +0200 Subject: [PATCH 07/12] OpenXR - Refactor variable name --- Common/VR/PPSSPPVR.cpp | 2 +- Common/VR/PPSSPPVR.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index af828ebe18..6426d19ba4 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -268,7 +268,7 @@ void PostGLCommand(const void* data) { } } -void SetVRCompat(VRCompat flag, long value) { +void SetVRCompat(VRCompatFlag flag, long value) { vrCompat[flag] = value; } diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 5a944419a9..c6c52b8512 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -3,7 +3,7 @@ #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" -enum VRCompat { +enum VRCompatFlag { //compatibility tweaks VR_COMPAT_SKYPLANE, @@ -31,7 +31,7 @@ void UpdateVRScreenKey(const KeyInput &key); void PreGLRenderPass(const void* step); void PreGLCommand(const void* data); void PostGLCommand(const void* data); -void SetVRCompat(VRCompat flag, long value); +void SetVRCompat(VRCompatFlag flag, long value); // VR rendering integration void BindVRFramebuffer(); @@ -60,7 +60,7 @@ inline void UpdateVRScreenKey(const KeyInput &key) {} inline void PreGLRenderPass(const void* step) {} inline void PreGLCommand(const void* data) {} inline void PostGLCommand(const void* data) {} -inline void SetVRCompat(VRCompat flag, long value) {} +inline void SetVRCompat(VRCompatFlag flag, long value) {} // VR rendering integration inline void BindVRFramebuffer() {} From e4f44e680df193ccea55538cc2a2e0792733c83a Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 13 Sep 2022 21:16:03 +0200 Subject: [PATCH 08/12] OpenXR - Move skyplane compat flag into compatvr.ini --- Common/VR/PPSSPPVR.cpp | 2 +- Core/Compatibility.cpp | 2 +- Core/Compatibility.h | 2 +- assets/compat.ini | 17 ----------------- assets/compatvr.ini | 18 ++++++++++++++++++ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 9353fdfb6c..88101e7838 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -301,7 +301,7 @@ bool PreVRRender() { VR_SetConfig(VR_CONFIG_3D_GEOMETRY_COUNT, VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) / 2); // Set compatibility - vrCompat[VR_COMPAT_SKYPLANE] = PSP_CoreParameter().compat.flags().VRSkyplane; + vrCompat[VR_COMPAT_SKYPLANE] = PSP_CoreParameter().compat.vrCompat().Skyplane; // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index a99756d7bd..f86ebbbcea 100644 --- a/Core/Compatibility.cpp +++ b/Core/Compatibility.cpp @@ -46,6 +46,7 @@ void Compatibility::Load(const std::string &gameID) { IniFile compat; // This loads from assets. if (compat.LoadFromVFS("compatvr.ini")) { + CheckSetting(compat, gameID, "Skyplane", &vrCompat_.Skyplane); CheckSetting(compat, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter); } } @@ -108,7 +109,6 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) { CheckSetting(iniFile, gameID, "SplitFramebufferMargin", &flags_.SplitFramebufferMargin); CheckSetting(iniFile, gameID, "ForceLowerResolutionForEffectsOn", &flags_.ForceLowerResolutionForEffectsOn); CheckSetting(iniFile, gameID, "AllowDownloadCLUT", &flags_.AllowDownloadCLUT); - CheckSetting(iniFile, gameID, "VRSkyplane", &flags_.VRSkyplane); } void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) { diff --git a/Core/Compatibility.h b/Core/Compatibility.h index 97396180b0..0fee77b805 100644 --- a/Core/Compatibility.h +++ b/Core/Compatibility.h @@ -89,10 +89,10 @@ struct CompatFlags { bool SplitFramebufferMargin; bool ForceLowerResolutionForEffectsOn; bool AllowDownloadCLUT; - bool VRSkyplane; }; struct VRCompat { + bool Skyplane; float UnitsPerMeter; }; diff --git a/assets/compat.ini b/assets/compat.ini index 33d5028a92..3d2846d377 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1302,20 +1302,3 @@ ULKS46087 = true [AllowDownloadCLUT] # Temporary compatibility option, while developing a GPU CLUT-from-framebuffer path. - -[VRSkyplane] -# Grand Theft Auto: Liberty City Stories -ULUS10041 = true -ULES00151 = true -ULJM05255 = true -ULJM05359 = true -ULJM05885 = true -NPJH50825 = true - -# Grand Theft Auto: Vice City Stories -ULES00502 = true -ULUS10160 = true -ULJM05297 = true -ULJM05395 = true -ULJM05884 = true -NPJH50827 = true diff --git a/assets/compatvr.ini b/assets/compatvr.ini index 4c47ddffa9..c3ec3f926a 100644 --- a/assets/compatvr.ini +++ b/assets/compatvr.ini @@ -29,6 +29,24 @@ # Issue numbers refer to issues on https://github.com/hrydgard/ppsspp/issues # ======================================================================================== + +[Skyplane] +# Grand Theft Auto: Liberty City Stories +ULUS10041 = true +ULES00151 = true +ULJM05255 = true +ULJM05359 = true +ULJM05885 = true +NPJH50825 = true + +# Grand Theft Auto: Vice City Stories +ULES00502 = true +ULUS10160 = true +ULJM05297 = true +ULJM05395 = true +ULJM05884 = true +NPJH50827 = true + [UnitsPerMeter] # Values exported from https://github.com/CarlKenner/ppsspp/tree/VR/Sys/GameSettings ELF000000 = 10.0 From 209b5b30799b491d506aa99137b60fd691888bb1 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 20 Sep 2022 21:53:32 +0200 Subject: [PATCH 09/12] OpenXR - Compile fix --- Common/VR/PPSSPPVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 520a43b0c8..322b485842 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -250,7 +250,7 @@ void PreGLCommand(const void* data) { } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { const auto* glrData = (const GLRRenderData*)data; if (glrData->cmd == GLRRenderCommand::BINDPROGRAM) { - vrCompat[VR_USE_CLIP] = glrData->program.program->use_clip_distance0; + vrCompat[VR_USE_CLIP] = glrData->program.program->use_clip_distance[0]; } else if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(glrData)) { glColorMask(false, false, false, false); } From 84b748579883fb92d46d7b132746c15154f5dd28 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 24 Sep 2022 11:14:20 +0200 Subject: [PATCH 10/12] OpenXR - Get rid of an ugly if condition --- Common/VR/PPSSPPVR.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 1711cc3e79..e2520d8002 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -232,15 +232,24 @@ void PreGLRenderPass(const void* step) { return; } const auto* glrStep = (const GLRStep*)step; - vrCompat[VR_COMPAT_GEOMETRY] = strcmp(glrStep->tag, "FramebufferSwitch") == 0; - // Clear the screen with fog color, only for passes containing geometry (and no lens flares) - if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY] && (glrStep->commands.size() > 50)) { - float color[4]; - Uint8x3ToFloat4(color, vrCompat[VR_COMPAT_FOG_COLOR]); - glClearColor(color[0], color[1], color[2], 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - glClearColor(0, 0, 0, 1); + // Clear the screen with fog color, only for passes containing geometry + if (vrCompat[VR_COMPAT_SKYPLANE]) { + vrCompat[VR_COMPAT_GEOMETRY] = true; + for (auto& cmd : glrStep->commands) { + if (cmd.cmd == GLRRenderCommand::BIND_FB_TEXTURE) { + vrCompat[VR_COMPAT_GEOMETRY] = false; + break; + } + } + + if (vrCompat[VR_COMPAT_GEOMETRY]) { + float color[4]; + Uint8x3ToFloat4(color, vrCompat[VR_COMPAT_FOG_COLOR]); + glClearColor(color[0], color[1], color[2], 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + glClearColor(0, 0, 0, 1); + } } } From 09bf5f507bac4dbed0c5f18566e29a866e115e0c Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 24 Sep 2022 11:35:51 +0200 Subject: [PATCH 11/12] OpenXR - Simplify skyplane detection in GTA --- Common/VR/PPSSPPVR.cpp | 16 ++++------------ Common/VR/PPSSPPVR.h | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index e2520d8002..df2a813202 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -219,14 +219,6 @@ void UpdateVRScreenKey(const KeyInput &key) { ================================================================================ */ -bool IsSkyPlane(const GLRRenderData* data) { - if ((data->drawIndexed.count <= 60) && !vrCompat[VR_USE_CLIP]) { - //TODO:fix HUD items - return true; - } - return false; -} - void PreGLRenderPass(const void* step) { if (IsFlatVRScene()) { return; @@ -258,9 +250,9 @@ void PreGLCommand(const void* data) { return; } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { const auto* glrData = (const GLRRenderData*)data; - if (glrData->cmd == GLRRenderCommand::BINDPROGRAM) { - vrCompat[VR_USE_CLIP] = glrData->program.program->use_clip_distance[0]; - } else if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(glrData)) { + if (glrData->cmd == GLRRenderCommand::DEPTH) { + vrCompat[VR_COMPAT_DEPTH_ENABLED] = glrData->depth.enabled; + } else if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && !vrCompat[VR_COMPAT_DEPTH_ENABLED]) { glColorMask(false, false, false, false); } } @@ -271,7 +263,7 @@ void PostGLCommand(const void* data) { return; } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { const auto* glrData = (const GLRRenderData*)data; - if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && IsSkyPlane(glrData)) { + if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && !vrCompat[VR_COMPAT_DEPTH_ENABLED]) { glColorMask(true, true, true, true); } } diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 69f0a129e2..298a9a138e 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -8,7 +8,7 @@ enum VRCompatFlag { VR_COMPAT_SKYPLANE, //render state - VR_COMPAT_GEOMETRY, VR_USE_CLIP, + VR_COMPAT_GEOMETRY, VR_COMPAT_DEPTH_ENABLED, //uniforms VR_COMPAT_FOG_COLOR, From 5b334a7945a6b0246bb890ac234deb43f932232f Mon Sep 17 00:00:00 2001 From: Lubos Date: Sat, 24 Sep 2022 16:32:55 +0200 Subject: [PATCH 12/12] OpenXR - PreprocessStep function implemented --- Common/GPU/OpenGL/GLQueueRunner.cpp | 13 +++--- Common/VR/PPSSPPVR.cpp | 68 +++++++++++++---------------- Common/VR/PPSSPPVR.h | 10 ++--- 3 files changed, 40 insertions(+), 51 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 6157b2e1d1..c7f0bc93b9 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -701,7 +701,13 @@ void GLQueueRunner::RunSteps(const std::vector &steps, bool skipGLCal switch (step.stepType) { case GLRStepType::RENDER: renderCount++; - PerformRenderPass(step, renderCount == 1, renderCount == totalRenderCount); + if (IsVRBuild()) { + GLRStep vrStep = step; + PreprocessStepVR(&vrStep); + PerformRenderPass(vrStep, renderCount == 1, renderCount == totalRenderCount); + } else { + PerformRenderPass(step, renderCount == 1, renderCount == totalRenderCount); + } break; case GLRStepType::COPY: PerformCopy(step); @@ -773,9 +779,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last PerformBindFramebufferAsRenderTarget(step); - const bool isVR = IsVRBuild(); - if (isVR) PreGLRenderPass(&step); - if (first) { glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); @@ -823,7 +826,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last CHECK_GL_ERROR_IF_DEBUG(); auto &commands = step.commands; for (const auto &c : commands) { - if (isVR) PreGLCommand(&c); switch (c.cmd) { case GLRRenderCommand::DEPTH: if (c.depth.enabled) { @@ -1335,7 +1337,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last Crash(); break; } - if (isVR) PostGLCommand(&c); } for (int i = 0; i < 7; i++) { diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index df2a813202..9d1db94576 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -219,54 +219,45 @@ void UpdateVRScreenKey(const KeyInput &key) { ================================================================================ */ -void PreGLRenderPass(const void* step) { +void PreprocessSkyplane(GLRStep* step) { + + // Do not do anything if the scene is not in VR. if (IsFlatVRScene()) { return; } - const auto* glrStep = (const GLRStep*)step; - // Clear the screen with fog color, only for passes containing geometry - if (vrCompat[VR_COMPAT_SKYPLANE]) { - vrCompat[VR_COMPAT_GEOMETRY] = true; - for (auto& cmd : glrStep->commands) { - if (cmd.cmd == GLRRenderCommand::BIND_FB_TEXTURE) { - vrCompat[VR_COMPAT_GEOMETRY] = false; - break; - } + // Check if it is the step we need to modify. + for (auto& cmd : step->commands) { + if (cmd.cmd == GLRRenderCommand::BIND_FB_TEXTURE) { + return; } + } - if (vrCompat[VR_COMPAT_GEOMETRY]) { - float color[4]; - Uint8x3ToFloat4(color, vrCompat[VR_COMPAT_FOG_COLOR]); - glClearColor(color[0], color[1], color[2], 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - glClearColor(0, 0, 0, 1); + // Clear sky with the fog color. + if (!vrCompat[VR_COMPAT_FBO_CLEAR]) { + GLRRenderData skyClear {}; + skyClear.cmd = GLRRenderCommand::CLEAR; + skyClear.clear.colorMask = 0xF; + skyClear.clear.clearMask = GL_COLOR_BUFFER_BIT; + skyClear.clear.clearColor = vrCompat[VR_COMPAT_FOG_COLOR]; + step->commands.insert(step->commands.begin(), skyClear); + vrCompat[VR_COMPAT_FBO_CLEAR] = true; + } + + // Remove original sky plane. + bool depthEnabled = false; + for (auto& command : step->commands) { + if (command.cmd == GLRRenderCommand::DEPTH) { + depthEnabled = command.depth.enabled; + } else if ((command.cmd == GLRRenderCommand::DRAW_INDEXED) && !depthEnabled) { + command.drawIndexed.count = 0; } } } -void PreGLCommand(const void* data) { - if (IsFlatVRScene()) { - return; - } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { - const auto* glrData = (const GLRRenderData*)data; - if (glrData->cmd == GLRRenderCommand::DEPTH) { - vrCompat[VR_COMPAT_DEPTH_ENABLED] = glrData->depth.enabled; - } else if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && !vrCompat[VR_COMPAT_DEPTH_ENABLED]) { - glColorMask(false, false, false, false); - } - } -} - -void PostGLCommand(const void* data) { - if (IsFlatVRScene()) { - return; - } else if (vrCompat[VR_COMPAT_SKYPLANE] && vrCompat[VR_COMPAT_GEOMETRY]) { - const auto* glrData = (const GLRRenderData*)data; - if ((glrData->cmd == GLRRenderCommand::DRAW_INDEXED) && !vrCompat[VR_COMPAT_DEPTH_ENABLED]) { - glColorMask(true, true, true, true); - } - } +void PreprocessStepVR(void* step) { + auto* glrStep = (GLRStep*)step; + if (vrCompat[VR_COMPAT_SKYPLANE]) PreprocessSkyplane(glrStep); } void SetVRCompat(VRCompatFlag flag, long value) { @@ -320,6 +311,7 @@ void FinishVRRender() { void PreVRFrameRender(int fboIndex) { VR_BeginFrame(VR_GetEngine(), fboIndex); + vrCompat[VR_COMPAT_FBO_CLEAR] = false; } void PostVRFrameRender() { diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 298a9a138e..fe6f7c4e98 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -8,7 +8,7 @@ enum VRCompatFlag { VR_COMPAT_SKYPLANE, //render state - VR_COMPAT_GEOMETRY, VR_COMPAT_DEPTH_ENABLED, + VR_COMPAT_FBO_CLEAR, //uniforms VR_COMPAT_FOG_COLOR, @@ -28,9 +28,7 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con void UpdateVRScreenKey(const KeyInput &key); // VR games compatibility -void PreGLRenderPass(const void* step); -void PreGLCommand(const void* data); -void PostGLCommand(const void* data); +void PreprocessStepVR(void* step); void SetVRCompat(VRCompatFlag flag, long value); // VR rendering integration @@ -57,9 +55,7 @@ inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTou inline void UpdateVRScreenKey(const KeyInput &key) {} // VR games compatibility -inline void PreGLRenderPass(const void* step) {} -inline void PreGLCommand(const void* data) {} -inline void PostGLCommand(const void* data) {} +inline void PreprocessStepVR(void* step) {} inline void SetVRCompat(VRCompatFlag flag, long value) {} // VR rendering integration