CPU/PGXP: Use GTE MAX_Z for Z normalization

Fixes clipping with depth buffer in some games, e.g. Final Fantasy VII battles.
This commit is contained in:
Stenzek 2025-03-06 19:49:23 +10:00
parent 8cfd843d8f
commit b230c9c639
No known key found for this signature in database
5 changed files with 25 additions and 16 deletions

View File

@ -613,7 +613,7 @@ bool CPU::PGXP::GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, i
{
*out_x = TruncateVertexPosition(vert->x) + static_cast<float>(xOffs);
*out_y = TruncateVertexPosition(vert->y) + static_cast<float>(yOffs);
*out_w = vert->z / 32768.0f;
*out_w = vert->z / static_cast<float>(GTE::MAX_Z);
#ifdef LOG_LOOKUPS
GL_INS_FMT("0x{:08X} {},{} => {},{} ({},{},{}) ({},{})", addr, x, y, *out_x, *out_y,
@ -635,7 +635,7 @@ bool CPU::PGXP::GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, i
{
*out_x = TruncateVertexPosition(vert->x) + static_cast<float>(xOffs);
*out_y = TruncateVertexPosition(vert->y) + static_cast<float>(yOffs);
*out_w = vert->z / 32768.0f;
*out_w = vert->z / static_cast<float>(GTE::MAX_Z);
if (IsWithinTolerance(*out_x, *out_y, x, y))
return false;

View File

@ -791,9 +791,9 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
}
else
{
precise_x = static_cast<float>(x) / 4096.0f;
precise_x = static_cast<float>(x) / (static_cast<float>(1 << shift));
precise_y = static_cast<float>(y) / (static_cast<float>(1 << shift));
precise_z = static_cast<float>(z) / (static_cast<float>(1 << shift));
precise_z = static_cast<float>(z) / 4096.0f;
}
precise_sz3 = precise_z;

View File

@ -11,7 +11,8 @@ enum : u32
{
NUM_DATA_REGS = 32,
NUM_CONTROL_REGS = 32,
NUM_REGS = NUM_DATA_REGS + NUM_CONTROL_REGS
NUM_REGS = NUM_DATA_REGS + NUM_CONTROL_REGS,
MAX_Z = 65535,
};
union FLAGS

View File

@ -4,6 +4,7 @@
#include "settings.h"
#include "achievements.h"
#include "controller.h"
#include "gte.h"
#include "host.h"
#include "imgui_overlays.h"
#include "system.h"
@ -90,7 +91,20 @@ float SettingInfo::FloatStepValue() const
return step_value ? StringUtil::FromChars<float>(step_value).value_or(fallback_value) : fallback_value;
}
GPUSettings::GPUSettings() = default;
GPUSettings::GPUSettings()
{
SetPGXPDepthClearThreshold(DEFAULT_GPU_PGXP_DEPTH_THRESHOLD);
}
float GPUSettings::GetPGXPDepthClearThreshold() const
{
return gpu_pgxp_depth_clear_threshold * static_cast<float>(GTE::MAX_Z);
}
void GPUSettings::SetPGXPDepthClearThreshold(float value)
{
gpu_pgxp_depth_clear_threshold = value / static_cast<float>(GTE::MAX_Z);
}
#ifdef DYNAMIC_HOST_PAGE_SIZE
// See note in settings.h - 16K ends up faster with LUT because of nearby code/data.

View File

@ -150,7 +150,7 @@ struct GPUSettings
float display_osd_scale = DEFAULT_OSD_SCALE;
float display_osd_margin = 0.0f;
float gpu_pgxp_tolerance = -1.0f;
float gpu_pgxp_depth_clear_threshold = DEFAULT_GPU_PGXP_DEPTH_THRESHOLD / GPU_PGXP_DEPTH_THRESHOLD_SCALE;
float gpu_pgxp_depth_clear_threshold = 0.0f;
// texture replacements
struct TextureReplacementSettings
@ -209,6 +209,8 @@ struct GPUSettings
std::string overlay_image_path;
float GetDisplayAspectRatioValue() const;
float GetPGXPDepthClearThreshold() const;
void SetPGXPDepthClearThreshold(float value);
ALWAYS_INLINE bool IsUsingSoftwareRenderer() const { return (gpu_renderer == GPURenderer::Software); }
ALWAYS_INLINE bool IsUsingAccurateBlending() const { return (gpu_accurate_blending && !gpu_true_color); }
@ -220,14 +222,6 @@ struct GPUSettings
ALWAYS_INLINE bool UsingPGXPCPUMode() const { return gpu_pgxp_enable && gpu_pgxp_cpu; }
ALWAYS_INLINE bool UsingPGXPDepthBuffer() const { return gpu_pgxp_enable && gpu_pgxp_depth_buffer; }
ALWAYS_INLINE float GetPGXPDepthClearThreshold() const
{
return gpu_pgxp_depth_clear_threshold * GPU_PGXP_DEPTH_THRESHOLD_SCALE;
}
ALWAYS_INLINE void SetPGXPDepthClearThreshold(float value)
{
gpu_pgxp_depth_clear_threshold = value / GPU_PGXP_DEPTH_THRESHOLD_SCALE;
}
static constexpr GPURenderer DEFAULT_GPU_RENDERER = GPURenderer::Automatic;
static constexpr GPUTextureFilter DEFAULT_GPU_TEXTURE_FILTER = GPUTextureFilter::Nearest;
@ -236,7 +230,7 @@ struct GPUSettings
static constexpr GPUWireframeMode DEFAULT_GPU_WIREFRAME_MODE = GPUWireframeMode::Disabled;
static constexpr GPUDumpCompressionMode DEFAULT_GPU_DUMP_COMPRESSION_MODE = GPUDumpCompressionMode::ZstDefault;
static constexpr float DEFAULT_GPU_PGXP_DEPTH_THRESHOLD = 300.0f;
static constexpr float GPU_PGXP_DEPTH_THRESHOLD_SCALE = 4096.0f;
static constexpr float GPU_PGXP_DEPTH_THRESHOLD_SCALE = 65536.0f;
static constexpr DisplayDeinterlacingMode DEFAULT_DISPLAY_DEINTERLACING_MODE = DisplayDeinterlacingMode::Progressive;
static constexpr DisplayCropMode DEFAULT_DISPLAY_CROP_MODE = DisplayCropMode::Overscan;