From 48c39543afe606ecf9df89dd04725d43df537a1b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 10 Oct 2022 21:54:24 -0700 Subject: [PATCH] GE Debugger: Normalize framebuffer texture preview. Previously, we would show the render-to-texture with its original dimensions. While useful, this skewed the preview coordinates and was sometimes confusing. Additionally, depth texturing didn't preview. This pads and subsets the texture preview so it's the right size. --- GPU/Common/GPUDebugInterface.cpp | 5 +++++ GPU/Common/GPUDebugInterface.h | 2 ++ GPU/Common/TextureCacheCommon.cpp | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/GPU/Common/GPUDebugInterface.cpp b/GPU/Common/GPUDebugInterface.cpp index 1f7d04369e..a94a3b46a1 100644 --- a/GPU/Common/GPUDebugInterface.cpp +++ b/GPU/Common/GPUDebugInterface.cpp @@ -985,6 +985,11 @@ void GPUDebugBuffer::Free() { data_ = NULL; } +void GPUDebugBuffer::ZeroBytes() { + _dbg_assert_(data_); + memset(data_, 0, PixelSize() * stride_ * height_); +} + u32 GPUDebugBuffer::PixelSize() const { switch (fmt_) { case GPU_DBG_FORMAT_8888: diff --git a/GPU/Common/GPUDebugInterface.h b/GPU/Common/GPUDebugInterface.h index f584dfd576..a2e1e2627b 100644 --- a/GPU/Common/GPUDebugInterface.h +++ b/GPU/Common/GPUDebugInterface.h @@ -136,6 +136,8 @@ struct GPUDebugBuffer { void Allocate(u32 stride, u32 height, GPUDebugBufferFormat fmt, bool flipped = false); void Free(); + void ZeroBytes(); + u8 *GetData() { return data_; } diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 8a33791337..3601a17c62 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1167,8 +1167,26 @@ bool TextureCacheCommon::GetCurrentFramebufferTextureDebug(GPUDebugBuffer &buffe return false; VirtualFramebuffer *vfb = nextFramebufferTexture_; - buffer.Allocate(vfb->bufferWidth, vfb->bufferHeight, GPU_DBG_FORMAT_8888, false); - bool retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_COLOR_BIT, 0, 0, vfb->bufferWidth, vfb->bufferHeight, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), vfb->bufferWidth, "GetCurrentTextureDebug"); + u8 sf = vfb->renderScaleFactor; + int x = gstate_c.curTextureXOffset * sf; + int y = gstate_c.curTextureYOffset * sf; + int desiredW = gstate.getTextureWidth(0) * sf; + int desiredH = gstate.getTextureHeight(0) * sf; + int w = std::min(desiredW, vfb->bufferWidth * sf - x); + int h = std::min(desiredH, vfb->bufferHeight * sf - y); + + bool retval; + if (nextFramebufferTextureChannel_ == RASTER_DEPTH) { + buffer.Allocate(desiredW, desiredH, GPU_DBG_FORMAT_FLOAT, false); + if (w < desiredW || h < desiredH) + buffer.ZeroBytes(); + retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_DEPTH_BIT, x, y, w, h, Draw::DataFormat::D32F, buffer.GetData(), desiredW, "GetCurrentTextureDebug"); + } else { + buffer.Allocate(desiredW, desiredH, GPU_DBG_FORMAT_8888, false); + if (w < desiredW || h < desiredH) + buffer.ZeroBytes(); + retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_COLOR_BIT, x, y, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), desiredW, "GetCurrentTextureDebug"); + } // Vulkan requires us to re-apply all dynamic state for each command buffer, and the above will cause us to start a new cmdbuf. // So let's dirty the things that are involved in Vulkan dynamic state. Readbacks are not frequent so this won't hurt other backends.