Fix faulty formula for block transfer size-check.

This commit is contained in:
Henrik Rydgård 2024-05-10 13:50:49 +02:00
parent 359b4fe1cf
commit 70ae4a35c1
2 changed files with 5 additions and 3 deletions

View File

@ -337,6 +337,7 @@ inline u32 ValidSize(const u32 address, const u32 requested_size) {
return requested_size;
}
// NOTE: If size == 0, any address will be accepted. This may not be ideal for all cases.
inline bool IsValidRange(const u32 address, const u32 size) {
return ValidSize(address, size) == size;
}

View File

@ -1675,11 +1675,12 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
if ((dstBasePtr & 0x04800000) == 0x04800000)
dstBasePtr &= ~0x00800000;
// Use height less one to account for width, which can be greater or less than stride.
// Use height less one to account for width, which can be greater or less than stride, and then add it on for the last line.
// NOTE: The sizes are only used for validity checks and memory info tracking.
const uint32_t src = srcBasePtr + (srcY * srcStride + srcX) * bpp;
const uint32_t srcSize = (height - 1) * (srcStride + width) * bpp;
const uint32_t dst = dstBasePtr + (dstY * dstStride + dstX) * bpp;
const uint32_t dstSize = (height - 1) * (dstStride + width) * bpp;
const uint32_t srcSize = ((height - 1) * srcStride) + width * bpp;
const uint32_t dstSize = ((height - 1) * dstStride) + width * bpp;
bool srcDstOverlap = src + srcSize > dst && dst + dstSize > src;
bool srcValid = Memory::IsValidRange(src, srcSize);