From d2d46be8dad119156435ba90f2c0e2254eeaa38d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 8 Jan 2025 17:30:17 +0100 Subject: [PATCH] [dxvk] Set debug names for memory allocations Makes it easier to work out what is allocated where. --- src/dxvk/dxvk_memory.cpp | 47 ++++++++++++++++++++++++++++++++++++++-- src/dxvk/dxvk_memory.h | 11 ++++++---- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 3e0e1e413..c58cfcd4e 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -1217,11 +1217,55 @@ namespace dxvk { } } + result.cookie = ++m_nextCookie; + + if (unlikely(m_device->isDebugEnabled())) + assignMemoryDebugName(result, type); + type.stats.memoryAllocated += size; return result; } + void DxvkMemoryAllocator::assignMemoryDebugName( + const DxvkDeviceMemory& memory, + const DxvkMemoryType& type) { + auto vk = m_device->vkd(); + + const char* memoryType = "Unspecified memory"; + + if (type.properties.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) { + if (type.properties.propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) + memoryType = "Cached system memory"; + else if (type.properties.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) + memoryType = "Mapped video memory"; + else + memoryType = "Write-combined system memory"; + } else if (type.properties.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { + memoryType = "Video memory"; + } + + std::string memoryName = str::format(memoryType, " (", memory.cookie, ")"); + + VkDebugUtilsObjectNameInfoEXT nameInfo = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT }; + nameInfo.objectType = VK_OBJECT_TYPE_DEVICE_MEMORY; + nameInfo.objectHandle = vk::getObjectHandle(memory.memory); + nameInfo.pObjectName = memoryName.c_str(); + + vk->vkSetDebugUtilsObjectNameEXT(vk->device(), &nameInfo); + + if (memory.buffer) { + std::string bufferName = str::format("Global buffer (", memory.cookie, ")"); + + nameInfo.objectType = VK_OBJECT_TYPE_BUFFER; + nameInfo.objectHandle = vk::getObjectHandle(memory.buffer); + nameInfo.pObjectName = bufferName.c_str(); + + vk->vkSetDebugUtilsObjectNameEXT(vk->device(), &nameInfo); + } + } + + bool DxvkMemoryAllocator::allocateChunkInPool( DxvkMemoryType& type, DxvkMemoryPool& pool, @@ -1255,7 +1299,6 @@ 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; pool.chunks[chunkIndex].canMove = true; return true; } @@ -1687,7 +1730,7 @@ 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; + chunkStats.cookie = pool.chunks[i].memory.cookie; size_t maskCount = (chunkStats.pageCount + 31u) / 32u; stats.pageMasks.resize(chunkStats.pageMaskOffset + maskCount); diff --git a/src/dxvk/dxvk_memory.h b/src/dxvk/dxvk_memory.h index 01cf5ecb1..bd7f685d1 100644 --- a/src/dxvk/dxvk_memory.h +++ b/src/dxvk/dxvk_memory.h @@ -67,6 +67,7 @@ namespace dxvk { VkDeviceSize size = 0u; void* mapPtr = nullptr; VkDeviceAddress gpuVa = 0u; + uint64_t cookie = 0u; }; @@ -83,8 +84,6 @@ 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; /// Whether defragmentation can be performed on this chunk. /// Only relevant for chunks in non-mappable device memory. VkBool32 canMove = true; @@ -115,8 +114,6 @@ 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; /// Next chunk to relocate for defragmentation uint32_t nextDefragChunk = ~0u; @@ -1322,6 +1319,8 @@ namespace dxvk { DxvkResourceAllocationPool m_allocationPool; + uint64_t m_nextCookie = 0u; + alignas(CACHE_LINE_SIZE) high_resolution_clock::time_point m_taskDeadline = { }; std::array m_adapterHeapStats = { }; @@ -1338,6 +1337,10 @@ namespace dxvk { VkDeviceSize size, const void* next); + void assignMemoryDebugName( + const DxvkDeviceMemory& memory, + const DxvkMemoryType& type); + bool allocateChunkInPool( DxvkMemoryType& type, DxvkMemoryPool& pool,