From 5be3a8aef4cd8712147ab68914e4844dd704a2df Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 12 Jun 2025 14:13:17 +0200 Subject: [PATCH] Utility to name vulkan objects --- server/utils/wivrn_vk_bundle.cpp | 11 +++++++++ server/utils/wivrn_vk_bundle.h | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/server/utils/wivrn_vk_bundle.cpp b/server/utils/wivrn_vk_bundle.cpp index c91330c1..5a01c2a9 100644 --- a/server/utils/wivrn_vk_bundle.cpp +++ b/server/utils/wivrn_vk_bundle.cpp @@ -224,3 +224,14 @@ uint32_t wivrn::wivrn_vk_bundle::get_memory_type(uint32_t type_bits, vk::MemoryP } throw std::runtime_error("Failed to get memory type"); } + +void wivrn::wivrn_vk_bundle::name(vk::ObjectType type, uint64_t handle, const char * value) +{ + if (not vk.has_EXT_debug_utils) + return; + device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{ + .objectType = type, + .objectHandle = handle, + .pObjectName = value, + }); +} diff --git a/server/utils/wivrn_vk_bundle.h b/server/utils/wivrn_vk_bundle.h index 946485ea..6da274a9 100644 --- a/server/utils/wivrn_vk_bundle.h +++ b/server/utils/wivrn_vk_bundle.h @@ -22,6 +22,7 @@ #include "vk/vk_allocator.h" #include #include +#include #include #include @@ -53,6 +54,36 @@ struct raii_device : public vk::raii::Device } }; +namespace details +{ +template +struct vk_handle +{ + uint64_t operator()(const T & handle) + { + typename T::CType chandle = handle; + return uint64_t(chandle); + } +}; + +// vk::raii specialization +template +struct vk_handle> +{ + uint64_t operator()(const T & handle) + { + typename T::CType chandle = *handle; + return uint64_t(chandle); + } +}; +} // namespace details + +template +uint64_t vk_handle(const T & handle) +{ + return details::vk_handle{}(handle); +} + struct wivrn_vk_bundle { vk_bundle & vk; @@ -75,5 +106,14 @@ struct wivrn_vk_bundle wivrn_vk_bundle(vk_bundle & vk, std::span requested_instance_extensions, std::span requested_device_extensions); uint32_t get_memory_type(uint32_t type_bits, vk::MemoryPropertyFlags memory_props); + + template + void name(const T & handle, const char * value) + { + return name(T::objectType, vk_handle(handle), value); + } + +private: + void name(vk::ObjectType, uint64_t handle, const char * value); }; } // namespace wivrn