From 9b1ee6fce68abb9a0dc95e806dbec72f3f934ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 11 Oct 2017 13:37:00 +0200 Subject: [PATCH] Unify GetFramebuffer in GLES and D3D11. D3D9 is left behind for now, and Vulkan still needs implementation - got a branch with initial work towards that. --- GPU/Common/FramebufferCommon.cpp | 43 +++++++++++++++++++++++++++ GPU/Common/FramebufferCommon.h | 2 +- GPU/D3D11/FramebufferManagerD3D11.cpp | 42 -------------------------- GPU/D3D11/FramebufferManagerD3D11.h | 1 - GPU/GLES/FramebufferManagerGLES.cpp | 43 --------------------------- GPU/GLES/FramebufferManagerGLES.h | 1 - 6 files changed, 44 insertions(+), 88 deletions(-) diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index f1ec9de4a5..a49781ee2d 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -1835,3 +1835,46 @@ void FramebufferManagerCommon::ShowScreenResolution() { host->NotifyUserMessage(messageStream.str(), 2.0f, 0xFFFFFF, "resize"); INFO_LOG(SYSTEM, "%s", messageStream.str().c_str()); } + +bool FramebufferManagerCommon::GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) { + VirtualFramebuffer *vfb = currentRenderVfb_; + if (!vfb) { + vfb = GetVFBAt(fb_address); + } + + if (!vfb) { + // If there's no vfb and we're drawing there, must be memory? + buffer = GPUDebugBuffer(Memory::GetPointer(fb_address | 0x04000000), fb_stride, 512, format); + return true; + } + + int w = vfb->renderWidth, h = vfb->renderHeight; + + Draw::Framebuffer *bound = nullptr; + + if (vfb->fbo) { + if (maxRes > 0 && vfb->renderWidth > vfb->width * maxRes) { + w = vfb->width * maxRes; + h = vfb->height * maxRes; + + Draw::Framebuffer *tempFBO = GetTempFBO(w, h); + VirtualFramebuffer tempVfb = *vfb; + tempVfb.fbo = tempFBO; + tempVfb.bufferWidth = vfb->width; + tempVfb.bufferHeight = vfb->height; + tempVfb.renderWidth = w; + tempVfb.renderHeight = h; + BlitFramebuffer(&tempVfb, 0, 0, vfb, 0, 0, vfb->width, vfb->height, 0); + + bound = tempFBO; + } else { + bound = vfb->fbo; + } + } + + buffer.Allocate(w, h, GE_FORMAT_8888, !useBufferedRendering_, true); + bool retval = draw_->CopyFramebufferToMemorySync(bound, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w); + // We may have blitted to a temp FBO. + RebindFramebuffer(); + return retval; +} diff --git a/GPU/Common/FramebufferCommon.h b/GPU/Common/FramebufferCommon.h index 27aef50cab..0e6ba30a65 100644 --- a/GPU/Common/FramebufferCommon.h +++ b/GPU/Common/FramebufferCommon.h @@ -278,7 +278,7 @@ public: Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth colorDepth = Draw::FBO_8888); // Debug features - virtual bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) = 0; + virtual bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes); virtual bool GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_address, int z_stride, GPUDebugBuffer &buffer) = 0; virtual bool GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) = 0; virtual bool GetOutputFramebuffer(GPUDebugBuffer &buffer) = 0; diff --git a/GPU/D3D11/FramebufferManagerD3D11.cpp b/GPU/D3D11/FramebufferManagerD3D11.cpp index 9f72382682..94cabe7509 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.cpp +++ b/GPU/D3D11/FramebufferManagerD3D11.cpp @@ -875,48 +875,6 @@ void FramebufferManagerD3D11::Resized() { CompilePostShader(); } -// Lots of this code could be shared (like the downsampling). -bool FramebufferManagerD3D11::GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) { - VirtualFramebuffer *vfb = currentRenderVfb_; - if (!vfb) { - vfb = GetVFBAt(fb_address); - } - - if (!vfb) { - // If there's no vfb and we're drawing there, must be memory? - buffer = GPUDebugBuffer(Memory::GetPointer(fb_address | 0x04000000), fb_stride, 512, format); - return true; - } - - int w = vfb->renderWidth, h = vfb->renderHeight; - Draw::Framebuffer *bound = nullptr; - if (vfb->fbo) { - if (maxRes > 0 && vfb->renderWidth > vfb->width * maxRes) { - w = vfb->width * maxRes; - h = vfb->height * maxRes; - - Draw::Framebuffer *tempFBO = GetTempFBO(w, h); - VirtualFramebuffer tempVfb = *vfb; - tempVfb.fbo = tempFBO; - tempVfb.bufferWidth = vfb->width; - tempVfb.bufferHeight = vfb->height; - tempVfb.renderWidth = w; - tempVfb.renderHeight = h; - BlitFramebuffer(&tempVfb, 0, 0, vfb, 0, 0, vfb->width, vfb->height, 0); - - bound = tempFBO; - } else { - bound = vfb->fbo; - } - } - if (!bound) - return false; - - buffer.Allocate(w, h, GE_FORMAT_8888, !useBufferedRendering_, true); - - return draw_->CopyFramebufferToMemorySync(bound, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w); -} - bool FramebufferManagerD3D11::GetDepthStencilBuffer(VirtualFramebuffer *vfb, GPUDebugBuffer &buffer, bool stencil) { int w = vfb->renderWidth, h = vfb->renderHeight; Draw::Framebuffer *fboForRead = nullptr; diff --git a/GPU/D3D11/FramebufferManagerD3D11.h b/GPU/D3D11/FramebufferManagerD3D11.h index 3ef5f5c7bf..dda9419725 100644 --- a/GPU/D3D11/FramebufferManagerD3D11.h +++ b/GPU/D3D11/FramebufferManagerD3D11.h @@ -67,7 +67,6 @@ public: virtual bool NotifyStencilUpload(u32 addr, int size, bool skipZero = false) override; - bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) override; bool GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_address, int z_stride, GPUDebugBuffer &buffer) override; bool GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) override; bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override; diff --git a/GPU/GLES/FramebufferManagerGLES.cpp b/GPU/GLES/FramebufferManagerGLES.cpp index f623120a15..aa1665e3b7 100644 --- a/GPU/GLES/FramebufferManagerGLES.cpp +++ b/GPU/GLES/FramebufferManagerGLES.cpp @@ -1167,49 +1167,6 @@ void FramebufferManagerGLES::Resized() { } } -bool FramebufferManagerGLES::GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) { - VirtualFramebuffer *vfb = currentRenderVfb_; - if (!vfb) { - vfb = GetVFBAt(fb_address); - } - - if (!vfb) { - // If there's no vfb and we're drawing there, must be memory? - buffer = GPUDebugBuffer(Memory::GetPointer(fb_address | 0x04000000), fb_stride, 512, format); - return true; - } - - int w = vfb->renderWidth, h = vfb->renderHeight; - - Draw::Framebuffer *bound = nullptr; - - if (vfb->fbo) { - if (maxRes > 0 && vfb->renderWidth > vfb->width * maxRes) { - w = vfb->width * maxRes; - h = vfb->height * maxRes; - - Draw::Framebuffer *tempFBO = GetTempFBO(w, h); - VirtualFramebuffer tempVfb = *vfb; - tempVfb.fbo = tempFBO; - tempVfb.bufferWidth = vfb->width; - tempVfb.bufferHeight = vfb->height; - tempVfb.renderWidth = w; - tempVfb.renderHeight = h; - BlitFramebuffer(&tempVfb, 0, 0, vfb, 0, 0, vfb->width, vfb->height, 0); - - bound = tempFBO; - } else { - bound = vfb->fbo; - } - } - - buffer.Allocate(w, h, GE_FORMAT_8888, !useBufferedRendering_, true); - bool retval = draw_->CopyFramebufferToMemorySync(bound, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w); - // We may have blitted to a temp FBO. - RebindFramebuffer(); - return retval; -} - bool FramebufferManagerGLES::GetOutputFramebuffer(GPUDebugBuffer &buffer) { int pw = PSP_CoreParameter().pixelWidth; int ph = PSP_CoreParameter().pixelHeight; diff --git a/GPU/GLES/FramebufferManagerGLES.h b/GPU/GLES/FramebufferManagerGLES.h index 7c43c11b24..b860ea92dd 100644 --- a/GPU/GLES/FramebufferManagerGLES.h +++ b/GPU/GLES/FramebufferManagerGLES.h @@ -84,7 +84,6 @@ public: bool NotifyStencilUpload(u32 addr, int size, bool skipZero = false) override; - bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes) override; bool GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_address, int z_stride, GPUDebugBuffer &buffer) override; bool GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) override; bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;