Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport fixes #14609

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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