Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scorched3d/X11: Blank screen #261

Closed
smcv opened this issue Oct 13, 2022 · 5 comments
Closed

scorched3d/X11: Blank screen #261

smcv opened this issue Oct 13, 2022 · 5 comments

Comments

@smcv
Copy link
Contributor

smcv commented Oct 13, 2022

Prerequisites:

  • Debian testing (Debian 12 alpha)
  • Video: GNOME 43 in Wayland mode (with Mesa 22.2.0 on AMD Vega, if it matters)
  • Audio: Pipewire 0.3.59, with pipewire-pulse emulating PulseAudio
  • apt install scorched3d (Debian package version 44+dfsg-7+b2)
  • Some relevant libraries:
    • libsdl1.2-compat either 1.2.58-1 (packaged in Debian experimental) or commit 63e4393 (locally built)
    • libsdl2-2.0-0 version 2.24.1+dfsg-1
    • libsdl-image1.2 version 1.2.12-13+b1
    • libsdl-mixer1.2 version 1.2.12-17+b2
    • libsdl1.2debian (real SDL 1.2) version 1.2.15+dfsg2-8

To reproduce:

  • scorched3d
  • LD_LIBRARY_PATH=.../sdl12-compat/_build scorched3d

You'll see a menu: Play / Start Server / Settings / Help / Donate / Quit. Choose Play. You should get a larger window with a 3D island and a menu that starts with Tutorial.

Expected result: it runs

Actual result: Real SDL 1.2 works. With sdl12-compat, the second (larger) window is blank.

Native Wayland is out of scope here (doesn't work, I'll open a separate bug).

@icculus
Copy link
Collaborator

icculus commented Oct 19, 2022

Disabling GL scaling fixes this, so I added a quirk, but I haven't looked further to see why GL scaling breaks this...it doesn't appear to use FBOs, but I could be wrong.

@icculus
Copy link
Collaborator

icculus commented Oct 19, 2022

Also, this patch needs work, but applying this to Debian's GLEW makes it use SDL_GL_GetProcAddress if the symbol is in the process, and fall back to glXGetProcAddress if not.

And if it's using SDL, it won't try to initialize the GLX portions.

This is enough to make scorched3d work natively on Wayland with sdl12-compat. If this patch were to go forward, we'd want it to make sure glxewInit isn't in the library, to keep the sdl12-compat heuristic that forces X11, for builds of GLEW that don't have this.

--- glew-2.2.0/src/glew.c	2020-09-26 12:41:58.000000000 -0400
+++ new-glew/src/glew.c	2022-10-19 14:06:42.712664769 -0400
@@ -74,11 +74,13 @@
 #  endif
 #  define glGetProcAddressREGAL GLEW_GET_FUN(__glewGetProcAddressREGAL)
 
-#elif defined(__sgi) || defined (__sun) || defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
+#elif defined(__sgi) || defined (__sun) || defined(__HAIKU__) || defined(GLEW_APPLE_GLX) || defined(__linux__)
 #include <dlfcn.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+static int is_sdl = 0;
+
 void* dlGetProcAddress (const GLubyte* name)
 {
   static void* h = NULL;
@@ -86,8 +88,13 @@
 
   if (h == NULL)
   {
-    if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
-    gpa = dlsym(h, "glXGetProcAddress");
+    if ((h = dlopen(NULL, RTLD_NOW | RTLD_LOCAL)) == NULL) return NULL;
+
+    gpa = dlsym(h, "SDL_GL_GetProcAddress");
+    if (gpa != NULL)
+      is_sdl = 1;
+    else
+      gpa = dlsym(h, "glXGetProcAddress");
   }
 
   if (gpa != NULL)
@@ -175,7 +182,7 @@
 #elif defined(__native_client__)
 #  define glewGetProcAddress(name) NULL /* TODO */
 #else /* __linux */
-#  define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
+#  define glewGetProcAddress(name) dlGetProcAddress(name)
 #endif
 
 /*
@@ -22773,6 +22780,10 @@
   int major, minor;
   const GLubyte* extStart;
   const GLubyte* extEnd;
+
+  if (is_sdl)
+    return GLEW_OK;
+
   /* initialize core GLX 1.2 */
   if (_glewInit_GLX_VERSION_1_2()) return GLEW_ERROR_GLX_VERSION_11_ONLY;
   /* check for a display */

@smcv
Copy link
Contributor Author

smcv commented Oct 19, 2022

If this patch were to go forward, we'd want it to make sure glxewInit isn't in the library

I think that would be an ABI break, because it's public ABI in GLEW. Instead, we'd have to make the version of GLEW that supports automatic choice of GLX vs. EGL export more symbols, and then make the quirk work like this (pseudocode):

if (we found glxewInit && we didn't find the new symbol that indicates support for runtime platform selection) {
    force X11;
}

... and adding or changing ABI downstream is generally not something that Debian and other downstream distros should be doing (it often causes us worse problems at some point in the future), so that should happen in GLEW upstream, not in distros.

nigels-com/glew#172 seems to be the issue for supporting this properly in a future GLEW version. nigels-com/glew#306, nigels-com/glew#315 and nigels-com/glew#343 also look relevant.

I'm not so sure that GLEW upstream would be willing to call into SDL (which from their perspective is an arbitrary third party library), but I might be wrong...

@icculus
Copy link
Collaborator

icculus commented Oct 19, 2022

Yeah, I don't have the energy to get into it with upstream, but it would solve so many problems if something like this landed.

(for example, with this patch to GLEW, you don't need the quirk we added for this game, either.)

@smcv
Copy link
Contributor Author

smcv commented Oct 24, 2022

Confirmed fixed with 67f8b3a, 1.2.58 + 29 commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants