diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 8f90122f39..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); diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 13b424832c..9d1db94576 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" @@ -10,6 +12,7 @@ #include "Core/KeyMap.h" #include "Core/System.h" +static long vrCompat[VR_COMPAT_MAX]; /* ================================================================================ @@ -211,6 +214,59 @@ void UpdateVRScreenKey(const KeyInput &key) { /* ================================================================================ +// VR games compatibility + +================================================================================ +*/ + +void PreprocessSkyplane(GLRStep* step) { + + // Do not do anything if the scene is not in VR. + if (IsFlatVRScene()) { + return; + } + + // Check if it is the step we need to modify. + for (auto& cmd : step->commands) { + if (cmd.cmd == GLRRenderCommand::BIND_FB_TEXTURE) { + return; + } + } + + // 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 PreprocessStepVR(void* step) { + auto* glrStep = (GLRStep*)step; + if (vrCompat[VR_COMPAT_SKYPLANE]) PreprocessSkyplane(glrStep); +} + +void SetVRCompat(VRCompatFlag flag, long value) { + vrCompat[flag] = value; +} + +/* +================================================================================ + VR rendering integration ================================================================================ @@ -237,6 +293,9 @@ bool StartVRRender() { } VR_SetConfig(VR_CONFIG_3D_GEOMETRY_COUNT, VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) / 2); + // Set compatibility + vrCompat[VR_COMPAT_SKYPLANE] = PSP_CoreParameter().compat.vrCompat().Skyplane; + // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.iCanvasDistance); @@ -252,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 cf385735db..fe6f7c4e98 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -3,6 +3,20 @@ #include "Common/Input/InputState.h" #include "Common/Input/KeyCodes.h" +enum VRCompatFlag { + //compatibility tweaks + VR_COMPAT_SKYPLANE, + + //render state + VR_COMPAT_FBO_CLEAR, + + //uniforms + VR_COMPAT_FOG_COLOR, + + //end + VR_COMPAT_MAX +}; + #ifdef OPENXR // VR app flow integration @@ -13,6 +27,10 @@ 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 PreprocessStepVR(void* step); +void SetVRCompat(VRCompatFlag flag, long value); + // VR rendering integration void BindVRFramebuffer(); bool StartVRRender(); @@ -36,6 +54,10 @@ 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 PreprocessStepVR(void* step) {} +inline void SetVRCompat(VRCompatFlag flag, long value) {} + // VR rendering integration inline void BindVRFramebuffer() {} inline bool StartVRRender() { return false; } diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index 75c0623ead..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); } } diff --git a/Core/Compatibility.h b/Core/Compatibility.h index 04f3ab22b7..0fee77b805 100644 --- a/Core/Compatibility.h +++ b/Core/Compatibility.h @@ -92,6 +92,7 @@ struct CompatFlags { }; struct VRCompat { + bool Skyplane; float UnitsPerMeter; }; diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index c9ad82cd36..92dfa9488f 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -363,6 +363,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; 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