Skip to content

Commit

Permalink
Improve scissor rect clipping. Affected D3D11 validation when maximiz…
Browse files Browse the repository at this point in the history
…ing/minimizing.
  • Loading branch information
hrydgard committed Jan 24, 2023
1 parent 4228837 commit 91cca1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Common/GPU/D3D11/thin3d_d3d11.cpp
Expand Up @@ -437,6 +437,8 @@ void D3D11DrawContext::SetViewports(int count, Viewport *viewports) {
}

void D3D11DrawContext::SetScissorRect(int left, int top, int width, int height) {
_assert_(width >= 0);
_assert_(height >= 0);
DisplayRect<float> frc{ (float)left, (float)top, (float)width, (float)height };
if (curRenderTargetView_ == bbRenderTargetView_) // Only the backbuffer is actually rotated wrong!
RotateRectToDisplay(frc, curRTWidth_, curRTHeight_);
Expand Down
19 changes: 14 additions & 5 deletions Common/UI/Context.cpp
Expand Up @@ -173,12 +173,21 @@ void UIContext::ActivateTopScissor() {
if (x < 0 || y < 0 || x + w > pixel_xres || y + h > pixel_yres) {
// This won't actually report outside a game, but we can try.
ERROR_LOG(G3D, "UI scissor out of bounds in %sScreen: %d,%d-%d,%d / %d,%d", screenTag_ ? screenTag_ : "N/A", x, y, w, h, pixel_xres, pixel_yres);
x = std::max(0, x);
y = std::max(0, y);
w = std::min(w, pixel_xres - x);
h = std::min(h, pixel_yres - y);
if (x < 0) { w += x; x = 0; }
if (y < 0) { h += y; y = 0; }
if (x >= pixel_xres) { x = pixel_xres - 1; }
if (y >= pixel_yres) { y = pixel_yres - 1; }
if (x + w > pixel_xres) { w = std::min(w, pixel_xres - x); }
if (y + w > pixel_yres) { h = std::min(h, pixel_yres - y); }
if (w == 0) w = 1;
if (h == 0) h = 1;
draw_->SetScissorRect(x, y, w, h);
} else {
// Avoid invalid rects
if (w == 0) w = 1;
if (h == 0) h = 1;
draw_->SetScissorRect(x, y, w, h);
}
draw_->SetScissorRect(x, y, w, h);
} else {
// Avoid rounding errors
draw_->SetScissorRect(0, 0, pixel_xres, pixel_yres);
Expand Down

0 comments on commit 91cca1c

Please sign in to comment.