From 437d6d30a0dd3cc1d31fc4763e76a8edff4562b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 31 Aug 2022 11:40:10 +0200 Subject: [PATCH] KillZone: Fix margin detection on the title screen, fixing some glitches. Need more fixes though to fix the shimmer effect. See #6207 comments --- GPU/Common/FramebufferManagerCommon.cpp | 15 +++++++++------ GPU/Common/FramebufferManagerCommon.h | 10 ++++++---- GPU/GPUCommon.cpp | 11 ++++++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 94ebdaf410..3079a6b5a2 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -333,8 +333,11 @@ void GetFramebufferHeuristicInputs(FramebufferHeuristicParams *params, const GPU params->viewportHeight = (int)(fabsf(vpy) * 2.0f); params->regionWidth = gstate.getRegionX2() + 1; params->regionHeight = gstate.getRegionY2() + 1; - params->scissorWidth = gstate.getScissorX2() + 1; - params->scissorHeight = gstate.getScissorY2() + 1; + + params->scissorLeft = gstate.getScissorX1(); + params->scissorTop = gstate.getScissorY1(); + params->scissorRight = gstate.getScissorX2() + 1; + params->scissorBottom = gstate.getScissorY2() + 1; if (gstate.getRegionRateX() != 0x100 || gstate.getRegionRateY() != 0x100) { WARN_LOG_REPORT_ONCE(regionRate, G3D, "Drawing region rate add non-zero: %04x, %04x of %04x, %04x", gstate.getRegionRateX(), gstate.getRegionRateY(), gstate.getRegionX2(), gstate.getRegionY2()); @@ -352,7 +355,7 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(Framebuffer // As there are no clear "framebuffer width" and "framebuffer height" registers, // we need to infer the size of the current framebuffer somehow. 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); + EstimateDrawingSize(params.fb_address, std::max(params.fb_stride, (u16)4), params.fb_format, params.viewportWidth, params.viewportHeight, params.regionWidth, params.regionHeight, params.scissorRight, params.scissorBottom, drawing_width, drawing_height); 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) @@ -2876,10 +2879,10 @@ VirtualFramebuffer *FramebufferManagerCommon::ResolveFramebufferColorToFormat(Vi static void ApplyKillzoneFramebufferSplit(FramebufferHeuristicParams *params, int *drawing_width) { // Detect whether we're rendering to the margin. bool margin; - if (params->scissorWidth == 32) { - // Title screen has this easy case. + if ((params->scissorRight - params->scissorLeft) == 32) { + // Title screen has this easy case. It also uses non-through verts, so lucky for us that we have this. margin = true; - } else if (params->scissorWidth == 480) { + } else if (params->scissorRight == 480) { margin = false; } else { // Go deep, look at the vertices. Killzone-specific, of course. diff --git a/GPU/Common/FramebufferManagerCommon.h b/GPU/Common/FramebufferManagerCommon.h index d7e5a866f0..dad0a887f1 100644 --- a/GPU/Common/FramebufferManagerCommon.h +++ b/GPU/Common/FramebufferManagerCommon.h @@ -165,10 +165,12 @@ struct FramebufferHeuristicParams { bool isBlending; int viewportWidth; int viewportHeight; - int regionWidth; - int regionHeight; - int scissorWidth; - int scissorHeight; + int16_t regionWidth; + int16_t regionHeight; + int16_t scissorLeft; + int16_t scissorTop; + int16_t scissorRight; + int16_t scissorBottom; }; struct GPUgstate; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 476368e1f7..22b323c713 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1686,9 +1686,14 @@ 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); + if (PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { + switch (gstate.vertType & 0xFFFFFF) { + case 0x00800102: // through, u16 uv, u16 pos (used for the framebuffer effect in-game) + case 0x0080011c: // through, 8888 color, s16 pos (used for clearing in the margin of the title screen) + case 0x00000183: // float uv, float pos (used for drawing in the margin of the title screen) + // Need to re-check the framebuffer every one of these draws, to update the split if needed. + gstate_c.Dirty(DIRTY_FRAMEBUF); + } } // This also makes skipping drawing very effective.