From a81efdb597c1f39116eb653ac5df6c0d97c80515 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Tue, 12 Jan 2010 23:40:30 +0000 Subject: [PATCH] D3D: Fix some texture wrapping issues by setting the texture state for every texture used at draw time. Hopefully there will not be a noticable slowdown, thanks to the state caching. Also some minor cleanup. Should fix issues like repeated shadows. TODO: In theory it should have worked without this, so I should investigate why this change was needed. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4815 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/BPFunctions.h | 2 +- Source/Core/VideoCommon/Src/BPStructs.cpp | 69 ++++--------------- .../Plugin_VideoDX9/Src/BPFunctions.cpp | 5 +- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 2 +- .../Plugin_VideoDX9/Src/VertexManager.cpp | 3 +- .../Plugin_VideoOGL/Src/BPFunctions.cpp | 2 +- 6 files changed, 19 insertions(+), 64 deletions(-) diff --git a/Source/Core/VideoCommon/Src/BPFunctions.h b/Source/Core/VideoCommon/Src/BPFunctions.h index 1edc506a8c..8c73e076ec 100644 --- a/Source/Core/VideoCommon/Src/BPFunctions.h +++ b/Source/Core/VideoCommon/Src/BPFunctions.h @@ -50,7 +50,7 @@ void ClearScreen(const BPCmd &bp, const EFBRectangle &rc); void RestoreRenderState(const BPCmd &bp); u8 *GetPointer(const u32 &address); bool GetConfig(const int &type); -void SetSamplerState(const BPCmd &bp); +void SetTextureMode(const BPCmd &bp); void SetInterlacingMode(const BPCmd &bp); }; diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp index befd0ad21f..aea5d43c48 100644 --- a/Source/Core/VideoCommon/Src/BPStructs.cpp +++ b/Source/Core/VideoCommon/Src/BPStructs.cpp @@ -430,13 +430,7 @@ void BPWritten(const BPCmd& bp) // Texture Environment Order // ------------------------- case BPMEM_TREF: - case BPMEM_TREF+1: - case BPMEM_TREF+2: - case BPMEM_TREF+3: case BPMEM_TREF+4: - case BPMEM_TREF+5: - case BPMEM_TREF+6: - case BPMEM_TREF+7: break; // ---------------------- // Set wrap size @@ -464,22 +458,13 @@ void BPWritten(const BPCmd& bp) // BPMEM_TX_SETMODE1 - (LOD Stuff) - Max LOD, Min LOD // ------------------------ case BPMEM_TX_SETMODE0: // (0x90 for linear) - case BPMEM_TX_SETMODE0+1: - case BPMEM_TX_SETMODE0+2: - case BPMEM_TX_SETMODE0+3: - SetSamplerState(bp); - case BPMEM_TX_SETMODE1: - case BPMEM_TX_SETMODE1+1: - case BPMEM_TX_SETMODE1+2: - case BPMEM_TX_SETMODE1+3: case BPMEM_TX_SETMODE0_4: - case BPMEM_TX_SETMODE0_4+1: - case BPMEM_TX_SETMODE0_4+2: - case BPMEM_TX_SETMODE0_4+3: + // Shouldn't need to call this here, we call it for each active texture right before rendering + SetTextureMode(bp); + break; + + case BPMEM_TX_SETMODE1: case BPMEM_TX_SETMODE1_4: - case BPMEM_TX_SETMODE1_4+1: - case BPMEM_TX_SETMODE1_4+2: - case BPMEM_TX_SETMODE1_4+3: break; // -------------------------------------------- // BPMEM_TX_SETIMAGE0 - Texture width, height, format @@ -488,51 +473,22 @@ void BPWritten(const BPCmd& bp) // BPMEM_TX_SETIMAGE3 - Address of Texture in main memory // -------------------------------------------- case BPMEM_TX_SETIMAGE0: - case BPMEM_TX_SETIMAGE0+1: - case BPMEM_TX_SETIMAGE0+2: - case BPMEM_TX_SETIMAGE0+3: case BPMEM_TX_SETIMAGE0_4: - case BPMEM_TX_SETIMAGE0_4+1: - case BPMEM_TX_SETIMAGE0_4+2: - case BPMEM_TX_SETIMAGE0_4+3: case BPMEM_TX_SETIMAGE1: - case BPMEM_TX_SETIMAGE1+1: - case BPMEM_TX_SETIMAGE1+2: - case BPMEM_TX_SETIMAGE1+3: case BPMEM_TX_SETIMAGE1_4: - case BPMEM_TX_SETIMAGE1_4+1: - case BPMEM_TX_SETIMAGE1_4+2: - case BPMEM_TX_SETIMAGE1_4+3: case BPMEM_TX_SETIMAGE2: - case BPMEM_TX_SETIMAGE2+1: - case BPMEM_TX_SETIMAGE2+2: - case BPMEM_TX_SETIMAGE2+3: case BPMEM_TX_SETIMAGE2_4: - case BPMEM_TX_SETIMAGE2_4+1: - case BPMEM_TX_SETIMAGE2_4+2: - case BPMEM_TX_SETIMAGE2_4+3: case BPMEM_TX_SETIMAGE3: - case BPMEM_TX_SETIMAGE3+1: - case BPMEM_TX_SETIMAGE3+2: - case BPMEM_TX_SETIMAGE3+3: case BPMEM_TX_SETIMAGE3_4: - case BPMEM_TX_SETIMAGE3_4+1: - case BPMEM_TX_SETIMAGE3_4+2: - case BPMEM_TX_SETIMAGE3_4+3: break; // ------------------------------- // Set a TLUT // BPMEM_TX_SETTLUT - Format, TMEM Offset (offset of TLUT from start of TMEM high bank > > 5) // ------------------------------- case BPMEM_TX_SETTLUT: - case BPMEM_TX_SETTLUT+1: - case BPMEM_TX_SETTLUT+2: - case BPMEM_TX_SETTLUT+3: case BPMEM_TX_SETLUT_4: - case BPMEM_TX_SETLUT_4+1: - case BPMEM_TX_SETLUT_4+2: - case BPMEM_TX_SETLUT_4+3: break; + // --------------------------------------------------- // Set the TEV Color // --------------------------------------------------- @@ -544,15 +500,14 @@ void BPWritten(const BPCmd& bp) case BPMEM_TEV_REGISTER_H+4: case BPMEM_TEV_REGISTER_L+6: // Reg 4 case BPMEM_TEV_REGISTER_H+6: + if (bp.address & 1) // only run this code for the _H! is this right? what if L is set independently? { - if (bp.address & 1) - { - // don't compare with changes! - int num = (bp.address >> 1 ) & 0x3; - PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num); - } - break; + // don't compare with changes! + int num = (bp.address >> 1) & 0x3; + PixelShaderManager::SetColorChanged(bpmem.tevregs[num].high.type, num); } + break; + // ------------------------------------------------ // On Default, we try to look for other things // before we give up and say its an unknown opcode diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp index f8dbf20a5d..3d86f6ee80 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp @@ -140,10 +140,9 @@ u8 *GetPointer(const u32 &address) return g_VideoInitialize.pGetMemoryPointer(address); } -void SetSamplerState(const BPCmd &bp) +void SetTextureMode(const BPCmd &bp) { - int stage = (bp.address & 3);//(addr>>4)&2; - Renderer::SetSamplerState(stage,(bp.address & 0xE0) == 0xA0); + Renderer::SetSamplerState(bp.address & 3, (bp.address & 0xE0) == 0xA0); } void SetInterlacingMode(const BPCmd &bp) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 3e11bea9e2..0a8308befd 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -1059,7 +1059,7 @@ void Renderer::SetLineWidth() D3D::SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&psize)); } -void Renderer::SetSamplerState(int stage,int texindex) +void Renderer::SetSamplerState(int stage, int texindex) { const FourTexUnits &tex = bpmem.tex[texindex]; const TexMode0 &tm0 = tex.texMode0[stage]; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index 651515c901..4344a62da3 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -243,10 +243,11 @@ void Flush() for (int i = 0; i < 8; i++) { if (usedtextures & (1 << i)) { + Renderer::SetSamplerState(i & 3, i >> 2); FourTexUnits &tex = bpmem.tex[i >> 2]; TextureCache::TCacheEntry* tentry = TextureCache::Load(i, (tex.texImage3[i&3].image_base/* & 0x1FFFFF*/) << 5, - tex.texImage0[i&3].width+1, tex.texImage0[i&3].height+1, + tex.texImage0[i&3].width + 1, tex.texImage0[i&3].height + 1, tex.texImage0[i&3].format, tex.texTlut[i&3].tmem_offset<<9, tex.texTlut[i&3].tlut_format); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp index 02cca6592e..6825cd1563 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp @@ -129,7 +129,7 @@ u8 *GetPointer(const u32 &address) return g_VideoInitialize.pGetMemoryPointer(address); } -void SetSamplerState(const BPCmd &bp) +void SetTextureMode(const BPCmd &bp) { // TODO }