diff --git a/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp b/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp index fb45ad7d8..f15db2fcf 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.hpp @@ -64,6 +64,8 @@ namespace Nz void Execute(); + inline void InsertDebugLabel(std::string_view label, const Color& color); + inline std::size_t GetBindingIndex() const; inline std::size_t GetPoolIndex() const; inline const OpenGLCommandPool& GetOwner() const; @@ -94,6 +96,7 @@ namespace Nz cb(DrawCommand) \ cb(DrawIndexedCommand) \ cb(EndDebugRegionCommand) \ + cb(InsertDebugLabelCommand) \ cb(MemoryBarrier) \ lastCb(SetFrameBufferCommand) \ @@ -124,6 +127,7 @@ namespace Nz inline void Execute(const GL::Context* context, const DrawCommand& command); inline void Execute(const GL::Context* context, const DrawIndexedCommand& command); inline void Execute(const GL::Context* context, const EndDebugRegionCommand& command); + inline void Execute(const GL::Context* context, const InsertDebugLabelCommand& command); inline void Execute(const GL::Context* context, const MemoryBarrier& command); inline void Execute(const GL::Context*& context, const SetFrameBufferCommand& command); @@ -237,6 +241,12 @@ namespace Nz { }; + struct InsertDebugLabelCommand + { + std::string label; + Color color; + }; + struct MemoryBarrier { GLbitfield barriers; diff --git a/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.inl b/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.inl index 599ecd692..98b1b3e7c 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.inl +++ b/include/Nazara/OpenGLRenderer/OpenGLCommandBuffer.inl @@ -188,6 +188,15 @@ namespace Nz m_commands.emplace_back(EndDebugRegionCommand{}); } + inline void OpenGLCommandBuffer::InsertDebugLabel(std::string_view label, const Color& color) + { + InsertDebugLabelCommand debugLabelCommand; + debugLabelCommand.color = color; + debugLabelCommand.label = label; + + m_commands.emplace_back(std::move(debugLabelCommand)); + } + inline std::size_t OpenGLCommandBuffer::GetBindingIndex() const { return m_bindingIndex; diff --git a/include/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp b/include/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp index f8f09355b..58cfb2808 100644 --- a/include/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp +++ b/include/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.hpp @@ -52,6 +52,8 @@ namespace Nz void EndDebugRegion() override; void EndRenderPass() override; + void InsertDebugLabel(std::string_view label, const Color& color) override; + void NextSubpass() override; void PreTransferBarrier() override; diff --git a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp index ac0a8e5c4..5843d3787 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp @@ -78,6 +78,7 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLch cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \ cb(glCreateShader, PFNGLCREATESHADERPROC) \ cb(glCullFace, PFNGLCULLFACEPROC) \ + cb(glDebugMessageInsert, PFNGLDEBUGMESSAGEINSERTPROC) \ cb(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \ cb(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \ cb(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \ diff --git a/include/Nazara/Renderer/CommandBufferBuilder.hpp b/include/Nazara/Renderer/CommandBufferBuilder.hpp index 6c3086011..420a76820 100644 --- a/include/Nazara/Renderer/CommandBufferBuilder.hpp +++ b/include/Nazara/Renderer/CommandBufferBuilder.hpp @@ -70,6 +70,8 @@ namespace Nz virtual void EndDebugRegion() = 0; virtual void EndRenderPass() = 0; + virtual void InsertDebugLabel(std::string_view label, const Color& color) = 0; + virtual void NextSubpass() = 0; virtual void PreTransferBarrier() = 0; diff --git a/include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp b/include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp index 89b94124b..ac1c71634 100644 --- a/include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp +++ b/include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp @@ -52,6 +52,8 @@ namespace Nz void EndDebugRegion() override; void EndRenderPass() override; + void InsertDebugLabel(std::string_view label, const Color& color) override; + inline Vk::CommandBuffer& GetCommandBuffer(); void NextSubpass() override; diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index fb8ab9d29..9874c5971 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -209,6 +209,12 @@ namespace Nz context->glPopDebugGroup(); } + inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const InsertDebugLabelCommand& command) + { + if (context->glDebugMessageInsert) + context->glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, command.label.size(), command.label.data()); + } + inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const MemoryBarrier& command) { if (context->glMemoryBarrier) diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.cpp index 5e4a969c2..48b6b71b9 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBufferBuilder.cpp @@ -148,6 +148,11 @@ namespace Nz /* nothing to do */ } + void OpenGLCommandBufferBuilder::InsertDebugLabel(std::string_view label, const Color& color) + { + m_commandBuffer.InsertDebugLabel(label, color); + } + void OpenGLCommandBufferBuilder::NextSubpass() { /* nothing to do */ diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp index 09d4f86a4..d19c87883 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp @@ -603,13 +603,16 @@ namespace Nz::GL if (glDebugMessageControl) { - // Disable push/pop debug groups notifications + // Disable push/pop debug groups and markers notifications if (glPushDebugGroup) glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_PUSH_GROUP, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE); if (glPopDebugGroup) glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_POP_GROUP, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE); + if (glDebugMessageInsert) + glDebugMessageControl(GL_DONT_CARE, GL_DEBUG_TYPE_MARKER, GL_DEBUG_SEVERITY_NOTIFICATION, 0, nullptr, GL_FALSE); + // Handle verbosity level if (m_params.validationLevel < RenderAPIValidationLevel::Debug) // Disable driver notifications except in debug (NVidia driver is very verbose) diff --git a/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp b/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp index da406b50c..e56f67898 100644 --- a/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp +++ b/src/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.cpp @@ -315,6 +315,16 @@ namespace Nz m_currentRenderPass = nullptr; } + void VulkanCommandBufferBuilder::InsertDebugLabel(std::string_view label, const Color& color) + { + // Ensure \0 at the end of string + StackArray labelEOS = NazaraStackArrayNoInit(char, label.size() + 1); + std::memcpy(labelEOS.data(), label.data(), label.size()); + labelEOS[label.size()] = '\0'; + + m_commandBuffer.InsertDebugLabel(labelEOS.data(), color); + } + void VulkanCommandBufferBuilder::NextSubpass() { m_commandBuffer.NextSubpass();