From db8feac8c3671c3e29b0403cb495e589f86e53de Mon Sep 17 00:00:00 2001 From: gabest11 Date: Wed, 3 Jun 2009 22:45:28 +0000 Subject: [PATCH] GSdx: the BeginScene/EndScene optimization for dx9 (Issue 256) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1312 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GSDevice.h | 16 ++++++++-------- plugins/GSdx/GSDevice9.cpp | 8 ++++++-- plugins/GSdx/GSTextureFX10.cpp | 9 ++++++++- plugins/GSdx/GSTextureFX9.cpp | 10 ++++++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index a9229c8455..41502653f8 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -78,15 +78,15 @@ public: virtual bool IsLost() {return false;} virtual void Present(const GSVector4i& r, int shader); - virtual void Flip() {}; + virtual void Flip() {} - virtual void BeginScene() {}; - virtual void EndScene() {}; + virtual void BeginScene() {} + virtual void EndScene() {} - virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {}; - virtual void ClearRenderTarget(GSTexture* t, uint32 c) {}; - virtual void ClearDepth(GSTexture* t, float c) {}; - virtual void ClearStencil(GSTexture* t, uint8 c) {}; + virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {} + virtual void ClearRenderTarget(GSTexture* t, uint32 c) {} + virtual void ClearDepth(GSTexture* t, float c) {} + virtual void ClearStencil(GSTexture* t, uint8 c) {} virtual GSTexture* CreateRenderTarget(int w, int h, int format = 0); virtual GSTexture* CreateDepthStencil(int w, int h, int format = 0); @@ -105,5 +105,5 @@ public: void Interlace(const GSVector2i& ds, int field, int mode, float yoffset); virtual void PSSetShaderResources(GSTexture* sr0, GSTexture* sr1) {} - virtual void OMSetRenderTargets(GSTexture* rt, GSTexture* ds) {}; + virtual void OMSetRenderTargets(GSTexture* rt, GSTexture* ds) {} }; diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 443b1e56b5..af728d7b42 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -349,6 +349,8 @@ bool GSDevice9::IsLost() void GSDevice9::Flip() { + m_dev->EndScene(); + if(m_swapchain) { m_swapchain->Present(NULL, NULL, NULL, NULL, 0); @@ -357,11 +359,13 @@ void GSDevice9::Flip() { m_dev->Present(NULL, NULL, NULL, NULL); } + + m_dev->BeginScene(); } void GSDevice9::BeginScene() { - m_dev->BeginScene(); + // m_dev->BeginScene(); } void GSDevice9::DrawPrimitive() @@ -393,7 +397,7 @@ void GSDevice9::DrawPrimitive() void GSDevice9::EndScene() { - m_dev->EndScene(); + // m_dev->EndScene(); m_vertices.start += m_vertices.count; m_vertices.count = 0; diff --git a/plugins/GSdx/GSTextureFX10.cpp b/plugins/GSdx/GSTextureFX10.cpp index 6afc9b114d..dd223a508e 100644 --- a/plugins/GSdx/GSTextureFX10.cpp +++ b/plugins/GSdx/GSTextureFX10.cpp @@ -143,7 +143,8 @@ bool GSTextureFX10::SetupVS(VSSelector sel, const VSConstantBuffer* cb) } m_vs[sel] = vs; - i = m_vs.find( sel ); + + i = m_vs.find(sel); } if(m_vs_cb_cache.Update(cb)) @@ -247,9 +248,11 @@ void GSTextureFX10::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSampl }; CComPtr ps; + hr = m_dev->CompileShader(IDR_TFX10_FX, "ps_main", macro, &ps); m_ps[sel] = ps; + i = m_ps.find(sel); } @@ -364,9 +367,11 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, } CComPtr dss; + hr = (*m_dev)->CreateDepthStencilState(&dsd, &dss); m_om_dss[dssel] = dss; + i = m_om_dss.find(dssel); } @@ -503,9 +508,11 @@ void GSTextureFX10::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, if(bsel.wa) bd.RenderTargetWriteMask[0] |= D3D10_COLOR_WRITE_ENABLE_ALPHA; CComPtr bs; + hr = (*m_dev)->CreateBlendState(&bd, &bs); m_om_bs[bsel] = bs; + j = m_om_bs.find(bsel); } diff --git a/plugins/GSdx/GSTextureFX9.cpp b/plugins/GSdx/GSTextureFX9.cpp index be2aaeec2d..5a28c42b3e 100644 --- a/plugins/GSdx/GSTextureFX9.cpp +++ b/plugins/GSdx/GSTextureFX9.cpp @@ -135,10 +135,11 @@ bool GSTextureFX9::SetupVS(VSSelector sel, const VSConstantBuffer* cb) } m_vs[sel] = vs; - i = m_vs.find( sel ); + + i = m_vs.find(sel); } - m_dev->VSSetShader( (*i).second, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); + m_dev->VSSetShader((*i).second, (const float*)cb, sizeof(*cb) / sizeof(GSVector4)); return true; } @@ -218,9 +219,11 @@ void GSTextureFX9::UpdatePS(PSSelector sel, const PSConstantBuffer* cb, PSSample }; CComPtr ps; + hr = m_dev->CompileShader(IDR_TFX9_FX, "ps_main", macro, &ps); m_ps[sel] = ps; + i = m_ps.find(sel); } @@ -313,6 +316,7 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, } m_om_dss[dssel] = dss; + i = m_om_dss.find(dssel); } @@ -323,6 +327,7 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, if(j == m_om_bs.end()) { Direct3DBlendState9* bs = new Direct3DBlendState9(); + memset(bs, 0, sizeof(*bs)); bs->BlendEnable = bsel.abe; @@ -448,6 +453,7 @@ void GSTextureFX9::UpdateOM(OMDepthStencilSelector dssel, OMBlendSelector bsel, if(bsel.wa) bs->RenderTargetWriteMask |= D3DCOLORWRITEENABLE_ALPHA; m_om_bs[bsel] = bs; + j = m_om_bs.find(bsel); }