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
This commit is contained in:
Jake.Stine 2009-10-31 01:06:23 +00:00
parent 5326ae7686
commit c274d4e43c
21 changed files with 82 additions and 66 deletions

View File

@ -69,11 +69,12 @@ bool GPURenderer::Create(HWND hWnd)
m_wnd.Show(); m_wnd.Show();
if(!m_dev->Create(&m_wnd, m_vsync)) if(!m_dev->Create(&m_wnd))
{ {
return false; return false;
} }
m_dev->SetVsync(m_vsync);
Reset(); Reset();
return true; return true;
@ -162,7 +163,7 @@ void GPURenderer::VSync()
GetClientRect(m_hWnd, r); 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) bool GPURenderer::MakeSnapshot(const string& path)

View File

@ -39,6 +39,7 @@ static GSRenderer* s_gs = NULL;
static void (*s_irq)() = NULL; static void (*s_irq)() = NULL;
static uint8* s_basemem = NULL; static uint8* s_basemem = NULL;
static int s_renderer = -1; static int s_renderer = -1;
static bool s_framelimit = true;
EXPORT_C_(uint32) PS2EgetLibType() EXPORT_C_(uint32) PS2EgetLibType()
{ {
@ -441,9 +442,12 @@ EXPORT_C GSsetFrameSkip(int frameskip)
s_gs->SetFrameSkip(frameskip); s_gs->SetFrameSkip(frameskip);
} }
EXPORT_C GSsetFrameLimit(int limit) EXPORT_C GSsetFrameLimit(int limit)
{ {
s_gs->SetFrameLimit(limit != 0); s_framelimit = limit != 0;
if( s_gs )
s_gs->SetFrameLimit(s_framelimit);
} }
#ifdef _WINDOWS #ifdef _WINDOWS

View File

@ -25,6 +25,7 @@
GSDevice::GSDevice() GSDevice::GSDevice()
: m_wnd(NULL) : m_wnd(NULL)
, m_vsync(false)
, m_rbswapped(false) , m_rbswapped(false)
, m_backbuffer(NULL) , m_backbuffer(NULL)
, m_merge(NULL) , m_merge(NULL)
@ -51,10 +52,9 @@ GSDevice::~GSDevice()
delete m_1x1; delete m_1x1;
} }
bool GSDevice::Create(GSWnd* wnd, bool vsync) bool GSDevice::Create(GSWnd* wnd)
{ {
m_wnd = wnd; m_wnd = wnd;
m_vsync = vsync;
return true; return true;
} }
@ -82,7 +82,7 @@ bool GSDevice::Reset(int w, int h)
return m_wnd != NULL; 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(); 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]); 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) GSTexture* GSDevice::Fetch(int type, int w, int h, bool msaa, int format)

View File

@ -80,15 +80,16 @@ public:
enum {Windowed, Fullscreen, DontCare}; 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 Reset(int w, int h);
virtual bool IsLost(bool update = false) {return false;} virtual bool IsLost(bool update = false) {return false;}
virtual void Present(const GSVector4i& r, int shader, bool limit); virtual void Present(const GSVector4i& r, int shader);
virtual void Flip(bool limit) {} virtual void Flip() {}
virtual void BeginScene() {} virtual void BeginScene() {}
virtual void DrawPrimitive() {}; virtual void DrawPrimitive() {};
virtual void EndScene(); virtual void EndScene();
virtual void SetVsync(bool enable) { m_vsync = enable; }
virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {} virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {}
virtual void ClearRenderTarget(GSTexture* t, uint32 c) {} virtual void ClearRenderTarget(GSTexture* t, uint32 c) {}

View File

@ -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; return false;
} }
@ -260,9 +260,9 @@ bool GSDevice10::Reset(int w, int h)
return true; 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() void GSDevice10::DrawPrimitive()

View File

@ -107,10 +107,10 @@ public:
GSDevice10(); GSDevice10();
virtual ~GSDevice10(); virtual ~GSDevice10();
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool CreateTextureFX(); bool CreateTextureFX();
bool Reset(int w, int h); bool Reset(int w, int h);
void Flip(bool limit); void Flip();
void DrawPrimitive(); void DrawPrimitive();

View File

@ -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; return false;
} }
@ -251,9 +251,9 @@ bool GSDevice11::Reset(int w, int h)
return true; 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() void GSDevice11::DrawPrimitive()

View File

