From 2c55cce6ba930821edb6707633588cc7e728cd3a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 20 Oct 2022 19:34:07 +1000 Subject: [PATCH] GS/TextureCache: Use Inside() for checking display target The existing code was adding however many pages the framebuffer crossed unconditionally, when practically this last row will only be read when the height isn't page-aligned. --- pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 8a3d559ab9..e8124a3032 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -485,18 +485,13 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, con // 2nd try ! Try to find a frame that include the bp if (!dst) { - const int page_width = std::max(1, (real_w / psm_s.pgs.x)); - const int page_height = std::max(1, (real_h / psm_s.pgs.y)); - const int pitch = (std::max(1U, TEX0.TBW) * 64) / psm_s.pgs.x; - const u32 end_bp = bp + ((page_width << 5) + ((page_height * pitch) << 5)); - for (auto t : list) { // Make sure the target is inside the texture - if (t->m_TEX0.TBP0 < bp && bp <= t->m_end_block && end_bp > t->m_TEX0.TBP0 && end_bp <= t->m_end_block) + if (t->m_TEX0.TBP0 <= bp && bp <= t->m_end_block && t->Inside(bp, TEX0.TBW, TEX0.PSM, GSVector4i(0, 0, real_w, real_h))) { dst = t; - GL_CACHE("TC: Lookup Frame %dx%d, inclusive hit: %d (0x%x, took 0x%x -> 0x%x %s endbp 0x%x)", size.x, size.y, t->m_texture->GetID(), bp, t->m_TEX0.TBP0, t->m_end_block, psm_str(TEX0.PSM), end_bp); + GL_CACHE("TC: Lookup Frame %dx%d, inclusive hit: %d (0x%x, took 0x%x -> 0x%x %s)", size.x, size.y, t->m_texture->GetID(), bp, t->m_TEX0.TBP0, t->m_end_block, psm_str(TEX0.PSM)); if (real_h > 0 || real_w > 0) ScaleTargetForDisplay(dst, TEX0, real_w, real_h);