GPU: Use accurate depth for depth range hack.

This should be easier to ensure stays well tested.
This commit is contained in:
Unknown W. Brackets 2022-12-04 19:27:23 -08:00
parent 5de3a7c252
commit 77e510bd90
5 changed files with 9 additions and 41 deletions

View File

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

View File

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

View File

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

View File

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

View File

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