From 73c984a63775aa30f63e623369fe939b7e14df1f Mon Sep 17 00:00:00 2001 From: kd-11 Date: Fri, 24 Oct 2025 13:40:07 +0300 Subject: [PATCH] vk: Filter out re-bar usage from memory pressure watchdog --- rpcs3/Emu/RSX/VK/vkutils/device.cpp | 2 ++ rpcs3/Emu/RSX/VK/vkutils/device.h | 2 ++ rpcs3/Emu/RSX/VK/vkutils/memory.cpp | 23 +++++++++++++++++++++++ rpcs3/Emu/RSX/VK/vkutils/memory.h | 8 ++++++++ 4 files changed, 35 insertions(+) diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index f5f2745ab4..e29a9b66c2 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -1010,6 +1010,8 @@ namespace vk .heap = memory_properties.memoryHeaps[i], .types = {} }); + + result.heaps.push_back({ i, memory_properties.memoryHeaps[i].flags, memory_properties.memoryHeaps[i].size }); } for (u32 i = 0; i < memory_properties.memoryTypeCount; i++) diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.h b/rpcs3/Emu/RSX/VK/vkutils/device.h index 0511802aac..c121d1b20a 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.h +++ b/rpcs3/Emu/RSX/VK/vkutils/device.h @@ -30,6 +30,8 @@ namespace vk struct memory_type_mapping { + std::vector heaps; + memory_type_info host_visible_coherent; memory_type_info device_local; memory_type_info device_bar; diff --git a/rpcs3/Emu/RSX/VK/vkutils/memory.cpp b/rpcs3/Emu/RSX/VK/vkutils/memory.cpp index 80ffc50295..2b84e1f61c 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/memory.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/memory.cpp @@ -200,6 +200,23 @@ namespace vk // Allow fastest possible allocation on start set_fastest_allocation_flags(); + + // Determine the rebar heap. We will exclude it from stats + const auto& memory_map = dev.get_memory_mapping(); + if (memory_map.device_bar_total_bytes != + memory_map.device_local_total_bytes) + { + for (u32 i = 0; i < ::size32(memory_map.heaps); ++i) + { + const auto& heap = memory_map.heaps[i]; + if ((heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) && + heap.size == memory_map.device_bar_total_bytes) + { + m_rebar_heap_idx = i; + break; + } + } + } } void mem_allocator_vma::destroy() @@ -313,6 +330,12 @@ namespace vk { vmaGetHeapBudgets(m_allocator, stats.data()); + // Filter out the Re-BAR heap + if (::size32(stats) > m_rebar_heap_idx) + { + stats[m_rebar_heap_idx].budget = 0; + } + float max_usage = 0.f; for (const auto& info : stats) { diff --git a/rpcs3/Emu/RSX/VK/vkutils/memory.h b/rpcs3/Emu/RSX/VK/vkutils/memory.h index 83e09cdd30..abe0c75582 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/memory.h +++ b/rpcs3/Emu/RSX/VK/vkutils/memory.h @@ -59,6 +59,13 @@ namespace vk void rebalance(); }; + struct memory_heap_info + { + u32 index; + u32 flags; + u64 size; + }; + class mem_allocator_base { public: @@ -113,6 +120,7 @@ namespace vk private: VmaAllocator m_allocator; std::array stats; + u32 m_rebar_heap_idx = UINT32_MAX; };