From 78b2848622085043bf07d79eabd238428bdf89df Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 25 Sep 2016 11:51:48 +0200 Subject: [PATCH] gsdx: factorize the TEX0 generation for mipmap --- plugins/GSdx/GSRendererHW.cpp | 48 +++----------------------- plugins/GSdx/GSRendererSW.cpp | 64 ++--------------------------------- plugins/GSdx/GSState.cpp | 54 +++++++++++++++++++++++++++++ plugins/GSdx/GSState.h | 1 + 4 files changed, 62 insertions(+), 105 deletions(-) diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index 857fdb5197..e842895893 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -484,7 +484,6 @@ void GSRendererHW::Draw() const GSLocalMemory::psm_t& tex_psm = GSLocalMemory::m_psm[m_context->TEX0.PSM]; int lod = 0; GIFRegCLAMP MIP_CLAMP = context->CLAMP; - TEX0 = m_context->TEX0; // Code from the SW renderer if (IsMipMapActive()) { @@ -513,54 +512,13 @@ void GSRendererHW::Draw() lod = std::max((int)round(m_vt.m_lod.x), 0); } + TEX0 = GetTex0Layer(lod); + MIP_CLAMP.MINU >>= lod; MIP_CLAMP.MINV >>= lod; MIP_CLAMP.MAXU >>= lod; MIP_CLAMP.MAXV >>= lod; - switch(lod) - { - case 0: - break; - case 1: - TEX0.TBP0 = m_context->MIPTBP1.TBP1; - TEX0.TBW = m_context->MIPTBP1.TBW1; - break; - case 2: - TEX0.TBP0 = m_context->MIPTBP1.TBP2; - TEX0.TBW = m_context->MIPTBP1.TBW2; - break; - case 3: - TEX0.TBP0 = m_context->MIPTBP1.TBP3; - TEX0.TBW = m_context->MIPTBP1.TBW3; - break; - case 4: - TEX0.TBP0 = m_context->MIPTBP2.TBP4; - TEX0.TBW = m_context->MIPTBP2.TBW4; - break; - case 5: - TEX0.TBP0 = m_context->MIPTBP2.TBP5; - TEX0.TBW = m_context->MIPTBP2.TBW5; - break; - case 6: - TEX0.TBP0 = m_context->MIPTBP2.TBP6; - TEX0.TBW = m_context->MIPTBP2.TBW6; - break; - default: - __assume(0); - } - - if (TEX0.TH <= lod) { - TEX0.TH = 1; - } else { - TEX0.TH -= lod; - } - if (TEX0.TW <= lod) { - TEX0.TW = 1; - } else { - TEX0.TW -= lod; - } - for (int i = 0; i < lod; i++) { m_vt.m_min.t *= 0.5f; m_vt.m_max.t *= 0.5f; @@ -569,6 +527,8 @@ void GSRendererHW::Draw() m_context->offset.tex = m_mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM); GL_INS("Mipmap LOD %d (%f %f) new size %dx%d", lod, m_vt.m_lod.x, m_vt.m_lod.y, 1 << TEX0.TW, 1 << TEX0.TH); + } else { + TEX0 = GetTex0Layer(0); } diff --git a/plugins/GSdx/GSRendererSW.cpp b/plugins/GSdx/GSRendererSW.cpp index 1baaeb1f02..f99e3ff042 100644 --- a/plugins/GSdx/GSRendererSW.cpp +++ b/plugins/GSdx/GSRendererSW.cpp @@ -1201,7 +1201,6 @@ bool GSRendererSW::GetScanlineGlobalData(SharedData* data) gd.k = GSVector4((float)k); } - GIFRegTEX0 MIP_TEX0 = TEX0; GIFRegCLAMP MIP_CLAMP = context->CLAMP; GSVector4 tmin = m_vt.m_min.t; @@ -1211,38 +1210,7 @@ bool GSRendererSW::GetScanlineGlobalData(SharedData* data) for(int i = 1, j = std::min((int)context->TEX1.MXL, 6); i <= j; i++) { - switch(i) - { - case 1: - MIP_TEX0.TBP0 = context->MIPTBP1.TBP1; - MIP_TEX0.TBW = context->MIPTBP1.TBW1; - break; - case 2: - MIP_TEX0.TBP0 = context->MIPTBP1.TBP2; - MIP_TEX0.TBW = context->MIPTBP1.TBW2; - break; - case 3: - MIP_TEX0.TBP0 = context->MIPTBP1.TBP3; - MIP_TEX0.TBW = context->MIPTBP1.TBW3; - break; - case 4: - MIP_TEX0.TBP0 = context->MIPTBP2.TBP4; - MIP_TEX0.TBW = context->MIPTBP2.TBW4; - break; - case 5: - MIP_TEX0.TBP0 = context->MIPTBP2.TBP5; - MIP_TEX0.TBW = context->MIPTBP2.TBW5; - break; - case 6: - MIP_TEX0.TBP0 = context->MIPTBP2.TBP6; - MIP_TEX0.TBW = context->MIPTBP2.TBW6; - break; - default: - __assume(0); - } - - if(MIP_TEX0.TW > 0) MIP_TEX0.TW--; - if(MIP_TEX0.TH > 0) MIP_TEX0.TH--; + const GIFRegTEX0& MIP_TEX0 = GetTex0Layer(i); MIP_CLAMP.MINU >>= 1; MIP_CLAMP.MINV >>= 1; @@ -1670,35 +1638,9 @@ void GSRendererSW::SharedData::UpdateSource() { for(size_t i = 0; m_tex[i].t != NULL; i++) { - int TBP0 = 0; - switch(i) - { - case 0: - TBP0 = m_parent->m_context->TEX0.TBP0; - break; - case 1: - TBP0 = m_parent->m_context->MIPTBP1.TBP1; - break; - case 2: - TBP0 = m_parent->m_context->MIPTBP1.TBP2; - break; - case 3: - TBP0 = m_parent->m_context->MIPTBP1.TBP3; - break; - case 4: - TBP0 = m_parent->m_context->MIPTBP2.TBP4; - break; - case 5: - TBP0 = m_parent->m_context->MIPTBP2.TBP5; - break; - case 6: - TBP0 = m_parent->m_context->MIPTBP2.TBP6; - break; - default: - __assume(0); - } + const GIFRegTEX0& TEX0 = m_parent->GetTex0Layer(i); - s = format("%05d_f%lld_tex%d_%05x_%s.bmp", m_parent->s_n - 2, frame, i, TBP0, psm_str((int)m_parent->m_context->TEX0.PSM)); + s = format("%05d_f%lld_tex%d_%05x_%s.bmp", m_parent->s_n - 2, frame, i, TEX0.TBP0, psm_str(TEX0.PSM)); m_tex[i].t->Save(root_sw+s); } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 69852da404..8ddbf311e2 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -3084,6 +3084,60 @@ bool GSState::IsMipMapActive() return m_mipmap && m_context->TEX1.MXL > 0 && m_context->TEX1.MMIN >= 2 && m_context->TEX1.MMIN <= 5 && m_vt.m_lod.y > 0; } +GIFRegTEX0 GSState::GetTex0Layer(int lod) +{ + // Shortcut + if (lod == 0) { + return m_context->TEX0; + } + + GIFRegTEX0 TEX0 = m_context->TEX0; + + switch(lod) + { + case 1: + TEX0.TBP0 = m_context->MIPTBP1.TBP1; + TEX0.TBW = m_context->MIPTBP1.TBW1; + break; + case 2: + TEX0.TBP0 = m_context->MIPTBP1.TBP2; + TEX0.TBW = m_context->MIPTBP1.TBW2; + break; + case 3: + TEX0.TBP0 = m_context->MIPTBP1.TBP3; + TEX0.TBW = m_context->MIPTBP1.TBW3; + break; + case 4: + TEX0.TBP0 = m_context->MIPTBP2.TBP4; + TEX0.TBW = m_context->MIPTBP2.TBW4; + break; + case 5: + TEX0.TBP0 = m_context->MIPTBP2.TBP5; + TEX0.TBW = m_context->MIPTBP2.TBW5; + break; + case 6: + TEX0.TBP0 = m_context->MIPTBP2.TBP6; + TEX0.TBW = m_context->MIPTBP2.TBW6; + break; + default: + __assume(0); + } + + // Correct the texture size + if (TEX0.TH <= lod) { + TEX0.TH = 1; + } else { + TEX0.TH -= lod; + } + if (TEX0.TW <= lod) { + TEX0.TW = 1; + } else { + TEX0.TW -= lod; + } + + return TEX0; +} + // GSTransferBuffer GSState::GSTransferBuffer::GSTransferBuffer() diff --git a/plugins/GSdx/GSState.h b/plugins/GSdx/GSState.h index b6d824fae4..9d00be5958 100644 --- a/plugins/GSdx/GSState.h +++ b/plugins/GSdx/GSState.h @@ -204,6 +204,7 @@ protected: bool TryAlphaTest(uint32& fm, uint32& zm); bool IsOpaque(); bool IsMipMapActive(); + GIFRegTEX0 GetTex0Layer(int lod); public: GIFPath m_path[4];