@ -109,10 +109,10 @@ public:
GSDevice11(); GSDevice11();
virtual ~GSDevice11(); virtual ~GSDevice11();
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool CreateTextureFX(); bool CreateTextureFX();
bool Reset(int w, int h); bool Reset(int w, int h);
void Flip(bool limit); void Flip();
void DrawPrimitive(); void DrawPrimitive();

View File

@ -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; return false;
} }
@ -136,7 +136,7 @@ bool GSDevice7::Reset(int w, int h)
return true; return true;
} }
void GSDevice7::Present(const GSVector4i& r, int shader, bool limit) void GSDevice7::Present(const GSVector4i& r, int shader)
{ {
HRESULT hr; 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); MapWindowPoints((HWND)m_wnd->GetHandle(), HWND_DESKTOP, (POINT*)&r2, 2);
if(m_vsync && limit) if(m_vsync)
{ {
hr = m_dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); hr = m_dd->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
} }

View File

@ -40,8 +40,8 @@ public:
GSDevice7(); GSDevice7();
virtual ~GSDevice7(); virtual ~GSDevice7();
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool Reset(int w, int h); bool Reset(int w, int h);
bool IsLost(bool update) {return m_lost;} bool IsLost(bool update) {return m_lost;}
void Present(const GSVector4i& r, int shader, bool limit); void Present(const GSVector4i& r, int shader);
}; };

View File

@ -50,9 +50,9 @@ GSDevice9::~GSDevice9()
if(m_state.ps_cb) _aligned_free(m_state.ps_cb); 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; return false;
} }
@ -377,7 +377,7 @@ bool GSDevice9::IsLost(bool update)
return m_lost; return m_lost;
} }
void GSDevice9::Flip(bool limit) void GSDevice9::Flip()
{ {
m_dev->EndScene(); m_dev->EndScene();

View File

@ -141,10 +141,10 @@ public:
GSDevice9(); GSDevice9();
virtual ~GSDevice9(); virtual ~GSDevice9();
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool Reset(int w, int h); bool Reset(int w, int h);
bool IsLost(bool update); bool IsLost(bool update);
void Flip(bool limit); void Flip();
void BeginScene(); void BeginScene();
void DrawPrimitive(); void DrawPrimitive();

View File

@ -262,9 +262,9 @@ public:
GSDeviceDX() {}; GSDeviceDX() {};
virtual ~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) virtual bool Reset(int w, int h)
@ -272,8 +272,8 @@ public:
return __super::Reset( w, h ); return __super::Reset( w, h );
} }
//virtual void Present(const GSVector4i& r, int shader, bool limit); //virtual void Present(const GSVector4i& r, int shader);
//virtual void Flip(bool limit) {} //virtual void Flip() {}
virtual void SetupIA(const void* vertices, int count, int prim) = 0; virtual void SetupIA(const void* vertices, int count, int prim) = 0;
virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0; virtual void SetupVS(VSSelector sel, const VSConstantBuffer* cb) = 0;

View File

@ -22,9 +22,9 @@
#include "stdafx.h" #include "stdafx.h"
#include "GSDeviceNull.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; return false;
} }

View File

@ -35,6 +35,6 @@ private:
public: public:
GSDeviceNull() {} GSDeviceNull() {}
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool Reset(int w, int h); bool Reset(int w, int h);
}; };

View File

