Skip to content

Commit 2f9c75c

Browse files
committed
Add support for debug labels and query if tool cares about it.
1 parent d44fdd9 commit 2f9c75c

File tree

4 files changed

+51
-21
lines changed

4 files changed

+51
-21
lines changed

vulkan/command_buffer.cpp

+38-21
Original file line numberDiff line numberDiff line change
@@ -3086,35 +3086,52 @@ void CommandBuffer::end()
30863086
device->request_staging_block_nolock(staging_block, 0);
30873087
}
30883088

3089-
void CommandBuffer::begin_region(const char *name, const float *color)
3089+
void CommandBuffer::insert_label(const char *name, const float *color)
30903090
{
3091-
if (device->ext.supports_debug_utils)
3092-
{
3093-
VkDebugUtilsLabelEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT };
3094-
if (color)
3095-
{
3096-
for (unsigned i = 0; i < 4; i++)
3097-
info.color[i] = color[i];
3098-
}
3099-
else
3100-
{
3101-
for (unsigned i = 0; i < 4; i++)
3102-
info.color[i] = 1.0f;
3103-
}
3091+
if (!device->ext.supports_debug_utils || !vkCmdInsertDebugUtilsLabelEXT)
3092+
return;
31043093

3105-
info.pLabelName = name;
3106-
if (vkCmdBeginDebugUtilsLabelEXT)
3107-
vkCmdBeginDebugUtilsLabelEXT(cmd, &info);
3094+
VkDebugUtilsLabelEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT };
3095+
if (color)
3096+
{
3097+
for (unsigned i = 0; i < 4; i++)
3098+
info.color[i] = color[i];
3099+
}
3100+
else
3101+
{
3102+
for (unsigned i = 0; i < 4; i++)
3103+
info.color[i] = 1.0f;
31083104
}
3105+
3106+
info.pLabelName = name;
3107+
vkCmdInsertDebugUtilsLabelEXT(cmd, &info);
31093108
}
31103109

3111-
void CommandBuffer::end_region()
3110+
void CommandBuffer::begin_region(const char *name, const float *color)
31123111
{
3113-
if (device->ext.supports_debug_utils)
3112+
if (!device->ext.supports_debug_utils || !vkCmdBeginDebugUtilsLabelEXT)
3113+
return;
3114+
3115+
VkDebugUtilsLabelEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT };
3116+
if (color)
3117+
{
3118+
for (unsigned i = 0; i < 4; i++)
3119+
info.color[i] = color[i];
3120+
}
3121+
else
31143122
{
3115-
if (vkCmdEndDebugUtilsLabelEXT)
3116-
vkCmdEndDebugUtilsLabelEXT(cmd);
3123+
for (unsigned i = 0; i < 4; i++)
3124+
info.color[i] = 1.0f;
31173125
}
3126+
3127+
info.pLabelName = name;
3128+
vkCmdBeginDebugUtilsLabelEXT(cmd, &info);
3129+
}
3130+
3131+
void CommandBuffer::end_region()
3132+
{
3133+
if (device->ext.supports_debug_utils && vkCmdEndDebugUtilsLabelEXT)
3134+
vkCmdEndDebugUtilsLabelEXT(cmd);
31183135
}
31193136

31203137
void CommandBuffer::enable_profiling()

vulkan/command_buffer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class CommandBuffer : public Util::IntrusivePtrEnabled<CommandBuffer, CommandBuf
301301
}
302302

303303
void begin_region(const char *name, const float *color = nullptr);
304+
void insert_label(const char *name, const float *color = nullptr);
304305
void end_region();
305306

306307
Device &get_device()

vulkan/device.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,12 @@ void Device::init_workarounds()
912912
LOGI("Detected non-profiling tracing tool, forcing host cached memory types for performance.\n");
913913
workarounds.force_host_cached = true;
914914
}
915+
916+
if (!debug_marker_sensitive && (t.purposes & VK_TOOL_PURPOSE_DEBUG_MARKERS_BIT_EXT) != 0)
917+
{
918+
LOGI("Detected tool which cares about debug markers.\n");
919+
debug_marker_sensitive = true;
920+
}
915921
}
916922
}
917923
}

vulkan/device.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ class Device
479479
return ext;
480480
}
481481

482+
bool consumes_debug_markers() const
483+
{
484+
return debug_marker_sensitive;
485+
}
486+
482487
bool swapchain_touched() const;
483488

484489
double convert_device_timestamp_delta(uint64_t start_ticks, uint64_t end_ticks) const;
@@ -544,6 +549,7 @@ class Device
544549
VkPhysicalDeviceProperties gpu_props;
545550

546551
DeviceFeatures ext;
552+
bool debug_marker_sensitive = false;
547553
void init_stock_samplers();
548554
void init_stock_sampler(StockSampler sampler, float max_aniso, float lod_bias);
549555
void init_timeline_semaphores();

0 commit comments

Comments
 (0)