Skip to content

Commit

Permalink
Merge pull request #14609 from hrydgard/viewport-fixes
Browse files Browse the repository at this point in the history
Viewport fixes
  • Loading branch information
hrydgard authored Jul 12, 2021
2 parents 852e0c6 + 69ae3f4 commit 11957dd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions GPU/Common/GPUStateUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,6 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo
renderHeightFactor = renderHeight / 272.0f;
}

_assert_(renderWidthFactor > 0.0);
_assert_(renderHeightFactor > 0.0);

renderX = gstate_c.curRTOffsetX;

// Scissor
Expand Down Expand Up @@ -667,6 +664,12 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo
left += overageLeft;
right -= overageRight;

// Protect against the viewport being entirely outside the scissor.
// Emit a tiny but valid viewport. Really, we should probably emit a flag to ignore draws.
if (right <= left) {
right = left + 1.0f;
}

wScale = vpWidth / (right - left);
xOffset = drift / (right - left);
}
Expand All @@ -690,18 +693,21 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo
top += overageTop;
bottom -= overageBottom;

// Protect against the viewport being entirely outside the scissor.
// Emit a tiny but valid viewport. Really, we should probably emit a flag to ignore draws.
if (bottom <= top) {
bottom = top + 1.0f;
}

hScale = vpHeight / (bottom - top);
yOffset = drift / (bottom - top);
}
}

out.viewportX = left * renderWidthFactor + displayOffsetX;
out.viewportY = top * renderHeightFactor + displayOffsetY;

// The calculations should end up with zero or positive values, but let's protect against any
// precision issues. See #13921.
out.viewportW = std::max(0.0f, (right - left) * renderWidthFactor);
out.viewportH = std::max(0.0f, (bottom - top) * renderHeightFactor);
out.viewportW = (right - left) * renderWidthFactor;
out.viewportH = (bottom - top) * renderHeightFactor;

// The depth viewport parameters are the same, but we handle it a bit differently.
// When clipping is enabled, depth is clamped to [0, 65535]. And minz/maxz discard.
Expand Down

0 comments on commit 11957dd

Please sign in to comment.