From ba5e0b0759e777d79edbf027bb098c8da212ea48 Mon Sep 17 00:00:00 2001 From: Lander Gallastegi Date: Mon, 16 Jun 2025 19:06:26 +0200 Subject: [PATCH] Sync on region mutex for thw whole protection This is a temporary workarround until a fix is found for the page manager having issues when multiple threads update the same page at the same time. --- src/video_core/buffer_cache/region_manager.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/video_core/buffer_cache/region_manager.h b/src/video_core/buffer_cache/region_manager.h index 2711bdc38..5584f9afe 100644 --- a/src/video_core/buffer_cache/region_manager.h +++ b/src/video_core/buffer_cache/region_manager.h @@ -81,14 +81,14 @@ public: */ template void ChangeRegionState(u64 dirty_addr, u64 size) noexcept(type == Type::GPU) { + RENDERER_TRACE; const size_t offset = dirty_addr - cpu_addr; const size_t start_page = SanitizeAddress(offset) / BYTES_PER_PAGE; const size_t end_page = Common::DivCeil(SanitizeAddress(offset + size), BYTES_PER_PAGE); if (start_page >= NUM_REGION_PAGES || end_page <= start_page) { return; } - RENDERER_TRACE; - std::unique_lock lk{lock}; + std::scoped_lock lk{lock}; static_assert(type != Type::Writeable); RegionBits& bits = GetRegionBits(); @@ -98,7 +98,7 @@ public: bits.UnsetRange(start_page, end_page); } if constexpr (type == Type::CPU) { - UpdateProtection(std::move(lk)); + UpdateProtection(); } } @@ -119,7 +119,7 @@ public: if (start_page >= NUM_REGION_PAGES || end_page <= start_page) { return; } - std::unique_lock lk{lock}; + std::scoped_lock lk{lock}; static_assert(type != Type::Writeable); RegionBits& bits = GetRegionBits(); @@ -132,7 +132,7 @@ public: if constexpr (clear) { bits.UnsetRange(start_page, end_page); if constexpr (type == Type::CPU) { - UpdateProtection(std::move(lk)); + UpdateProtection(); } } } @@ -169,12 +169,11 @@ private: * * @tparam add_to_tracker True when the tracker should start tracking the new pages */ - template - void UpdateProtection(Lock&& lk) { + template + void UpdateProtection() { RENDERER_TRACE; RegionBits mask = cpu ^ writeable; writeable = cpu; - lk.unlock(); tracker->UpdatePageWatchersMasked(cpu_addr, mask); }