From 098e1d3d996c7ef6b626bc5e01a9c498fb50a50a Mon Sep 17 00:00:00 2001 From: serenity4 Date: Sun, 18 Aug 2024 12:14:19 +0200 Subject: [PATCH] Add convenience function for setting debug names --- src/Vulkan.jl | 2 ++ src/debug.jl | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.jl | 11 ++++++++-- test/api.jl | 10 +++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/debug.jl diff --git a/src/Vulkan.jl b/src/Vulkan.jl index 3e6ef384..994865f8 100644 --- a/src/Vulkan.jl +++ b/src/Vulkan.jl @@ -66,6 +66,7 @@ elseif Sys.iswindows() end include("utils.jl") +include("debug.jl") include("driver.jl") include("validation.jl") include("instance.jl") @@ -119,6 +120,7 @@ export # Debugging default_debug_callback, + set_debug_name, # Pointer utilities function_pointer, diff --git a/src/debug.jl b/src/debug.jl new file mode 100644 index 00000000..fa2a9c68 --- /dev/null +++ b/src/debug.jl @@ -0,0 +1,61 @@ +function set_debug_name(handle::Handle, name) + device = device_or_nothing(handle) + isnothing(device) && error("No parent device found for $handle; you must provide the device explicitly as first argument") + set_debug_name(device::Device, handle, name) +end +set_debug_name(device::Device, handle::Handle, name::Symbol) = set_debug_name(device, handle, string(name)) +function set_debug_name(device::Device, handle::Handle, name::String) + object_type = ObjectType(handle) + address = UInt64(convert(Ptr{Cvoid}, handle)) + info = DebugUtilsObjectNameInfoEXT(object_type, address; object_name = name) + set_debug_utils_object_name_ext(device, info) +end + +ObjectType(::Handle) = OBJECT_TYPE_UNKNOWN +ObjectType(::Instance) = OBJECT_TYPE_INSTANCE +ObjectType(::PhysicalDevice) = OBJECT_TYPE_PHYSICAL_DEVICE +ObjectType(::Device) = OBJECT_TYPE_DEVICE +ObjectType(::Queue) = OBJECT_TYPE_QUEUE +ObjectType(::Semaphore) = OBJECT_TYPE_SEMAPHORE +ObjectType(::CommandBuffer) = OBJECT_TYPE_COMMAND_BUFFER +ObjectType(::Fence) = OBJECT_TYPE_FENCE +ObjectType(::DeviceMemory) = OBJECT_TYPE_DEVICE_MEMORY +ObjectType(::Buffer) = OBJECT_TYPE_BUFFER +ObjectType(::Image) = OBJECT_TYPE_IMAGE +ObjectType(::Event) = OBJECT_TYPE_EVENT +ObjectType(::QueryPool) = OBJECT_TYPE_QUERY_POOL +ObjectType(::BufferView) = OBJECT_TYPE_BUFFER_VIEW +ObjectType(::ImageView) = OBJECT_TYPE_IMAGE_VIEW +ObjectType(::ShaderModule) = OBJECT_TYPE_SHADER_MODULE +ObjectType(::PipelineCache) = OBJECT_TYPE_PIPELINE_CACHE +ObjectType(::PipelineLayout) = OBJECT_TYPE_PIPELINE_LAYOUT +ObjectType(::RenderPass) = OBJECT_TYPE_RENDER_PASS +ObjectType(::Pipeline) = OBJECT_TYPE_PIPELINE +ObjectType(::DescriptorSetLayout) = OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT +ObjectType(::Sampler) = OBJECT_TYPE_SAMPLER +ObjectType(::DescriptorPool) = OBJECT_TYPE_DESCRIPTOR_POOL +ObjectType(::DescriptorSet) = OBJECT_TYPE_DESCRIPTOR_SET +ObjectType(::Framebuffer) = OBJECT_TYPE_FRAMEBUFFER +ObjectType(::CommandPool) = OBJECT_TYPE_COMMAND_POOL +ObjectType(::SamplerYcbcrConversion) = OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION +ObjectType(::DescriptorUpdateTemplate) = OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE +ObjectType(::PrivateDataSlot) = OBJECT_TYPE_PRIVATE_DATA_SLOT +ObjectType(::SurfaceKHR) = OBJECT_TYPE_SURFACE_KHR +ObjectType(::SwapchainKHR) = OBJECT_TYPE_SWAPCHAIN_KHR +ObjectType(::DisplayKHR) = OBJECT_TYPE_DISPLAY_KHR +ObjectType(::DisplayModeKHR) = OBJECT_TYPE_DISPLAY_MODE_KHR +ObjectType(::DebugReportCallbackEXT) = OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT +ObjectType(::CuModuleNVX) = OBJECT_TYPE_CU_MODULE_NVX +ObjectType(::CuFunctionNVX) = OBJECT_TYPE_CU_FUNCTION_NVX +ObjectType(::DebugUtilsMessengerEXT) = OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT +ObjectType(::AccelerationStructureKHR) = OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR +ObjectType(::ValidationCacheEXT) = OBJECT_TYPE_VALIDATION_CACHE_EXT +ObjectType(::AccelerationStructureNV) = OBJECT_TYPE_ACCELERATION_STRUCTURE_NV +ObjectType(::PerformanceConfigurationINTEL) = OBJECT_TYPE_PERFORMANCE_CONFIGURATION_INTEL +ObjectType(::DeferredOperationKHR) = OBJECT_TYPE_DEFERRED_OPERATION_KHR +ObjectType(::IndirectCommandsLayoutNV) = OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV + +# These don't have wrappers defined yet. +# ObjectType(::) = OBJECT_TYPE_VIDEO_SESSION_KHR +# ObjectType(::) = OBJECT_TYPE_VIDEO_SESSION_PARAMETERS_KHR +# ObjectType(::) = OBJECT_TYPE_BUFFER_COLLECTION_FUCHSIA diff --git a/src/device.jl b/src/device.jl index 02ab6c73..7c6cc722 100644 --- a/src/device.jl +++ b/src/device.jl @@ -82,5 +82,12 @@ function find_queue_family(physical_device::PhysicalDevice, queue_capabilities:: index - 1 end -device(device::Device)::Device = device -device(handle::Handle)::Device = device(parent(handle)) +device(device::Device) = device +function device(handle::Handle) + next = parent(handle) + isnothing(next) && error("No parent device found") + device(next)::Device +end +device_or_nothing(device::Device) = device +device_or_nothing(handle::Handle) = device_or_nothing(parent(handle)) +device_or_nothing(::Nothing) = nothing diff --git a/test/api.jl b/test/api.jl index 223cda71..77931636 100644 --- a/test/api.jl +++ b/test/api.jl @@ -54,6 +54,16 @@ end @test CALLBACK_DEBUG_SIGNAL[] end end + + @testset "Setting object names" begin + if WITH_DEBUG + buffer = Buffer(device, 30, BUFFER_USAGE_TRANSFER_DST_BIT, SHARING_MODE_EXCLUSIVE, UInt32[0]) + ret = set_debug_name(buffer, "Test buffer") + @test unwrap(ret) == SUCCESS + ret = set_debug_name(buffer, :buffer_1) + @test unwrap(ret) == SUCCESS + end + end end @testset "Bitmask flags" begin