mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
synced 2024-11-05 04:10:06 +00:00
Improve SetDebugUtilsObjectName
This commit is contained in:
parent
2547e8e940
commit
b51e05e28b
@ -42,7 +42,7 @@ extern bool VK_KHR_maintenance5_enabled;
|
|||||||
extern PFN_vkGetBufferDeviceAddressKHR g_vkGetBufferDeviceAddressKHR;
|
extern PFN_vkGetBufferDeviceAddressKHR g_vkGetBufferDeviceAddressKHR;
|
||||||
void BeginSingleTimeCommands();
|
void BeginSingleTimeCommands();
|
||||||
void EndSingleTimeCommands();
|
void EndSingleTimeCommands();
|
||||||
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const char* name);
|
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, std::string);
|
||||||
|
|
||||||
#ifndef VMA_DEBUG_MARGIN
|
#ifndef VMA_DEBUG_MARGIN
|
||||||
#define VMA_DEBUG_MARGIN 0
|
#define VMA_DEBUG_MARGIN 0
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <Shlwapi.h>
|
#include <Shlwapi.h>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#pragma comment(lib, "shlwapi.lib")
|
#pragma comment(lib, "shlwapi.lib")
|
||||||
|
|
||||||
@ -261,16 +262,30 @@ struct CommandLineParameters
|
|||||||
}
|
}
|
||||||
} g_CommandLineParameters;
|
} g_CommandLineParameters;
|
||||||
|
|
||||||
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, const char* name)
|
void SetDebugUtilsObjectName(VkObjectType type, uint64_t handle, std::string name)
|
||||||
{
|
{
|
||||||
if(vkSetDebugUtilsObjectNameEXT_Func == nullptr)
|
TEST(!name.empty());
|
||||||
|
|
||||||
|
// We must make sure the std::string we pass as name is still valid memory until the program ends.
|
||||||
|
// Since Vulkan is a C-Style API, it only accepts const char* as pObjectName parameter.
|
||||||
|
// Naming objects with unformatted names like "g_hTemporaryCommandBuffer" is no problem because
|
||||||
|
// this string ends up in the read-only data section of the program. However, if we for example want to
|
||||||
|
// name every item in a dynamic array of items (swapchain images for example), we can only use a std::string,
|
||||||
|
// and we must make sure the object lifetime of that string does not end before it's read as pObjectName.
|
||||||
|
// Therefore, we store the strings as a static unordered_set here just to be sure.
|
||||||
|
// Do not use a std::vector because it would continue to grow, eventually running out of memory.
|
||||||
|
static std::unordered_set<std::string> debug_names;
|
||||||
|
auto result = debug_names.insert(name);
|
||||||
|
const char* pObjectName = result.first->c_str();
|
||||||
|
|
||||||
|
if (vkSetDebugUtilsObjectNameEXT_Func == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
VkDebugUtilsObjectNameInfoEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT };
|
VkDebugUtilsObjectNameInfoEXT info = { VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT };
|
||||||
info.objectType = type;
|
info.objectType = type;
|
||||||
info.objectHandle = handle;
|
info.objectHandle = handle;
|
||||||
info.pObjectName = name;
|
info.pObjectName = pObjectName;
|
||||||
vkSetDebugUtilsObjectNameEXT_Func(g_hDevice, &info);
|
ERR_GUARD_VULKAN( vkSetDebugUtilsObjectNameEXT_Func(g_hDevice, &info) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginSingleTimeCommands()
|
void BeginSingleTimeCommands()
|
||||||
|
Loading…
Reference in New Issue
Block a user