From 45b0f13dd6194989e264c17742f90228e2c67c2c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 24 Oct 2024 16:41:25 +0200 Subject: [PATCH] frog --- src/dxvk/dxvk_memory.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 0b8c0717..2de434f8 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -2136,7 +2136,6 @@ namespace dxvk { return; DxvkAllocationModes mode( - DxvkAllocationMode::NoAllocation, DxvkAllocationMode::NoFallback); // Iterate over the chunk's allocation list and look up resources @@ -2164,11 +2163,29 @@ namespace dxvk { } } + static uint32_t lastDefrag = 0u; + void DxvkMemoryAllocator::pickDefragChunk( DxvkMemoryType& type) { auto& pool = type.devicePool; + if (pool.chunks.size() == 0) + return; + + for (uint32_t i = 1; i <= pool.chunks.size(); i++) { + auto index = (lastDefrag + i) % pool.chunks.size(); + + if (pool.chunks[index].canMove && pool.pageAllocator.pagesUsed(index)) { + pool.nextDefragChunk = index; + pool.pageAllocator.killChunk(index); + lastDefrag = index; + return; + } + } + + return; + // Only engage defragmentation at all if we have a significant // amount of memory wasted, or if we're under memory pressure. auto heapStats = getMemoryStats(type.heap->index); @@ -2265,7 +2282,7 @@ namespace dxvk { void DxvkMemoryAllocator::performTimedTasks() { - static constexpr auto Interval = std::chrono::milliseconds(500u); + static constexpr auto Interval = std::chrono::milliseconds(50u); // This function shouldn't be called concurrently, so checking and // updating the deadline is fine without taking the global lock