From bd759790b025df70fcd869f1043ec0d25a77fa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 28 Sep 2022 14:09:40 +0200 Subject: [PATCH] Update the Vulkan debug names when reassigning depth buffers. --- Common/GPU/Vulkan/VulkanRenderManager.cpp | 22 ++++++++++++++++++++-- Common/GPU/Vulkan/VulkanRenderManager.h | 2 ++ Common/GPU/Vulkan/thin3d_vulkan.cpp | 3 +++ Common/GPU/thin3d.h | 1 + GPU/Common/FramebufferManagerCommon.cpp | 14 +++++++++----- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 49abbde2d0..b0d8327301 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -153,16 +153,34 @@ VKRFramebuffer::VKRFramebuffer(VulkanContext *vk, VkCommandBuffer initCmd, VKRRe _dbg_assert_(tag); CreateImage(vulkan_, initCmd, color, width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, true, tag); - vulkan_->SetDebugName(color.image, VK_OBJECT_TYPE_IMAGE, StringFromFormat("fb_color_%s", tag).c_str()); if (createDepthStencilBuffer) { CreateImage(vulkan_, initCmd, depth, width, height, vulkan_->GetDeviceInfo().preferredDepthStencilFormat, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, false, tag); - vulkan_->SetDebugName(depth.image, VK_OBJECT_TYPE_IMAGE, StringFromFormat("fb_depth_%s", tag).c_str()); } + UpdateTag(tag); + // We create the actual framebuffer objects on demand, because some combinations might not make sense. // Framebuffer objects are just pointers to a set of images, so no biggie. } +void VKRFramebuffer::UpdateTag(const char *newTag) { + char name[128]; + snprintf(name, sizeof(name), "fb_color_%s", tag_.c_str()); + vulkan_->SetDebugName(color.image, VK_OBJECT_TYPE_IMAGE, name); + vulkan_->SetDebugName(color.image, VK_OBJECT_TYPE_IMAGE_VIEW, name); + if (depth.image) { + snprintf(name, sizeof(name), "fb_depth_%s", tag_.c_str()); + vulkan_->SetDebugName(depth.image, VK_OBJECT_TYPE_IMAGE, name); + vulkan_->SetDebugName(depth.image, VK_OBJECT_TYPE_IMAGE_VIEW, name); + } + for (int rpType = 0; rpType < RP_TYPE_COUNT; rpType++) { + if (framebuf[rpType]) { + snprintf(name, sizeof(name), "fb_%s", tag_.c_str()); + vulkan_->SetDebugName(framebuf[(int)rpType], VK_OBJECT_TYPE_FRAMEBUFFER, name); + } + } +} + VkFramebuffer VKRFramebuffer::Get(VKRRenderPass *compatibleRenderPass, RenderPassType rpType) { if (framebuf[(int)rpType]) { return framebuf[(int)rpType]; diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 5059324116..66692d99a7 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -57,6 +57,8 @@ public: return tag_.c_str(); } + void UpdateTag(const char *newTag); + // TODO: Hide. VulkanContext *vulkan_; private: diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index ceba56f78b..111cea1d2b 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -1490,6 +1490,9 @@ public: buf_ = nullptr; } VKRFramebuffer *GetFB() const { return buf_; } + void UpdateTag(const char *newTag) override { + buf_->UpdateTag(newTag); + } private: VKRFramebuffer *buf_; }; diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 0fba6ee6f2..ee0d50602a 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -411,6 +411,7 @@ class Framebuffer : public RefCountedObject { public: int Width() { return width_; } int Height() { return height_; } + virtual void UpdateTag(const char *tag) {} protected: int width_ = -1, height_ = -1; }; diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 807472703d..f97f2e91c0 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -49,6 +49,10 @@ #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" +static size_t FormatFramebufferName(VirtualFramebuffer *vfb, char *tag, size_t len) { + return snprintf(tag, len, "FB_%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, vfb->bufferWidth, vfb->bufferHeight, GeBufferFormatToString(vfb->fb_format)); +} + FramebufferManagerCommon::FramebufferManagerCommon(Draw::DrawContext *draw) : draw_(draw), draw2D_(draw_) { presentation_ = new PresentationCommon(draw); @@ -553,11 +557,15 @@ void FramebufferManagerCommon::SetDepthFrameBuffer(bool isClearingDepth) { uint32_t boundDepthBuffer = gstate.getDepthBufAddress() & 0x3FFFFFFF; if (currentRenderVfb_->z_address != boundDepthBuffer) { - WARN_LOG(G3D, "Framebuffer at %08x/%d has switched associated depth buffer from %08x to %08x, updating.", + WARN_LOG_N_TIMES(z_reassign, 5, G3D, "Framebuffer at %08x/%d has switched associated depth buffer from %08x to %08x, updating.", currentRenderVfb_->fb_address, currentRenderVfb_->fb_stride, currentRenderVfb_->z_address, boundDepthBuffer); + // Technically, here we should copy away the depth buffer to another framebuffer that uses that z_address, or maybe // even write it back to RAM. However, this is rare. Silent Hill is one example, see #16126. currentRenderVfb_->z_address = boundDepthBuffer; + char tag[128]; + FormatFramebufferName(currentRenderVfb_, tag, sizeof(tag)); + currentRenderVfb_->fbo->UpdateTag(tag); } // If this first draw call is anything other than a clear, "resolve" the depth buffer, @@ -1495,10 +1503,6 @@ void FramebufferManagerCommon::DecimateFBOs() { } } -static size_t FormatFramebufferName(VirtualFramebuffer *vfb, char *tag, size_t len) { - return snprintf(tag, len, "FB_%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, vfb->bufferWidth, vfb->bufferHeight, GeBufferFormatToString(vfb->fb_format)); -} - // Requires width/height to be set already. void FramebufferManagerCommon::ResizeFramebufFBO(VirtualFramebuffer *vfb, int w, int h, bool force, bool skipCopy) { _dbg_assert_(w > 0);