diff options
| author | JMC47 <JMC4789@gmail.com> | 2021-09-15 13:26:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-15 13:26:23 -0400 |
| commit | 4d1bd54917f097510e814d0ffcd625de6867fcc0 (patch) | |
| tree | 45ad4a3e7c7ae88bb200fe0e4bb15e66adf85ee6 /Source/Core | |
| parent | 57a8ee049f30d267909fe57ae4422d19f6d9a0dd (diff) | |
| parent | eb8bfabdfda83dd2cbacfa5c2bc89a5254e587b3 (diff) | |
Merge pull request #10095 from phire/fix-out-of-range-efb
BPStructs: fix out-of-range EFB copy clamping
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/VideoCommon/BPStructs.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 97c78474e1..57a418e8d0 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -3,6 +3,7 @@ #include "VideoCommon/BPStructs.h" +#include <algorithm> #include <cmath> #include <cstring> #include <string> @@ -237,27 +238,20 @@ static void BPWritten(const BPCmd& bp) // writing the junk data, we don't write anything to RAM at all for over-sized copies, and clamp // to the EFB borders for over-offset copies. The arcade virtual console games (e.g. 1942) are // known for configuring these out-of-range copies. - u32 copy_width = srcRect.GetWidth(); - u32 copy_height = srcRect.GetHeight(); - if (srcRect.right > EFB_WIDTH || srcRect.bottom > EFB_HEIGHT) + + if (u32(srcRect.right) > EFB_WIDTH || u32(srcRect.bottom) > EFB_HEIGHT) { - WARN_LOG_FMT(VIDEO, "Oversized EFB copy: {}x{} (offset {},{} stride {})", copy_width, - copy_height, srcRect.left, srcRect.top, destStride); + WARN_LOG_FMT(VIDEO, "Oversized EFB copy: {}x{} (offset {},{} stride {})", srcRect.GetWidth(), + srcRect.GetHeight(), srcRect.left, srcRect.top, destStride); - // Adjust the copy size to fit within the EFB. So that we don't end up with a stretched image, - // instead of clamping the source rectangle, we reduce it by the over-sized amount. - if (copy_width > EFB_WIDTH) - { - srcRect.right -= copy_width - EFB_WIDTH; - copy_width = EFB_WIDTH; - } - if (copy_height > EFB_HEIGHT) - { - srcRect.bottom -= copy_height - EFB_HEIGHT; - copy_height = EFB_HEIGHT; - } + // Clamp the copy region to fit within EFB. So that we don't end up with a stretched image. + srcRect.right = std::clamp<int>(srcRect.right, 0, EFB_WIDTH); + srcRect.bottom = std::clamp<int>(srcRect.bottom, 0, EFB_HEIGHT); } + const u32 copy_width = srcRect.GetWidth(); + const u32 copy_height = srcRect.GetHeight(); + // Check if we are to copy from the EFB or draw to the XFB const UPE_Copy PE_copy = bpmem.triggerEFBCopy; if (PE_copy.copy_to_xfb == 0) |
