From 2204885fbb3ac76ae8a083aec35cee3a7669fa89 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 3 Jul 2017 20:02:16 +0200 Subject: [PATCH 1/5] gsdx ogl: factorize common context init code --- plugins/GSdx/GSWnd.cpp | 8 ++++++++ plugins/GSdx/GSWnd.h | 6 ++++-- plugins/GSdx/GSWndEGL.cpp | 16 ++++++---------- plugins/GSdx/GSWndEGL.h | 1 + plugins/GSdx/GSWndOGL.cpp | 24 ++++++++---------------- plugins/GSdx/GSWndOGL.h | 1 + plugins/GSdx/GSWndWGL.cpp | 22 +++++++--------------- plugins/GSdx/GSWndWGL.h | 1 + 8 files changed, 36 insertions(+), 43 deletions(-) diff --git a/plugins/GSdx/GSWnd.cpp b/plugins/GSdx/GSWnd.cpp index 386785bda9..53f93d25b3 100644 --- a/plugins/GSdx/GSWnd.cpp +++ b/plugins/GSdx/GSWnd.cpp @@ -183,3 +183,11 @@ void GSWndGL::PopulateGlFunction() // renderer/device GLLoader::check_gl_requirements(); } + +void GSWndGL::FullContextInit() +{ + CreateContext(3, 3); + AttachContext(); + PopulateGlFunction(); + PopulateWndGlFunction(); +} diff --git a/plugins/GSdx/GSWnd.h b/plugins/GSdx/GSWnd.h index e05584a00c..981e5f2824 100644 --- a/plugins/GSdx/GSWnd.h +++ b/plugins/GSdx/GSWnd.h @@ -62,6 +62,10 @@ protected: bool m_ctx_attached; bool IsContextAttached() const { return m_ctx_attached; } + void PopulateGlFunction(); + virtual void PopulateWndGlFunction() = 0; + void FullContextInit(); + virtual void CreateContext(int major, int minor) = 0; public: GSWndGL() : m_ctx_attached(false) {}; @@ -85,6 +89,4 @@ public: virtual void HideFrame() = 0; virtual void Flip() = 0; virtual void SetVSync(int vsync) = 0; - - void PopulateGlFunction(); }; diff --git a/plugins/GSdx/GSWndEGL.cpp b/plugins/GSdx/GSWndEGL.cpp index a11e6d991a..c83492d6ad 100644 --- a/plugins/GSdx/GSWndEGL.cpp +++ b/plugins/GSdx/GSWndEGL.cpp @@ -153,6 +153,10 @@ void GSWndEGL::DetachContext() } } +void GSWndEGL::PopulateWndGlFunction() +{ +} + void GSWndEGL::BindAPI() { eglBindAPI(EGL_OPENGL_API); @@ -171,11 +175,7 @@ bool GSWndEGL::Attach(void* handle, bool managed) OpenEGLDisplay(); - CreateContext(3, 3); - - AttachContext(); - - PopulateGlFunction(); + FullContextInit(); return true; } @@ -209,11 +209,7 @@ bool GSWndEGL::Create(const string& title, int w, int h) m_native_window = CreateNativeWindow(w, h); - CreateContext(3, 3); - - AttachContext(); - - PopulateGlFunction(); + FullContextInit(); return true; } diff --git a/plugins/GSdx/GSWndEGL.h b/plugins/GSdx/GSWndEGL.h index e3edd6b57e..387065c30b 100644 --- a/plugins/GSdx/GSWndEGL.h +++ b/plugins/GSdx/GSWndEGL.h @@ -38,6 +38,7 @@ class GSWndEGL : public GSWndGL int m_platform; + void PopulateWndGlFunction(); void CreateContext(int major, int minor); void BindAPI(); diff --git a/plugins/GSdx/GSWndOGL.cpp b/plugins/GSdx/GSWndOGL.cpp index 37d3d4bb54..b9a6f0ff56 100644 --- a/plugins/GSdx/GSWndOGL.cpp +++ b/plugins/GSdx/GSWndOGL.cpp @@ -122,6 +122,12 @@ void GSWndOGL::DetachContext() } } +void GSWndOGL::PopulateWndGlFunction() +{ + m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT"); + m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); +} + bool GSWndOGL::Attach(void* handle, bool managed) { m_NativeWindow = *(Window*)handle; @@ -129,14 +135,7 @@ bool GSWndOGL::Attach(void* handle, bool managed) m_NativeDisplay = XOpenDisplay(NULL); - CreateContext(3, 3); - - AttachContext(); - - m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT"); - m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); - - PopulateGlFunction(); + FullContextInit(); return true; } @@ -175,14 +174,7 @@ bool GSWndOGL::Create(const string& title, int w, int h) if (m_NativeWindow == 0) throw GSDXRecoverableError(); - CreateContext(3, 3); - - AttachContext(); - - m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT"); - m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); - - PopulateGlFunction(); + FullContextInit(); return true; } diff --git a/plugins/GSdx/GSWndOGL.h b/plugins/GSdx/GSWndOGL.h index 0d8da9a2d7..012cf4f317 100644 --- a/plugins/GSdx/GSWndOGL.h +++ b/plugins/GSdx/GSWndOGL.h @@ -34,6 +34,7 @@ class GSWndOGL final : public GSWndGL PFNGLXSWAPINTERVALEXTPROC m_swapinterval_ext; PFNGLXSWAPINTERVALMESAPROC m_swapinterval_mesa; + void PopulateWndGlFunction(); void CreateContext(int major, int minor); public: diff --git a/plugins/GSdx/GSWndWGL.cpp b/plugins/GSdx/GSWndWGL.cpp index b5cb1d22a7..16424ab8af 100644 --- a/plugins/GSdx/GSWndWGL.cpp +++ b/plugins/GSdx/GSWndWGL.cpp @@ -139,6 +139,11 @@ void GSWndWGL::DetachContext() } } +void GSWndWGL::PopulateWndGlFunction() +{ + m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); +} + bool GSWndWGL::Attach(void* handle, bool managed) { m_NativeWindow = (HWND)handle; @@ -146,13 +151,7 @@ bool GSWndWGL::Attach(void* handle, bool managed) OpenWGLDisplay(); - CreateContext(3, 3); - - AttachContext(); - - m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - - PopulateGlFunction(); + FullContextInit(); UpdateWindow(m_NativeWindow); @@ -288,16 +287,9 @@ bool GSWndWGL::Create(const string& title, int w, int h) OpenWGLDisplay(); - CreateContext(3, 3); - - AttachContext(); - - m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - - PopulateGlFunction(); + FullContextInit(); return true; - } //Same as DX diff --git a/plugins/GSdx/GSWndWGL.h b/plugins/GSdx/GSWndWGL.h index c4ccec4a2d..643893042f 100644 --- a/plugins/GSdx/GSWndWGL.h +++ b/plugins/GSdx/GSWndWGL.h @@ -31,6 +31,7 @@ class GSWndWGL : public GSWndGL PFNWGLSWAPINTERVALEXTPROC m_swapinterval; + void PopulateWndGlFunction(); void CreateContext(int major, int minor); void CloseWGLDisplay(); From 2e4643a3981350392ea120590d57850b4d708d17 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 3 Jul 2017 22:13:59 +0200 Subject: [PATCH 2/5] gsdx ogl: factorize SetVSync Move common logic into base class Add API to handle late Vsync (only stub) --- plugins/GSdx/GSWnd.cpp | 10 ++++++++++ plugins/GSdx/GSWnd.h | 8 ++++++-- plugins/GSdx/GSWndEGL.cpp | 2 +- plugins/GSdx/GSWndEGL.h | 4 +++- plugins/GSdx/GSWndOGL.cpp | 2 +- plugins/GSdx/GSWndOGL.h | 4 +++- plugins/GSdx/GSWndWGL.cpp | 2 +- plugins/GSdx/GSWndWGL.h | 4 +++- 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/plugins/GSdx/GSWnd.cpp b/plugins/GSdx/GSWnd.cpp index 53f93d25b3..79aa303fbd 100644 --- a/plugins/GSdx/GSWnd.cpp +++ b/plugins/GSdx/GSWnd.cpp @@ -191,3 +191,13 @@ void GSWndGL::FullContextInit() PopulateGlFunction(); PopulateWndGlFunction(); } + +void GSWndGL::SetVSync(int vsync) +{ + if (!HasLateVsyncSupport() && vsync < 0) + m_vsync = -vsync; // Late vsync not supported, fallback to standard vsync + else + m_vsync = vsync; + + SetSwapInterval(m_vsync); +} diff --git a/plugins/GSdx/GSWnd.h b/plugins/GSdx/GSWnd.h index 981e5f2824..486b1a8ec5 100644 --- a/plugins/GSdx/GSWnd.h +++ b/plugins/GSdx/GSWnd.h @@ -60,6 +60,7 @@ class GSWndGL : public GSWnd { protected: bool m_ctx_attached; + int m_vsync; bool IsContextAttached() const { return m_ctx_attached; } void PopulateGlFunction(); @@ -67,8 +68,11 @@ protected: void FullContextInit(); virtual void CreateContext(int major, int minor) = 0; + virtual void SetSwapInterval(int vsync) = 0; + virtual bool HasLateVsyncSupport() = 0; + public: - GSWndGL() : m_ctx_attached(false) {}; + GSWndGL() : m_ctx_attached(false), m_vsync(0) {}; virtual ~GSWndGL() {}; virtual bool Create(const string& title, int w, int h) = 0; @@ -88,5 +92,5 @@ public: virtual void Hide() = 0; virtual void HideFrame() = 0; virtual void Flip() = 0; - virtual void SetVSync(int vsync) = 0; + virtual void SetVSync(int vsync) final; }; diff --git a/plugins/GSdx/GSWndEGL.cpp b/plugins/GSdx/GSWndEGL.cpp index c83492d6ad..16dc0ce022 100644 --- a/plugins/GSdx/GSWndEGL.cpp +++ b/plugins/GSdx/GSWndEGL.cpp @@ -235,7 +235,7 @@ GSVector4i GSWndEGL::GetClientRect() return GSVector4i(0, 0, w, h); } -void GSWndEGL::SetVSync(int vsync) +void GSWndEGL::SetSwapInterval(int vsync) { // 0 -> disable vsync // n -> wait n frame diff --git a/plugins/GSdx/GSWndEGL.h b/plugins/GSdx/GSWndEGL.h index 387065c30b..619bca3f2a 100644 --- a/plugins/GSdx/GSWndEGL.h +++ b/plugins/GSdx/GSWndEGL.h @@ -42,6 +42,9 @@ class GSWndEGL : public GSWndGL void CreateContext(int major, int minor); void BindAPI(); + void SetSwapInterval(int vsync) final; + bool HasLateVsyncSupport() final { return false; } + void OpenEGLDisplay(); void CloseEGLDisplay(); @@ -66,7 +69,6 @@ public: void* GetProcAddress(const char* name, bool opt = false) final; void Flip() final; - void SetVSync(int vsync) final; // Deprecated API void Show() final {}; diff --git a/plugins/GSdx/GSWndOGL.cpp b/plugins/GSdx/GSWndOGL.cpp index b9a6f0ff56..1785c23dac 100644 --- a/plugins/GSdx/GSWndOGL.cpp +++ b/plugins/GSdx/GSWndOGL.cpp @@ -235,7 +235,7 @@ bool GSWndOGL::SetWindowText(const char* title) return true; } -void GSWndOGL::SetVSync(int vsync) +void GSWndOGL::SetSwapInterval(int vsync) { // m_swapinterval uses an integer as parameter // 0 -> disable vsync diff --git a/plugins/GSdx/GSWndOGL.h b/plugins/GSdx/GSWndOGL.h index 012cf4f317..2aabec8928 100644 --- a/plugins/GSdx/GSWndOGL.h +++ b/plugins/GSdx/GSWndOGL.h @@ -37,6 +37,9 @@ class GSWndOGL final : public GSWndGL void PopulateWndGlFunction(); void CreateContext(int major, int minor); + void SetSwapInterval(int vsync); + bool HasLateVsyncSupport() { return false; } + public: GSWndOGL(); virtual ~GSWndOGL() {}; @@ -58,7 +61,6 @@ public: void Hide(); void HideFrame(); void Flip(); - void SetVSync(int vsync); }; #endif diff --git a/plugins/GSdx/GSWndWGL.cpp b/plugins/GSdx/GSWndWGL.cpp index 16424ab8af..1e1405ada6 100644 --- a/plugins/GSdx/GSWndWGL.cpp +++ b/plugins/GSdx/GSWndWGL.cpp @@ -315,7 +315,7 @@ void* GSWndWGL::GetProcAddress(const char* name, bool opt) //TODO: check extensions supported or not //FIXME : extension allocation -void GSWndWGL::SetVSync(int vsync) +void GSWndWGL::SetSwapInterval(int vsync) { // m_swapinterval uses an integer as parameter // 0 -> disable vsync diff --git a/plugins/GSdx/GSWndWGL.h b/plugins/GSdx/GSWndWGL.h index 643893042f..c235367f78 100644 --- a/plugins/GSdx/GSWndWGL.h +++ b/plugins/GSdx/GSWndWGL.h @@ -37,6 +37,9 @@ class GSWndWGL : public GSWndGL void CloseWGLDisplay(); void OpenWGLDisplay(); + void SetSwapInterval(int vsync); + bool HasLateVsyncSupport() { return false; } + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); public: @@ -60,7 +63,6 @@ public: void Hide(); void HideFrame(); void Flip(); - void SetVSync(int vsync); }; #endif From 17d2d9217b918e63b61908391bf5e476530b5c60 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Mon, 3 Jul 2017 22:36:31 +0200 Subject: [PATCH 3/5] gsdx ogl: test adaptive/late vsync driver support Supported on GLX (but not Linux free driver) and WGL --- plugins/GSdx/GSWndOGL.cpp | 5 ++++- plugins/GSdx/GSWndOGL.h | 3 ++- plugins/GSdx/GSWndWGL.cpp | 11 ++++++++++- plugins/GSdx/GSWndWGL.h | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/GSdx/GSWndOGL.cpp b/plugins/GSdx/GSWndOGL.cpp index 1785c23dac..d30ac951ed 100644 --- a/plugins/GSdx/GSWndOGL.cpp +++ b/plugins/GSdx/GSWndOGL.cpp @@ -24,7 +24,7 @@ #if defined(__unix__) GSWndOGL::GSWndOGL() - : m_NativeWindow(0), m_NativeDisplay(NULL), m_context(0), m_swapinterval_ext(NULL), m_swapinterval_mesa(NULL) + : m_NativeWindow(0), m_NativeDisplay(nullptr), m_context(0), m_has_late_vsync(false), m_swapinterval_ext(nullptr), m_swapinterval_mesa(nullptr) { } @@ -126,6 +126,9 @@ void GSWndOGL::PopulateWndGlFunction() { m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT"); m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); + + const char* ext = glXQueryExtensionsString(m_NativeDisplay, DefaultScreen(m_NativeDisplay)); + m_has_late_vsync = m_swapinterval_ext && ext && strstr(ext, "GLX_EXT_swap_control"); } bool GSWndOGL::Attach(void* handle, bool managed) diff --git a/plugins/GSdx/GSWndOGL.h b/plugins/GSdx/GSWndOGL.h index 2aabec8928..1602f6705e 100644 --- a/plugins/GSdx/GSWndOGL.h +++ b/plugins/GSdx/GSWndOGL.h @@ -30,6 +30,7 @@ class GSWndOGL final : public GSWndGL Window m_NativeWindow; Display* m_NativeDisplay; GLXContext m_context; + bool m_has_late_vsync; PFNGLXSWAPINTERVALEXTPROC m_swapinterval_ext; PFNGLXSWAPINTERVALMESAPROC m_swapinterval_mesa; @@ -38,7 +39,7 @@ class GSWndOGL final : public GSWndGL void CreateContext(int major, int minor); void SetSwapInterval(int vsync); - bool HasLateVsyncSupport() { return false; } + bool HasLateVsyncSupport() { return m_has_late_vsync; } public: GSWndOGL(); diff --git a/plugins/GSdx/GSWndWGL.cpp b/plugins/GSdx/GSWndWGL.cpp index 1e1405ada6..bdeb35d73b 100644 --- a/plugins/GSdx/GSWndWGL.cpp +++ b/plugins/GSdx/GSWndWGL.cpp @@ -40,7 +40,7 @@ static void win_error(const char* msg, bool fatal = true) GSWndWGL::GSWndWGL() - : m_NativeWindow(NULL), m_NativeDisplay(NULL), m_context(NULL) + : m_NativeWindow(nullptr), m_NativeDisplay(nullptr), m_context(nullptr), m_has_late_vsync(false) { } @@ -142,6 +142,15 @@ void GSWndWGL::DetachContext() void GSWndWGL::PopulateWndGlFunction() { m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + + // To ease the process, extension management is itself an extension. Clever isn't it! + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); + if (wglGetExtensionsStringARB) { + const char* ext = wglGetExtensionsStringARB(m_NativeDisplay); + m_has_late_vsync = m_swapinterval && ext && strstr(ext, "WGL_EXT_swap_control_tear"); + } else { + m_has_late_vsync = false; + } } bool GSWndWGL::Attach(void* handle, bool managed) diff --git a/plugins/GSdx/GSWndWGL.h b/plugins/GSdx/GSWndWGL.h index c235367f78..d15fde45f0 100644 --- a/plugins/GSdx/GSWndWGL.h +++ b/plugins/GSdx/GSWndWGL.h @@ -28,6 +28,7 @@ class GSWndWGL : public GSWndGL HWND m_NativeWindow; HDC m_NativeDisplay; HGLRC m_context; + bool m_has_late_vsync; PFNWGLSWAPINTERVALEXTPROC m_swapinterval; @@ -38,7 +39,7 @@ class GSWndWGL : public GSWndGL void OpenWGLDisplay(); void SetSwapInterval(int vsync); - bool HasLateVsyncSupport() { return false; } + bool HasLateVsyncSupport() { return m_has_late_vsync; } static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); From e8636136c8c28a9baba079ccd090b2828b9138f5 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 14 Jul 2017 15:10:46 +0200 Subject: [PATCH 4/5] core: add a getter for the vsync option v2: allow all combinations of framelimiter and vsync options v3: * disable vsync when the user disable framelimiter with F4 * Use g_Conf->EmuOptions instead of EmuConfig --- pcsx2/Config.h | 2 ++ pcsx2/MTGS.cpp | 2 +- pcsx2/Pcsx2Config.cpp | 9 +++++++++ pcsx2/gui/AppCorePlugins.cpp | 5 ++--- pcsx2/gui/GlobalCommands.cpp | 22 ++++++++++++++++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/pcsx2/Config.h b/pcsx2/Config.h index a43db4a9c7..a2c04f6499 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -305,6 +305,8 @@ struct Pcsx2Config GSOptions(); void LoadSave( IniInterface& conf ); + int GetVsync() const; + bool operator ==( const GSOptions& right ) const { return diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index e0658c01ea..d9878a40b7 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -203,7 +203,7 @@ void SysMtgsThread::OpenPlugin() result = GSopen( (void*)pDsp, "PCSX2", renderswitch ? 2 : 1 ); - GSsetVsync(EmuConfig.GS.FrameLimitEnable && EmuConfig.GS.VsyncEnable); + GSsetVsync(EmuConfig.GS.GetVsync()); if( result != 0 ) { diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 2d9d704132..f53d7cda90 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -20,6 +20,7 @@ #include "Utilities/IniInterface.h" #include "Config.h" #include "GS.h" +#include "gui/GSFrame.h" void TraceLogFilters::LoadSave( IniInterface& ini ) { @@ -234,6 +235,14 @@ void Pcsx2Config::GSOptions::LoadSave( IniInterface& ini ) IniEntry( FramesToSkip ); } +int Pcsx2Config::GSOptions::GetVsync() const +{ + if (g_LimiterMode == Limit_Turbo) + return 0; + + return VsyncEnable; +} + const wxChar *const tbl_GamefixNames[] = { L"VuAddSub", diff --git a/pcsx2/gui/AppCorePlugins.cpp b/pcsx2/gui/AppCorePlugins.cpp index 2c317e6113..5a74bb696e 100644 --- a/pcsx2/gui/AppCorePlugins.cpp +++ b/pcsx2/gui/AppCorePlugins.cpp @@ -359,9 +359,8 @@ bool AppCorePlugins::OpenPlugin_GS() bool retval = _parent::OpenPlugin_GS(); - if( g_LimiterMode == Limit_Turbo ) - GSsetVsync( false ); - + GSsetVsync(EmuConfig.GS.GetVsync()); + return retval; } diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index 3800b74fa6..5be6ece48c 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -91,7 +91,6 @@ namespace Implementations } else if( g_LimiterMode == Limit_Turbo ) { - GSsetVsync( g_Conf->EmuOptions.GS.VsyncEnable ); g_LimiterMode = Limit_Nominal; if ( g_Conf->Framerate.SkipOnLimit) @@ -107,7 +106,6 @@ namespace Implementations } else { - GSsetVsync( false ); g_LimiterMode = Limit_Turbo; if ( g_Conf->Framerate.SkipOnTurbo) @@ -121,7 +119,11 @@ namespace Implementations g_Conf->EmuOptions.GS.FrameSkipEnable = false; } } + gsUpdateFrequency(g_Conf->EmuOptions); + + GSsetVsync(g_Conf->EmuOptions.GS.GetVsync()); + pauser.AllowResume(); } @@ -134,7 +136,6 @@ namespace Implementations // out a better consistency approach... -air ScopedCoreThreadPause pauser; - GSsetVsync( g_Conf->EmuOptions.GS.VsyncEnable ); if( g_LimiterMode == Limit_Slomo ) { g_LimiterMode = Limit_Nominal; @@ -146,7 +147,11 @@ namespace Implementations OSDlog( Color_StrongRed, true, "(FrameLimiter) SlowMotion ENABLED." ); g_Conf->EmuOptions.GS.FrameLimitEnable = true; } + gsUpdateFrequency(g_Conf->EmuOptions); + + GSsetVsync(g_Conf->EmuOptions.GS.GetVsync()); + pauser.AllowResume(); } @@ -154,8 +159,17 @@ namespace Implementations { ScopedCoreThreadPause pauser; g_Conf->EmuOptions.GS.FrameLimitEnable = !g_Conf->EmuOptions.GS.FrameLimitEnable; - GSsetVsync( g_Conf->EmuOptions.GS.FrameLimitEnable && g_Conf->EmuOptions.GS.VsyncEnable ); OSDlog( Color_StrongRed, true, "(FrameLimiter) %s.", g_Conf->EmuOptions.GS.FrameLimitEnable ? "ENABLED" : "DISABLED" ); + + // Turbo/Slowmo don't make sense when framelimiter is toggled + g_LimiterMode = Limit_Nominal; + + // Disable Vsync when frame limited is disabled + if( g_Conf->EmuOptions.GS.FrameLimitEnable ) + GSsetVsync(g_Conf->EmuOptions.GS.GetVsync()); + else + GSsetVsync(0); + pauser.AllowResume(); } From f5838c51787bd97dc88c2b049bef6678a916ad2c Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 14 Jul 2017 15:15:37 +0200 Subject: [PATCH 5/5] pcsx2 gui: uses a combo box for Vsync The possible values are * Disabled * Enabled * Adaptive Vsync (the new possibility) --- pcsx2/Config.h | 13 ++++++++++--- pcsx2/Pcsx2Config.cpp | 14 ++++++++++--- pcsx2/gui/AppCoreThread.cpp | 2 +- pcsx2/gui/Panels/ConfigurationPanels.h | 1 + pcsx2/gui/Panels/GSWindowPanel.cpp | 27 ++++++++++++++++++++------ 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pcsx2/Config.h b/pcsx2/Config.h index a2c04f6499..157d4bf71e 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -63,6 +63,13 @@ enum GamefixId GamefixId_COUNT }; +enum class VsyncMode +{ + Off, + On, + Adaptive, +}; + // Template function for casting enumerations to their underlying type template typename std::underlying_type::type enum_cast(Enumeration E) @@ -291,9 +298,9 @@ struct Pcsx2Config bool DisableOutput; int VsyncQueueSize; - bool FrameLimitEnable; - bool FrameSkipEnable; - bool VsyncEnable; + bool FrameLimitEnable; + bool FrameSkipEnable; + VsyncMode VsyncEnable; int FramesToDraw; // number of consecutive frames (fields) to render int FramesToSkip; // number of consecutive frames (fields) to skip diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index f53d7cda90..77397813e7 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -201,7 +201,7 @@ Pcsx2Config::GSOptions::GSOptions() { FrameLimitEnable = true; FrameSkipEnable = false; - VsyncEnable = false; + VsyncEnable = VsyncMode::Off; SynchronousMTGS = false; DisableOutput = false; @@ -225,7 +225,7 @@ void Pcsx2Config::GSOptions::LoadSave( IniInterface& ini ) IniEntry( FrameLimitEnable ); IniEntry( FrameSkipEnable ); - IniEntry( VsyncEnable ); + ini.EnumEntry( L"VsyncEnable", VsyncEnable, NULL, VsyncEnable ); IniEntry( LimitScalar ); IniEntry( FramerateNTSC ); @@ -240,7 +240,15 @@ int Pcsx2Config::GSOptions::GetVsync() const if (g_LimiterMode == Limit_Turbo) return 0; - return VsyncEnable; + // D3D only support a boolean state. OpenGL waits a number of vsync + // interrupt (negative value for late vsync). + switch (VsyncEnable) { + case VsyncMode::Adaptive: return -1; + case VsyncMode::Off: return 0; + case VsyncMode::On: return 1; + + default: return 0; + } } const wxChar *const tbl_GamefixNames[] = diff --git a/pcsx2/gui/AppCoreThread.cpp b/pcsx2/gui/AppCoreThread.cpp index c448850284..a34268cf48 100644 --- a/pcsx2/gui/AppCoreThread.cpp +++ b/pcsx2/gui/AppCoreThread.cpp @@ -356,7 +356,7 @@ static void _ApplySettings( const Pcsx2Config& src, Pcsx2Config& fixup ) if( overrides.ProfilingMode ) { fixup.GS.FrameLimitEnable = false; - fixup.GS.VsyncEnable = false; + fixup.GS.VsyncEnable = VsyncMode::Off; } wxString gameCRC; diff --git a/pcsx2/gui/Panels/ConfigurationPanels.h b/pcsx2/gui/Panels/ConfigurationPanels.h index 3fc183a1bb..b38b8e834c 100644 --- a/pcsx2/gui/Panels/ConfigurationPanels.h +++ b/pcsx2/gui/Panels/ConfigurationPanels.h @@ -267,6 +267,7 @@ namespace Panels { protected: wxComboBox* m_combo_AspectRatio; + wxComboBox* m_combo_vsync; wxTextCtrl* m_text_Zoom; diff --git a/pcsx2/gui/Panels/GSWindowPanel.cpp b/pcsx2/gui/Panels/GSWindowPanel.cpp index f47d503a64..6a8ff3fbe1 100644 --- a/pcsx2/gui/Panels/GSWindowPanel.cpp +++ b/pcsx2/gui/Panels/GSWindowPanel.cpp @@ -32,11 +32,22 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) _("Widescreen (16:9)") }; + // Warning must match the order of the VsyncMode Enum + const wxString vsync_label[] = + { + _("Disabled"), + _("Standard"), + _("Adaptive"), + }; + m_text_Zoom = CreateNumericalTextCtrl( this, 5 ); m_combo_AspectRatio = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, ArraySize(aspect_ratio_labels), aspect_ratio_labels, wxCB_READONLY ); + m_combo_vsync = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, + ArraySize(vsync_label), vsync_label, wxCB_READONLY ); + m_text_WindowWidth = CreateNumericalTextCtrl( this, 5 ); m_text_WindowHeight = CreateNumericalTextCtrl( this, 5 ); @@ -47,7 +58,6 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) m_check_HideMouse = new pxCheckBox( this, _("Always hide mouse cursor") ); m_check_CloseGS = new pxCheckBox( this, _("Hide window when paused") ); m_check_Fullscreen = new pxCheckBox( this, _("Default to fullscreen mode on open") ); - m_check_VsyncEnable = new pxCheckBox( this, _("Wait for Vsync on refresh") ); m_check_DclickFullscreen = new pxCheckBox( this, _("Double-click toggles fullscreen mode") ); m_check_AspectRatioSwitch = new pxCheckBox(this, _("Switch to 4:3 aspect ratio when an FMV plays")); //m_check_ExclusiveFS = new pxCheckBox( this, _("Use exclusive fullscreen mode (if available)") ); @@ -55,7 +65,7 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) m_text_Zoom->SetToolTip( pxEt( L"Zoom = 100: Fit the entire image to the window without any cropping.\nAbove/Below 100: Zoom In/Out\n0: Automatic-Zoom-In untill the black-bars are gone (Aspect ratio is kept, some of the image goes out of screen).\n NOTE: Some games draw their own black-bars, which will not be removed with '0'.\n\nKeyboard: CTRL + NUMPAD-PLUS: Zoom-In, CTRL + NUMPAD-MINUS: Zoom-Out, CTRL + NUMPAD-*: Toggle 100/0" ) ); - m_check_VsyncEnable->SetToolTip( pxEt( L"Vsync eliminates screen tearing but typically has a big performance hit. It usually only applies to fullscreen mode, and may not work with all GS plugins." + m_combo_vsync->SetToolTip( pxEt( L"Vsync eliminates screen tearing but typically has a big performance hit. It usually only applies to fullscreen mode, and may not work with all GS plugins." ) ); m_check_HideMouse->SetToolTip( pxEt( L"Check this to force the mouse cursor invisible inside the GS window; useful if using the mouse as a primary control device for gaming. By default the mouse auto-hides after 2 seconds of inactivity." @@ -91,6 +101,11 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) s_AspectRatio += Label(_("Zoom:")) | StdExpand(); s_AspectRatio += m_text_Zoom; + wxFlexGridSizer& s_vsync( *new wxFlexGridSizer( 2, StdPadding, StdPadding ) ); + s_vsync.AddGrowableCol( 1 ); + + s_vsync += Label(_("Wait for Vsync on refresh:")) | pxMiddle; + s_vsync += m_combo_vsync | pxExpand; *this += s_AspectRatio | StdExpand(); *this += m_check_SizeLock; @@ -105,7 +120,7 @@ Panels::GSWindowSettingsPanel::GSWindowSettingsPanel( wxWindow* parent ) //*this += m_check_ExclusiveFS; *this += new wxStaticLine( this ) | StdExpand(); - *this += m_check_VsyncEnable; + *this += s_vsync; wxBoxSizer* centerSizer = new wxBoxSizer( wxVERTICAL ); *centerSizer += GetSizer() | pxCenter; @@ -140,8 +155,8 @@ void Panels::GSWindowSettingsPanel::ApplyConfigToGui( AppConfig& configToApply, m_text_WindowHeight ->ChangeValue( wxsFormat( L"%d", conf.WindowSize.GetHeight() ) ); } - m_check_VsyncEnable->SetValue( configToApply.EmuOptions.GS.VsyncEnable ); - m_check_VsyncEnable->Enable ( !configToApply.EnablePresets );//grayed-out when presets are enabled + m_combo_vsync->SetSelection(enum_cast(configToApply.EmuOptions.GS.VsyncEnable)); + m_combo_vsync->Enable( !configToApply.EnablePresets );//grayed-out when presets are enabled } void Panels::GSWindowSettingsPanel::Apply() @@ -157,7 +172,7 @@ void Panels::GSWindowSettingsPanel::Apply() appconf.AspectRatio = (AspectRatioType)m_combo_AspectRatio->GetSelection(); appconf.Zoom = Fixed100::FromString( m_text_Zoom->GetValue() ); - gsconf.VsyncEnable = m_check_VsyncEnable->GetValue(); + gsconf.VsyncEnable = static_cast(m_combo_vsync->GetSelection()); appconf.IsToggleFullscreenOnDoubleClick = m_check_DclickFullscreen->GetValue(); appconf.IsToggleAspectRatioSwitch = m_check_AspectRatioSwitch->GetValue();