From 77e510bd907dcf83b8b403e1ee8e689837f4c72d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Dec 2022 19:27:23 -0800 Subject: [PATCH] GPU: Use accurate depth for depth range hack. This should be easier to ensure stays well tested. --- GPU/GLES/GPU_GLES.cpp | 5 ----- GPU/GLES/ShaderManagerGLES.cpp | 32 -------------------------------- GPU/GPUCommon.cpp | 5 +++++ GPU/GPUState.cpp | 6 +++--- GPU/GPUState.h | 2 +- 5 files changed, 9 insertions(+), 41 deletions(-) diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index a707915eb1..380fe2d2c7 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -173,11 +173,6 @@ u32 GPU_GLES::CheckGPUFeatures() const { if (gl_extensions.ARB_texture_float || gl_extensions.OES_texture_float) features |= GPU_USE_TEXTURE_FLOAT; - // The Phantasy Star hack :( - if (PSP_CoreParameter().compat.flags().DepthRangeHack && (features & GPU_USE_ACCURATE_DEPTH) == 0) { - features |= GPU_USE_DEPTH_RANGE_HACK; - } - if (!draw_->GetShaderLanguageDesc().bitwiseOps) { features |= GPU_USE_FRAGMENT_TEST_CACHE; } diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 7e4ae0f881..cc5211a19f 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -319,38 +319,6 @@ static inline void FlipProjMatrix(Matrix4x4 &in, bool useBufferedRendering) { in[8] = -in[8]; in[12] = -in[12]; } - - // 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 (gstate_c.Use(GPU_USE_DEPTH_RANGE_HACK)) { - float zScale = gstate.getViewportZScale() / 65535.0f; - float zCenter = gstate.getViewportZCenter() / 65535.0f; - - // if far depth range < 0 - if (zCenter + zScale < 0.0f) { - // if perspective projection - if (in[11] < 0.0f) { - float depthMax = gstate.getDepthRangeMax() / 65535.0f; - float depthMin = gstate.getDepthRangeMin() / 65535.0f; - - float a = in[10]; - float b = in[14]; - - float n = b / (a - 1.0f); - float f = b / (a + 1.0f); - - f = (n * f) / (n + ((zCenter + zScale) * (n - f) / (depthMax - depthMin))); - - a = (n + f) / (n - f); - b = (2.0f * n * f) / (n - f); - - if (!my_isnan(a) && !my_isnan(b)) { - in[10] = a; - in[14] = b; - } - } - } - } } static inline bool GuessVRDrawingHUD(bool is2D, bool flatScreen) { diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 20d97649df..bbfa7f3090 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -3537,6 +3537,11 @@ u32 GPUCommon::CheckGPUFeatures() const { features |= GPU_USE_CLEAR_RAM_HACK; } + // Even without depth clamp, force accurate depth on for some games that break without it. + if (PSP_CoreParameter().compat.flags().DepthRangeHack) { + features |= GPU_USE_ACCURATE_DEPTH; + } + return features; } diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index 95568e1e93..ba0e650bb6 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -375,7 +375,7 @@ static const char *const gpuUseFlagNames[32] = { "GPU_USE_VS_RANGE_CULLING", "GPU_USE_BLEND_MINMAX", "GPU_USE_LOGIC_OP", - "GPU_USE_DEPTH_RANGE_HACK", + "N/A", "GPU_USE_TEXTURE_NPOT", "GPU_USE_ANISOTROPY", "GPU_USE_CLEAR_RAM_HACK", @@ -388,7 +388,7 @@ static const char *const gpuUseFlagNames[32] = { "GPU_USE_DEPTH_TEXTURE", "GPU_USE_ACCURATE_DEPTH", "GPU_USE_GS_CULLING", - "GPU_USE_REVERSE_COLOR_ORDER", + "N/A", "GPU_USE_FRAMEBUFFER_FETCH", "GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT", "GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT", @@ -409,4 +409,4 @@ const char *GpuUseFlagToString(int useFlag) { } else { return "N/A"; } -} \ No newline at end of file +} diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 02fba9c309..e5acb39a18 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -478,7 +478,7 @@ enum { GPU_USE_VS_RANGE_CULLING = FLAG_BIT(3), GPU_USE_BLEND_MINMAX = FLAG_BIT(4), GPU_USE_LOGIC_OP = FLAG_BIT(5), - GPU_USE_DEPTH_RANGE_HACK = FLAG_BIT(6), + // Bit 6 is free. GPU_USE_TEXTURE_NPOT = FLAG_BIT(7), GPU_USE_ANISOTROPY = FLAG_BIT(8), GPU_USE_CLEAR_RAM_HACK = FLAG_BIT(9),