From 194c4b0286956e9da1e1d997fb2e6e6c96bdb460 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 27 Nov 2022 21:15:15 -0800 Subject: [PATCH] TexCache: Support offset in rendered CLUTs. We already copy to a temp, so just use that copy to normalize out the offset. Should even get RECT2LIN correct, but most cases are 1 pixel high anyway. --- GPU/Common/TextureCacheCommon.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 86134f14c6..fda7533fdf 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1250,6 +1250,10 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { VirtualFramebuffer *chosenFramebuffer = nullptr; for (VirtualFramebuffer *framebuffer : framebuffers) { + // Let's not deal with divide by zero. + if (framebuffer->fb_stride == 0) + continue; + const u32 fb_address = framebuffer->fb_address; const u32 fb_bpp = BufferFormatBytesPerPixel(framebuffer->fb_format); int offset = clutLoadAddr - fb_address; @@ -1302,12 +1306,18 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { dynamicClutTemp_ = draw_->CreateFramebuffer(desc); } + // We'll need to copy from the offset. + const u32 fb_bpp = BufferFormatBytesPerPixel(chosenFramebuffer->fb_format); + const int totalPixelsOffset = clutRenderOffset_ / fb_bpp; + const int clutYOffset = totalPixelsOffset / chosenFramebuffer->fb_stride; + const int clutXOffset = totalPixelsOffset % chosenFramebuffer->fb_stride; + const int scale = chosenFramebuffer->renderScaleFactor; + // Copy the pixels to our temp clut, scaling down if needed and wrapping. - // TODO: Take the clutRenderOffset_ into account here. framebufferManager_->BlitUsingRaster( - chosenFramebuffer->fbo, 0.0f, 0.0f, 512.0f * chosenFramebuffer->renderScaleFactor, 1.0f, + chosenFramebuffer->fbo, clutXOffset * scale, clutYOffset * scale, (clutXOffset + 512.0f) * scale, (clutYOffset + 1.0f) * scale, dynamicClutTemp_, 0.0f, 0.0f, 512.0f, 1.0f, - false, chosenFramebuffer->renderScaleFactor, framebufferManager_->Get2DPipeline(DRAW2D_COPY_COLOR_RECT2LIN), "copy_clut_to_temp"); + false, scale, framebufferManager_->Get2DPipeline(DRAW2D_COPY_COLOR_RECT2LIN), "copy_clut_to_temp"); framebufferManager_->RebindFramebuffer("after_copy_clut_to_temp"); clutRenderFormat_ = chosenFramebuffer->fb_format;