From 0b73c1ce83306f96fc6c2555eb75ea7c11d5404e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 9 Sep 2021 20:05:41 -0700 Subject: [PATCH] softgpu: Correct guardband cull behavior. Culling is based on whether clipping happens, not whether clamping happens. This is important for issues like #12348. --- GPU/Software/TransformUnit.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 65baa6f363..dc1bc88a5c 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -111,18 +111,19 @@ static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool * // Account for rounding for X and Y. // TODO: Validate actual rounding range. const float SCREEN_BOUND = 4095.0f + (15.5f / 16.0f); - const float DEPTH_BOUND = 65535.5f; // This matches hardware tests - depth is clamped when this flag is on. if (gstate.isDepthClampEnabled()) { - // Note: if the depth is clamped, the outside_range_flag should NOT be set, even for x and y. + // Note: if the depth is clipped (z/w <= -1.0), the outside_range_flag should NOT be set, even for x and y. + if (outside_range_flag && coords.z > -coords.w && (x >= SCREEN_BOUND || y >= SCREEN_BOUND || x < 0 || y < 0)) { + *outside_range_flag = true; + } + if (z < 0.f) z = 0.f; else if (z > 65535.0f) z = 65535.0f; - else if (outside_range_flag && (x >= SCREEN_BOUND || y >= SCREEN_BOUND || x < 0 || y < 0)) - *outside_range_flag = true; - } else if (outside_range_flag && (x > SCREEN_BOUND || y >= SCREEN_BOUND || x < 0 || y < 0 || z < 0 || z >= DEPTH_BOUND)) { + } else if (outside_range_flag && (x > SCREEN_BOUND || y >= SCREEN_BOUND || x < 0 || y < 0)) { *outside_range_flag = true; }