From 698f890500fa94ba0b3532740afb78b4545d6a8f Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Wed, 9 Apr 2025 22:48:38 -0700 Subject: [PATCH] Add GPU debug labels for render passes --- kraken/KRDevice.cpp | 5 +++++ kraken/KRDevice.h | 1 + kraken/KRRenderGraph.cpp | 1 + kraken/KRRenderGraphBlackFrame.cpp | 4 ++++ kraken/KRRenderGraphDeferred.cpp | 24 ++++++++++++++++++++++++ kraken/KRRenderGraphForward.cpp | 18 ++++++++++++++++++ kraken/KRRenderPass.cpp | 4 ++++ kraken/KRRenderPass.h | 3 +++ 8 files changed, 60 insertions(+) diff --git a/kraken/KRDevice.cpp b/kraken/KRDevice.cpp index b49c23d..93e17a6 100644 --- a/kraken/KRDevice.cpp +++ b/kraken/KRDevice.cpp @@ -587,6 +587,11 @@ void KRDevice::setDebugLabel(const VkCommandBuffer& commandBuffer, const char* d setDebugLabel((uint64_t)commandBuffer, VK_OBJECT_TYPE_COMMAND_BUFFER, debugLabel); } +void KRDevice::setDebugLabel(const VkRenderPass& renderPass, const char* debugLabel) +{ + setDebugLabel((uint64_t)renderPass, VK_OBJECT_TYPE_RENDER_PASS, debugLabel); +} + void KRDevice::setDebugLabel(const VkDevice& device, const char* debugLabel) { setDebugLabel((uint64_t)device, VK_OBJECT_TYPE_DEVICE, debugLabel); diff --git a/kraken/KRDevice.h b/kraken/KRDevice.h index 13a6ecb..4fa78d1 100644 --- a/kraken/KRDevice.h +++ b/kraken/KRDevice.h @@ -56,6 +56,7 @@ public: void setDebugLabel(const VkBuffer& buffer, const char* debugLabel); void setDebugLabel(const VkQueue& queue, const char* debugLabel); void setDebugLabel(const VkCommandBuffer& commandBuffer, const char* debugLabel); + void setDebugLabel(const VkRenderPass& renderPass, const char* debugLabel); void setDebugLabel(const VkDevice& device, const char* debugLabel); #endif // KRENGINE_DEBUG_GPU_LABELS diff --git a/kraken/KRRenderGraph.cpp b/kraken/KRRenderGraph.cpp index 297fa4e..fde9de3 100644 --- a/kraken/KRRenderGraph.cpp +++ b/kraken/KRRenderGraph.cpp @@ -133,6 +133,7 @@ void KRRenderGraph::addRenderPass(KRDevice& device, const RenderPassInfo& info) KRRenderPass *pass = new KRRenderPass(getContext()); pass->create(device, info, renderPassInfo); + m_renderPasses.push_back(pass); } diff --git a/kraken/KRRenderGraphBlackFrame.cpp b/kraken/KRRenderGraphBlackFrame.cpp index 3b65281..61e6d66 100644 --- a/kraken/KRRenderGraphBlackFrame.cpp +++ b/kraken/KRRenderGraphBlackFrame.cpp @@ -63,6 +63,10 @@ KrResult KRRenderGraphBlackFrame::initialize(KRSurface &surface) info.depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; info.finalPass = true; info.type = RenderPassType::RENDER_PASS_BLACK_FRAME; + +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Black Frame", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); return KR_SUCCESS; diff --git a/kraken/KRRenderGraphDeferred.cpp b/kraken/KRRenderGraphDeferred.cpp index 1eb2c1a..86eeaf5 100644 --- a/kraken/KRRenderGraphDeferred.cpp +++ b/kraken/KRRenderGraphDeferred.cpp @@ -71,6 +71,9 @@ KrResult KRRenderGraphDeferred::initialize(KRSurface &surface) info.finalPass = false; info.type = RenderPassType::RENDER_PASS_PRESTREAM; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "PreStream", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); for (int shadow_index = 0; shadow_index < shadow_buffer_count; shadow_index++) { @@ -80,6 +83,9 @@ KrResult KRRenderGraphDeferred::initialize(KRSurface &surface) info.depthAttachment.clearVaue.depthStencil.depth = 1.0f; info.depthAttachment.clearVaue.depthStencil.stencil = 0; info.type = RenderPassType::RENDER_PASS_SHADOWMAP; +#if KRENGINE_DEBUG_GPU_LABELS + snprintf(info.debugLabel, KRENGINE_DEBUG_GPU_LABEL_MAX_LEN, "Shadow Map %i", shadow_index); +#endif addRenderPass(*surface.getDevice(), info); } @@ -100,6 +106,9 @@ KrResult KRRenderGraphDeferred::initialize(KRSurface &surface) info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; info.type = RenderPassType::RENDER_PASS_DEFERRED_GBUFFER; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Deferred GBuffer", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); // ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====---- @@ -115,12 +124,18 @@ KrResult KRRenderGraphDeferred::initialize(KRSurface &surface) info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; info.colorAttachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; info.type = RenderPassType::RENDER_PASS_DEFERRED_LIGHTS; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Deferred Lights", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); // ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====---- info.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; info.colorAttachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; info.type = RenderPassType::RENDER_PASS_DEFERRED_OPAQUE; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Deferred Opaque", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); info.colorAttachments[1] = {}; @@ -141,13 +156,22 @@ KrResult KRRenderGraphDeferred::initialize(KRSurface &surface) info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; info.type = RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Forward Transparent", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); info.type = RenderPassType::RENDER_PASS_DEBUG_OVERLAYS; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Debug Overlays", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); info.finalPass = true; info.type = RenderPassType::RENDER_PASS_POST_COMPOSITE; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Post Composite", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); return KR_SUCCESS; diff --git a/kraken/KRRenderGraphForward.cpp b/kraken/KRRenderGraphForward.cpp index ca5aacc..15875fd 100644 --- a/kraken/KRRenderGraphForward.cpp +++ b/kraken/KRRenderGraphForward.cpp @@ -70,6 +70,9 @@ KrResult KRRenderGraphForward::initialize(KRSurface &surface) info.finalPass = false; info.type = RenderPassType::RENDER_PASS_PRESTREAM; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "PreStream", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); for (int shadow_index = 0; shadow_index < shadow_buffer_count; shadow_index++) { @@ -79,6 +82,9 @@ KrResult KRRenderGraphForward::initialize(KRSurface &surface) info.depthAttachment.clearVaue.depthStencil.depth = 1.0f; info.depthAttachment.clearVaue.depthStencil.stencil = 0; info.type = RenderPassType::RENDER_PASS_SHADOWMAP; +#if KRENGINE_DEBUG_GPU_LABELS + snprintf(info.debugLabel, KRENGINE_DEBUG_GPU_LABEL_MAX_LEN, "Shadow Map %i", shadow_index); +#endif addRenderPass(*surface.getDevice(), info); } @@ -98,6 +104,9 @@ KrResult KRRenderGraphForward::initialize(KRSurface &surface) info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; info.type = RenderPassType::RENDER_PASS_FORWARD_OPAQUE; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Forward Opaque", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); // ----====---- Transparent Geometry, Forward Rendering ----====---- @@ -116,13 +125,22 @@ KrResult KRRenderGraphForward::initialize(KRSurface &surface) info.colorAttachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; info.type = RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Forward Transparent", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); info.type = RenderPassType::RENDER_PASS_DEBUG_OVERLAYS; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Debug Overlays", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); info.finalPass = true; info.type = RenderPassType::RENDER_PASS_POST_COMPOSITE; +#if KRENGINE_DEBUG_GPU_LABELS + strncpy(info.debugLabel, "Post Composite", KRENGINE_DEBUG_GPU_LABEL_MAX_LEN); +#endif addRenderPass(*surface.getDevice(), info); return KR_SUCCESS; diff --git a/kraken/KRRenderPass.cpp b/kraken/KRRenderPass.cpp index 6f55be4..427e238 100644 --- a/kraken/KRRenderPass.cpp +++ b/kraken/KRRenderPass.cpp @@ -56,6 +56,10 @@ void KRRenderPass::create(KRDevice& device, const RenderPassInfo& info, const Vk if (vkCreateRenderPass(device.m_logicalDevice, &createInfo, nullptr, &m_renderPass) != VK_SUCCESS) { // failed! TODO - Error handling } + +#if KRENGINE_DEBUG_GPU_LABELS + device.setDebugLabel(m_renderPass, info.debugLabel); +#endif } void KRRenderPass::destroy(KRDevice& device) diff --git a/kraken/KRRenderPass.h b/kraken/KRRenderPass.h index 43d47e9..58e96b3 100644 --- a/kraken/KRRenderPass.h +++ b/kraken/KRRenderPass.h @@ -68,6 +68,9 @@ struct RenderPassInfo RenderPassType type; RenderPassAttachmentInfo colorAttachments[RENDER_PASS_ATTACHMENT_MAX_COUNT]; RenderPassAttachmentInfo depthAttachment; +#if KRENGINE_DEBUG_GPU_LABELS + char debugLabel[KRENGINE_DEBUG_GPU_LABEL_MAX_LEN]; +#endif bool finalPass; };