Skip to content

Commit 225d157

Browse files
committed
Add requested changes to SetDebugUtilsObjectName
1 parent a2f0a42 commit 225d157

2 files changed

Lines changed: 3 additions & 17 deletions

File tree

src/Tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern bool VK_KHR_maintenance5_enabled;
4242
extern PFN_vkGetBufferDeviceAddressKHR g_vkGetBufferDeviceAddressKHR;
4343
void BeginSingleTimeCommands();
4444
void EndSingleTimeCommands();
45-
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, std::string);
45+
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const std::string&);
4646

4747
#ifndef VMA_DEBUG_MARGIN
4848
#define VMA_DEBUG_MARGIN 0

src/VulkanSample.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,15 @@ struct CommandLineParameters
262262
}
263263
} g_CommandLineParameters;
264264

265-
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, std::string name)
265+
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const std::string &name)
266266
{
267-
TEST(!name.empty());
268-
269-
// We must make sure the std::string we pass as name is still valid memory until the program ends.
270-
// Since Vulkan is a C-Style API, it only accepts const char* as pObjectName parameter.
271-
// Naming objects with unformatted names like "g_hTemporaryCommandBuffer" is no problem because
272-
// this string ends up in the read-only data section of the program. However, if we for example want to
273-
// name every item in a dynamic array of items (swapchain images for example), we can only use a std::string,
274-
// and we must make sure the object lifetime of that string does not end before it's read as pObjectName.
275-
// Therefore, we store the strings as a static unordered_set here just to be sure.
276-
// Do not use a std::vector because it would continue to grow, eventually running out of memory.
277-
static std::unordered_set<std::string> debug_names;
278-
auto result = debug_names.insert(name);
279-
const char* pObjectName = result.first->c_str();
280-
281267
if (vkSetDebugUtilsObjectNameEXT_Func == nullptr)
282268
return;
283269

284270
VkDebugUtilsObjectNameInfoEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT };
285271
info.objectType = type;
286272
info.objectHandle = handle;
287-
info.pObjectName = pObjectName;
273+
info.pObjectName = name.c_str();
288274
ERR_GUARD_VULKAN( vkSetDebugUtilsObjectNameEXT_Func(g_hDevice, &info) );
289275
}
290276

0 commit comments

Comments
 (0)