@ -66,9 +66,9 @@ void GSDeviceOGL::OnCgError(CGcontext ctx, CGerror err)
printf("%s\n", cgGetLastListing(ctx)); // ? 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; return false;
} }
@ -115,15 +115,6 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
return false; return false;
} }
#ifdef _WINDOWS
if(WGLEW_EXT_swap_control)
{
wglSwapIntervalEXT(vsync ? 1 : 0);
}
#endif
const char* vendor = (const char*)glGetString(GL_VENDOR); const char* vendor = (const char*)glGetString(GL_VENDOR);
const char* renderer = (const char*)glGetString(GL_RENDERER); const char* renderer = (const char*)glGetString(GL_RENDERER);
const char* version = (const char*)glGetString(GL_VERSION); const char* version = (const char*)glGetString(GL_VERSION);
@ -155,6 +146,20 @@ bool GSDeviceOGL::Create(GSWnd* wnd, bool vsync)
return true; 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) bool GSDeviceOGL::Reset(int w, int h)
{ {
if(!__super::Reset(w, h)) if(!__super::Reset(w, h))
@ -185,16 +190,16 @@ bool GSDeviceOGL::Reset(int w, int h)
return true; 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(); glBindFramebuffer(GL_FRAMEBUFFER, 0); CheckError();
// TODO: m_current => backbuffer // TODO: m_current => backbuffer
Flip(limit); Flip();
} }
void GSDeviceOGL::Flip(bool limit) void GSDeviceOGL::Flip()
{ {
#ifdef _WINDOWS #ifdef _WINDOWS

View File

@ -109,10 +109,11 @@ public:
GSDeviceOGL(); GSDeviceOGL();
virtual ~GSDeviceOGL(); virtual ~GSDeviceOGL();
bool Create(GSWnd* wnd, bool vsync); bool Create(GSWnd* wnd);
bool Reset(int w, int h); bool Reset(int w, int h);
void Present(const GSVector4i& r, int shader, bool limit); void Present(const GSVector4i& r, int shader);
void Flip(bool limit); void Flip();
void SetVsync(bool enable);
void DrawPrimitive(); void DrawPrimitive();

View File

@ -77,12 +77,13 @@ bool GSRenderer::CreateDevice(GSDevice* dev)
ASSERT(dev); ASSERT(dev);
ASSERT(!m_dev); ASSERT(!m_dev);
if(!dev->Create(&m_wnd, m_vsync)) if(!dev->Create(&m_wnd))
{ {
return false; return false;
} }
m_dev = dev; m_dev = dev;
m_dev->SetVsync( m_vsync && m_framelimit );
return true; return true;
} }
@ -271,6 +272,12 @@ bool GSRenderer::Merge(int field)
return true; 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) void GSRenderer::VSync(int field)
{ {
GSPerfMonAutoTimer pmat(m_perfmon); GSPerfMonAutoTimer pmat(m_perfmon);
@ -343,7 +350,7 @@ void GSRenderer::VSync(int field)
// present // 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 // snapshot

View File

@ -46,6 +46,7 @@ protected:
bool m_nativeres; bool m_nativeres;
bool m_aa1; bool m_aa1;
bool m_blur; bool m_blur;
bool m_framelimit;
uint8* m_tex_buff; uint8* m_tex_buff;
@ -94,6 +95,8 @@ public:
return m_upscale_multiplier; return m_upscale_multiplier;
} }
void SetFrameLimit(bool limit);
// TODO : Implement proper locking here *if needed* (not sure yet if it is) --air // TODO : Implement proper locking here *if needed* (not sure yet if it is) --air
uint8* GetTextureBufferLock() { return m_tex_buff; } uint8* GetTextureBufferLock() { return m_tex_buff; }
void ReleaseTextureBufferLock() { } void ReleaseTextureBufferLock() { }

View File

@ -33,7 +33,6 @@ GSState::GSState()
, m_vprim(1) , m_vprim(1)
, m_version(5) , m_version(5)
, m_frameskip(0) , m_frameskip(0)
, m_framelimit(true)
, m_vkf(NULL) , m_vkf(NULL)
{ {
m_sssize = 0; m_sssize = 0;
@ -1617,6 +1616,7 @@ int GSState::Defrost(const GSFreezeData* fd)
if(version > m_version) if(version > m_version)
{ {
fprintf(stderr, "GSdx: Savestate version is incompatible. Load aborted.\n" );
return -1; return -1;
} }
@ -1776,11 +1776,6 @@ void GSState::SetFrameSkip(int skip)
} }
} }
void GSState::SetFrameLimit(bool limit)
{
m_framelimit = limit;
}
// GSTransferBuffer // GSTransferBuffer
GSState::GSTransferBuffer::GSTransferBuffer() GSState::GSTransferBuffer::GSTransferBuffer()

View File

@ -249,7 +249,6 @@ public:
void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;} void GetLastTag(uint32* tag) {*tag = m_path3hack; m_path3hack = 0;}
virtual void SetGameCRC(uint32 crc, int options); virtual void SetGameCRC(uint32 crc, int options);
void SetFrameSkip(int skip); void SetFrameSkip(int skip);
void SetFrameLimit(bool limit);
void SetRegsMem(uint8* basemem); void SetRegsMem(uint8* basemem);
void SetIrqCallback(void (*irq)()); void SetIrqCallback(void (*irq)());
void SetMultithreaded(bool isMT=true); void SetMultithreaded(bool isMT=true);