diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 5fee82953..98f2f7589 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -1195,6 +1195,7 @@ namespace dxvk { pool.chunks.resize(std::max(pool.chunks.size(), chunkIndex + 1u)); pool.chunks[chunkIndex].memory = chunk; pool.chunks[chunkIndex].unusedTime = high_resolution_clock::time_point(); + pool.chunks[chunkIndex].chunkCookie = ++pool.nextChunkCookie; return true; } @@ -1591,6 +1592,8 @@ namespace dxvk { DxvkMemoryAllocationStats& stats) { auto& typeStats = stats.memoryTypes[type.index]; + size_t first = stats.chunks.size(); + for (uint32_t i = 0; i < pool.chunks.size(); i++) { if (!pool.chunks[i].memory.memory) continue; @@ -1604,12 +1607,18 @@ namespace dxvk { chunkStats.pageCount = pool.pageAllocator.pageCount(i); chunkStats.mapped = &pool == &type.mappedPool; chunkStats.active = pool.pageAllocator.chunkIsAvailable(i); + chunkStats.cookie = pool.chunks[i].chunkCookie; size_t maskCount = (chunkStats.pageCount + 31u) / 32u; stats.pageMasks.resize(chunkStats.pageMaskOffset + maskCount); pool.pageAllocator.getPageAllocationMask(i, &stats.pageMasks[chunkStats.pageMaskOffset]); } + + std::sort(stats.chunks.begin() + first, stats.chunks.end(), + [] (const DxvkMemoryChunkStats& a, const DxvkMemoryChunkStats& b) { + return a.cookie < b.cookie; + }); } diff --git a/src/dxvk/dxvk_memory.h b/src/dxvk/dxvk_memory.h index 157528de0..6e7049bb6 100644 --- a/src/dxvk/dxvk_memory.h +++ b/src/dxvk/dxvk_memory.h @@ -82,6 +82,8 @@ namespace dxvk { high_resolution_clock::time_point unusedTime = { }; /// Unordered list of resources suballocated from this chunk. DxvkResourceAllocation* allocationList = nullptr; + /// Chunk cookie + uint32_t chunkCookie = 0u; void addAllocation(DxvkResourceAllocation* allocation); void removeAllocation(DxvkResourceAllocation* allocation); @@ -109,6 +111,8 @@ namespace dxvk { VkDeviceSize nextChunkSize = MinChunkSize; /// Maximum chunk size for the memory pool. Hard limit. VkDeviceSize maxChunkSize = MaxChunkSize; + /// Next chunk cookie, used to order chunks in statistics + uint32_t nextChunkCookie = 0u; force_inline int64_t alloc(uint64_t size, uint64_t align) { if (size <= DxvkPoolAllocator::MaxSize) @@ -198,6 +202,8 @@ namespace dxvk { bool mapped = false; /// Whether this chunk is active bool active = false; + /// Chunk cookie + uint32_t cookie = 0u; };