diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index f6889e5cb0..8a33791337 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1162,6 +1162,24 @@ bool TextureCacheCommon::SetOffsetTexture(u32 yOffset) { } } +bool TextureCacheCommon::GetCurrentFramebufferTextureDebug(GPUDebugBuffer &buffer) { + if (!nextFramebufferTexture_) + 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"); + + // 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. + gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); + // We may have blitted to a temp FBO. + framebufferManager_->RebindFramebuffer("RebindFramebuffer - GetCurrentTextureDebug"); + if (!retval) + ERROR_LOG(G3D, "Failed to get debug texture: copy to memory failed"); + return retval; +} + void TextureCacheCommon::NotifyConfigChanged() { int scaleFactor = g_Config.iTexScalingLevel; diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 48c44d981f..996f0003e8 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -399,6 +399,7 @@ protected: bool GetBestFramebufferCandidate(const TextureDefinition &entry, u32 texAddrOffset, AttachCandidate *bestCandidate) const; void SetTextureFramebuffer(const AttachCandidate &candidate); + bool GetCurrentFramebufferTextureDebug(GPUDebugBuffer &buffer); virtual void BoundFramebufferTexture() {} diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 8d051c915c..50eca0200f 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -456,21 +456,7 @@ DXGI_FORMAT TextureCacheD3D11::GetDestFormat(GETextureFormat format, GEPaletteFo bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { SetTexture(); if (!nextTexture_) { - if (nextFramebufferTexture_) { - 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"); - // 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. - gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); - // We may have blitted to a temp FBO. - framebufferManager_->RebindFramebuffer("RebindFramebuffer - GetCurrentTextureDebug"); - if (!retval) - ERROR_LOG(G3D, "Failed to get debug texture: copy to memory failed"); - return retval; - } else { - return false; - } + return GetCurrentFramebufferTextureDebug(buffer); } // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 0870299ac5..bbb7934da1 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -364,6 +364,10 @@ D3DFORMAT TextureCacheDX9::GetDestFormat(GETextureFormat format, GEPaletteFormat bool TextureCacheDX9::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { SetTexture(); + if (!nextTexture_) { + return GetCurrentFramebufferTextureDebug(buffer); + } + ApplyTexture(); LPDIRECT3DBASETEXTURE9 baseTex; diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 83309208b8..e9591736cf 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -389,22 +389,7 @@ bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) InvalidateLastTexture(); SetTexture(); if (!nextTexture_) { - if (nextFramebufferTexture_) { - 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"); - // 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. - gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); - // We may have blitted to a temp FBO. - framebufferManager_->RebindFramebuffer("RebindFramebuffer - GetCurrentTextureDebug"); - if (!retval) - ERROR_LOG(G3D, "Failed to get debug texture: copy to memory failed"); - return retval; - } else { - ERROR_LOG(G3D, "Failed to get debug texture: no texture set"); - return false; - } + return GetCurrentFramebufferTextureDebug(buffer); } // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer. diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 75b067cc40..670a469cb6 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -777,21 +777,7 @@ void TextureCacheVulkan::BoundFramebufferTexture() { bool TextureCacheVulkan::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) { SetTexture(); if (!nextTexture_) { - if (nextFramebufferTexture_) { - 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"); - // 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. - gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); - // We may have blitted to a temp FBO. - framebufferManager_->RebindFramebuffer("RebindFramebuffer - GetCurrentTextureDebug"); - if (!retval) - ERROR_LOG(G3D, "Failed to get debug texture: copy to memory failed"); - return retval; - } else { - return false; - } + return GetCurrentFramebufferTextureDebug(buffer); } // Apply texture may need to rebuild the texture if we're about to render, or bind a framebuffer.