diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 1a8bd673d7..9242b8cb3c 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -777,30 +777,17 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra WARN_LOG_ONCE(bta, G3D, "WARNING: Reinterpret encountered with BlueToAlpha on"); } - if (IsBufferFormat16Bit(src->fb_format) && !IsBufferFormat16Bit(dst->fb_format)) { - // We halve the X coordinates in the destination framebuffer. - // The shader will collect two pixels worth of input data and merge into one. - dstX1 *= 0.5f; - dstX2 *= 0.5f; - } else if (!IsBufferFormat16Bit(src->fb_format) && IsBufferFormat16Bit(dst->fb_format)) { - // We double the X coordinates in the destination framebuffer. - // The shader will sample and depending on the X coordinate & 1, use the upper or lower bits. - dstX1 *= 2.0f; - dstX2 *= 2.0f; - } - // Reinterpret! WARN_LOG_N_TIMES(reint, 5, G3D, "Reinterpret detected from %08x_%s to %08x_%s", src->fb_address, GeBufferFormatToString(src->fb_format), dst->fb_address, GeBufferFormatToString(dst->fb_format)); - pipeline = reinterpretFromTo_[(int)src->fb_format][(int)dst->fb_format]; + + float scaleFactorX = 1.0f; + pipeline = GetReinterpretPipeline(src->fb_format, dst->fb_format, &scaleFactorX); + dstX1 *= 0.5f; + dstX2 *= 0.5f; + pass_name = reinterpretStrings[(int)src->fb_format][(int)dst->fb_format]; - if (!pipeline) { - pipeline = draw2D_.Create2DPipeline([=](ShaderWriter &shaderWriter) -> Draw2DPipelineInfo { - return GenerateReinterpretFragmentShader(shaderWriter, src->fb_format, dst->fb_format); - }); - reinterpretFromTo_[(int)src->fb_format][(int)dst->fb_format] = pipeline; - } gpuStats.numReinterpretCopies++; } @@ -823,6 +810,27 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra textureCache_->ForgetLastTexture(); } +Draw2DPipeline *FramebufferManagerCommon::GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX) { + if (IsBufferFormat16Bit(from) && !IsBufferFormat16Bit(to)) { + // We halve the X coordinates in the destination framebuffer. + // The shader will collect two pixels worth of input data and merge into one. + *scaleFactorX = 0.5f; + } else if (!IsBufferFormat16Bit(from) && IsBufferFormat16Bit(to)) { + // We double the X coordinates in the destination framebuffer. + // The shader will sample and depending on the X coordinate & 1, use the upper or lower bits. + *scaleFactorX = 2.0f; + } + + Draw2DPipeline *pipeline = reinterpretFromTo_[(int)from][(int)to]; + if (!pipeline) { + pipeline = draw2D_.Create2DPipeline([=](ShaderWriter &shaderWriter) -> Draw2DPipelineInfo { + return GenerateReinterpretFragmentShader(shaderWriter, from, to); + }); + reinterpretFromTo_[(int)from][(int)to] = pipeline; + } + return pipeline; +} + void FramebufferManagerCommon::DestroyFramebuf(VirtualFramebuffer *v) { // Notify the texture cache of both the color and depth buffers. textureCache_->NotifyFramebuffer(v, NOTIFY_FB_DESTROYED); diff --git a/GPU/Common/FramebufferManagerCommon.h b/GPU/Common/FramebufferManagerCommon.h index b54cc0611d..905996979b 100644 --- a/GPU/Common/FramebufferManagerCommon.h +++ b/GPU/Common/FramebufferManagerCommon.h @@ -421,14 +421,15 @@ public: // Returns the resolved framebuffer. VirtualFramebuffer *ResolveFramebufferColorToFormat(VirtualFramebuffer *vfb, GEBufferFormat newFormat); + Draw2DPipeline *Get2DPipeline(Draw2DShader shader); + Draw2DPipeline *GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX); + protected: virtual void PackFramebufferSync(VirtualFramebuffer *vfb, int x, int y, int w, int h, RasterChannel channel); void SetViewport2D(int x, int y, int w, int h); Draw::Texture *MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height); void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags); - Draw2DPipeline *Get2DPipeline(Draw2DShader shader); - void CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dest); void CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest);