From fd49a1e80a36addc19a5a9ce9419fb3aa4aa58c4 Mon Sep 17 00:00:00 2001 From: iMineLink Date: Sun, 16 Jan 2022 18:15:48 +0100 Subject: [PATCH] GS: preserve target on different format write. affects hardware texture cache. --- pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 40 +++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index e43fc85997..dfbad2ba3d 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -876,11 +876,40 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r } else { - list.erase(j); - GL_CACHE("TC: Remove Target(%s) %d (0x%x)", to_string(type), - t->m_texture ? t->m_texture->GetID() : 0, - t->m_TEX0.TBP0); - delete t; + // YOLO skipping t->m_TEX0.TBW = bw; It would change the surface offset results... + const SurfaceOffset so = ComputeSurfaceOffset(off, r, t); + if (so.is_valid) + { + // Offset from Target to Write in Target coords. + t->m_dirty.push_back(GSDirtyRect(so.b2a_offset, psm, bw)); + GL_CACHE("TC: Dirty in the middle [aggressive] of Target(%s) %d [PSM:%s BP:0x%x->0x%x BW:%u rect(%d,%d=>%d,%d)] write[PSM:%s BP:0x%x BW:%u rect(%d,%d=>%d,%d)]", + to_string(type), + t->m_texture ? t->m_texture->GetID() : 0, + psm_str(t->m_TEX0.PSM), + t->m_TEX0.TBP0, + t->m_end_block, + t->m_TEX0.TBW, + so.b2a_offset.x, + so.b2a_offset.y, + so.b2a_offset.z, + so.b2a_offset.w, + psm_str(psm), + bp, + bw, + r.x, + r.y, + r.z, + r.w + ); + } + else + { + list.erase(j); + GL_CACHE("TC: Remove Target(%s) %d (0x%x)", to_string(type), + t->m_texture ? t->m_texture->GetID() : 0, + t->m_TEX0.TBP0); + delete t; + } continue; } } @@ -894,6 +923,7 @@ void GSTextureCache::InvalidateVideoMem(const GSOffset& off, const GSVector4i& r } // GH: Try to detect texture write that will overlap with a target buffer + // TODO Use ComputeSurfaceOffset below. if (GSUtil::HasSharedBits(psm, t->m_TEX0.PSM)) { if (bp < t->m_TEX0.TBP0)