diff --git a/GPU/Software/BinManager.cpp b/GPU/Software/BinManager.cpp index c1e4d12dc5..b39aaeed6d 100644 --- a/GPU/Software/BinManager.cpp +++ b/GPU/Software/BinManager.cpp @@ -359,8 +359,19 @@ inline void BinDirtyRange::Expand(uint32_t newBase, uint32_t bpp, uint32_t strid return; } - if (stride != 0) - height += ((int)base - (int)newBase) / (stride * bpp); + if (stride != 0) { + // Careful with the subtraction: stride * bpp is unsigned, so a signed difference gets converted + // before the division. When newBase was above base that turned into ~4 billion rows, and the + // wrapped height made HasPendingWrite() report "no overlap" for every later query. + const uint32_t newStrideBytes = stride * bpp; + if (newBase < base) { + // The base moves up, so everything we already tracked shifts down by this many rows. + height += (base - newBase) / newStrideBytes; + } else { + // The new range starts further down - make sure the height still reaches its bottom. + height = std::max(height, (newBase - base) / newStrideBytes + h); + } + } base = std::min(base, newBase); strideBytes = std::max(strideBytes, stride * bpp); widthBytes = strideBytes; diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index aff9d47ad9..2726641cea 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -703,6 +703,11 @@ bool SoftGPU::ClearDirty(uint32_t addr, uint32_t bytes, SoftGPUVRAMDirty value) uint32_t start = ((addr - PSP_GetVidMemBase()) & 0x001FFFFF) >> 10; uint32_t end = start + ((bytes + 1023) >> 10); + // Same clamp as MarkDirty - the endpoint checks above accept the whole mirrored 8MB window, so + // bytes can carry us past the end of the array. Without this the loop below writes past it. + if (end > sizeof(vramDirty_)) { + end = sizeof(vramDirty_); + } bool result = false; for (uint32_t i = start; i < end; ++i) { if (vramDirty_[i] & (uint8_t)value) {