From 4d1da5859c72ddf1e845b5a9a8c7979e85bfac86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 13 Oct 2022 22:34:21 +0200 Subject: [PATCH] Add simple way to add debug annotation in the middle of the command stream. Vulkan-only. --- Common/GPU/Vulkan/VulkanQueueRunner.cpp | 9 +++++++++ Common/GPU/Vulkan/VulkanQueueRunner.h | 4 ++++ Common/GPU/Vulkan/VulkanRenderManager.h | 7 +++++++ Common/GPU/Vulkan/thin3d_vulkan.cpp | 8 ++++++++ Common/GPU/thin3d.h | 2 ++ GPU/Common/FragmentShaderGenerator.cpp | 3 ++- 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index 6ce019b1fb..5a55e1e916 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -1579,6 +1579,15 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c } break; } + + case VKRRenderCommand::DEBUG_ANNOTATION: + if (vulkan_->Extensions().EXT_debug_utils) { + VkDebugUtilsLabelEXT labelInfo{ VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT }; + labelInfo.pLabelName = c.debugAnnotation.annotation; + vkCmdInsertDebugUtilsLabelEXT(cmd, &labelInfo); + } + break; + default: ERROR_LOG(G3D, "Unimpl queue command"); } diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.h b/Common/GPU/Vulkan/VulkanQueueRunner.h index 7036029149..396a37edae 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.h +++ b/Common/GPU/Vulkan/VulkanQueueRunner.h @@ -38,6 +38,7 @@ enum class VKRRenderCommand : uint8_t { DRAW_INDEXED, PUSH_CONSTANTS, SELF_DEPENDENCY_BARRIER, + DEBUG_ANNOTATION, NUM_RENDER_COMMANDS, }; @@ -136,6 +137,9 @@ struct VkRenderData { uint8_t size; uint8_t data[40]; // Should be enough for now. } push; + struct { + const char *annotation; + } debugAnnotation; }; }; diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 7ba98b485c..3c2f9dd12d 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -429,6 +429,13 @@ public: curRenderStep_->render.numDraws++; } + // These can be useful both when inspecting in RenderDoc, and when manually inspecting recorded commands + // in the debugger. + void DebugAnnotate(const char *annotation) { + VkRenderData data{ VKRRenderCommand::DEBUG_ANNOTATION }; + data.debugAnnotation.annotation = annotation; + } + VkCommandBuffer GetInitCmd(); // Gets a frame-unique ID of the current step being recorded. Can be used to figure out diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index dc1b806011..7d3b0e8218 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -367,6 +367,8 @@ public: VKContext(VulkanContext *vulkan); virtual ~VKContext(); + void DebugAnnotate(const char *annotation) override; + const DeviceCaps &GetDeviceCaps() const override { return caps_; } @@ -1010,6 +1012,8 @@ VkDescriptorSet VKContext::GetOrCreateDescriptorSet(VkBuffer buf) { return VK_NULL_HANDLE; } + vulkan_->SetDebugName(descSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, "(thin3d desc set)"); + VkDescriptorBufferInfo bufferDesc; bufferDesc.buffer = buf; bufferDesc.offset = 0; @@ -1651,4 +1655,8 @@ uint64_t VKContext::GetNativeObject(NativeObject obj, void *srcObject) { } } +void VKContext::DebugAnnotate(const char *annotation) { + renderManager_.DebugAnnotate(annotation); +} + } // namespace Draw diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 132c0e02f9..8c440deb04 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -616,6 +616,8 @@ public: virtual void SetErrorCallback(ErrorCallbackFn callback, void *userdata) {} + virtual void DebugAnnotate(const char *annotation) {} + // Partial pipeline state, used to create pipelines. (in practice, in d3d11 they'll use the native state objects directly). // TODO: Possibly ditch these and just put the descs directly in PipelineDesc since only D3D11 benefits. virtual DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) = 0; diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index c9bb2d0992..efd7c5a229 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -120,8 +120,9 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool isModeClear = id.Bit(FS_BIT_CLEARMODE); const char *shading = ""; - if (compat.glslES30 || compat.shaderLanguage == ShaderLanguage::GLSL_VULKAN) + if (compat.glslES30 || compat.shaderLanguage == ShaderLanguage::GLSL_VULKAN) { shading = doFlatShading ? "flat" : ""; + } bool useDiscardStencilBugWorkaround = id.Bit(FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL);