From d9088dd2a9d9ee6b96376ed575b0de7bb7ddf610 Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 31 Aug 2022 19:45:33 +0200 Subject: [PATCH] Add helpers to mark object names automatically. Can be trivially extended as required. --- gfx/common/vulkan_common.c | 34 ++++++++++++++++++++++++++++++++++ gfx/common/vulkan_common.h | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 3687cb8e18..a9a43ccdef 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -358,6 +358,40 @@ static unsigned vulkan_num_miplevels(unsigned width, unsigned height) return levels; } +static void vulkan_debug_mark_object(VkDevice device, + VkObjectType object_type, uint64_t object_handle, const char *name, unsigned count) +{ + if (vkSetDebugUtilsObjectNameEXT) + { + char merged_name[1024]; + snprintf(merged_name, sizeof(merged_name), "%s (%u)", name, count); + + VkDebugUtilsObjectNameInfoEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT }; + info.objectType = object_type; + info.objectHandle = object_handle; + info.pObjectName = merged_name; + vkSetDebugUtilsObjectNameEXT(device, &info); + } +} + +void vulkan_debug_mark_buffer(VkDevice device, VkBuffer buffer) +{ + static unsigned object_count; + vulkan_debug_mark_object(device, VK_OBJECT_TYPE_BUFFER, (uint64_t)buffer, "marked buffer", ++object_count); +} + +void vulkan_debug_mark_image(VkDevice device, VkImage image) +{ + static unsigned object_count; + vulkan_debug_mark_object(device, VK_OBJECT_TYPE_IMAGE, (uint64_t)image, "marked image", ++object_count); +} + +void vulkan_debug_mark_memory(VkDevice device, VkDeviceMemory memory) +{ + static unsigned object_count; + vulkan_debug_mark_object(device, VK_OBJECT_TYPE_DEVICE_MEMORY, (uint64_t)memory, "marked memory", ++object_count); +} + struct vk_texture vulkan_create_texture(vk_t *vk, struct vk_texture *old, unsigned width, unsigned height, diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index ca4034d07f..d85263eff4 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -783,6 +783,10 @@ void vulkan_set_uniform_buffer( VkDeviceSize offset, VkDeviceSize range); +void vulkan_debug_mark_buffer(VkDevice device, VkBuffer buffer); +void vulkan_debug_mark_image(VkDevice device, VkImage image); +void vulkan_debug_mark_memory(VkDevice device, VkDeviceMemory memory); + RETRO_END_DECLS #endif