Skip to content

Commit

Permalink
Switched from VK_EXT_debug_marker to VK_EXT_debug_utils as the primar…
Browse files Browse the repository at this point in the history
…y backend for debug names and markers, added object types for debug_utils.
  • Loading branch information
apanteleev committed Nov 14, 2024
1 parent 0a8bdf1 commit d1d737f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/vulkan/vulkan-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ namespace nvrhi::vulkan
bool EXT_conservative_rasterization = false;
bool EXT_opacity_micromap = false;
bool NV_ray_tracing_invocation_reorder = false;
#if NVRHI_WITH_AFTERMATH
bool EXT_debug_utils = false;
#if NVRHI_WITH_AFTERMATH
bool NV_device_diagnostic_checkpoints = false;
bool NV_device_diagnostics_config= false;
#endif
Expand All @@ -194,7 +194,8 @@ namespace nvrhi::vulkan
#endif
vk::DescriptorSetLayout emptyDescriptorSetLayout;

void nameVKObject(const void* handle, vk::DebugReportObjectTypeEXT objtype, const char* name) const;
void nameVKObject(const void* handle, const vk::ObjectType objtype,
const vk::DebugReportObjectTypeEXT objtypeEXT, const char* name) const;
void error(const std::string& message) const;
void warning(const std::string& message) const;
};
Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/vulkan-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ namespace nvrhi::vulkan
vk::Result res = m_Context.device.createBuffer(&bufferInfo, m_Context.allocationCallbacks, &buffer->buffer);
CHECK_VK_FAIL(res);

m_Context.nameVKObject(VkBuffer(buffer->buffer), vk::DebugReportObjectTypeEXT::eBuffer, desc.debugName.c_str());
m_Context.nameVKObject(VkBuffer(buffer->buffer), vk::ObjectType::eBuffer, vk::DebugReportObjectTypeEXT::eBuffer, desc.debugName.c_str());

