diff --git a/FlingEngine/Graphics/src/CommandBuffer.cpp b/FlingEngine/Graphics/src/CommandBuffer.cpp index 81e089eb..98906400 100644 --- a/FlingEngine/Graphics/src/CommandBuffer.cpp +++ b/FlingEngine/Graphics/src/CommandBuffer.cpp @@ -67,6 +67,26 @@ namespace Fling vkCmdBeginRenderPass(GetHandle(), &begin_info, VK_SUBPASS_CONTENTS_INLINE); } + void CommandBuffer::BeginLabel(const char* t_Name) + { + if (vkCmdBeginDebugUtilsLabelEXT == nullptr) + { + return; + } + VkDebugUtilsLabelEXT Label = {}; + Label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + Label.pLabelName = t_Name; + vkCmdBeginDebugUtilsLabelEXT(GetHandle(), &Label); + } + + void CommandBuffer::EndLabel() + { + if (vkCmdEndDebugUtilsLabelEXT != nullptr) + { + vkCmdEndDebugUtilsLabelEXT(GetHandle()); + } + } + void CommandBuffer::NextSubpass() { // track pipeline state ? diff --git a/FlingEngine/Graphics/src/CommandBuffer.h b/FlingEngine/Graphics/src/CommandBuffer.h index 24e88dfb..06296cd0 100644 --- a/FlingEngine/Graphics/src/CommandBuffer.h +++ b/FlingEngine/Graphics/src/CommandBuffer.h @@ -59,6 +59,15 @@ namespace Fling /** Stop recording commands to the command buffer */ void End(); + /** + * Open a named group of commands, shown by a graphics debugger (RenderDoc, Nsight). + * Does nothing when VK_EXT_debug_utils is off. Close it with EndLabel. + */ + void BeginLabel(const char* t_Name); + + /** Close the group opened by the last BeginLabel. */ + void EndLabel(); + inline bool IsRecording() const { return m_State == State::Recording; } private: diff --git a/FlingEngine/Graphics/src/DebugSubpass.h b/FlingEngine/Graphics/src/DebugSubpass.h index d8f45926..666a5282 100644 --- a/FlingEngine/Graphics/src/DebugSubpass.h +++ b/FlingEngine/Graphics/src/DebugSubpass.h @@ -38,6 +38,8 @@ namespace Fling void PrepareAttachments() override; + const char* DebugName() const override { return "Debug draw"; } + void CreateGraphicsPipeline() override; void CleanUp() override; diff --git a/FlingEngine/Graphics/src/GeometrySubpass.h b/FlingEngine/Graphics/src/GeometrySubpass.h index b5214334..c224d89a 100644 --- a/FlingEngine/Graphics/src/GeometrySubpass.h +++ b/FlingEngine/Graphics/src/GeometrySubpass.h @@ -79,6 +79,8 @@ namespace Fling /** * @param t_FrameBuffer The swap chain frame buffer */ + const char* DebugName() const override { return "Lighting"; } + void CreateGraphicsPipeline() override; virtual void OnSwapchainResized() override final; diff --git a/FlingEngine/Graphics/src/ImGuiSubpass.h b/FlingEngine/Graphics/src/ImGuiSubpass.h index f78b0fab..bf0ac3c4 100644 --- a/FlingEngine/Graphics/src/ImGuiSubpass.h +++ b/FlingEngine/Graphics/src/ImGuiSubpass.h @@ -37,6 +37,8 @@ namespace Fling void PrepareAttachments() override; + const char* DebugName() const override { return "UI"; } + void CreateGraphicsPipeline() override; void CleanUp() override; diff --git a/FlingEngine/Graphics/src/Instance.cpp b/FlingEngine/Graphics/src/Instance.cpp index 39841604..130cb860 100644 --- a/FlingEngine/Graphics/src/Instance.cpp +++ b/FlingEngine/Graphics/src/Instance.cpp @@ -126,6 +126,22 @@ namespace Fling return true; } + bool Instance::IsInstanceExtensionSupported(const char* t_Name) + { + uint32 Count = 0; + vkEnumerateInstanceExtensionProperties(nullptr, &Count, nullptr); + std::vector Properties(Count); + vkEnumerateInstanceExtensionProperties(nullptr, &Count, Properties.data()); + for (const VkExtensionProperties& Property : Properties) + { + if (strcmp(Property.extensionName, t_Name) == 0) + { + return true; + } + } + return false; + } + std::vector Instance::GetRequiredExtensions() { std::vector extensions; @@ -140,11 +156,18 @@ namespace Fling } } - if (m_EnableValidationLayers) - { + // Pass labels need VK_EXT_debug_utils, and a Release capture needs them most. Turn the + // extension on when the driver has it, in every build but Shipping. + bool bWantDebugUtils = false; #if FLING_DEBUG - extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + bWantDebugUtils = m_EnableValidationLayers; #endif +#ifndef FLING_SHIPPING + bWantDebugUtils = bWantDebugUtils || IsInstanceExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); +#endif + if (bWantDebugUtils) + { + extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } return extensions; diff --git a/FlingEngine/Graphics/src/Instance.h b/FlingEngine/Graphics/src/Instance.h index 607c2de2..643d6c7a 100644 --- a/FlingEngine/Graphics/src/Instance.h +++ b/FlingEngine/Graphics/src/Instance.h @@ -60,6 +60,9 @@ namespace Fling */ void CreateInstance(); + /** True if the Vulkan loader lists this instance extension. */ + static bool IsInstanceExtensionSupported(const char* t_Name); + std::vector GetRequiredExtensions(); bool CheckValidationLayerSupport(); diff --git a/FlingEngine/Graphics/src/OffscreenSubpass.cpp b/FlingEngine/Graphics/src/OffscreenSubpass.cpp index d664fe0a..6b87fbf1 100644 --- a/FlingEngine/Graphics/src/OffscreenSubpass.cpp +++ b/FlingEngine/Graphics/src/OffscreenSubpass.cpp @@ -295,6 +295,7 @@ namespace Fling /** offsetY */ 0); t_CmdBuf.Begin(); + t_CmdBuf.BeginLabel(DebugName()); t_CmdBuf.BeginRenderPass(*m_OffscreenFrameBuf, m_ClearValues); t_CmdBuf.SetViewport(0, {viewport}); @@ -337,6 +338,7 @@ namespace Fling } t_CmdBuf.EndRenderPass(); + t_CmdBuf.EndLabel(); t_CmdBuf.End(); } diff --git a/FlingEngine/Graphics/src/OffscreenSubpass.h b/FlingEngine/Graphics/src/OffscreenSubpass.h index 6156c0b5..346191cf 100644 --- a/FlingEngine/Graphics/src/OffscreenSubpass.h +++ b/FlingEngine/Graphics/src/OffscreenSubpass.h @@ -60,6 +60,8 @@ namespace Fling void PrepareAttachments() override final; + const char* DebugName() const override { return "G-buffer"; } + void CreateGraphicsPipeline() override final; void GatherPresentDependencies(std::vector& t_CmdBuffs, diff --git a/FlingEngine/Graphics/src/RenderPipeline.cpp b/FlingEngine/Graphics/src/RenderPipeline.cpp index c6393de1..c385e576 100644 --- a/FlingEngine/Graphics/src/RenderPipeline.cpp +++ b/FlingEngine/Graphics/src/RenderPipeline.cpp @@ -49,7 +49,10 @@ namespace Fling for (size_t i = 0; i < m_Subpasses.size(); ++i) { // Build the subpasses for the active frame in flight + // The label groups this pass's commands in a capture + t_CmdBuf.BeginLabel(m_Subpasses[i]->DebugName()); m_Subpasses[i]->Draw(t_CmdBuf, t_ActiveFrameInFlight, t_Snapshot, DeltaTime); + t_CmdBuf.EndLabel(); } } diff --git a/FlingEngine/Graphics/src/SkyboxSubpass.h b/FlingEngine/Graphics/src/SkyboxSubpass.h index 9ed82efc..fd69f9c0 100644 --- a/FlingEngine/Graphics/src/SkyboxSubpass.h +++ b/FlingEngine/Graphics/src/SkyboxSubpass.h @@ -42,6 +42,8 @@ namespace Fling void CreateDescriptorSets(VkDescriptorPool t_Pool) override; + const char* DebugName() const override { return "Sky"; } + void CreateGraphicsPipeline() override; void OnSwapchainResized() override; diff --git a/FlingEngine/Graphics/src/Subpass.h b/FlingEngine/Graphics/src/Subpass.h index ac8aaeb9..ae35896d 100644 --- a/FlingEngine/Graphics/src/Subpass.h +++ b/FlingEngine/Graphics/src/Subpass.h @@ -40,6 +40,9 @@ namespace Fling virtual void CreateGraphicsPipeline() = 0; + /** The name a graphics debugger shows for this pass's commands. */ + virtual const char* DebugName() const { return "Subpass"; } + /** * Record this pass for one frame. A pass reads only the snapshot, never the * world, so the world can change while the frame is drawn. diff --git a/FlingEngine/Graphics/src/VulkanFunctions.inl b/FlingEngine/Graphics/src/VulkanFunctions.inl index 059fa01d..a3157462 100644 --- a/FlingEngine/Graphics/src/VulkanFunctions.inl +++ b/FlingEngine/Graphics/src/VulkanFunctions.inl @@ -63,6 +63,10 @@ FLING_VK_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties) FLING_VK_INSTANCE_OPTIONAL(vkCreateDebugUtilsMessengerEXT) FLING_VK_INSTANCE_OPTIONAL(vkDestroyDebugUtilsMessengerEXT) +// Pass labels for a graphics debugger (RenderDoc, Nsight). Null when VK_EXT_debug_utils is off. +FLING_VK_INSTANCE_OPTIONAL(vkCmdBeginDebugUtilsLabelEXT) +FLING_VK_INSTANCE_OPTIONAL(vkCmdEndDebugUtilsLabelEXT) + // VK_KHR_surface: an offscreen renderer (--offscreen) does not enable it. // VulkanLoader::MissingPresentCommand checks them when there is a window. FLING_VK_INSTANCE_OPTIONAL(vkDestroySurfaceKHR)