Update the Vulkan debug names when reassigning depth buffers.

This commit is contained in:
Henrik Rydgård 2022-09-28 14:09:40 +02:00
parent 3adad176cc
commit bd759790b0
5 changed files with 35 additions and 7 deletions

View file

@ -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];

View file

@ -57,6 +57,8 @@ public:
return tag_.c_str();
}
void UpdateTag(const char *newTag);
// TODO: Hide.
VulkanContext *vulkan_;
private:

View file

@ -1490,6 +1490,9 @@ public:
buf_ = nullptr;
}
VKRFramebuffer *GetFB() const { return buf_; }
void UpdateTag(const char *newTag) override {
buf_->UpdateTag(newTag);
}
private:
VKRFramebuffer *buf_;
};

View file

@ -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;
};

View file

@ -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);