From ede6095a99111967626be9a9fb427f5535fe7236 Mon Sep 17 00:00:00 2001 From: Utkarsh Dalal Date: Wed, 4 Nov 2026 18:47:26 +0530 Subject: [PATCH] glx/xlib: count the alpha channel in GLX_BUFFER_SIZE The xlib GLX emulation reports GLX_BUFFER_SIZE as the X visual's depth. When the visual carries an alpha channel on top of its stored planes (an 8/8/8/8 config on a depth-24 TrueColor visual, which is what Xwayland offers), that makes the format 24 colour bits with 8 alpha bits. A DRI GLX fbconfig for the same channels reports 32, and Wine turns GLX_BUFFER_SIZE into cColorBits, so wglChoosePixelFormatARB requests for 32 colour bits (a minimum match) found no format under gamescope: Tomb Raider I-III Remastered then used an uninitialised format index and crashed right after its window mapped. Count the alpha bits when the visual depth only covers the RGB channels. On the in-app X server the single visual is depth 32, so nothing changes there. --- src/gallium/frontends/glx/xlib/glx_api.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/glx/xlib/glx_api.c b/src/gallium/frontends/glx/xlib/glx_api.c index d984125b04a..62f6df57dd4 100644 --- a/src/gallium/frontends/glx/xlib/glx_api.c +++ b/src/gallium/frontends/glx/xlib/glx_api.c @@ -1510,7 +1510,17 @@ get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) *value = (int) True; return 0; case GLX_BUFFER_SIZE: - *value = xmvis->visinfo->depth; + /* The X visual's depth only counts the planes the server stores. + * When the visual carries an alpha channel on top of those planes + * (an 8/8/8/8 config on a depth-24 TrueColor visual), count it the + * way a DRI GLX fbconfig does, so GLX_BUFFER_SIZE is 32 and not 24: + * Windows apps ask wglChoosePixelFormatARB for 32 colour bits. */ + *value = xmvis->visinfo->depth; + if (xmvis->mesa_visual.alphaBits > 0 && + xmvis->visinfo->depth <= xmvis->mesa_visual.redBits + + xmvis->mesa_visual.greenBits + + xmvis->mesa_visual.blueBits) + *value += xmvis->mesa_visual.alphaBits; return 0; case GLX_LEVEL: *value = 0;