1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-01 08:52:11 +01:00

[dxvk] Set debug names for memory allocations

Makes it easier to work out what is allocated where.
This commit is contained in:
Philip Rebohle 2025-01-08 17:30:17 +01:00 committed by Philip Rebohle
parent 3339b165cd
commit d2d46be8da
2 changed files with 52 additions and 6 deletions

View File

@ -1217,11 +1217,55 @@ namespace dxvk {
} }
} }
result.cookie = ++m_nextCookie;
if (unlikely(m_device->isDebugEnabled()))
assignMemoryDebugName(result, type);
type.stats.memoryAllocated += size; type.stats.memoryAllocated += size;
return result; 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( bool DxvkMemoryAllocator::allocateChunkInPool(
DxvkMemoryType& type, DxvkMemoryType& type,
DxvkMemoryPool& pool, DxvkMemoryPool& pool,
@ -1255,7 +1299,6 @@ namespace dxvk {
pool.chunks.resize(std::max<size_t>(pool.chunks.size(), chunkIndex + 1u)); pool.chunks.resize(std::max<size_t>(pool.chunks.size(), chunkIndex + 1u));
pool.chunks[chunkIndex].memory = chunk; pool.chunks[chunkIndex].memory = chunk;
pool.chunks[chunkIndex].unusedTime = high_resolution_clock::time_point(); pool.chunks[chunkIndex].unusedTime = high_resolution_clock::time_point();
pool.chunks[chunkIndex].chunkCookie = ++pool.nextChunkCookie;
pool.chunks[chunkIndex].canMove = true; pool.chunks[chunkIndex].canMove = true;
return true; return true;
} }
@ -1687,7 +1730,7 @@ namespace dxvk {
chunkStats.pageCount = pool.pageAllocator.pageCount(i); chunkStats.pageCount = pool.pageAllocator.pageCount(i);
chunkStats.mapped = &pool == &type.mappedPool; chunkStats.mapped = &pool == &type.mappedPool;
chunkStats.active = pool.pageAllocator.chunkIsAvailable(i); 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; size_t maskCount = (chunkStats.pageCount + 31u) / 32u;
stats.pageMasks.resize(chunkStats.pageMaskOffset + maskCount); stats.pageMasks.resize(chunkStats.pageMaskOffset + maskCount);

View File

@ -67,6 +67,7 @@ namespace dxvk {
VkDeviceSize size = 0u; VkDeviceSize size = 0u;
void* mapPtr = nullptr; void* mapPtr = nullptr;
VkDeviceAddress gpuVa = 0u; VkDeviceAddress gpuVa = 0u;
uint64_t cookie = 0u;
}; };
@ -83,8 +84,6 @@ namespace dxvk {
high_resolution_clock::time_point unusedTime = { }; high_resolution_clock::time_point unusedTime = { };
/// Unordered list of resources suballocated from this chunk. /// Unordered list of resources suballocated from this chunk.
DxvkResourceAllocation* allocationList = nullptr; DxvkResourceAllocation* allocationList = nullptr;
/// Chunk cookie
uint32_t chunkCookie = 0u;
/// Whether defragmentation can be performed on this chunk. /// Whether defragmentation can be performed on this chunk.
/// Only relevant for chunks in non-mappable device memory. /// Only relevant for chunks in non-mappable device memory.
VkBool32 canMove = true; VkBool32 canMove = true;
@ -115,8 +114,6 @@ namespace dxvk {
VkDeviceSize nextChunkSize = MinChunkSize; VkDeviceSize nextChunkSize = MinChunkSize;
/// Maximum chunk size for the memory pool. Hard limit. /// Maximum chunk size for the memory pool. Hard limit.
VkDeviceSize maxChunkSize = MaxChunkSize; VkDeviceSize maxChunkSize = MaxChunkSize;
/// Next chunk cookie, used to order chunks in statistics
uint32_t nextChunkCookie = 0u;
/// Next chunk to relocate for defragmentation /// Next chunk to relocate for defragmentation
uint32_t nextDefragChunk = ~0u; uint32_t nextDefragChunk = ~0u;
@ -1322,6 +1319,8 @@ namespace dxvk {
DxvkResourceAllocationPool m_allocationPool; DxvkResourceAllocationPool m_allocationPool;
uint64_t m_nextCookie = 0u;
alignas(CACHE_LINE_SIZE) alignas(CACHE_LINE_SIZE)
high_resolution_clock::time_point m_taskDeadline = { }; high_resolution_clock::time_point m_taskDeadline = { };
std::array<DxvkMemoryStats, VK_MAX_MEMORY_HEAPS> m_adapterHeapStats = { }; std::array<DxvkMemoryStats, VK_MAX_MEMORY_HEAPS> m_adapterHeapStats = { };
@ -1338,6 +1337,10 @@ namespace dxvk {
VkDeviceSize size, VkDeviceSize size,
const void* next); const void* next);
void assignMemoryDebugName(
const DxvkDeviceMemory& memory,
const DxvkMemoryType& type);
bool allocateChunkInPool( bool allocateChunkInPool(
DxvkMemoryType& type, DxvkMemoryType& type,
DxvkMemoryPool& pool, DxvkMemoryPool& pool,