From c274d4e43c6a2d8cd8607ead7105195528bf3009 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sat, 31 Oct 2009 01:06:23 +0000 Subject: [PATCH] GSdx: Cleanups to the vsync framelimiter linkage. Ensures that the vsync settings are preserved across plugin shutdown/init, and removes a lot of function parameter mess trying to pass a single parameter across some 6-8 classes and 4 nested function calls. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2099 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GPURenderer.cpp | 5 +++-- plugins/GSdx/GS.cpp | 6 +++++- plugins/GSdx/GSDevice.cpp | 8 ++++---- plugins/GSdx/GSDevice.h | 7 ++++--- plugins/GSdx/GSDevice10.cpp | 8 ++++---- plugins/GSdx/GSDevice10.h | 4 ++-- plugins/GSdx/GSDevice11.cpp | 8 ++++---- plugins/GSdx/GSDevice11.h | 4 ++-- plugins/GSdx/GSDevice7.cpp | 8 ++++---- plugins/GSdx/GSDevice7.h | 4 ++-- plugins/GSdx/GSDevice9.cpp | 6 +++--- plugins/GSdx/GSDevice9.h | 4 ++-- plugins/GSdx/GSDeviceDX.h | 8 ++++---- plugins/GSdx/GSDeviceNull.cpp | 4 ++-- plugins/GSdx/GSDeviceNull.h | 2 +- plugins/GSdx/GSDeviceOGL.cpp | 33 +++++++++++++++++++-------------- plugins/GSdx/GSDeviceOGL.h | 7 ++++--- plugins/GSdx/GSRenderer.cpp | 11 +++++++++-- plugins/GSdx/GSRenderer.h | 3 +++ plugins/GSdx/GSState.cpp | 7 +------ plugins/GSdx/GSState.h | 1 - 21 files changed, 82 insertions(+), 66 deletions(-) diff --git a/plugins/GSdx/GPURenderer.cpp b/plugins/GSdx/GPURenderer.cpp index 670c9d9c92..4b6076dbf9 100644 --- a/plugins/GSdx/GPURenderer.cpp +++ b/plugins/GSdx/GPURenderer.cpp @@ -69,11 +69,12 @@ bool GPURenderer::Create(HWND hWnd) m_wnd.Show(); - if(!m_dev->Create(&m_wnd, m_vsync)) + if(!m_dev->Create(&m_wnd)) { return false; } + m_dev->SetVsync(m_vsync); Reset(); return true; @@ -162,7 +163,7 @@ void GPURenderer::VSync() GetClientRect(m_hWnd, r); - m_dev->Present(r.fit(m_aspectratio), 0, true); + m_dev->Present(r.fit(m_aspectratio), 0); } bool GPURenderer::MakeSnapshot(const string& path) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index 53075ab624..3e61855f27 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -39,6 +39,7 @@ static GSRenderer* s_gs = NULL; static void (*s_irq)() = NULL; static uint8* s_basemem = NULL; static int s_renderer = -1; +static bool s_framelimit = true; EXPORT_C_(uint32) PS2EgetLibType() { @@ -441,9 +442,12 @@ EXPORT_C GSsetFrameSkip(int frameskip) s_gs->SetFrameSkip(frameskip); } + EXPORT_C GSsetFrameLimit(int limit) { - s_gs->SetFrameLimit(limit != 0); + s_framelimit = limit != 0; + if( s_gs ) + s_gs->SetFrameLimit(s_framelimit); } #ifdef _WINDOWS diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index 1939fb4d9d..6f3377eddc 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -25,6 +25,7 @@ GSDevice::GSDevice() : m_wnd(NULL) + , m_vsync(false) , m_rbswapped(false) , m_backbuffer(NULL) , m_merge(NULL) @@ -51,10 +52,9 @@ GSDevice::~GSDevice() delete m_1x1; } -bool GSDevice::Create(GSWnd* wnd, bool vsync) +bool GSDevice::Create(GSWnd* wnd) { m_wnd = wnd; - m_vsync = vsync; return true; } @@ -82,7 +82,7 @@ bool GSDevice::Reset(int w, int h) return m_wnd != NULL; } -void GSDevice::Present(const GSVector4i& r, int shader, bool limit) +void GSDevice::Present(const GSVector4i& r, int shader) { GSVector4i cr = m_wnd->GetClientRect(); @@ -106,7 +106,7 @@ void GSDevice::Present(const GSVector4i& r, int shader, bool limit) StretchRect(m_current, m_backbuffer, GSVector4(r), s_shader[shader]); } - Flip(limit); + Flip(); } GSTexture* GSDevice::Fetch(int type, int w, int h, bool msaa, int format) diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index 197c63a6ee..7a7b6f7f0d 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -80,15 +80,16 @@ public: enum {Windowed, Fullscreen, DontCare}; - virtual bool Create(GSWnd* wnd, bool vsync); + virtual bool Create(GSWnd* wnd); virtual bool Reset(int w, int h); virtual bool IsLost(bool update = false) {return false;} - virtual void Present(const GSVector4i& r, int shader, bool limit); - virtual void Flip(bool limit) {} + virtual void Present(const GSVector4i& r, int shader); + virtual void Flip() {} virtual void BeginScene() {} virtual void DrawPrimitive() {}; virtual void EndScene(); + virtual void SetVsync(bool enable) { m_vsync = enable; } virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {} virtual void ClearRenderTarget(GSTexture* t, uint32 c) {} diff --git a/plugins/GSdx/GSDevice10.cpp b/plugins/GSdx/GSDevice10.cpp index d6f5c2cb6d..42fc3c7304 100644 --- a/plugins/GSdx/GSDevice10.cpp +++ b/plugins/GSdx/GSDevice10.cpp @@ -38,9 +38,9 @@ GSDevice10::~GSDevice10() { } -bool GSDevice10::Create(GSWnd* wnd, bool vsync) +bool GSDevice10::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } @@ -260,9 +260,9 @@ bool GSDevice10::Reset(int w, int h) return true; } -void GSDevice10::Flip(bool limit) +void GSDevice10::Flip() { - m_swapchain->Present(m_vsync && limit ? 1 : 0, 0); + m_swapchain->Present(m_vsync, 0); } void GSDevice10::DrawPrimitive() diff --git a/plugins/GSdx/GSDevice10.h b/plugins/GSdx/GSDevice10.h index 9546786ce4..58b6fa1e27 100644 --- a/plugins/GSdx/GSDevice10.h +++ b/plugins/GSdx/GSDevice10.h @@ -107,10 +107,10 @@ public: GSDevice10(); virtual ~GSDevice10(); - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool CreateTextureFX(); bool Reset(int w, int h); - void Flip(bool limit); + void Flip(); void DrawPrimitive(); diff --git a/plugins/GSdx/GSDevice11.cpp b/plugins/GSdx/GSDevice11.cpp index 866c40c799..2e2d788901 100644 --- a/plugins/GSdx/GSDevice11.cpp +++ b/plugins/GSdx/GSDevice11.cpp @@ -38,9 +38,9 @@ GSDevice11::~GSDevice11() { } -bool GSDevice11::Create(GSWnd* wnd, bool vsync) +bool GSDevice11::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } @@ -251,9 +251,9 @@ bool GSDevice11::Reset(int w, int h) return true; } -void GSDevice11::Flip(bool limit) +void GSDevice11::Flip() { - m_swapchain->Present(m_vsync && limit ? 1 : 0, 0); + m_swapchain->Present(m_vsync, 0); } void GSDevice11::DrawPrimitive() diff --git a/plugins/GSdx/GSDevice11.h b/plugins/GSdx/GSDevice11.h index 44459556d7..427cf2331e 100644 --- a/plugins/GSdx/GSDevice11.h +++ b/plugins/GSdx/GSDevice11.h @@ -109,10 +109,10 @@ public: GSDevice11(); virtual ~GSDevice11(); - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool CreateTextureFX(); bool Reset(int w, int h); - void Flip(bool limit); + void Flip(); void DrawPrimitive(); diff --git a/plugins/GSdx/GSDevice7.cpp b/plugins/GSdx/GSDevice7.cpp index 312e48fda9..5d0a907c21 100644 --- a/plugins/GSdx/GSDevice7.cpp +++ b/plugins/GSdx/GSDevice7.cpp @@ -33,9 +33,9 @@ GSDevice7::~GSDevice7() { } -bool GSDevice7::Create(GSWnd* wnd, bool vsync) +bool GSDevice7::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } @@ -136,7 +136,7 @@ bool GSDevice7::Reset(int w, int h) return true; } -void GSDevice7::Present(const GSVector4i& r, int shader, bool limit) +void GSDevice7::Present(const GSVector4i& r, int shader) { HRESULT hr; @@ -177,7 +177,7 @@ void GSDevice7::Present(const GSVector4i& r, int shader, bool limit) MapWindowPoints((HWND)m_wnd->GetHandle(), HWND_DESKTOP, (POINT*)&r2, 2); - if(m_vsync && limit) + if(m_vsync) { hr = m_dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); } diff --git a/plugins/GSdx/GSDevice7.h b/plugins/GSdx/GSDevice7.h index c395839720..81d2540c48 100644 --- a/plugins/GSdx/GSDevice7.h +++ b/plugins/GSdx/GSDevice7.h @@ -40,8 +40,8 @@ public: GSDevice7(); virtual ~GSDevice7(); - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool Reset(int w, int h); bool IsLost(bool update) {return m_lost;} - void Present(const GSVector4i& r, int shader, bool limit); + void Present(const GSVector4i& r, int shader); }; diff --git a/plugins/GSdx/GSDevice9.cpp b/plugins/GSdx/GSDevice9.cpp index 059e231e4a..4c088aaf20 100644 --- a/plugins/GSdx/GSDevice9.cpp +++ b/plugins/GSdx/GSDevice9.cpp @@ -50,9 +50,9 @@ GSDevice9::~GSDevice9() if(m_state.ps_cb) _aligned_free(m_state.ps_cb); } -bool GSDevice9::Create(GSWnd* wnd, bool vsync) +bool GSDevice9::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } @@ -377,7 +377,7 @@ bool GSDevice9::IsLost(bool update) return m_lost; } -void GSDevice9::Flip(bool limit) +void GSDevice9::Flip() { m_dev->EndScene(); diff --git a/plugins/GSdx/GSDevice9.h b/plugins/GSdx/GSDevice9.h index 735f914473..36734feb28 100644 --- a/plugins/GSdx/GSDevice9.h +++ b/plugins/GSdx/GSDevice9.h @@ -141,10 +141,10 @@ public: GSDevice9(); virtual ~GSDevice9(); - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool Reset(int w, int h); bool IsLost(bool update); - void Flip(bool limit); + void Flip(); void BeginScene(); void DrawPrimitive(); diff --git a/plugins/GSdx/GSDeviceDX.h b/plugins/GSdx/GSDeviceDX.h index 269f2a106e..eb2d906a90 100644 --- a/plugins/GSdx/GSDeviceDX.h +++ b/plugins/GSdx/GSDeviceDX.h @@ -262,9 +262,9 @@ public: GSDeviceDX() {}; virtual ~GSDeviceDX() {} - virtual bool Create(GSWnd* wnd, bool vsync) + virtual bool Create(GSWnd* wnd) { - return __super::Create( wnd, vsync ); + return __super::Create( wnd ); } virtual bool Reset(int w, int h) @@ -272,8 +272,8 @@ public: return __super::Reset( w, h ); } - //virtual void Present(const GSVector4i& r, int shader, bool limit); - //virtual void Flip(bool limit) {} + //virtual void Present(const GSVector4i& r, int shader); + //virtual void Flip() {} virtual void SetupIA(const void* vertices, int count, int prim) = 0; virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0; diff --git a/plugins/GSdx/GSDeviceNull.cpp b/plugins/GSdx/GSDeviceNull.cpp index 8acda26b25..061e5ca571 100644 --- a/plugins/GSdx/GSDeviceNull.cpp +++ b/plugins/GSdx/GSDeviceNull.cpp @@ -22,9 +22,9 @@ #include "stdafx.h" #include "GSDeviceNull.h" -bool GSDeviceNull::Create(GSWnd* wnd, bool vsync) +bool GSDeviceNull::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } diff --git a/plugins/GSdx/GSDeviceNull.h b/plugins/GSdx/GSDeviceNull.h index bfe96e77d7..d360d4ac28 100644 --- a/plugins/GSdx/GSDeviceNull.h +++ b/plugins/GSdx/GSDeviceNull.h @@ -35,6 +35,6 @@ private: public: GSDeviceNull() {} - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool Reset(int w, int h); }; diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 332d4d1b43..65dbb9b866 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -66,9 +66,9 @@ void GSDeviceOGL::OnCgError(CGcontext ctx, CGerror err) printf("%s\n", cgGetLastListing(ctx)); // ? } -bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync) +bool GSDeviceOGL::Create(GSWnd* wnd) { - if(!__super::Create(wnd, vsync)) + if(!__super::Create(wnd)) { return false; } @@ -115,15 +115,6 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync) return false; } - #ifdef _WINDOWS - - if(WGLEW_EXT_swap_control) - { - wglSwapIntervalEXT(vsync ? 1 : 0); - } - - #endif - const char* vendor = (const char*)glGetString(GL_VENDOR); const char* renderer = (const char*)glGetString(GL_RENDERER); const char* version = (const char*)glGetString(GL_VERSION); @@ -155,6 +146,20 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync) return true; } +void GSDeviceOGL::SetVsync(bool enable) +{ + __super::SetVsync(enable); + +#ifdef _WINDOWS + + if(WGLEW_EXT_swap_control) + { + wglSwapIntervalEXT(m_vsync ? 1 : 0); + } + +#endif +} + bool GSDeviceOGL::Reset(int w, int h) { if(!__super::Reset(w, h)) @@ -185,16 +190,16 @@ bool GSDeviceOGL::Reset(int w, int h) return true; } -void GSDeviceOGL::Present(const GSVector4i& r, int shader, bool limit) +void GSDeviceOGL::Present(const GSVector4i& r, int shader) { glBindFramebuffer(GL_FRAMEBUFFER, 0); CheckError(); // TODO: m_current => backbuffer - Flip(limit); + Flip(); } -void GSDeviceOGL::Flip(bool limit) +void GSDeviceOGL::Flip() { #ifdef _WINDOWS diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index ca847428ea..306aa16856 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -109,10 +109,11 @@ public: GSDeviceOGL(); virtual ~GSDeviceOGL(); - bool Create(GSWnd* wnd, bool vsync); + bool Create(GSWnd* wnd); bool Reset(int w, int h); - void Present(const GSVector4i& r, int shader, bool limit); - void Flip(bool limit); + void Present(const GSVector4i& r, int shader); + void Flip(); + void SetVsync(bool enable); void DrawPrimitive(); diff --git a/plugins/GSdx/GSRenderer.cpp b/plugins/GSdx/GSRenderer.cpp index 94288e23e1..71043d03c9 100644 --- a/plugins/GSdx/GSRenderer.cpp +++ b/plugins/GSdx/GSRenderer.cpp @@ -77,12 +77,13 @@ bool GSRenderer::CreateDevice(GSDevice* dev) ASSERT(dev); ASSERT(!m_dev); - if(!dev->Create(&m_wnd, m_vsync)) + if(!dev->Create(&m_wnd)) { return false; } m_dev = dev; + m_dev->SetVsync( m_vsync && m_framelimit ); return true; } @@ -271,6 +272,12 @@ bool GSRenderer::Merge(int field) return true; } +void GSRenderer::SetFrameLimit(bool limit) +{ + m_framelimit = limit; + if( m_dev ) m_dev->SetVsync(m_vsync && m_framelimit); +} + void GSRenderer::VSync(int field) { GSPerfMonAutoTimer pmat(m_perfmon); @@ -343,7 +350,7 @@ void GSRenderer::VSync(int field) // present - m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader, m_framelimit); + m_dev->Present(m_wnd.GetClientRect().fit(m_aspectratio), m_shader); // snapshot diff --git a/plugins/GSdx/GSRenderer.h b/plugins/GSdx/GSRenderer.h index acbc572e89..6018442230 100644 --- a/plugins/GSdx/GSRenderer.h +++ b/plugins/GSdx/GSRenderer.h @@ -46,6 +46,7 @@ protected: bool m_nativeres; bool m_aa1; bool m_blur; + bool m_framelimit; uint8* m_tex_buff; @@ -94,6 +95,8 @@ public: return m_upscale_multiplier; } + void SetFrameLimit(bool limit); + // TODO : Implement proper locking here *if needed* (not sure yet if it is) --air uint8* GetTextureBufferLock() { return m_tex_buff; } void ReleaseTextureBufferLock() { } diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index 05d2e0a4ea..99b0e4e40a 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -33,7 +33,6 @@ GSState::GSState() , m_vprim(1) , m_version(5) , m_frameskip(0) - , m_framelimit(true) , m_vkf(NULL) { m_sssize = 0; @@ -1617,6 +1616,7 @@ int GSState::Defrost(const GSFreezeData* fd) if(version > m_version) { + fprintf(stderr, "GSdx: Savestate version is incompatible. Load aborted.\n" ); return -1; } @@ -1776,11 +1776,6 @@ void GSState::SetFrameSkip(int skip) } } -void GSState::SetFrameLimit(bool limit) -{ - m_framelimit = limit; -} - // GSTransferBuffer GSState::GSTransferBuffer::GSTransferBuffer() diff --git a/plugins/GSdx/GSState.h b/plugins/GSdx/GSState.h index 3ebc631638..202fb2e8a8 100644 --- a/plugins/GSdx/GSState.h +++ b/plugins/GSdx/GSState.h @@ -249,7 +249,6 @@ public: void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;} virtual void SetGameCRC(uint32 crc, int options); void SetFrameSkip(int skip); - void SetFrameLimit(bool limit); void SetRegsMem(uint8* basemem); void SetIrqCallback(void (*irq)()); void SetMultithreaded(bool isMT=true);