From 0ca39e9b8f1c1db56ccfa6042616a4aa62c6825c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 18 Oct 2024 18:48:43 +0200 Subject: [PATCH] [dxvk] Limit number of allocations to move per submissions --- src/dxvk/dxvk_context.cpp | 3 ++- src/dxvk/dxvk_memory.cpp | 18 +++++++++++++----- src/dxvk/dxvk_memory.h | 14 +++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index e2e017e5..636a390d 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -6478,7 +6478,8 @@ namespace dxvk { void DxvkContext::relocateQueuedResources() { - auto resourceList = m_common->memoryManager().pollRelocationList(); + constexpr static uint32_t MaxRelocationsPerSubmission = 128u; + auto resourceList = m_common->memoryManager().pollRelocationList(MaxRelocationsPerSubmission); if (resourceList.empty()) return; diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 980bb1f9..e0f04cfc 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -469,16 +469,24 @@ namespace dxvk { } - std::vector DxvkRelocationList::poll() { + std::vector DxvkRelocationList::poll(uint32_t count) { std::lock_guard lock(m_mutex); std::vector result; - result.reserve(m_entries.size()); + count = std::min(count, uint32_t(m_entries.size())); - for (const auto& p : m_entries) - result.push_back({ p.first, p.second }); + if (!count) + return result; + + result.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + auto iter = m_entries.begin(); + + result.push_back({ iter->first, iter->second }); + m_entries.erase(iter); + } - m_entries.clear(); return result; } diff --git a/src/dxvk/dxvk_memory.h b/src/dxvk/dxvk_memory.h index cb742960..eb503f37 100644 --- a/src/dxvk/dxvk_memory.h +++ b/src/dxvk/dxvk_memory.h @@ -993,11 +993,13 @@ namespace dxvk { /** * \brief Retrieves list of resources to move * - * Clears the internally stored list. Any - * duplicate entries will be removed. + * Removes items from the internally stored list. + * Any duplicate entries will be removed. + * \param [in] count Number of entries to return * \returns List of resources to move */ - std::vector poll(); + std::vector poll( + uint32_t count); /** * \brief Adds relocation entry to the list @@ -1238,10 +1240,12 @@ namespace dxvk { /** * \brief Polls relocation list + * + * \param [in] count Desired entry count * \returns Relocation entries */ - auto pollRelocationList() { - return m_relocations.poll(); + auto pollRelocationList(uint32_t count) { + return m_relocations.poll(count); } private: