diff --git a/src/core/cpu_pgxp.cpp b/src/core/cpu_pgxp.cpp index a9adc512c..d2e0d133a 100644 --- a/src/core/cpu_pgxp.cpp +++ b/src/core/cpu_pgxp.cpp @@ -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(xOffs); *out_y = TruncateVertexPosition(vert->y) + static_cast(yOffs); - *out_w = vert->z / 32768.0f; + *out_w = vert->z / static_cast(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(xOffs); *out_y = TruncateVertexPosition(vert->y) + static_cast(yOffs); - *out_w = vert->z / 32768.0f; + *out_w = vert->z / static_cast(GTE::MAX_Z); if (IsWithinTolerance(*out_x, *out_y, x, y)) return false; diff --git a/src/core/gte.cpp b/src/core/gte.cpp index 8e017059e..672dad33e 100644 --- a/src/core/gte.cpp +++ b/src/core/gte.cpp @@ -791,9 +791,9 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last) } else { - precise_x = static_cast(x) / 4096.0f; + precise_x = static_cast(x) / (static_cast(1 << shift)); precise_y = static_cast(y) / (static_cast(1 << shift)); - precise_z = static_cast(z) / (static_cast(1 << shift)); + precise_z = static_cast(z) / 4096.0f; } precise_sz3 = precise_z; diff --git a/src/core/gte_types.h b/src/core/gte_types.h index 84ea19ce0..b3a32776e 100644 --- a/src/core/gte_types.h +++ b/src/core/gte_types.h @@ -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 diff --git a/src/core/settings.cpp b/src/core/settings.cpp index edc737997..c86fa5d35 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -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(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(GTE::MAX_Z); +} + +void GPUSettings::SetPGXPDepthClearThreshold(float value) +{ + gpu_pgxp_depth_clear_threshold = value / static_cast(GTE::MAX_Z); +} #ifdef DYNAMIC_HOST_PAGE_SIZE // See note in settings.h - 16K ends up faster with LUT because of nearby code/data. diff --git a/src/core/settings.h b/src/core/settings.h index afba49baf..801c61705 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -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;