Skip to content

Commit

Permalink
SoftGPU: Fix some minor rounding on viewport cull.
Browse files Browse the repository at this point in the history
Had some tests failing when on the edge due to this.
  • Loading branch information
unknownbrackets committed Aug 6, 2018
1 parent 44be615 commit 31d5c39
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions GPU/Software/TransformUnit.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@ static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool *
float y = coords.y * yScale / coords.w + yCenter; float y = coords.y * yScale / coords.w + yCenter;
float z = coords.z * zScale / coords.w + zCenter; 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.

Copy link
@hrydgard

hrydgard Aug 9, 2018

Owner

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

This comment has been minimized.

Copy link
@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.

Copy link
@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. // This matches hardware tests - depth is clamped when this flag is on.
if (gstate.isDepthClampEnabled()) { 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 clamped, the outside_range_flag should NOT be set, even for x and y.
if (z < 0.f) if (z < 0.f)
z = 0.f; z = 0.f;
else if (z > 65535.f) else if (z > 65535.0f)
z = 65535.f; z = 65535.0f;
else if (outside_range_flag && (x > 4095.9375f || y > 4095.9375f || x < 0 || y < 0)) else if (outside_range_flag && (x >= SCREEN_BOUND || y >= SCREEN_BOUND || x < 0 || y < 0))
*outside_range_flag = true; *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.

Copy link
@Nucleoprotein

Nucleoprotein Aug 9, 2018

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

This comment has been minimized.

Copy link
@unknownbrackets

unknownbrackets Aug 9, 2018

Author Collaborator

You're right, will push this up.

-[Unknown]

*outside_range_flag = true; *outside_range_flag = true;
} }


Expand Down

0 comments on commit 31d5c39

Please sign in to comment.