Merge pull request #15984 from lvonasek/compat_openxr_gta

OpenXR - Sky fix for GTA games
This commit is contained in:
Henrik Rydgård 2022-09-24 17:16:28 +02:00 committed by GitHub
commit c3b4caa30b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 1 deletions

View File

@ -701,7 +701,13 @@ void GLQueueRunner::RunSteps(const std::vector<GLRStep *> &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);

View File

@ -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() {

View File

@ -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; }

View File

@ -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);
}
}

View File

@ -92,6 +92,7 @@ struct CompatFlags {
};
struct VRCompat {
bool Skyplane;
float UnitsPerMeter;
};

View File

@ -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;

View File

@ -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