From 0c1cbf2d38cbd0db5c9cfb86559b4fc5e4acee0d Mon Sep 17 00:00:00 2001 From: Rye Date: Thu, 30 Oct 2025 17:22:09 -0400 Subject: Add support for GLX and EGL to GL extension loader Fix dullahan wayland support Fix shader GL_ERROR under GL Core profile in Mesa Signed-off-by: Rye --- indra/llwindow/llwindowsdl.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'indra/llwindow/llwindowsdl.cpp') diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp index 57110f8634..1cfb0b2acb 100644 --- a/indra/llwindow/llwindowsdl.cpp +++ b/indra/llwindow/llwindowsdl.cpp @@ -40,11 +40,11 @@ #include "llpreeditor.h" #include "llsdl.h" +#if LL_LINUX #ifdef LL_GLIB #include #endif -#if LL_LINUX extern "C" { # include "fontconfig/fontconfig.h" } @@ -55,6 +55,13 @@ extern "C" { #include #include #include + +#if LL_X11 +LLWindowSDL::X11_DATA LLWindowSDL::sX11Data = {}; +#endif +#if LL_WAYLAND +LLWindowSDL::WAYLAND_DATA LLWindowSDL::sWaylandData = {}; +#endif #endif // LL_LINUX #if LL_DARWIN @@ -248,7 +255,7 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b if(mFullscreen) { - tryFindFullscreenSize( width, height ); + tryFindFullscreenSize(width, height); } SDL_PropertiesID props = SDL_CreateProperties(); @@ -322,6 +329,52 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b mRefreshRate = DEFAULT_REFRESH_RATE; } + /* Grab the window manager specific information */ +#if LL_LINUX + if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) + { + LL_INFOS() << "Running under X11" << LL_ENDL; + mServerProtocol = X11; + + gGLManager.mIsX11 = true; + +#if LL_X11 + sX11Data.xdisplay = (Display *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr); + sX11Data.xwindow = (Window)SDL_GetNumberProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); + sX11Data.xscreen = (int)SDL_GetNumberProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_SCREEN_NUMBER, -1); + if (sX11Data.xdisplay && sX11Data.xwindow) + { + + } +#endif + + gGLManager.initGLX(); + } + else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) + { + LL_INFOS() << "Running under Wayland" << LL_ENDL; + mServerProtocol = Wayland; + + gGLManager.mIsWayland = true; + +#if LL_WAYLAND + sWaylandData.display = (struct wl_display *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr); + sWaylandData.surface = (struct wl_surface *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, nullptr); + if (sWaylandData.display && sWaylandData.surface) + { + } +#endif + + gGLManager.initEGL(); + + // If set (XWayland) remove DISPLAY, this will prompt dullahan to also use Wayland + if(getenv("DISPLAY")) + { + unsetenv("DISPLAY"); + } + } +#endif + SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits); SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &greenBits); SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blueBits); -- cgit v1.3 From 0b3c2f6770db3b019be95802a6168e02aca7bfb5 Mon Sep 17 00:00:00 2001 From: Rye Date: Thu, 30 Oct 2025 04:44:22 -0400 Subject: Fix threaded GL contexts on linux backend Enable core profile context support on linux Signed-off-by: Rye --- indra/llwindow/llwindowsdl.cpp | 89 +++++++++++++++++++++++++++++++++--------- indra/llwindow/llwindowsdl.h | 5 +++ 2 files changed, 75 insertions(+), 19 deletions(-) (limited to 'indra/llwindow/llwindowsdl.cpp') diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp index 1cfb0b2acb..3fc0257a7f 100644 --- a/indra/llwindow/llwindowsdl.cpp +++ b/indra/llwindow/llwindowsdl.cpp @@ -231,25 +231,22 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBits); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GLContextFlag context_flags{}; if(LLRender::sGLCoreProfile) { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); #if LL_DARWIN - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + context_flags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG; #endif - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); } - SDL_GLContextFlag context_flags{}; if (gDebugGL) { context_flags |= SDL_GL_CONTEXT_DEBUG_FLAG; } -#if LL_DARWIN - context_flags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG; -#endif SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, context_flags); SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); @@ -275,6 +272,7 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b { LL_WARNS() << "Window creation failure. SDL: " << SDL_GetError() << LL_ENDL; setupFailure("Window creation error", "Error", OSMB_OK); + SDL_DestroyProperties(props); return false; } SDL_DestroyProperties(props); // Free properties once window is created @@ -431,29 +429,65 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b void* LLWindowSDL::createSharedContext() { - SDL_GLContext pContext = SDL_GL_CreateContext(mWindow); - if (pContext) + SDL_PropertiesID props = SDL_CreateProperties(); + SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "Second Life OSR Utility"); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 1); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 1); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, false); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN, true); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, false); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_UTILITY_BOOLEAN, true); + SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN, gHiDPISupport); + + auto osr_window = SDL_CreateWindowWithProperties(props); + if (osr_window == nullptr) + { + SDL_DestroyProperties(props); + return nullptr; + } + SDL_DestroyProperties(props); // Free properties once window is created + SDL_GLContext pContext = SDL_GL_CreateContext(osr_window); + + // Hack to ensure main window context is bound + SDL_GL_MakeCurrent(mWindow, mContext); + + if (!pContext) { - // HACK to ensure windows GL context is set correctly when threaded - Rye - SDL_GL_MakeCurrent(mWindow, pContext); - SDL_GL_MakeCurrent(mWindow, mContext); - LL_DEBUGS() << "Creating shared OpenGL context successful!" << LL_ENDL; - return (void*)pContext; + LL_WARNS() << "Creating shared OpenGL context failed!" << LL_ENDL; + SDL_DestroyWindow(osr_window); + return nullptr; } - LL_WARNS() << "Creating shared OpenGL context failed!" << LL_ENDL; - return nullptr; + { + LLMutexLock osr_lock(&mOSRMutex); + mOSRContexts.emplace(pContext, osr_window); + } + + LL_DEBUGS() << "Creating shared OpenGL context successful!" << LL_ENDL; + return (void*)pContext; } void LLWindowSDL::makeContextCurrent(void* contextPtr) { - SDL_GL_MakeCurrent(mWindow, (SDL_GLContext)contextPtr); + LLMutexLock osr_lock(&mOSRMutex); + auto it = mOSRContexts.find((SDL_GLContext)contextPtr); + if(it != mOSRContexts.end()) + { + SDL_GL_MakeCurrent((SDL_Window*)it->second, (SDL_GLContext)it->first); + } LL_PROFILER_GPU_CONTEXT; } void LLWindowSDL::destroySharedContext(void* contextPtr) { - SDL_GL_DestroyContext((SDL_GLContext)contextPtr); + LLMutexLock osr_lock(&mOSRMutex); + auto it = mOSRContexts.find((SDL_GLContext)contextPtr); + if(it != mOSRContexts.end()) + { + SDL_GL_DestroyContext((SDL_GLContext)it->first); + mDeadOSRWindows.push_back((SDL_Window*)it->second); + } } void LLWindowSDL::toggleVSync(bool enable_vsync) @@ -502,6 +536,15 @@ void LLWindowSDL::destroyContext() { LL_INFOS() << "destroyContext begins" << LL_ENDL; + { + LLMutexLock osr_lock(&mOSRMutex); + for(SDL_Window* pWindow : mDeadOSRWindows) + { + SDL_DestroyWindow(pWindow); + } + mDeadOSRWindows.clear(); + } + // Stop unicode input SDL_StopTextInput(mWindow); @@ -1167,6 +1210,14 @@ U32 LLWindowSDL::SDLCheckGrabbyKeys(U32 keysym, bool gain) // virtual void LLWindowSDL::processMiscNativeEvents() { + { + LLMutexLock osr_lock(&mOSRMutex); + for(SDL_Window* pWindow : mDeadOSRWindows) + { + SDL_DestroyWindow(pWindow); + } + mDeadOSRWindows.clear(); + } } void LLWindowSDL::gatherInput() diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h index 8a8e9dd1bf..4d4a7a5f65 100644 --- a/indra/llwindow/llwindowsdl.h +++ b/indra/llwindow/llwindowsdl.h @@ -31,6 +31,7 @@ #include "llwindow.h" #include "lltimer.h" +#include "llmutex.h" #include "SDL3/SDL.h" #include "SDL3/SDL_endian.h" @@ -225,6 +226,10 @@ private: U32 mKeyVirtualKey = 0; U32 mKeyModifiers = SDL_KMOD_NONE; + LLMutex mOSRMutex; + std::unordered_map mOSRContexts; + std::list mDeadOSRWindows; + void tryFindFullscreenSize(int &aWidth, int &aHeight); enum EServerProtocol{ X11, Wayland, Unknown }; -- cgit v1.3