diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 0b8c07176..2de434f8d 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