From e53bbd668b4e0f72b8f94f921d34af522c5b7a6a Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 4 Apr 2022 21:39:33 +0300 Subject: [PATCH] rsx: Fix surface cache scanning and removal --- rpcs3/Emu/RSX/Common/surface_store.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/surface_store.h b/rpcs3/Emu/RSX/Common/surface_store.h index eb1ead6009..873f30da4f 100644 --- a/rpcs3/Emu/RSX/Common/surface_store.h +++ b/rpcs3/Emu/RSX/Common/surface_store.h @@ -656,6 +656,7 @@ namespace rsx } } + rsx_log.notice("rsx::surface_cache::check_for_duplicates_fast analysed %u overlapping sections and removed %u", ::size32(sections), removed_count); return removed_count; } @@ -673,6 +674,8 @@ namespace rsx u32* overrun_test_ptr = utils::bless(marker.data() + range.length()); *overrun_test_ptr = overrun_cookie_value; + u32 removed_count = 0; + auto compare_and_tag_row = [&](const u32 offset, u32 length) -> bool { u64 mask = 0; @@ -740,7 +743,7 @@ namespace rsx if (row_offset < native_pitch) { - compare_and_tag_row(0, native_pitch - row_offset); + compare_and_tag_row(0, std::min(native_pitch - row_offset, range.length())); } // Jump to next row... @@ -773,11 +776,15 @@ namespace rsx if (!valid) { + removed_count++; rsx_log.warning("Stale surface at address 0x%x will be deleted", it->base_address); invalidate_surface_address(it->base_address, it->is_depth); } } + // Notify + rsx_log.notice("rsx::surface_cache::check_for_duplicates_fallback analysed %u overlapping sections and removed %u", ::size32(sections), removed_count); + // Verify no OOB ensure(*overrun_test_ptr == overrun_cookie_value); } @@ -1103,9 +1110,17 @@ namespace rsx void check_for_duplicates(std::vector& sections, const rsx::address_range& range) { - if (!remove_duplicates_fast_impl(sections, range)) + utils::address_range test_range; + for (const auto& section : sections) { - remove_duplicates_fallback_impl(sections, range); + const auto range = section.surface->get_memory_range(); + test_range.start = std::min(test_range.start, range.start); + test_range.end = std::max(test_range.end, range.end); + } + + if (!remove_duplicates_fast_impl(sections, test_range)) + { + remove_duplicates_fallback_impl(sections, test_range); } }