From 1d9dd8d29d42a3e7a10ece75fedd9cf81906eaae Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 28 Apr 2021 00:11:36 +0300 Subject: [PATCH] vk: Add support for tagging objects to ease debugging - Makes use of VK_EXT_debug_utils --- rpcs3/Emu/RSX/VK/VKRenderTargets.h | 2 ++ rpcs3/Emu/RSX/VK/VKTextureCache.h | 2 ++ rpcs3/Emu/RSX/VK/vkutils/device.cpp | 11 +++++++++++ rpcs3/Emu/RSX/VK/vkutils/device.h | 3 +++ rpcs3/Emu/RSX/VK/vkutils/image.cpp | 14 ++++++++++++++ rpcs3/Emu/RSX/VK/vkutils/image.h | 3 +++ rpcs3/Emu/RSX/VK/vkutils/instance.hpp | 6 ++++++ 7 files changed, 41 insertions(+) diff --git a/rpcs3/Emu/RSX/VK/VKRenderTargets.h b/rpcs3/Emu/RSX/VK/VKRenderTargets.h index 69e1ca895a..ff86380f8c 100644 --- a/rpcs3/Emu/RSX/VK/VKRenderTargets.h +++ b/rpcs3/Emu/RSX/VK/VKRenderTargets.h @@ -120,6 +120,7 @@ namespace rsx usage_flags, 0, RSX_FORMAT_CLASS_COLOR); + rtt->set_debug_name(fmt::format("RTV @0x%x", address)); rtt->change_layout(cmd, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); rtt->set_format(format); @@ -180,6 +181,7 @@ namespace rsx usage_flags, 0, rsx::classify_format(format)); + ds->set_debug_name(fmt::format("DSV @0x%x", address)); ds->change_layout(cmd, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); ds->set_format(format); diff --git a/rpcs3/Emu/RSX/VK/VKTextureCache.h b/rpcs3/Emu/RSX/VK/VKTextureCache.h index 6565c16647..f1f8ce6f17 100644 --- a/rpcs3/Emu/RSX/VK/VKTextureCache.h +++ b/rpcs3/Emu/RSX/VK/VKTextureCache.h @@ -927,6 +927,8 @@ namespace vk rsx::texture_create_flags::default_component_order); auto image = section->get_raw_texture(); + image->set_debug_name(fmt::format("Raw Texture @0x%x", rsx_range.start)); + vk::enter_uninterruptible(); bool input_swizzled = swizzled; diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index 417f2f4627..882914d086 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -58,6 +58,7 @@ namespace vk conditional_render_support = device_extensions.is_supported(VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME); external_memory_host_support = device_extensions.is_supported(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME); unrestricted_depth_range_support = device_extensions.is_supported(VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME); + debug_utils_support = instance_extensions.is_supported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); surface_capabilities_2_support = instance_extensions.is_supported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); } @@ -437,6 +438,11 @@ namespace vk _vkCmdEndConditionalRenderingEXT = reinterpret_cast(vkGetDeviceProcAddr(dev, "vkCmdEndConditionalRenderingEXT")); } + if (pgpu->debug_utils_support) + { + _vkSetDebugUtilsObjectNameEXT = reinterpret_cast(vkGetDeviceProcAddr(dev, "vkSetDebugUtilsObjectNameEXT")); + } + memory_map = vk::get_memory_mapping(pdev); m_formats_support = vk::get_optimal_tiling_supported_formats(pdev); m_pipeline_binding_table = vk::get_pipeline_binding_table(pdev); @@ -597,6 +603,11 @@ namespace vk return pgpu->surface_capabilities_2_support; } + bool render_device::get_debug_utils_support() const + { + return g_cfg.video.renderdoc_compatiblity && pgpu->debug_utils_support; + } + mem_allocator_base* render_device::get_allocator() const { return m_allocator.get(); diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.h b/rpcs3/Emu/RSX/VK/vkutils/device.h index c8316a40e1..d52dc5f26d 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.h +++ b/rpcs3/Emu/RSX/VK/vkutils/device.h @@ -52,6 +52,7 @@ namespace vk bool external_memory_host_support = false; bool unrestricted_depth_range_support = false; bool surface_capabilities_2_support = false; + bool debug_utils_support = false; friend class render_device; private: @@ -101,6 +102,7 @@ namespace vk // Exported device endpoints PFN_vkCmdBeginConditionalRenderingEXT _vkCmdBeginConditionalRenderingEXT = nullptr; PFN_vkCmdEndConditionalRenderingEXT _vkCmdEndConditionalRenderingEXT = nullptr; + PFN_vkSetDebugUtilsObjectNameEXT _vkSetDebugUtilsObjectNameEXT = nullptr; public: render_device() = default; @@ -126,6 +128,7 @@ namespace vk bool get_unrestricted_depth_range_support() const; bool get_external_memory_host_support() const; bool get_surface_capabilities_2_support() const; + bool get_debug_utils_support() const; VkQueue get_present_queue() const; VkQueue get_graphics_queue() const; diff --git a/rpcs3/Emu/RSX/VK/vkutils/image.cpp b/rpcs3/Emu/RSX/VK/vkutils/image.cpp index 5360bbd9c5..0ea2ff921f 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/image.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/image.cpp @@ -215,6 +215,20 @@ namespace vk current_queue_family = new_queue_family; } + void image::set_debug_name(const std::string& name) + { + if (g_render_device->get_debug_utils_support()) + { + VkDebugUtilsObjectNameInfoEXT name_info{}; + name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + name_info.objectType = VK_OBJECT_TYPE_IMAGE; + name_info.objectHandle = reinterpret_cast(value); + name_info.pObjectName = name.c_str(); + + g_render_device->_vkSetDebugUtilsObjectNameEXT(m_device, &name_info); + } + } + image_view::image_view(VkDevice dev, VkImage image, VkImageViewType view_type, VkFormat format, VkComponentMapping mapping, VkImageSubresourceRange range) : m_device(dev) { diff --git a/rpcs3/Emu/RSX/VK/vkutils/image.h b/rpcs3/Emu/RSX/VK/vkutils/image.h index 6490114982..0a8e89a097 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/image.h +++ b/rpcs3/Emu/RSX/VK/vkutils/image.h @@ -81,6 +81,9 @@ namespace vk void change_layout(const command_buffer& cmd, VkImageLayout new_layout); void change_layout(const command_buffer& cmd, VkImageLayout new_layout, u32 new_queue_family); + // Debug utils + void set_debug_name(const std::string& name); + private: VkDevice m_device; }; diff --git a/rpcs3/Emu/RSX/VK/vkutils/instance.hpp b/rpcs3/Emu/RSX/VK/vkutils/instance.hpp index 6eb8aefe11..ab944c6376 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/instance.hpp +++ b/rpcs3/Emu/RSX/VK/vkutils/instance.hpp @@ -159,6 +159,12 @@ namespace vk { extensions.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME); } + + if (g_cfg.video.renderdoc_compatiblity && support.is_supported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + { + extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + } + #ifdef _WIN32 extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); #elif defined(__APPLE__)