if (!desc.isVirtual)
{
res = m_Allocator.allocateBufferMemory(buffer, (usageFlags & vk::BufferUsageFlagBits::eShaderDeviceAddress) != vk::BufferUsageFlags(0));
CHECK_VK_FAIL(res)

m_Context.nameVKObject(buffer->memory, vk::DebugReportObjectTypeEXT::eDeviceMemory, desc.debugName.c_str());
m_Context.nameVKObject(buffer->memory, vk::ObjectType::eDeviceMemory, vk::DebugReportObjectTypeEXT::eDeviceMemory, desc.debugName.c_str());

if (desc.isVolatile)
{
Expand Down
44 changes: 23 additions & 21 deletions src/vulkan/vulkan-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ namespace nvrhi::vulkan

// maps Vulkan extension strings into the corresponding boolean flags in Device
const std::unordered_map<std::string, bool*> extensionStringMap = {
{ VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, &m_Context.extensions.KHR_synchronization2 },
{ VK_KHR_MAINTENANCE1_EXTENSION_NAME, &m_Context.extensions.KHR_maintenance1 },
{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, &m_Context.extensions.EXT_debug_report },
{ VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME, &m_Context.extensions.EXT_conservative_rasterization},
{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, &m_Context.extensions.EXT_debug_marker },
{ VK_EXT_DEBUG_REPORT_EXTENSION_NAME, &m_Context.extensions.EXT_debug_report },
{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, &m_Context.extensions.EXT_debug_utils },
{ VK_EXT_OPACITY_MICROMAP_EXTENSION_NAME, &m_Context.extensions.EXT_opacity_micromap },
{ VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, &m_Context.extensions.KHR_acceleration_structure },
{ VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME, &m_Context.extensions.buffer_device_address },
{ VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME, &m_Context.extensions.KHR_fragment_shading_rate },
{ VK_KHR_MAINTENANCE1_EXTENSION_NAME, &m_Context.extensions.KHR_maintenance1 },
{ VK_KHR_RAY_QUERY_EXTENSION_NAME,&m_Context.extensions.KHR_ray_query },
{ VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, &m_Context.extensions.KHR_ray_tracing_pipeline },
{ VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME, &m_Context.extensions.KHR_synchronization2 },
{ VK_NV_MESH_SHADER_EXTENSION_NAME, &m_Context.extensions.NV_mesh_shader },
{ VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME, &m_Context.extensions.EXT_conservative_rasterization},
{ VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME, &m_Context.extensions.KHR_fragment_shading_rate },
{ VK_EXT_OPACITY_MICROMAP_EXTENSION_NAME, &m_Context.extensions.EXT_opacity_micromap },
{ VK_NV_RAY_TRACING_INVOCATION_REORDER_EXTENSION_NAME, &m_Context.extensions.NV_ray_tracing_invocation_reorder },
#if NVRHI_WITH_AFTERMATH
{ VK_EXT_DEBUG_UTILS_EXTENSION_NAME, &m_Context.extensions.EXT_debug_utils },
{ VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME, &m_Context.extensions.NV_device_diagnostic_checkpoints },
{ VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, &m_Context.extensions.NV_device_diagnostics_config }
#endif
Expand Down Expand Up @@ -576,7 +576,7 @@ namespace nvrhi::vulkan

if (!d.debugName.empty())
{
m_Context.nameVKObject(heap->memory, vk::DebugReportObjectTypeEXT::eDeviceMemory, d.debugName.c_str());
m_Context.nameVKObject(heap->memory, vk::ObjectType::eDeviceMemory, vk::DebugReportObjectTypeEXT::eDeviceMemory, d.debugName.c_str());
}

return HeapHandle::Create(heap);
Expand All @@ -591,27 +591,29 @@ namespace nvrhi::vulkan
}
}

void VulkanContext::nameVKObject(const void* handle, const vk::DebugReportObjectTypeEXT objtype, const char* name) const
void VulkanContext::nameVKObject(const void* handle, const vk::ObjectType objtype,
const vk::DebugReportObjectTypeEXT objtypeEXT, const char* name) const
{
if (extensions.EXT_debug_marker && name && *name && handle)
{
auto info = vk::DebugMarkerObjectNameInfoEXT()
.setObjectType(objtype)
.setObject(reinterpret_cast<uint64_t>(handle))
.setPObjectName(name);
if (!(name && *name && handle))
return;

(void)device.debugMarkerSetObjectNameEXT(&info);
}
#if NVRHI_WITH_AFTERMATH
if (extensions.EXT_debug_utils && name && *name)
if (extensions.EXT_debug_utils)
{
auto info = vk::DebugUtilsObjectNameInfoEXT()
.setObjectType(vk::ObjectType::eUnknown)
.setObjectType(objtype)
.setObjectHandle(reinterpret_cast<uint64_t>(handle))
.setPObjectName(name);
device.setDebugUtilsObjectNameEXT(info);
}
#endif
else if (extensions.EXT_debug_marker)
{
auto info = vk::DebugMarkerObjectNameInfoEXT()
.setObjectType(objtypeEXT)
.setObject(reinterpret_cast<uint64_t>(handle))
.setPObjectName(name);

(void)device.debugMarkerSetObjectNameEXT(&info);
}
}

void VulkanContext::error(const std::string& message) const
Expand Down
20 changes: 18 additions & 2 deletions src/vulkan/vulkan-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,23 @@ namespace nvrhi::vulkan

void CommandList::beginMarker(const char* name)
{
if (m_Context.extensions.EXT_debug_marker)
if (m_Context.extensions.EXT_debug_utils)
{
assert(m_CurrentCmdBuf);

auto label = vk::DebugUtilsLabelEXT()
.setPLabelName(name);
m_CurrentCmdBuf->cmdBuf.beginDebugUtilsLabelEXT(&label);
}
else if (m_Context.extensions.EXT_debug_marker)
{
assert(m_CurrentCmdBuf);

auto markerInfo = vk::DebugMarkerMarkerInfoEXT()
.setPMarkerName(name);
m_CurrentCmdBuf->cmdBuf.debugMarkerBeginEXT(&markerInfo);
}

#if NVRHI_WITH_AFTERMATH
if (m_Device->isAftermathEnabled())
{
Expand All @@ -228,12 +237,19 @@ namespace nvrhi::vulkan

void CommandList::endMarker()
{
if (m_Context.extensions.EXT_debug_marker)
if (m_Context.extensions.EXT_debug_utils)
{
assert(m_CurrentCmdBuf);

m_CurrentCmdBuf->cmdBuf.endDebugUtilsLabelEXT();
}
else if (m_Context.extensions.EXT_debug_marker)
{
assert(m_CurrentCmdBuf);

m_CurrentCmdBuf->cmdBuf.debugMarkerEndEXT();
}

#if NVRHI_WITH_AFTERMATH
m_AftermathTracker.popEvent();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan-shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace nvrhi::vulkan
CHECK_VK_FAIL(res)

const std::string debugName = desc.debugName + ":" + desc.entryName;
m_Context.nameVKObject(VkShaderModule(shader->shaderModule), vk::DebugReportObjectTypeEXT::eShaderModule, debugName.c_str());
m_Context.nameVKObject(VkShaderModule(shader->shaderModule), vk::ObjectType::eShaderModule, vk::DebugReportObjectTypeEXT::eShaderModule, debugName.c_str());

return ShaderHandle::Create(shader);
}
Expand Down
6 changes: 3 additions & 3 deletions src/vulkan/vulkan-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ namespace nvrhi::vulkan
ASSERT_VK_OK(res);

const std::string debugName = std::string("ImageView for: ") + utils::DebugNameToString(desc.debugName);
m_Context.nameVKObject(VkImageView(view.view), vk::DebugReportObjectTypeEXT::eImageView, debugName.c_str());
m_Context.nameVKObject(VkImageView(view.view), vk::ObjectType::eImageView, vk::DebugReportObjectTypeEXT::eImageView, debugName.c_str());

return view;
}
Expand All @@ -336,7 +336,7 @@ namespace nvrhi::vulkan
ASSERT_VK_OK(res);
CHECK_VK_FAIL(res)

m_Context.nameVKObject(texture->image, vk::DebugReportObjectTypeEXT::eImage, desc.debugName.c_str());
m_Context.nameVKObject(texture->image, vk::ObjectType::eImage, vk::DebugReportObjectTypeEXT::eImage, desc.debugName.c_str());

if (!desc.isVirtual)
{
Expand All @@ -353,7 +353,7 @@ namespace nvrhi::vulkan
#endif
}

m_Context.nameVKObject(texture->memory, vk::DebugReportObjectTypeEXT::eDeviceMemory, desc.debugName.c_str());
m_Context.nameVKObject(texture->memory, vk::ObjectType::eDeviceMemory, vk::DebugReportObjectTypeEXT::eDeviceMemory, desc.debugName.c_str());
}

return TextureHandle::Create(texture);
Expand Down

0 comments on commit d1d737f

Please sign in to comment.