Skip to content

Commit

Permalink
Merge pull request #17656 from lvonasek/compat_openxr_fixes
Browse files Browse the repository at this point in the history
OpenXR - Game compatibility fixes
  • Loading branch information
hrydgard committed Jul 2, 2023
2 parents 2a3bf24 + 6e10f20 commit fc797ec
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
41 changes: 15 additions & 26 deletions Common/VR/PPSSPPVR.cpp
Expand Up @@ -53,7 +53,7 @@ static bool vrFlatForced = false;
static bool vrFlatGame = false;
static float vrMatrix[VR_MATRIX_COUNT][16];
static bool vrMirroring[VR_MIRRORING_COUNT];
static int vrMirroringVariant = -1;
static int vrMirroringVariant = 0;
static XrView vrView[2];

static void (*NativeAxis)(const AxisInput &axis);
Expand Down Expand Up @@ -626,7 +626,6 @@ bool StartVRRender() {
bool vrStereo = !PSP_CoreParameter().compat.vrCompat().ForceMono && g_Config.bEnableStereo;

// Get VR status
vrMirroringVariant = -1;
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {
vrView[eye] = VR_GetView(eye);
}
Expand Down Expand Up @@ -746,52 +745,42 @@ bool Is2DVRObject(float* projMatrix, bool ortho) {
return identity || ortho;
}

void UpdateVRParams(float* projMatrix, float* viewMatrix) {
void UpdateVRParams(float* projMatrix) {

// Set mirroring of axes
vrMirroring[VR_MIRRORING_AXIS_X] = projMatrix[0] < 0;
vrMirroring[VR_MIRRORING_AXIS_Y] = projMatrix[5] < 0;
vrMirroring[VR_MIRRORING_AXIS_Z] = projMatrix[10] > 0;

float up = 0;
for (int i = 4; i < 7; i++) {
up += viewMatrix[i];
}

int variant = projMatrix[0] < 0;
int variant = 1;
variant += projMatrix[0] < 0;
variant += (projMatrix[5] < 0) << 1;
variant += (projMatrix[10] < 0) << 2;
variant += (up < 0) << 3;
if (PSP_CoreParameter().compat.vrCompat().MirroringVariant > 0) {
variant = PSP_CoreParameter().compat.vrCompat().MirroringVariant;
}

switch (variant) {
case 0: //e.g. ATV
case 8: //e,g, Flatout (dynamic objects only)
case 1: //e.g. ATV
vrMirroring[VR_MIRRORING_PITCH] = false;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = true;
break;
case 1: //e.g. Tales of the World
case 2: //e.g. Tales of the World
vrMirroring[VR_MIRRORING_PITCH] = false;
vrMirroring[VR_MIRRORING_YAW] = false;
vrMirroring[VR_MIRRORING_ROLL] = false;
break;
case 2: //e.g.PES 2014
case 3: //untested
case 5: //e.g Dante's Inferno
case 7: //untested
case 9: //untested
case 10: //untested
case 11: //untested
case 13: //untested
case 15: //untested
case 3: //e.g.PES 2014
case 4: //untested
case 6: //e.g Dante's Inferno
case 8: //untested
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = true;
vrMirroring[VR_MIRRORING_ROLL] = false;
break;
case 4: //e.g. Assassins Creed
case 6: //e.g. Ghost in the shell
case 12: //e.g. GTA Vice City
case 14: //untested
case 5: //e.g. Assassins Creed
case 7: //e.g. Ghost in the shell
vrMirroring[VR_MIRRORING_PITCH] = true;
vrMirroring[VR_MIRRORING_YAW] = false;
vrMirroring[VR_MIRRORING_ROLL] = true;
Expand Down
2 changes: 1 addition & 1 deletion Common/VR/PPSSPPVR.h
Expand Up @@ -56,7 +56,7 @@ bool IsFlatVRGame();
bool IsFlatVRScene();
bool IsGameVRScene();
bool Is2DVRObject(float* projMatrix, bool ortho);
void UpdateVRParams(float* projMatrix, float* viewMatrix);
void UpdateVRParams(float* projMatrix);
void UpdateVRProjection(float* projMatrix, float* leftEye, float* rightEye);
void UpdateVRView(float* leftEye, float* rightEye);
void UpdateVRViewMatrices();
7 changes: 7 additions & 0 deletions Core/Compatibility.cpp
Expand Up @@ -137,6 +137,7 @@ void Compatibility::CheckVRSettings(IniFile &iniFile, const std::string &gameID)
CheckSetting(iniFile, gameID, "ForceFlatScreen", &vrCompat_.ForceFlatScreen);
CheckSetting(iniFile, gameID, "ForceMono", &vrCompat_.ForceMono);
CheckSetting(iniFile, gameID, "IdentityViewHack", &vrCompat_.IdentityViewHack);
CheckSetting(iniFile, gameID, "MirroringVariant", &vrCompat_.MirroringVariant);
CheckSetting(iniFile, gameID, "Skyplane", &vrCompat_.Skyplane);
CheckSetting(iniFile, gameID, "UnitsPerMeter", &vrCompat_.UnitsPerMeter);

Expand All @@ -159,3 +160,9 @@ void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, co
iniFile.Get(option, gameID.c_str(), &value, "0");
*flag = stof(value);
}

void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, int *flag) {
std::string value;
iniFile.Get(option, gameID.c_str(), &value, "0");
*flag = stof(value);
}
2 changes: 2 additions & 0 deletions Core/Compatibility.h
Expand Up @@ -107,6 +107,7 @@ struct VRCompat {
bool ForceMono;
bool ForceFlatScreen;
bool IdentityViewHack;
int MirroringVariant;
bool Skyplane;
float UnitsPerMeter;
};
Expand All @@ -132,6 +133,7 @@ class Compatibility {
void CheckVRSettings(IniFile &iniFile, const std::string &gameID);
void CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag);
void CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, float *value);
void CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, int *value);

