From ad08701cb1867703580f13ebed94974cef2471a9 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 24 Apr 2016 20:30:54 +0200 Subject: [PATCH] gsdx tc: trick the texture cache to use a depth format for depth texture This way we avoid the rescaling of the depth buffer and texture allocation. --- plugins/GSdx/GSRendererOGL.cpp | 4 +++- plugins/GSdx/GSTextureCache.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 1b575065a6..b994f3ac6a 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -873,7 +873,9 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour if (tex) { - const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM]; + // Warning fetch the texture PSM format rather than the context format. The latter could have been corrected in the texture cache for depth. + //const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM]; + const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[tex->m_TEX0.PSM]; const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[m_context->TEX0.CPSM] : psm; bool bilinear = m_filter == 2 ? m_vt.IsLinear() : m_filter != 0; bool simple_sample = !tex->m_palette && cpsm.fmt == 0 && m_context->CLAMP.WMS < 2 && m_context->CLAMP.WMT < 2 && !psm.depth; diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 6d36daebe3..a48d779310 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -295,8 +295,14 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const GIFRegTEX0& TEX0, con if(!t->m_age && t->m_used && t->m_dirty.empty() && GSUtil::HasSharedBits(bp, psm, t->m_TEX0.TBP0, t->m_TEX0.PSM)) { GL_INS("TC: Warning depth format read as color format. Pixels will be scrambled"); - dst = t; - break; + //dst = t; + //break; + // Let's fetch a depth format texture. Rational, it will avoid the texture allocation and the + // rescaling of the current function. + GIFRegTEX0 depth_TEX0; + depth_TEX0.u32[0] = TEX0.u32[0] | (0x30u << 20u); + depth_TEX0.u32[1] = TEX0.u32[1]; + return LookupDepthSource(depth_TEX0, TEXA, r); } } }