diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-11 09:13:16 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-11 09:13:16 +0200 |
commit | d756169881164a8234140e4f30fadf33aaf30e01 (patch) | |
tree | de4b7a945fae905b3669a1dbb49fccedfe2cfdef /thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp | |
parent | ef155c1aeb216fa5a732913b6f2dc321e4b512dc (diff) | |
download | redot-engine-d756169881164a8234140e4f30fadf33aaf30e01.tar.gz |
openxr: Sync with upstream 1.0.28
Diffstat (limited to 'thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp')
-rw-r--r-- | thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp b/thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp new file mode 100644 index 0000000000..451219d20f --- /dev/null +++ b/thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp @@ -0,0 +1,63 @@ +// Copyright (c) 2017-2023, The Khronos Group Inc. +// +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#ifdef XR_USE_GRAPHICS_API_VULKAN + +#include <vulkan/vulkan_core.h> +#include <stdexcept> + +/// Utility class for assigning debug names to Vulkan objects we create. +class VulkanDebugObjectNamer { + public: + /// Construct without initializing + VulkanDebugObjectNamer() = default; + + /// Construct and initialize + VulkanDebugObjectNamer(VkInstance instance, VkDevice device) : m_vkDevice{device} { + vkSetDebugUtilsObjectNameEXT = + (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"); + } + /// Copy constructor + VulkanDebugObjectNamer(const VulkanDebugObjectNamer&) = default; + /// Copy assignment operator + VulkanDebugObjectNamer& operator=(const VulkanDebugObjectNamer&) = default; + + /// Destructor + ~VulkanDebugObjectNamer() { Reset(); } + + /// (Re-) Initialize the namer: takes a valid `VkInstance` and `VkDevice` + void Init(VkInstance instance, VkDevice device) { + Reset(); + *this = VulkanDebugObjectNamer(instance, device); + } + + /// The main operation of the namer: actually set an object name. + /// + /// If the namer is not initialized, this exits silently. + VkResult SetName(VkObjectType objectType, uint64_t objectHandle, const char* pObjectName) const { + if (m_vkDevice == nullptr) { + return VK_SUCCESS; + } + if (vkSetDebugUtilsObjectNameEXT != nullptr) { + VkDebugUtilsObjectNameInfoEXT nameInfo{VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, nullptr, objectType, + objectHandle, pObjectName}; + return vkSetDebugUtilsObjectNameEXT(m_vkDevice, &nameInfo); + } + return VK_SUCCESS; + } + + /// De-initialize the namer, forgetting the device and the function pointer loaded from the instance. + void Reset() { + vkSetDebugUtilsObjectNameEXT = nullptr; + m_vkDevice = VK_NULL_HANDLE; + } + + private: + VkDevice m_vkDevice{VK_NULL_HANDLE}; + PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT{nullptr}; +}; + +#endif |