CompatFlags flags_{};
VRCompat vrCompat_{};
Expand Down
6 changes: 4 additions & 2 deletions GPU/GLES/ShaderManagerGLES.cpp
Expand Up @@ -356,6 +356,8 @@ static inline bool GuessVRDrawingHUD(bool is2D, bool flatScreen) {
else if (gstate.isClearModeDepthMask()) hud = false;
//HUD texture has to contain alpha channel
else if (!gstate.isTextureAlphaUsed()) hud = false;
//HUD texture cannot be in 5551 format
else if (gstate.getTextureFormat() == GETextureFormat::GE_TFMT_5551) hud = false;
//HUD texture cannot be in CLUT16 format
else if (gstate.getTextureFormat() == GETextureFormat::GE_TFMT_CLUT16) hud = false;
//HUD texture cannot be in CLUT32 format
Expand Down Expand Up @@ -427,6 +429,7 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, bool useBufferedRenderin
} else {
UpdateVRProjection(gstate.projMatrix, leftEyeMatrix.m, rightEyeMatrix.m);
}
UpdateVRParams(gstate.projMatrix);

FlipProjMatrix(leftEyeMatrix, useBufferedRendering);
FlipProjMatrix(rightEyeMatrix, useBufferedRendering);
Expand Down Expand Up @@ -564,14 +567,13 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, bool useBufferedRenderin
if (dirty & DIRTY_WORLDMATRIX) {
SetMatrix4x3(render_, &u_world, gstate.worldMatrix);
}
if ((dirty & DIRTY_VIEWMATRIX) || IsVREnabled()) {
if (dirty & DIRTY_VIEWMATRIX) {
if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
float leftEyeView[16];
float rightEyeView[16];
ConvertMatrix4x3To4x4Transposed(leftEyeView, gstate.viewMatrix);
ConvertMatrix4x3To4x4Transposed(rightEyeView, gstate.viewMatrix);
if (!is2D) {
UpdateVRParams(gstate.projMatrix, leftEyeView);
UpdateVRView(leftEyeView, rightEyeView);
}
render_->SetUniformM4x4Stereo("u_view", &u_view, leftEyeView, rightEyeView);
Expand Down
12 changes: 11 additions & 1 deletion assets/compatvr.ini
Expand Up @@ -84,7 +84,7 @@ ULUS10105 = true


[IdentityViewHack]
# Disables head tracking for render passes where view matrix is Identity
# Disables head tracking for render passes where view matrix is identity

# Sonic Rivals 1
ULES00622 = true
Expand All @@ -95,6 +95,16 @@ ULES00940 = true
ULUS10323 = true


[MirroringVariant]
# Forces mirroring of the view matrix

# Tony Hawk's Underground 2 Remix
ULES00033 = 3
ULES00034 = 3
ULES00035 = 3
ULUS10014 = 3


[Skyplane]
# Workaround to remove the background skyplane and add clearing framebuffer with a fog color.

Expand Down

0 comments on commit fc797ec

Please sign in to comment.