Path: blob/master/thirdparty/openxr/src/common/vulkan_debug_object_namer.hpp
9903 views
// Copyright (c) 2017-2025 The Khronos Group Inc.1//2// SPDX-License-Identifier: Apache-2.034#pragma once56#ifdef XR_USE_GRAPHICS_API_VULKAN78#include <vulkan/vulkan_core.h>9#include <stdexcept>1011/// Utility class for assigning debug names to Vulkan objects we create.12class VulkanDebugObjectNamer {13public:14/// Construct without initializing15VulkanDebugObjectNamer() = default;1617/// Construct and initialize18VulkanDebugObjectNamer(VkInstance instance, VkDevice device) : m_vkDevice{device} {19vkSetDebugUtilsObjectNameEXT =20(PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT");21}22/// Copy constructor23VulkanDebugObjectNamer(const VulkanDebugObjectNamer&) = default;24/// Copy assignment operator25VulkanDebugObjectNamer& operator=(const VulkanDebugObjectNamer&) = default;2627/// Destructor28~VulkanDebugObjectNamer() { Reset(); }2930/// (Re-) Initialize the namer: takes a valid `VkInstance` and `VkDevice`31void Init(VkInstance instance, VkDevice device) {32Reset();33*this = VulkanDebugObjectNamer(instance, device);34}3536/// The main operation of the namer: actually set an object name.37///38/// If the namer is not initialized, this exits silently.39VkResult SetName(VkObjectType objectType, uint64_t objectHandle, const char* pObjectName) const {40if (m_vkDevice == nullptr) {41return VK_SUCCESS;42}43if (vkSetDebugUtilsObjectNameEXT != nullptr) {44VkDebugUtilsObjectNameInfoEXT nameInfo{VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, nullptr, objectType,45objectHandle, pObjectName};46return vkSetDebugUtilsObjectNameEXT(m_vkDevice, &nameInfo);47}48return VK_SUCCESS;49}5051/// De-initialize the namer, forgetting the device and the function pointer loaded from the instance.52void Reset() {53vkSetDebugUtilsObjectNameEXT = nullptr;54m_vkDevice = VK_NULL_HANDLE;55}5657private:58VkDevice m_vkDevice{VK_NULL_HANDLE};59PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT{nullptr};60};6162#endif636465