From 70f7f74a05eeac82fa013f1ea215a22029449254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 31 Aug 2022 01:09:23 +0200 Subject: [PATCH] Check X coordinate of through-mode drawcalls to figure out which of the splits to render to --- GPU/Common/FramebufferManagerCommon.cpp | 36 ++++++++++++++++++++++--- GPU/Common/TextureCacheCommon.cpp | 7 ++++- GPU/GPUCommon.cpp | 5 ++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index d376f2c91e..d4c5a9828d 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -352,7 +352,6 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(Framebuffer int drawing_width, drawing_height; EstimateDrawingSize(params.fb_address, std::max(params.fb_stride, (u16)4), params.fb_format, params.viewportWidth, params.viewportHeight, params.regionWidth, params.regionHeight, params.scissorWidth, params.scissorHeight, drawing_width, drawing_height); - gstate_c.SetCurRTOffset(0, 0); if (params.fb_address == params.z_address) { // Most likely Z will not be used in this pass, as that would wreak havoc (undefined behavior for sure) @@ -362,15 +361,46 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(Framebuffer if (PSP_CoreParameter().compat.flags().SplitFramebufferMargin && params.fb_format == GE_FORMAT_8888) { // Detect whether we're rendering to the margin. - if (params.scissorWidth == 32 || params.scissorWidth == 512) { + bool margin; + if (params.scissorWidth == 32) { + // title screen + margin = true; + } else if (params.scissorWidth == 480) { + margin = false; + } else { + // Go deep, look at the vertices. + margin = false; + if ((gstate.vertType & 0xFFFFFF) == 0x00800102) { // through, u16, s16 + u16 *vdata = (u16 *)Memory::GetPointerUnchecked(gstate_c.vertexAddr); + int v0PosU = vdata[0]; + int v0PosV = vdata[1]; + int v0PosX = vdata[2]; + int v0PosY = vdata[3]; + int v1PosU = vdata[5]; + int v1PosV = vdata[6]; + int v1PosX = vdata[7]; + int v1PosY = vdata[8]; + //INFO_LOG(G3D, "v0: %d, %d (uv = %d, %d)", v0PosX, v0PosY, v0PosU, v0PosV); + //INFO_LOG(G3D, "v1: %d, %d (uv = %d, %d)", v1PosX, v1PosY, v1PosU, v1PosV); + // Texturing from surface to margin + if (v0PosX >= 480 && v0PosU < 480) { + margin = true; + } + } + } + + if (margin) { gstate_c.SetCurRTOffset(-480, 0); // Modify the fb_address and z_address too to avoid matching below. params.fb_address += 480 * 4; params.z_address += 480 * 2; drawing_width = 32; - } else if (params.scissorWidth == 480) { + } else { + gstate_c.SetCurRTOffset(0, 0); drawing_width = 480; } + } else { + gstate_c.SetCurRTOffset(0, 0); } // Find a matching framebuffer. diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 8f4e08a12f..c707bb549f 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -952,7 +952,12 @@ bool TextureCacheCommon::MatchFramebuffer( } } - if (matchInfo->yOffset + minSubareaHeight >= framebuffer->height) { + if (matchInfo->yOffset > 0 && matchInfo->yOffset + minSubareaHeight >= framebuffer->height) { + // Can't be inside the framebuffer. + return false; + } + + if (matchInfo->yOffset < 0 && matchInfo->yOffset - minSubareaHeight <= 0) { // Can't be inside the framebuffer. return false; } diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index f3dac1eabd..476368e1f7 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1686,6 +1686,11 @@ void GPUCommon::Execute_Prim(u32 op, u32 diff) { } } + if ((gstate.vertType & 0xFFFFFF) == 0x00800102 && PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { + // Need to re-check the framebuffer every draw. + gstate_c.Dirty(DIRTY_FRAMEBUF); + } + // This also makes skipping drawing very effective. VirtualFramebuffer *vfb = framebufferManager_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason); if (blueToAlpha) {