From 2d812deb845bac828595d3d6a3e4b64c6009ff64 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 8 Jun 2015 09:44:47 +0200 Subject: [PATCH] gsdx-tc: Depth and Target are interchangeable on the GS !!! Extend the texture cache to search Color target in Depth target --- plugins/GSdx/GSTextureCache.cpp | 51 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 5ce6f6bef7..c924af9252 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -240,38 +240,43 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int GL_CACHE("TC: Lookup Target(T%d) %dx%d, hit: %d (0x%x)", type, w, h, dst->m_texture->GetID(), bp); dst->Update(); - } else { + } else if (CanConvertDepth()) { - if (type == DepthStencil && CanConvertDepth()) { - // Depth stencil can be an older RT but only check recent RT to avoid to pick - // some bad data. - for(list::iterator i = m_dst[RenderTarget].begin(); i != m_dst[RenderTarget].end(); i++) + int rev_type = (type == DepthStencil) ? RenderTarget : DepthStencil; + GSVector4 sRect(0, 0, 1.0, 1.0); + GSVector4 dRect(0, 0, w, h); + + // Depth stencil/RT can be an older RT/DS but only check recent RT/DS to avoid to pick + // some bad data. + + for(list::iterator i = m_dst[rev_type].begin(); i != m_dst[rev_type].end(); i++) + { + Target* t = *i; + + if(!t->m_age && bp == t->m_TEX0.TBP0) { - Target* t = *i; - - if(!t->m_age && bp == t->m_TEX0.TBP0) - { + dst = CreateTarget(TEX0, w, h, type); + if (type == DepthStencil) { GL_CACHE("TC: Lookup Target(Depth) %dx%d, hit Color (0x%x)", w, h, bp); - // Convert the RenderTarget into a Depth Buffer - dst = CreateTarget(TEX0, w, h, type); - GSVector4 sRect(0, 0, 1.0, 1.0); - GSVector4 dRect(0, 0, w, h); m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, 12, false); + } else { + GL_CACHE("TC: Lookup Target(Color) %dx%d, hit Depth (0x%x)", w, h, bp); + m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, 11, false); } + + break; } } + } + + if(dst == NULL) + { + GL_CACHE("TC: Lookup Target(T%d) %dx%d, miss (0x%x)", type, w, h, bp); + + dst = CreateTarget(TEX0, w, h, type); if(dst == NULL) - { - GL_CACHE("TC: Lookup Target(T%d) %dx%d, miss (0x%x)", type, w, h, bp); - - dst = CreateTarget(TEX0, w, h, type); - - if(dst == NULL) - { - return NULL; - } - } + return NULL; } if(m_renderer->CanUpscale())