Skip to content

Commit

Permalink
Remove the depth range hack option, turning it into an ugly game spec…
Browse files Browse the repository at this point in the history
…ific compatibility hack.

I hate doing this, but it's not really better off as an option.

See #8171
  • Loading branch information
hrydgard committed Nov 5, 2015
1 parent d2701d7 commit 2f7f8a9
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions Core/Compatibility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ void Compatibility::Clear() {
void Compatibility::LoadIniSection(IniFile &iniFile, std::string section) {
iniFile.Get(section.c_str(), "NoDepthRounding", &flags_.NoDepthRounding, flags_.NoDepthRounding);
iniFile.Get(section.c_str(), "PixelDepthRounding", &flags_.PixelDepthRounding, flags_.PixelDepthRounding);
iniFile.Get(section.c_str(), "DepthRangeHack", &flags_.DepthRangeHack, flags_.DepthRangeHack);
}
1 change: 1 addition & 0 deletions Core/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
struct CompatFlags {
bool NoDepthRounding;
bool PixelDepthRounding;
bool DepthRangeHack;
};

class IniFile;
Expand Down
1 change: 0 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ static ConfigSetting graphicsSettings[] = {
ConfigSetting("VSyncInterval", &g_Config.bVSync, false, true, true),
ReportedConfigSetting("DisableStencilTest", &g_Config.bDisableStencilTest, false, true, true),
ReportedConfigSetting("AlwaysDepthWrite", &g_Config.bAlwaysDepthWrite, false, true, true),
ReportedConfigSetting("DepthRangeHack", &g_Config.bDepthRangeHack, false, true, true),
ReportedConfigSetting("BloomHack", &g_Config.iBloomHack, 0, true, true),

// Not really a graphics setting...
Expand Down
1 change: 0 additions & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ struct Config {
int iCwCheatRefreshRate;
bool bDisableStencilTest;
bool bAlwaysDepthWrite;
bool bDepthRangeHack;
int iBloomHack; //0 = off, 1 = safe, 2 = balanced, 3 = aggressive
bool bTimerHack;
bool bAlphaMaskHack;
Expand Down
12 changes: 11 additions & 1 deletion GPU/Directx9/GPU_DX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,24 @@ void DIRECTX9_GPU::UpdateCmdInfo() {
cmdInfo_[GE_CMD_VERTEXTYPE].func = &DIRECTX9_GPU::Execute_VertexType;
}

CheckGPUFeatures();
}

void DIRECTX9_GPU::CheckGPUFeatures() {
u32 features = 0;

// Set some flags that may be convenient in the future if we merge the backends more.
features |= GPU_SUPPORTS_BLEND_MINMAX;
features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL;

if (!PSP_CoreParameter().compat.flags().NoDepthRounding)
if (!PSP_CoreParameter().compat.flags().NoDepthRounding) {
features |= GPU_ROUND_DEPTH_TO_16BIT;
}

// The Phantasy Star hack :(
if (PSP_CoreParameter().compat.flags().DepthRangeHack) {
features |= GPU_USE_DEPTH_RANGE_HACK;
}

gstate_c.featureFlags = features;
}
Expand Down
1 change: 1 addition & 0 deletions GPU/Directx9/GPU_DX9.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DIRECTX9_GPU : public GPUCommon {
public:
DIRECTX9_GPU();
~DIRECTX9_GPU();
void CheckGPUFeatures();
void InitClear() override;
void PreExecuteOp(u32 op, u32 diff) override;
void ExecuteOp(u32 op, u32 diff) override;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Directx9/ShaderManagerDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void ShaderManagerDX9::VSUpdateUniforms(int dirtyUniforms) {

// In Phantasy Star Portable 2, depth range sometimes goes negative and is clamped by glDepthRange to 0,
// causing graphics clipping glitch (issue #1788). This hack modifies the projection matrix to work around it.
if (g_Config.bDepthRangeHack) {
if (gstate_c.Supports(GPU_USE_DEPTH_RANGE_HACK)) {
float zScale = gstate.getViewportZScale() / 65535.0f;
float zCenter = gstate.getViewportZCenter() / 65535.0f;

Expand Down
5 changes: 5 additions & 0 deletions GPU/GLES/GLES_GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ void GLES_GPU::CheckGPUFeatures() {
}
}

// The Phantasy Star hack :(
if (PSP_CoreParameter().compat.flags().DepthRangeHack) {
features |= GPU_USE_DEPTH_RANGE_HACK;
}

#ifdef MOBILE_DEVICE
// Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc.
features |= GPU_IS_MOBILE;
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void LinkedShader::UpdateUniforms(u32 vertType) {

// In Phantasy Star Portable 2, depth range sometimes goes negative and is clamped by glDepthRange to 0,
// causing graphics clipping glitch (issue #1788). This hack modifies the projection matrix to work around it.
if (g_Config.bDepthRangeHack) {
if (gstate_c.Supports(GPU_USE_DEPTH_RANGE_HACK)) {
float zScale = gstate.getViewportZScale() / 65535.0f;
float zCenter = gstate.getViewportZCenter() / 65535.0f;

Expand Down
1 change: 1 addition & 0 deletions GPU/GPUState.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ enum {
GPU_SUPPORTS_UNPACK_SUBIMAGE = FLAG_BIT(3),
GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4),
GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5),
GPU_USE_DEPTH_RANGE_HACK = FLAG_BIT(6),
GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20),
GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT = FLAG_BIT(22),
GPU_ROUND_DEPTH_TO_16BIT = FLAG_BIT(23), // Can be disabled either per game or if we use a real 16-bit depth buffer
Expand Down
3 changes: 0 additions & 3 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ void GameSettingsScreen::CreateViews() {
CheckBox *prescale = graphicsSettings->Add(new CheckBox(&g_Config.bPrescaleUV, gr->T("Texture Coord Speedhack")));
prescale->SetDisabledPtr(&g_Config.bSoftwareRendering);

CheckBox *depthRange = graphicsSettings->Add(new CheckBox(&g_Config.bDepthRangeHack, gr->T("Depth Range Hack (Phantasy Star Portable 2)")));
depthRange->SetDisabledPtr(&g_Config.bSoftwareRendering);

static const char *bloomHackOptions[] = { "Off", "Safe", "Balanced", "Aggressive" };
PopupMultiChoice *bloomHack = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iBloomHack, gr->T("Lower resolution for effects (reduces artifacts)"), bloomHackOptions, 0, ARRAY_SIZE(bloomHackOptions), gr->GetName(), screenManager()));
bloomHackEnable_ = !g_Config.bSoftwareRendering && (g_Config.iInternalResolution != 1);
Expand Down
25 changes: 25 additions & 0 deletions assets/compat.ini
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,28 @@ PixelDepthRounding = true
PixelDepthRounding = true
[ULJS00454]
PixelDepthRounding = true


# Phantasy Star Portable has a strange depth clipping issue that we have been unable to solve other ways.
[ULJM05309]
DepthRangeHack = true
[ULUS10410]
DepthRangeHack = true
[ULES01218]
DepthRangeHack = true
[ULJM08023]
DepthRangeHack = true
[ULES01218]
DepthRangeHack = true

# Phantasy Star Portable 2 has the same issue.
[ULJM05493]
DepthRangeHack = true
[NPJH50043]
DepthRangeHack = true
[ULJM08030]
DepthRangeHack = true
[NPJH50043]
DepthRangeHack = true
[ULES01439]
DepthRangeHack = true

0 comments on commit 2f7f8a9

Please sign in to comment.