From e3ca5833d03c1b4860b69ac49a707dcb4435307e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 20 Jan 2024 14:09:15 +1000 Subject: [PATCH] GS/HW: Fix false positive on shared bits with double-half clears --- pcsx2/GS/Renderers/HW/GSRendererHW.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp index 2760b4cb6c..aa0db5beb0 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.cpp @@ -5931,7 +5931,11 @@ bool GSRendererHW::DetectDoubleHalfClear(bool& no_rt, bool& no_ds) if (half > (base + written_pages) || half <= base) return false; + // CoD: World at War draws a shadow map with RGB masked at the same page as the depth buffer, which is + // double-half cleared. For testing, ignore any targets that don't have the bits we're drawing to. + const bool req_valid_alpha = ((frame_psm.fmsk & zbuf_psm.fmsk) & 0xFF000000u) != 0; GSTextureCache::Target* half_point = g_texture_cache->GetExactTarget(half << 5, m_cached_ctx.FRAME.FBW, clear_depth ? GSTextureCache::RenderTarget : GSTextureCache::DepthStencil, half << 5); + half_point = (half_point && half_point->m_valid_rgb && half_point->HasValidAlpha() == req_valid_alpha) ? half_point : nullptr; if (half_point && half_point->m_age <= 1) return false; @@ -5978,10 +5982,12 @@ bool GSRendererHW::DetectDoubleHalfClear(bool& no_rt, bool& no_ds) // Check for a target matching the starting point. It might be in Z or FRAME... GSTextureCache::Target* tgt = g_texture_cache->GetTargetWithSharedBits( base * BLOCKS_PER_PAGE, clear_depth ? m_cached_ctx.ZBUF.PSM : m_cached_ctx.FRAME.PSM); + tgt = (tgt && tgt->m_valid_rgb && tgt->HasValidAlpha() == req_valid_alpha) ? tgt : nullptr; if (!tgt) { tgt = g_texture_cache->GetTargetWithSharedBits( base * BLOCKS_PER_PAGE, clear_depth ? m_cached_ctx.FRAME.PSM : m_cached_ctx.ZBUF.PSM); + tgt = (tgt && tgt->m_valid_rgb && tgt->HasValidAlpha() == req_valid_alpha) ? tgt : nullptr; } u32 end_block = ((half + written_pages) * BLOCKS_PER_PAGE) - 1;