From 3df3a109751e9bc1d7abe0a9eced8c8f1214a679 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 4d31bbdf044..2963ca40fc4 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -2146,11 +2146,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);