From 43a81a3cb16c2e4dccd920a844f4f5da5efef5f2 Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Fri, 4 Jul 2025 00:17:40 +0100 Subject: [PATCH] GS/HW: Add CRC for Turok wrong width clear --- bin/resources/GameIndex.yaml | 6 ++++++ pcsx2/GS/Renderers/HW/GSHwHack.cpp | 22 ++++++++++++++++++++++ pcsx2/GS/Renderers/HW/GSHwHack.h | 1 + 3 files changed, 29 insertions(+) diff --git a/bin/resources/GameIndex.yaml b/bin/resources/GameIndex.yaml index 8d20180af0..f07befa8a8 100644 --- a/bin/resources/GameIndex.yaml +++ b/bin/resources/GameIndex.yaml @@ -15195,7 +15195,9 @@ SLES-50479: region: "PAL-M4" compat: 5 gsHWFixes: + halfPixelOffset: 2 # Fixes depth/fog lines. textureInsideRT: 1 # Fixes underwater levels. + getSkipCount: "GSC_Turok" SLES-50480: name: "Aggressive Inline" region: "PAL-M4" @@ -16704,7 +16706,9 @@ SLES-51124: region: "PAL-G" compat: 5 gsHWFixes: + halfPixelOffset: 2 # Fixes depth/fog lines. textureInsideRT: 1 # Fixes underwater levels. + getSkipCount: "GSC_Turok" SLES-51125: name: "Sega Soccer Slam" region: "PAL-E" @@ -64136,7 +64140,9 @@ SLUS-20333: region: "NTSC-U" compat: 5 gsHWFixes: + halfPixelOffset: 2 # Fixes depth/fog lines. textureInsideRT: 1 # Fixes underwater levels. + getSkipCount: "GSC_Turok" SLUS-20334: name: "Kelly Slater's Pro Surfer" region: "NTSC-U" diff --git a/pcsx2/GS/Renderers/HW/GSHwHack.cpp b/pcsx2/GS/Renderers/HW/GSHwHack.cpp index 9bec498f29..8cbb2f4524 100644 --- a/pcsx2/GS/Renderers/HW/GSHwHack.cpp +++ b/pcsx2/GS/Renderers/HW/GSHwHack.cpp @@ -822,6 +822,27 @@ bool GSHwHack::GSC_MetalGearSolid3(GSRendererHW& r, int& skip) return true; } +bool GSHwHack::GSC_Turok(GSRendererHW& r, int& skip) +{ + // Turok does some very silly clears where it will set the alpha channel with a 512x512 draw, then decides the image is actually 640x448 later, this causes havok for the texture cache and target end blocks. + // Since we can't look in to the future to check this, the options are either rearrange all the pages in a target when the width changes + // (very slow, could break a ton of stuff which stores different things in the alpha channel), or this. I choose this. + + if (r.m_index.tail == 6 && RPRIM->PRIM == 4 && !RTME && RFBMSK == 0x00FFFFFF && floor(r.m_vt.m_max.p.x) == 512 && r.m_env.CTXT[r.m_backed_up_ctx].FRAME.FBW == 10 && RFRAME.FBW == 8 && RFPSM == PSMCT32 && RTEST.ATE && RTEST.ATST == ATST_GEQUAL) + { + int num_pages = r.m_cached_ctx.FRAME.FBW * ((floor(r.m_vt.m_max.p.y) + 31) / 32); + r.m_cached_ctx.FRAME.FBW = 10; + // Round them up to fill the row, it later reads the bottom right corner clamped, but because we can't rearrange it ends up reading the black square. + num_pages = ((num_pages + 9) / 10) * 10; + + r.ReplaceVerticesWithSprite( + r.GetDrawRectForPages(r.m_cached_ctx.FRAME.FBW, r.m_cached_ctx.FRAME.PSM, num_pages), + GSVector2i(1, 1)); + } + + return true; +} + bool GSHwHack::OI_PointListPalette(GSRendererHW& r, GSTexture* rt, GSTexture* ds, GSTextureCache::Source* t) { const u32 n_vertices = r.m_vertex.next; @@ -1312,6 +1333,7 @@ const GSHwHack::Entry GSHwHack::s_get_skip_count_function CRC_F(GSC_PolyphonyDigitalGames), CRC_F(GSC_MetalGearSolid3), CRC_F(GSC_Battlefield2), + CRC_F(GSC_Turok), // Channel Effect CRC_F(GSC_NamcoGames), diff --git a/pcsx2/GS/Renderers/HW/GSHwHack.h b/pcsx2/GS/Renderers/HW/GSHwHack.h index 9b32701f3d..440829bfb4 100644 --- a/pcsx2/GS/Renderers/HW/GSHwHack.h +++ b/pcsx2/GS/Renderers/HW/GSHwHack.h @@ -26,6 +26,7 @@ public: static bool GSC_Battlefield2(GSRendererHW& r, int& skip); static bool GSC_PolyphonyDigitalGames(GSRendererHW& r, int& skip); static bool GSC_MetalGearSolid3(GSRendererHW& r, int& skip); + static bool GSC_Turok(GSRendererHW& r, int& skip); static bool OI_PointListPalette(GSRendererHW& r, GSTexture* rt, GSTexture* ds, GSTextureCache::Source* t); static bool OI_DBZBTGames(GSRendererHW& r, GSTexture* rt, GSTexture* ds, GSTextureCache::Source* t);