Skip to content
Permalink
Browse files

SoftGPU: Fix some minor rounding on viewport cull.

Had some tests failing when on the edge due to this.
  • Loading branch information...
unknownbrackets committed Aug 6, 2018
1 parent 44be615 commit 31d5c39858060d7d04861fa3af2d4fe877def37d
Showing with 9 additions and 4 deletions.
  1. +9 −4 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;

This comment has been minimized.

@hrydgard

hrydgard Aug 9, 2018

Owner

Hm, by the way. So this is supposed to be more than 4096 ?

This comment has been minimized.

@unknownbrackets

unknownbrackets Aug 9, 2018

Author Collaborator

Gah, oops. Should be 15.375f, I think. It rounds to 12.4 fixed point precision.

-[Unknown]

This comment has been minimized.

@unknownbrackets

unknownbrackets Aug 9, 2018

Author Collaborator

Actually, that's not right either. 4095.966797 definitely needs to pass, and 4095 + 15.375 / 16 is 4095.9609375.

Might have to do more tests to get the precision exactly right, but 15.5/16 seems okay for now.

-[Unknown]

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

This comment has been minimized.

@Nucleoprotein

Nucleoprotein Aug 9, 2018

x > 4095.9675f ? it should not be x >= SCREEN_BOUND ?

This comment has been minimized.

@unknownbrackets

unknownbrackets Aug 9, 2018

Author Collaborator

You're right, will push this up.

-[Unknown]

*outside_range_flag = true;
}

0 comments on commit 31d5c39

Please sign in to comment.
You can’t perform that action at this time.