From 000691bf2b3b12be6de32f1c3bc82ec5ac5f3241 Mon Sep 17 00:00:00 2001 From: Zi Ree Date: Thu, 16 Feb 2023 15:06:33 +0100 Subject: [PATCH] Linux: FIRE-32559: vsync not working after restart, also: remove weird inverted vsync logic for SDL based windows which was not even implemented correctly --- indra/llwindow/llwindowsdl.cpp | 10 ++++---- indra/llwindow/llwindowsdl.h | 8 +++--- indra/llwindow/llwindowsdl2.cpp | 43 ++++++++++++++++++++++++++------ indra/llwindow/llwindowsdl2.h | 6 ++--- indra/newview/llviewerwindow.cpp | 6 +++++ 5 files changed, 53 insertions(+), 20 deletions(-) diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp index 0783b1bab7..2b6e62c44b 100644 --- a/indra/llwindow/llwindowsdl.cpp +++ b/indra/llwindow/llwindowsdl.cpp @@ -437,7 +437,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, const std::string& title, S32 x, S32 y, S32 width, S32 height, U32 flags, BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, + BOOL enable_vsync, BOOL use_gl, // Legacy cursor setting from main program //BOOL ignore_pixel_depth, U32 fsaa_samples,) BOOL ignore_pixel_depth, U32 fsaa_samples, BOOL useLegacyCursors) @@ -483,7 +483,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, mWindowTitle = title; // Create the GL context and set it up for windowed or fullscreen, as appropriate. - if(createContext(x, y, width, height, 32, fullscreen, disable_vsync)) + if(createContext(x, y, width, height, 32, fullscreen, enable_vsync)) { gGLManager.initGL(); @@ -667,7 +667,7 @@ void LLWindowSDL::setTitle(const std::string &title) SDL_WM_SetCaption(title.c_str(), title.c_str()); } -BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) +BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync) { //bool glneedsinit = false; @@ -1001,7 +1001,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // changing fullscreen resolution, or switching between windowed and fullscreen mode. -BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp) +BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp) { const BOOL needsRebuild = TRUE; // Just nuke the context and start over. BOOL result = true; @@ -1011,7 +1011,7 @@ BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL if(needsRebuild) { destroyContext(); - result = createContext(0, 0, size.mX, size.mY, 0, fullscreen, disable_vsync); + result = createContext(0, 0, size.mX, size.mY, 0, fullscreen, enable_vsync); if (result) { gGLManager.initGL(); diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h index da6da0f4d8..a4aadb99fa 100644 --- a/indra/llwindow/llwindowsdl.h +++ b/indra/llwindow/llwindowsdl.h @@ -69,7 +69,7 @@ public: /*virtual*/ BOOL setPosition(LLCoordScreen position); /*virtual*/ BOOL setSizeImpl(LLCoordScreen size); /*virtual*/ BOOL setSizeImpl(LLCoordWindow size); - /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL); + /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL); /*virtual*/ BOOL setCursorPosition(LLCoordWindow position); /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position); /*virtual*/ void showCursor(); @@ -159,7 +159,7 @@ public: protected: LLWindowSDL(LLWindowCallbacks* callbacks, const std::string& title, int x, int y, int width, int height, U32 flags, - BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl, + BOOL fullscreen, BOOL clearBg, BOOL enable_vsync, BOOL use_gl, //BOOL ignore_pixel_depth, U32 fsaa_samples); BOOL ignore_pixel_depth, U32 fsaa_samples, BOOL useLegacyCursors); // Legacy cursor setting from main program ~LLWindowSDL(); @@ -186,7 +186,7 @@ protected: // // create or re-create the GL context/window. Called from the constructor and switchContext(). - BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync); + BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync); void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); void fixWindowSize(void); @@ -263,4 +263,4 @@ public: S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type); #endif //LL_LLWINDOWSDL_H -#endif \ No newline at end of file +#endif diff --git a/indra/llwindow/llwindowsdl2.cpp b/indra/llwindow/llwindowsdl2.cpp index 3e6dcf1ea2..129576f8fc 100644 --- a/indra/llwindow/llwindowsdl2.cpp +++ b/indra/llwindow/llwindowsdl2.cpp @@ -382,7 +382,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, const std::string& title, S32 x, S32 y, S32 width, S32 height, U32 flags, BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, + BOOL enable_vsync, BOOL use_gl, // Legacy cursor setting from main program //BOOL ignore_pixel_depth, U32 fsaa_samples,) BOOL ignore_pixel_depth, U32 fsaa_samples, BOOL useLegacyCursors) @@ -427,7 +427,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, mWindowTitle = title; // Create the GL context and set it up for windowed or fullscreen, as appropriate. - if(createContext(x, y, width, height, 32, fullscreen, disable_vsync)) + if(createContext(x, y, width, height, 32, fullscreen, enable_vsync)) { gGLManager.initGL(); @@ -663,7 +663,7 @@ void LLWindowSDL::tryFindFullscreenSize( int &width, int &height ) } } -BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) +BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync) { //bool glneedsinit = false; @@ -739,7 +739,6 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // We need stencil support for a few (minor) things. if (stencilBits) SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBits); - // *FIX: try to toggle vsync here? SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); @@ -763,7 +762,11 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B setupFailure("GL Context creation error creation error", "Error", OSMB_OK); return FALSE; } - // SDL_GL_SetSwapInterval(1); + + // FIRE-32559: This *should* work, but for some reason aftrer login vsync always acts as if it's disabled, so + // the flag will get set again later in void LLViewerWindow::setStartupComplete() -Zi + toggleVSync(enable_vsync); + mSurface = SDL_GetWindowSurface( mWindow ); } @@ -921,7 +924,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // changing fullscreen resolution, or switching between windowed and fullscreen mode. -BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp) +BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp) { const BOOL needsRebuild = TRUE; // Just nuke the context and start over. BOOL result = true; @@ -931,7 +934,7 @@ BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL if(needsRebuild) { destroyContext(); - result = createContext(0, 0, size.mX, size.mY, 0, fullscreen, disable_vsync); + result = createContext(0, 0, size.mX, size.mY, 0, fullscreen, enable_vsync); if (result) { gGLManager.initGL(); @@ -2731,7 +2734,31 @@ void LLWindowSDL::destroySharedContext(void* context) void LLWindowSDL::toggleVSync(bool enable_vsync) { - SDL_GL_SetSwapInterval(enable_vsync); + if (enable_vsync) + { + // try adaptive vsync first (-1) and if that fails, try regular vsync (1) + if (SDL_GL_SetSwapInterval(-1) == -1) + { + LL_INFOS() << "Failed to enable adaptive vsync, trying regular vsync" << LL_ENDL; + if (SDL_GL_SetSwapInterval(1) == -1) + { + LL_WARNS() << "Failed to enable vsync" << LL_ENDL; + } + else + { + LL_DEBUGS() << "Vsync enabled" << LL_ENDL; + } + } + else + { + LL_DEBUGS() << "Adaptive vsync enabled" << LL_ENDL; + } + } + else + { + SDL_GL_SetSwapInterval(0); + LL_DEBUGS() << "Vsync disabled" << LL_ENDL; + } } // diff --git a/indra/llwindow/llwindowsdl2.h b/indra/llwindow/llwindowsdl2.h index 83807d12db..878f2a579b 100644 --- a/indra/llwindow/llwindowsdl2.h +++ b/indra/llwindow/llwindowsdl2.h @@ -65,7 +65,7 @@ public: /*virtual*/ BOOL setPosition(LLCoordScreen position); /*virtual*/ BOOL setSizeImpl(LLCoordScreen size); /*virtual*/ BOOL setSizeImpl(LLCoordWindow size); - /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL); + /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL); // Make shared context work on Linux for multithreaded OpenGL void* createSharedContext() override; void makeContextCurrent(void* context) override; @@ -162,7 +162,7 @@ public: protected: LLWindowSDL(LLWindowCallbacks* callbacks, const std::string& title, int x, int y, int width, int height, U32 flags, - BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl, + BOOL fullscreen, BOOL clearBg, BOOL enable_vsync, BOOL use_gl, //BOOL ignore_pixel_depth, U32 fsaa_samples); BOOL ignore_pixel_depth, U32 fsaa_samples, BOOL useLegacyCursors); // Legacy cursor setting from main program ~LLWindowSDL(); @@ -189,7 +189,7 @@ protected: // // create or re-create the GL context/window. Called from the constructor and switchContext(). - BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync); + BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync); void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); void fixWindowSize(void); diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 7c82bfd23b..2592fd35ec 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -6730,6 +6730,12 @@ void LLViewerWindow::setStartupComplete() { mProgressView->setStartupComplete(); } + +#if LL_SDL2 + // FIRE-32559: For some reason aftrer login vsync always acts as if it's disabled, so + // the flag will get set again here after the 3D view is set up -Zi + getWindow()->toggleVSync(gSavedSettings.getBOOL("RenderVSyncEnable")); +#endif } BOOL LLViewerWindow::getShowProgress() const