From 26759578512cae1d0479925b459c28de41046708 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Fri, 4 Dec 2009 04:50:49 +0000 Subject: [PATCH] GSdx: Implement DX9 "on the fly" vsync enabler/disabler, and fix some dx9 vsync bugs in legacy gui (hopefully) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2302 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GS.cpp | 3 +++ plugins/GSdx/GSDevice9.cpp | 23 ++++++++++++++++------- plugins/GSdx/GSDevice9.h | 2 ++ plugins/GSdx/GSRenderer.cpp | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index 0a01121225..cdaeb1e287 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -257,6 +257,7 @@ EXPORT_C_(INT32) GSopen(void* dsp, char* title, int mt) { int renderer; + // Legacy GUI expects to acquire vsync from the configuration files. s_vsync = !!theApp.GetConfig("vsync", 0); if(mt == 2) @@ -573,6 +574,8 @@ EXPORT_C GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) uint8 regs[0x2000]; GSsetBaseMem(regs); + s_vsync = !!theApp.GetConfig("vsync", 0); + HWND hWnd = NULL; _GSopen(&hWnd, "", renderer); diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 7fb4b54aef..7d007c9298 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -239,6 +239,19 @@ bool GSDevice9::Create(GSWnd* wnd) return true; } +void GSDevice9::SetVsync(bool enable) +{ + if( m_vsync == enable ) return; + __super::SetVsync(enable); + + // Clever trick: Delete the backbuffer, so that the next Present will fail and + // cause a DXDevice9::Reset call, which re-creates the backbuffer with current + // vsync settings. :) + + delete m_backbuffer; + m_backbuffer = NULL; +} + bool GSDevice9::Reset(int w, int h) { if(!__super::Reset(w, h)) @@ -260,6 +273,7 @@ bool GSDevice9::Reset(int w, int h) m_pp.BackBufferWidth = w; m_pp.BackBufferHeight = h; + m_pp.PresentationInterval = m_vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; hr = m_dev->CreateAdditionalSwapChain(&m_pp, &m_swapchain); @@ -296,12 +310,7 @@ bool GSDevice9::Reset(int w, int h) m_pp.BackBufferFormat = D3DFMT_X8R8G8B8; m_pp.BackBufferWidth = 1; m_pp.BackBufferHeight = 1; - m_pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - - if(m_vsync) - { - m_pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // was D3DPRESENT_INTERVAL_DEFAULT, but ONE is like more "forceful"! - } + m_pp.PresentationInterval = m_vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; // m_pp.Flags |= D3DPRESENTFLAG_VIDEO; // enables tv-out (but I don't think anyone would still use a regular tv...) @@ -309,7 +318,7 @@ bool GSDevice9::Reset(int w, int h) int mh = theApp.GetConfig("ModeHeight", 0); int mrr = theApp.GetConfig("ModeRefreshRate", 0); - if(!m_wnd->IsManaged() && mode == Fullscreen && mw > 0 && mh > 0 && mrr >= 0) + if(m_wnd->IsManaged() && mode == Fullscreen && mw > 0 && mh > 0 && mrr >= 0) { m_pp.Windowed = FALSE; m_pp.BackBufferWidth = mw; diff --git a/plugins/GSdx/GSDevice9.h b/plugins/GSdx/GSDevice9.h index 58d0831c9d..ea37664621 100644 --- a/plugins/GSdx/GSDevice9.h +++ b/plugins/GSdx/GSDevice9.h @@ -153,6 +153,8 @@ public: bool Reset(int w, int h); bool IsLost(bool update); void Flip(); + + void SetVsync(bool enable); void BeginScene(); void DrawPrimitive(); diff --git a/plugins/GSdx/GSRenderer.cpp b/plugins/GSdx/GSRenderer.cpp index bc56b4b71c..93322b75dd 100644 --- a/plugins/GSdx/GSRenderer.cpp +++ b/plugins/GSdx/GSRenderer.cpp @@ -284,7 +284,7 @@ void GSRenderer::SetFrameLimit(bool limit) void GSRenderer::SetVsync(bool enabled) { m_vsync = enabled; - if( m_dev ) m_dev->SetVsync(m_vsync && m_framelimit); + if( m_dev ) m_dev->SetVsync(m_vsync); }