From 870194db210af424f77fb694f8e8e534435d8585 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Thu, 14 Aug 2008 19:57:46 +0000 Subject: [PATCH] Attempt to fix recent D3D plugin issue. Fix bug in debugger *<:-) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@198 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/Src/PowerPC/Jit64/Jit_LoadStore.cpp | 18 ++-- Source/Core/DebuggerWX/src/CodeWindow.cpp | 4 +- Source/Core/DolphinWX/src/Frame.cpp | 2 + .../Plugins/Plugin_VideoDX9/Src/D3DBase.cpp | 4 +- .../Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp | 100 ++++++++++++------ Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 2 +- 6 files changed, 81 insertions(+), 49 deletions(-) diff --git a/Source/Core/Core/Src/PowerPC/Jit64/Jit_LoadStore.cpp b/Source/Core/Core/Src/PowerPC/Jit64/Jit_LoadStore.cpp index a58094d941..64fad84c0c 100644 --- a/Source/Core/Core/Src/PowerPC/Jit64/Jit_LoadStore.cpp +++ b/Source/Core/Core/Src/PowerPC/Jit64/Jit_LoadStore.cpp @@ -83,8 +83,8 @@ namespace Jit64 if (!Core::GetStartupParameter().bUseDualCore && inst.OPCD == 32 && (inst.hex & 0xFFFF0000) == 0x800D0000 && - Memory::ReadUnchecked_U32(js.compilerPC+4) == 0x28000000 && - Memory::ReadUnchecked_U32(js.compilerPC+8) == 0x4182fff8) + Memory::ReadUnchecked_U32(js.compilerPC + 4) == 0x28000000 && + Memory::ReadUnchecked_U32(js.compilerPC + 8) == 0x4182fff8) { gpr.Flush(FLUSH_ALL); fpr.Flush(FLUSH_ALL); @@ -209,6 +209,8 @@ namespace Jit64 if (gpr.R(a).IsImm() && !update) { + // If we already know the address through constant folding, we can do some + // fun tricks... u32 addr = (u32)gpr.R(a).offset; addr += offset; if ((addr & 0xFFFFF000) == 0xCC008000 && jo.optimizeGatherPipe) @@ -219,6 +221,7 @@ namespace Jit64 switch (accessSize) { // No need to protect these, they don't touch any state + // question - should we inline them instead? Pro: Lose a CALL Con: Code bloat case 8: CALL((void *)Asm::fifoDirectWrite8); break; case 16: CALL((void *)Asm::fifoDirectWrite16); break; case 32: CALL((void *)Asm::fifoDirectWrite32); break; @@ -240,7 +243,7 @@ namespace Jit64 } // Optimized stack access? - if (accessSize == 32 && !gpr.R(a).IsImm() && a == 1 && js.st.isFirstBlockOfFunction && jo.optimizeStack) //Zelda does not like this + if (accessSize == 32 && !gpr.R(a).IsImm() && a == 1 && js.st.isFirstBlockOfFunction && jo.optimizeStack) { gpr.FlushLockX(ABI_PARAM1); MOV(32, R(ABI_PARAM1), gpr.R(a)); @@ -272,14 +275,7 @@ namespace Jit64 } TEST(32, R(ABI_PARAM2), Imm32(0x0C000000)); FixupBranch unsafe_addr = J_CC(CC_NZ); - if (accessSize == 32) - BSWAP(32, ABI_PARAM1); - else if (accessSize == 16) - { - // TODO(ector): xchg ch, cl? - BSWAP(32, ABI_PARAM1); - SHR(32, R(ABI_PARAM1), Imm8(16)); - } + BSWAP(accessSize, ABI_PARAM1); #ifdef _M_X64 MOV(accessSize, MComplex(RBX, ABI_PARAM2, SCALE_1, 0), R(ABI_PARAM1)); #else diff --git a/Source/Core/DebuggerWX/src/CodeWindow.cpp b/Source/Core/DebuggerWX/src/CodeWindow.cpp index 76fc8c60b6..544175552d 100644 --- a/Source/Core/DebuggerWX/src/CodeWindow.cpp +++ b/Source/Core/DebuggerWX/src/CodeWindow.cpp @@ -420,8 +420,6 @@ void CCodeWindow::Update() UpdateButtonStates(); - codeview->Center(PC); - Host_UpdateLogDisplay(); } @@ -676,7 +674,7 @@ void CCodeWindow::PopulateToolbar(wxToolBar* toolBar) toolBar->AddTool(IDM_STEPOVER, _T("Step Over"), m_Bitmaps[Toolbar_StepOver]); toolBar->AddTool(IDM_SKIP, _T("Skip"), m_Bitmaps[Toolbar_Skip]); toolBar->AddSeparator(); - toolBar->AddTool(IDM_GOTOPC, _T("Goto PC"), m_Bitmaps[Toolbar_GotoPC]); + toolBar->AddTool(IDM_GOTOPC, _T("Show PC"), m_Bitmaps[Toolbar_GotoPC]); toolBar->AddTool(IDM_SETPC, _T("Set PC"), m_Bitmaps[Toolbar_SetPC]); toolBar->AddSeparator(); toolBar->AddControl(new wxTextCtrl(toolBar, IDM_ADDRBOX, _T(""))); diff --git a/Source/Core/DolphinWX/src/Frame.cpp b/Source/Core/DolphinWX/src/Frame.cpp index 7aab820a8e..5716a9b2d7 100644 --- a/Source/Core/DolphinWX/src/Frame.cpp +++ b/Source/Core/DolphinWX/src/Frame.cpp @@ -368,6 +368,8 @@ CFrame::InitBitmaps() void CFrame::OnOpen(wxCommandEvent& WXUNUSED (event)) { + if (Core::GetState() != Core::CORE_UNINITIALIZED) + return; wxString path = wxFileSelector( _T("Select the file to load"), wxEmptyString, wxEmptyString, wxEmptyString, diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp index c12a4ac07b..c1cd8b75c4 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp @@ -206,7 +206,7 @@ namespace D3D adapter, D3DDEVTYPE_HAL, wnd, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_MULTITHREADED, + D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, // |D3DCREATE_MULTITHREADED /* | D3DCREATE_PUREDEVICE*/, //D3DCREATE_SOFTWARE_VERTEXPROCESSING , &d3dpp, &dev ) ) ) @@ -220,7 +220,7 @@ namespace D3D adapter, D3DDEVTYPE_HAL, wnd, - D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_MULTITHREADED, + D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, // |D3DCREATE_MULTITHREADED /* | D3DCREATE_PUREDEVICE*/, //D3DCREATE_SOFTWARE_VERTEXPROCESSING , &d3dpp, &dev ) ) ) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp index 10129b3240..7f5d2141a0 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp @@ -29,27 +29,7 @@ namespace D3D m_pTexture = NULL; m_pVB = NULL; } - - const int RS[6][2] = - { - { D3DRS_ALPHABLENDENABLE, TRUE }, - { D3DRS_SRCBLEND, D3DBLEND_SRCALPHA }, - { D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA }, - { D3DRS_CULLMODE, D3DCULL_NONE }, - { D3DRS_ZENABLE, FALSE }, - { D3DRS_FOGENABLE, FALSE }, - }; - const int TS[6][2] = - { - {D3DTSS_COLOROP, D3DTOP_MODULATE}, - {D3DTSS_COLORARG1, D3DTA_TEXTURE}, - {D3DTSS_COLORARG2, D3DTA_DIFFUSE }, - {D3DTSS_ALPHAOP, D3DTOP_MODULATE }, - {D3DTSS_ALPHAARG1, D3DTA_TEXTURE }, - {D3DTSS_ALPHAARG2, D3DTA_DIFFUSE }, - }; - - enum {m_dwTexWidth=512, m_dwTexHeight = 512}; + enum {m_dwTexWidth = 512, m_dwTexHeight = 512}; int CD3DFont::Init() { @@ -171,22 +151,77 @@ namespace D3D return S_OK; } + + const int RS[6][2] = + { + { D3DRS_ALPHABLENDENABLE, TRUE }, + { D3DRS_SRCBLEND, D3DBLEND_SRCALPHA }, + { D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA }, + { D3DRS_CULLMODE, D3DCULL_NONE }, + { D3DRS_ZENABLE, FALSE }, + { D3DRS_FOGENABLE, FALSE }, + }; + const int TS[6][2] = + { + {D3DTSS_COLOROP, D3DTOP_MODULATE}, + {D3DTSS_COLORARG1, D3DTA_TEXTURE}, + {D3DTSS_COLORARG2, D3DTA_DIFFUSE }, + {D3DTSS_ALPHAOP, D3DTOP_MODULATE }, + {D3DTSS_ALPHAARG1, D3DTA_TEXTURE }, + {D3DTSS_ALPHAARG2, D3DTA_DIFFUSE }, + }; + + static DWORD RS_old[6]; + static DWORD TS_old[6]; + static LPDIRECT3DBASETEXTURE9 texture_old; + static DWORD FVF_old; + static LPDIRECT3DVERTEXDECLARATION9 decl_old; + static LPDIRECT3DPIXELSHADER9 ps_old; + static LPDIRECT3DVERTEXSHADER9 vs_old; + + void SaveRenderStates() + { + for (int i = 0; i < 6; i++) { + dev->GetRenderState((_D3DRENDERSTATETYPE)RS[i][0], &(RS_old[i])); + dev->GetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), &(TS_old[i])); + } + dev->GetTexture(0, &texture_old); + dev->GetPixelShader(&ps_old); + dev->GetVertexShader(&vs_old); + dev->GetVertexDeclaration(&decl_old); + dev->GetFVF(&FVF_old); + } + void CD3DFont::SetRenderStates() { - for (int i=0; i<6; i++) + dev->SetTexture(0, m_pTexture); + dev->SetPixelShader(0); + dev->SetVertexShader(0); + dev->SetVertexDeclaration(0); + dev->SetFVF(D3DFVF_FONT2DVERTEX); + for (int i = 0; i < 6; i++) { dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0],RS[i][1]); - for (int i=0; i<6; i++) - dev->SetTextureStageState(0,(_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]),TS[i][1]); + dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]); + } + } + + void RestoreRenderStates() + { + dev->SetTexture(0, texture_old); + dev->SetPixelShader(ps_old); + dev->SetVertexShader(vs_old); + dev->SetVertexDeclaration(decl_old); + dev->SetFVF(FVF_old); + for (int i = 0; i < 6; i++) { + dev->SetRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS_old[i]); + dev->SetTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS_old[i]); + } } int CD3DFont::DrawTextScaled( float x, float y, float fXScale, float fYScale, float spacing, int dwColor, const char* strText, bool center ) { + SaveRenderStates(); SetRenderStates(); - dev->SetTexture( 0, m_pTexture ); - dev->SetPixelShader(0); - dev->SetVertexShader(0); - dev->SetVertexDeclaration(0); - dev->SetFVF( D3DFVF_FONT2DVERTEX ); dev->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) ); float vpWidth = 1; @@ -228,7 +263,7 @@ namespace D3D } float offset=-maxx/2; - strText=oldstrText; + strText = oldstrText; //Then let's draw it if (center) { @@ -293,13 +328,13 @@ namespace D3D m_pVB->Unlock(); if( dwNumTriangles > 0 ) dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles ); - - dev->SetRenderState(D3DRS_ZENABLE,TRUE); + RestoreRenderStates(); return S_OK; } void quad2d(float x1, float y1, float x2, float y2, DWORD color, float u1, float v1, float u2, float v2) { + SaveRenderStates(); struct Q2DVertex { float x,y,z,rhw; int color; float u, v; } coords[4] = { {x1-0.5f, y1-0.5f, 0, 1, color, u1, v1}, {x2-0.5f, y1-0.5f, 0, 1, color, u2, v1}, @@ -311,6 +346,7 @@ namespace D3D dev->SetVertexDeclaration(0); dev->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1); dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,coords,sizeof(Q2DVertex)); + RestoreRenderStates(); } } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index d53045fc23..60ddb2c528 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -103,7 +103,7 @@ void Renderer::ProcessMessages() if(time_left<0) alpha=0; } - alpha<<=24; + alpha <<= 24; RenderText(it->str, left+1, top+1, 0x000000|alpha); RenderText(it->str, left, top, 0xffff30|alpha);