From bf94ee1c8e66b32e58341eca09587b33e8cfcb24 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Tue, 3 Feb 2026 15:10:53 +0000 Subject: [PATCH] GS: Simplify Overlaps check --- pcsx2/GS/GSLocalMemory.cpp | 59 +++++++++----------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/pcsx2/GS/GSLocalMemory.cpp b/pcsx2/GS/GSLocalMemory.cpp index 03ea58149a..231f3ad6df 100644 --- a/pcsx2/GS/GSLocalMemory.cpp +++ b/pcsx2/GS/GSLocalMemory.cpp @@ -512,56 +512,25 @@ GSVector4i GSLocalMemory::GetRectForPageOffset(u32 base_bp, u32 offset_bp, u32 b bool GSLocalMemory::HasOverlap(const u32 src_bp, const u32 src_bw, const u32 src_psm, const GSVector4i src_rect, const u32 dst_bp, const u32 dst_bw, const u32 dst_psm, const GSVector4i dst_rect) { - const u32 src_start_bp = GSLocalMemory::GetStartBlockAddress(src_bp, src_bw, src_psm, src_rect) & ~(GS_BLOCKS_PER_PAGE - 1); - const u32 dst_start_bp = GSLocalMemory::GetStartBlockAddress(dst_bp, dst_bw, dst_psm, dst_rect) & ~(GS_BLOCKS_PER_PAGE - 1); + u32 src_start_bp = GSLocalMemory::GetStartBlockAddress(src_bp, src_bw, src_psm, src_rect) & ~(GS_BLOCKS_PER_PAGE - 1); + u32 dst_start_bp = GSLocalMemory::GetStartBlockAddress(dst_bp, dst_bw, dst_psm, dst_rect) & ~(GS_BLOCKS_PER_PAGE - 1); - u32 src_end_bp = ((GSLocalMemory::GetEndBlockAddress(src_bp, src_bw, src_psm, src_rect) + 1) + (GS_BLOCKS_PER_PAGE - 1)) & ~(GS_BLOCKS_PER_PAGE - 1); - u32 dst_end_bp = ((GSLocalMemory::GetEndBlockAddress(dst_bp, dst_bw, dst_psm, dst_rect) + 1) + (GS_BLOCKS_PER_PAGE - 1)) & ~(GS_BLOCKS_PER_PAGE - 1); + u32 src_end_bp = ((GSLocalMemory::GetUnwrappedEndBlockAddress(src_bp, src_bw, src_psm, src_rect) + 1) + (GS_BLOCKS_PER_PAGE - 1)) & ~(GS_BLOCKS_PER_PAGE - 1); + u32 dst_end_bp = ((GSLocalMemory::GetUnwrappedEndBlockAddress(dst_bp, dst_bw, dst_psm, dst_rect) + 1) + (GS_BLOCKS_PER_PAGE - 1)) & ~(GS_BLOCKS_PER_PAGE - 1); - if (src_start_bp == src_end_bp) + if (dst_end_bp > GS_MAX_BLOCKS && src_end_bp < dst_start_bp) { - src_end_bp = (src_end_bp + GS_BLOCKS_PER_PAGE) & ~(GS_MAX_BLOCKS - 1); + src_start_bp += GS_MAX_BLOCKS; + src_end_bp += GS_MAX_BLOCKS; + } + else if (src_end_bp > GS_MAX_BLOCKS && dst_end_bp < src_start_bp) + { + dst_start_bp += GS_MAX_BLOCKS; + dst_end_bp += GS_MAX_BLOCKS; } - if (dst_start_bp == dst_end_bp) - { - dst_end_bp = (dst_end_bp + GS_BLOCKS_PER_PAGE) & ~(GS_MAX_BLOCKS - 1); - } - - // Source has wrapped, 2 separate checks. - if (src_end_bp <= src_start_bp) - { - // Destination has also wrapped, so they *have* to overlap. - if (dst_end_bp <= dst_start_bp) - { - return true; - } - else - { - if (dst_end_bp > src_start_bp) - return true; - - if (dst_start_bp < src_end_bp) - return true; - } - } - else // No wrapping on source. - { - // Destination wraps. - if (dst_end_bp <= dst_start_bp) - { - if (src_end_bp > dst_start_bp) - return true; - - if (src_start_bp < dst_end_bp) - return true; - } - else - { - if (dst_start_bp < src_end_bp && dst_end_bp > src_start_bp) - return true; - } - } + if (src_start_bp < dst_end_bp && dst_start_bp < src_end_bp) + return true; return false; }