-
Notifications
You must be signed in to change notification settings - Fork 360
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
r_waylandcompat should be deprecated in favor of EGL_EXT_present_opaque #426
Comments
Mesa3D Bugreport: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4933 |
I wonder if the underlying issue can be fixed in dhewm3 so neither is necessary. By making sure that the alpha channel doesn't contain the wrong value or whatever exactly causes this |
I investigated the underlying issue a bit - the underlying issue is "why the hell does the window need alpha bits, it's not supposed to be translucent?!". So I set For reference, this is what the main menu is supposed to look like: Some observations:
|
Ok, the problem with apitrace was that its retrace tool (used to get screenshots of the frames and the buffers and further information about the OpenGL state at a specific gl-call) doesn't really use the same "visual" (settings for bits per color channel etc) as the traced program: https://github.com/apitrace/apitrace/blob/764c9786b2312b656ce0918dff73001c6a85f46f/retrace/glws_glx.cpp#L265-L273 I added a quick hack, that allows setting an environment variable to set the alpha bits: diff --git a/retrace/glws_glx.cpp b/retrace/glws_glx.cpp
index 749b58dd..dac3f17f 100644
--- a/retrace/glws_glx.cpp
+++ b/retrace/glws_glx.cpp
@@ -262,12 +262,18 @@ createVisual(bool doubleBuffer, unsigned samples, Profile profile) {
GlxVisual *visual = new GlxVisual(profile);
Attributes<int> attribs;
+ int alphabits = 8;
+ const char* alphaBitEnv = getenv("APITRACE_ALPHA_BITS");
+ if(alphaBitEnv != NULL) {
+ alphabits = atoi(alphaBitEnv);
+ }
+
attribs.add(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT);
attribs.add(GLX_RENDER_TYPE, GLX_RGBA_BIT);
attribs.add(GLX_RED_SIZE, 8);
attribs.add(GLX_GREEN_SIZE, 8);
attribs.add(GLX_BLUE_SIZE, 8);
- attribs.add(GLX_ALPHA_SIZE, 8);
+ attribs.add(GLX_ALPHA_SIZE, alphabits);
attribs.add(GLX_DOUBLEBUFFER, doubleBuffer ? GL_TRUE : GL_FALSE);
attribs.add(GLX_DEPTH_SIZE, 1);
attribs.add(GLX_STENCIL_SIZE, 1); So I can start the apitrace GUI with What I found out was: before the OpenGL drawcalls that made it look wrong, there were calls to to This makes sense - the source for blending is the currently rendered polys and their texture, the destination is the Default Framebuffer of the OpenGL context (more specifically GL_BACK) - which has 0 alphabits (=> no alpha channel), as requested. So what can we do about this? I guess one possibility is to use a Framebuffer Object (configured with an alpha chan) to render to, at least on hardware that supports GL_EXT_Framebuffer_object (or ideally GL_ARB_framebuffer_object), and only set alpha bits on the window/context on hardware that doesn't. |
Hmm that looks pretty much like X11 (or Windows+nvidia) with 0 alpha bits..
In the main menu those bars where the Doom3 logo should be are a texture that actually looks like that and is supposed to be blended onto the logo (with I assume that it's similar for the static in front of the video/cutscene: Probably it's just supposed to be some subtle static effect on top of the real scene, but for some reason the framebuffer doesn't have alpha so the blending with "destination alpha" makes it opaque. UPDATE: Some things worth testing: latest SDL git; making SDL use native wayland vs xwayland - and checking the dhewm3 console output (or the newly added ~/.local/share/dhewm3/dhewm3log.txt) for the |
Another try with SDL build from git, the exact commit was b06866ef9717d57ced4443d90ab8f0a5105be07a. dhewm3 was started with a clean config to rule out any configuration problems,
But apparently it hasn't. Exactly same setup under xwayland looks good. The menu renders correctly, the cutscene and the in game GUIs are working like they should. Some more information regarding my system:
|
Thank you very much! Mentioned the issue at libsdl-org/SDL#4306 (comment) |
I've opened a mesa bugreport: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5886 |
I pushed a workaround (it tells SDL2 to not use EGL_EXT_present_opaque and makes sure that the windows default framebuffer is opaque at the end of a frame). |
For some reason Wayland thought it would be clever to be the only windowing system that (non-optionally) uses the alpha chan of the window's default OpenGL framebuffer for window transparency. This always caused glitches with dhewm3, as Doom3 uses that alpha-chan for blending tricks (with GL_DST_ALPHA) - especially visible in the main menu or when the flashlight is on. So far the workaround has been r_waylandcompat which requests an OpenGL context/visual without alpha chan (0 alpha bits), but that also causes glitches. There's an EGL extension that's supposed to fix this issue (EGL_EXT_present_opaque), and newer SDL2 versions use it (when using the wayland backend) - but unfortunately the Mesa implementation is broken (seems to provide a visual without alpha channel even if one was requested), see https://gitlab.freedesktop.org/mesa/mesa/-/issues/5886 and libsdl-org/SDL#4306 (comment) for the corresponding SDL2 discussion To work around this issue, dhewm3 now disables the use of that EGL extension and (optionally) makes sure the alpha channel is opaque at the end of the frame. This behavior is controlled with the r_fillWindowAlphaChan CVar: If it's 1, this always is done (regardless if wayland is used or not), if it's 0 it's not done (even on wayland), if it's -1 (the default) it's only done if the SDL "video driver" is wayland (this could be easily enhanced later in case other windowing systems have the same issue) r_waylandcompat has been removed (it never worked properly anyway), so now the window always has an alpha chan
Sorry that extension was totally broken. It's fixed in https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27709 which should be shipped in Mesa 24.1 and hopefully some 24.0.x point releases. |
The fundamental problem here is that Doom 3 sets the alpha bits for some assets, most notably the menu and some in game GUIs. With GLX these are pseudotransparent to the background of the GL context, the clear color or something similar. With EGL they're transparent in the literal sense of the word, leading to all kind on interesting render problems. As a work around
r_waylandcompat
was added. When enabled, the alpha bits of the GL context are forced to 0. While this solves the direct problem, it causes a lot of other render problems... At least on Gnome 4.41 withr_waylandcompat 0
the game is playable, withr_waylandcompat 1
it's more or less broken.Luckily there's a solution for this. Mesa 21.3.0 added the
EGL_EXT_present_opaque
extension which can be used to force the presentation thing to be opaque. That's the same behavior as GLX had. And SDL 2.0.18 will support it. It's exposed by theSDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY
hint, set toSDL_TRUE
by default. Nvidia already said that they also support that EGL extension. I don't know if they've already implemented it or if it will be part of later update.So: Let's remove
r_waylandcompat
, it does more harm than good. Users who run the game under wayland (which must be forced by settingSDL_VIDEODRIVER=wayland
aynway) should use an up to date Mesa and SDL instead.The text was updated successfully, but these errors were encountered: