From f58fa53a1f18202c1f4de8a98a8180a65d252131 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 6 Nov 2024 11:06:12 +0100 Subject: [PATCH] [dxvk] Add debug regions to command buffers --- src/dxvk/dxvk_cmdlist.cpp | 29 +++++++++++++++++++++++++---- src/dxvk/dxvk_cmdlist.h | 4 +++- src/vulkan/vulkan_util.h | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/dxvk/dxvk_cmdlist.cpp b/src/dxvk/dxvk_cmdlist.cpp index c1edfef0c..234397aa8 100644 --- a/src/dxvk/dxvk_cmdlist.cpp +++ b/src/dxvk/dxvk_cmdlist.cpp @@ -115,7 +115,7 @@ namespace dxvk { } - VkCommandBuffer DxvkCommandPool::getCommandBuffer() { + VkCommandBuffer DxvkCommandPool::getCommandBuffer(DxvkCmdBuffer type) { auto vk = m_device->vkd(); if (m_next == m_commandBuffers.size()) { @@ -143,6 +143,24 @@ namespace dxvk { if (vk->vkBeginCommandBuffer(commandBuffer, &info)) throw DxvkError("DxvkCommandPool: Failed to begin command buffer"); + if (m_device->isDebugEnabled()) { + auto vki = m_device->vki(); + + VkDebugUtilsLabelEXT label = { }; + + switch (type) { + case DxvkCmdBuffer::ExecBuffer: label = vk::makeLabel(0x60b0ff, "Graphics commands"); break; + case DxvkCmdBuffer::InitBuffer: label = vk::makeLabel(0xb0ff60, "Init commands"); break; + case DxvkCmdBuffer::InitBarriers: label = vk::makeLabel(0xd0ffa0, "Init barriers"); break; + case DxvkCmdBuffer::SdmaBuffer: label = vk::makeLabel(0xff60b0, "Upload commands"); break; + case DxvkCmdBuffer::SdmaBarriers: label = vk::makeLabel(0xffa0d0, "Upload barriers"); break; + default: ; + } + + if (label.pLabelName) + vki->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &label); + } + return commandBuffer; } @@ -162,7 +180,7 @@ namespace dxvk { DxvkCommandList::DxvkCommandList(DxvkDevice* device) : m_device (device), m_vkd (device->vkd()), - m_vki (device->instance()->vki()) { + m_vki (device->vki()) { const auto& graphicsQueue = m_device->queues().graphics; const auto& transferQueue = m_device->queues().transfer; @@ -409,6 +427,9 @@ namespace dxvk { void DxvkCommandList::endCommandBuffer(VkCommandBuffer cmdBuffer) { auto vk = m_device->vkd(); + if (m_device->isDebugEnabled()) + m_vki->vkCmdEndDebugUtilsLabelEXT(cmdBuffer); + if (vk->vkEndCommandBuffer(cmdBuffer)) throw DxvkError("DxvkCommandList: Failed to end command buffer"); } @@ -416,8 +437,8 @@ namespace dxvk { VkCommandBuffer DxvkCommandList::allocateCommandBuffer(DxvkCmdBuffer type) { return type == DxvkCmdBuffer::SdmaBuffer || type == DxvkCmdBuffer::SdmaBarriers - ? m_transferPool->getCommandBuffer() - : m_graphicsPool->getCommandBuffer(); + ? m_transferPool->getCommandBuffer(type) + : m_graphicsPool->getCommandBuffer(type); } } diff --git a/src/dxvk/dxvk_cmdlist.h b/src/dxvk/dxvk_cmdlist.h index 96f826813..b7f6a2ff5 100644 --- a/src/dxvk/dxvk_cmdlist.h +++ b/src/dxvk/dxvk_cmdlist.h @@ -172,9 +172,11 @@ namespace dxvk { /** * \brief Retrieves or allocates a command buffer + * + * \param [in] type Command buffer type * \returns New command buffer in begun state */ - VkCommandBuffer getCommandBuffer(); + VkCommandBuffer getCommandBuffer(DxvkCmdBuffer type); /** * \brief Resets command pool and all command buffers diff --git a/src/vulkan/vulkan_util.h b/src/vulkan/vulkan_util.h index 2dd1de987..b324e3414 100644 --- a/src/vulkan/vulkan_util.h +++ b/src/vulkan/vulkan_util.h @@ -211,6 +211,22 @@ namespace dxvk::vk { } } + /** + * \brief Makes debug label + * + * \param [in] color Color, as BGR with implied opaque alpha + * \param [in] text Label text + */ + inline VkDebugUtilsLabelEXT makeLabel(uint32_t color, const char* text) { + VkDebugUtilsLabelEXT label = { VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT }; + label.color[0] = ((color >> 16u) & 0xffu) / 255.0f; + label.color[1] = ((color >> 8u) & 0xffu) / 255.0f; + label.color[2] = ((color >> 0u) & 0xffu) / 255.0f; + label.color[3] = 1.0f; + label.pLabelName = text; + return label; + } + }