From 31d5c39858060d7d04861fa3af2d4fe877def37d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Aug 2018 20:07:45 -0700 Subject: [PATCH] SoftGPU: Fix some minor rounding on viewport cull. Had some tests failing when on the edge due to this. --- GPU/Software/TransformUnit.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 7bd578a25f..5810a36c2d 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -104,16 +104,21 @@ static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool * float y = coords.y * yScale / coords.w + yCenter; float z = coords.z * zScale / coords.w + zCenter; + // Account for rounding for X and Y. + const float SCREEN_BOUND = 4095.0f + (15.0f / 16.0f) + 0.375f; + // TODO: Validate actual rounding range. + 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. if (z < 0.f) z = 0.f; - else if (z > 65535.f) - z = 65535.f; - else if (outside_range_flag && (x > 4095.9375f || y > 4095.9375f || x < 0 || y < 0)) + 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 > 4095.9375f || y > 4095.9375f || x < 0 || y < 0 || z < 0 || z > 65535.f)) { + } else if (outside_range_flag && (x > 4095.9675f || y >= SCREEN_BOUND || x < 0 || y < 0 || z < 0 || z >= DEPTH_BOUND)) { *outside_range_flag = true; }