Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp
9903 views
1
// Copyright (c) 2017-2025 The Khronos Group Inc.
2
//
3
// SPDX-License-Identifier: Apache-2.0
4
5
#pragma once
6
7
#ifdef XR_USE_GRAPHICS_API_VULKAN
8
9
#include <vulkan/vulkan_core.h>
10
#include <stdexcept>
11
12
/// Utility class for assigning debug names to Vulkan objects we create.
13
class VulkanDebugObjectNamer {
14
public:
15
/// Construct without initializing
16
VulkanDebugObjectNamer() = default;
17
18
/// Construct and initialize
19
VulkanDebugObjectNamer(VkInstance instance, VkDevice device) : m_vkDevice{device} {
20
vkSetDebugUtilsObjectNameEXT =
21
(PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT");
22
}
23
/// Copy constructor
24
VulkanDebugObjectNamer(const VulkanDebugObjectNamer&) = default;
25
/// Copy assignment operator
26
VulkanDebugObjectNamer& operator=(const VulkanDebugObjectNamer&) = default;
27
28
/// Destructor
29
~VulkanDebugObjectNamer() { Reset(); }
30
31
/// (Re-) Initialize the namer: takes a valid `VkInstance` and `VkDevice`
32
void Init(VkInstance instance, VkDevice device) {
33
Reset();
34
*this = VulkanDebugObjectNamer(instance, device);
35
}
36
37
/// The main operation of the namer: actually set an object name.
38
///
39
/// If the namer is not initialized, this exits silently.
40
VkResult SetName(VkObjectType objectType, uint64_t objectHandle, const char* pObjectName) const {
41
if (m_vkDevice == nullptr) {
42
return VK_SUCCESS;
43
}
44
if (vkSetDebugUtilsObjectNameEXT != nullptr) {
45
VkDebugUtilsObjectNameInfoEXT nameInfo{VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, nullptr, objectType,
46
objectHandle, pObjectName};
47
return vkSetDebugUtilsObjectNameEXT(m_vkDevice, &nameInfo);
48
}
49
return VK_SUCCESS;
50
}
51
52
/// De-initialize the namer, forgetting the device and the function pointer loaded from the instance.
53
void Reset() {
54
vkSetDebugUtilsObjectNameEXT = nullptr;
55
m_vkDevice = VK_NULL_HANDLE;
56
}
57
58
private:
59
VkDevice m_vkDevice{VK_NULL_HANDLE};
60
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT{nullptr};
61
};
62
63
#endif
64
65