From 8192f3092aa2db01855563601e5ab28c80470694 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 6 Nov 2024 12:25:56 +0100 Subject: [PATCH] [dxvk] Add debug name support to DxvkBuffer --- src/dxvk/dxvk_buffer.cpp | 7 +++++++ src/dxvk/dxvk_buffer.h | 7 +++++++ src/dxvk/dxvk_memory.cpp | 12 +++++++++++- src/dxvk/dxvk_memory.h | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_buffer.cpp b/src/dxvk/dxvk_buffer.cpp index 1f71da961..3b2cbbbc8 100644 --- a/src/dxvk/dxvk_buffer.cpp +++ b/src/dxvk/dxvk_buffer.cpp @@ -17,6 +17,13 @@ namespace dxvk { m_shaderStages (util::shaderStages(createInfo.stages)), m_sharingMode (device->getSharingMode()), m_info (createInfo) { + if (device->isDebugEnabled()) { + m_debugName = str::format(createInfo.debugName ? createInfo.debugName : "Buffer", " (", cookie(), ")"); + m_info.debugName = m_debugName.data(); + } else { + m_info.debugName = nullptr; + } + m_allocator->registerResource(this); // Create and assign actual buffer resource diff --git a/src/dxvk/dxvk_buffer.h b/src/dxvk/dxvk_buffer.h index c287b89cc..cd8e196ae 100644 --- a/src/dxvk/dxvk_buffer.h +++ b/src/dxvk/dxvk_buffer.h @@ -35,6 +35,10 @@ namespace dxvk { /// Buffer create flags VkBufferCreateFlags flags = 0; + + /// Buffer debug name. Setting this will result + /// in dedicated buffers being created. + const char* debugName = nullptr; }; @@ -315,6 +319,7 @@ namespace dxvk { DxvkAllocationInfo allocationInfo = { }; allocationInfo.resourceCookie = cookie(); allocationInfo.properties = m_properties; + allocationInfo.debugName = m_info.debugName; VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; info.flags = m_info.flags; @@ -429,6 +434,8 @@ namespace dxvk { std::unordered_map m_views; + std::string m_debugName; + }; diff --git a/src/dxvk/dxvk_memory.cpp b/src/dxvk/dxvk_memory.cpp index 1cc27645e..be6c1c709 100644 --- a/src/dxvk/dxvk_memory.cpp +++ b/src/dxvk/dxvk_memory.cpp @@ -742,7 +742,7 @@ namespace dxvk { DxvkLocalAllocationCache* allocationCache) { Rc allocation; - if (likely(!createInfo.flags)) { + if (likely(!createInfo.flags && !allocationInfo.debugName)) { VkMemoryRequirements memoryRequirements = { }; memoryRequirements.size = createInfo.size; memoryRequirements.alignment = GlobalBufferAlignment; @@ -886,6 +886,16 @@ namespace dxvk { if (createInfo.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) allocation->m_bufferAddress = getBufferDeviceAddress(buffer); + // Assign debug name to the buffer + if (allocationInfo.debugName && m_device->isDebugEnabled()) { + VkDebugUtilsObjectNameInfoEXT name = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT }; + name.objectType = VK_OBJECT_TYPE_BUFFER; + name.objectHandle = reinterpret_cast(buffer); + name.pObjectName = allocationInfo.debugName; + + vk->vkSetDebugUtilsObjectNameEXT(vk->device(), &name); + } + return allocation; } diff --git a/src/dxvk/dxvk_memory.h b/src/dxvk/dxvk_memory.h index 01cf5ecb1..5ef7c7584 100644 --- a/src/dxvk/dxvk_memory.h +++ b/src/dxvk/dxvk_memory.h @@ -979,6 +979,8 @@ namespace dxvk { VkMemoryPropertyFlags properties = 0u; /// Allocation mode flags DxvkAllocationModes mode = 0u; + /// Resource debug name + const char* debugName = nullptr; };