From 877b0b9c304cd66cd5db1668454cc194e091db85 Mon Sep 17 00:00:00 2001 From: Joshua Tam <297250+joshuatam@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:02:46 +0800 Subject: [PATCH 1/5] android: build the guest's GL stack with kopper The container image ships Mesa 24.3's classic libGL: the glx/xlib frontend on winsys/sw/xlib, presenting with XShmPutImage. A GL guest therefore renders through zink on a headless Vulkan instance and copies the result into the X server, so its frames never create a Vulkan surface of their own -- the ICD shim sees no swapchain, applies no acquire cap, generates nothing and never gets a release note. That is why every GL title on this stack is paced by gamescope's limiter alone. Kopper is zink's own WSI: it presents through GLX/DRI3, so the client creates a VkSurfaceKHR from its X window, and the shim already serves that (VK_KHR_xcb_surface). A GL guest then rides the same ring, the same gate and the same release notes as a Vulkan guest. So build one, from the same pinned upstream source the glamor stage uses (android/mesa-glamor/fetch-mesa.sh: Mesa 26.2.6 with its patches) and the same cross file, with platforms=x11, glx=dri and opengl=true; glamor's `-Dglx=disabled -Dopengl=false -Dplatforms=` is the opposite of what a GL client needs. glvnd and shared-glapi are off so the result is one libGL.so.1, the shape the container image already has. Measured on the build: libGL.so.1.2.0 is 765 KB with LIBGL_KOPPER_DISABLE present (the option a 24.3 library does not even contain), no XShmPutImage, and libgallium-26.2.6.so carries zink and the xcb surface path. The cross file's pkg_config_libdir lists only the overlay, which carries libdrm, libglvnd and zlib -- x11, xcb, xshmfence and the DRI protocol packages live in the termux prefix, so this build appends it, overlay first. C only, so the -I ordering hazard that keeps the prefix out of the glamor build does not apply. Not wired into the payload yet: nothing copies this stage, and it has not been run on a device. The version coupling is the thing to settle first -- the imagefs has Mesa 24.3's libglapi.so.0, and glapi is inside this libGL instead, so the stack has to travel as a set. --- .gitignore | 2 + android/mesa-gl/build-mesa-gl.sh | 136 +++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 android/mesa-gl/build-mesa-gl.sh diff --git a/.gitignore b/.gitignore index dc5c5dfae..64c30c7a0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ android/cross/aarch64-linux-android.txt # Work dir of android/mesa-glamor/build-mesa-glamor.sh (tarball, source, stage). /build-android-mesa-glamor/ +# Work dir of android/mesa-gl/build-mesa-gl.sh (same shape, the guest GL stack). +/build-android-mesa-gl/ diff --git a/android/mesa-gl/build-mesa-gl.sh b/android/mesa-gl/build-mesa-gl.sh new file mode 100644 index 000000000..2c9f11bb5 --- /dev/null +++ b/android/mesa-gl/build-mesa-gl.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +# NDK cross-build of the GL library a *guest* loads: Mesa zink with GLX + DRI3, +# i.e. the kopper path, as one monolithic libGL.so.1.5.0. +# +# Why this exists: the container image ships Mesa 24.3's classic libGL (glx/xlib +# frontend on winsys/sw/xlib, presenting with XShmPutImage). A GL guest then +# renders through zink on a headless Vulkan instance and copies the result into +# the X server, so its frames never create a Vulkan surface -- the ICD shim sees +# no swapchain, applies no acquire cap, generates nothing and never gets a release +# note. Kopper (zink's own WSI) presents through GLX/DRI3 instead: the client +# creates a VkSurfaceKHR from its X window, which the shim already serves +# (VK_KHR_xcb_surface, gamenative-drm#35), so GL rides the same ring and the same +# gate as a Vulkan guest. +# +# The source, cross file and patch set are the ones android/mesa-glamor already +# uses (pinned upstream tarball, fetch-mesa.sh), so both Mesas in the payload are +# one version and one toolchain. +# +# Installs into a stage prefix: +# lib/libGL.so.1.5.0, libGL.so.1, libGL.so the GL/GLX client, glapi built in +# lib/dri/zink_dri.so the swrast-free DRI driver +# share/glvnd/... absent: glvnd is disabled on purpose +# +# Env overrides are the same as build-mesa-glamor.sh: NDK, TERMUXFS, +# GN_MESA_GL_ROOT (work dir), GN_MESA_GL_STAGE (install prefix). + +set -euo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +GS_DIR="$(cd "$HERE/../.." && pwd)" +GLAMOR="$GS_DIR/android/mesa-glamor" +NDK="${NDK:-$HOME/Android/Sdk/ndk/27.3.13750724}" +TERMUXFS="${TERMUXFS:-$HOME/termuxfs/aarch64/data/data/com.termux/files/usr}" +ROOT="${GN_MESA_GL_ROOT:-$GS_DIR/build-android-mesa-gl}" +STAGE="${GN_MESA_GL_STAGE:-$ROOT/stage}" +BUILD_DIR="$ROOT/build" + +case "$(uname -s)" in + Darwin) NDK_HOST=darwin-x86_64 ;; + *) NDK_HOST=linux-x86_64 ;; +esac +NDK_BIN="$NDK/toolchains/llvm/prebuilt/$NDK_HOST/bin" +[ -x "$NDK_BIN/aarch64-linux-android28-clang" ] || { echo "NDK not found at $NDK" >&2; exit 1; } +[ -d "$TERMUXFS/include/libdrm" ] || { echo "no libdrm headers under $TERMUXFS" >&2; exit 1; } +[ -f "$TERMUXFS/include/xcb/xcb.h" ] || { echo "no libxcb headers under $TERMUXFS" >&2; exit 1; } +[ -f "$TERMUXFS/include/GL/glx.h" ] || { + echo "no GL/glx.h under $TERMUXFS/include — GLX needs the libGL headers" >&2; exit 1; } +BISON="$(command -v bison)" || { echo "bison not in PATH" >&2; exit 1; } +FLEX="$(command -v flex)" || { echo "flex not in PATH" >&2; exit 1; } +CCACHE="$(command -v ccache || true)" + +# Same build-tool venv rule as the glamor build: Mesa imports mako/PyYAML and +# needs meson >= 1.4, and a bare `meson` from PATH runs on an interpreter that +# usually has neither. +VENV="$ROOT/venv" +if [ ! -x "$VENV/bin/meson" ]; then + PYTHON=/usr/bin/python3 + [ -x "$PYTHON" ] || PYTHON=python3 + rm -rf "$VENV" + "$PYTHON" -m venv "$VENV" || { echo "cannot create the build-tool venv" >&2; exit 1; } + "$VENV/bin/pip" install --quiet 'meson>=1.4,<2' mako pyyaml packaging +fi +PATH="$VENV/bin:$PATH" + +# Short-circuit so the pinned tarball and its patches are shared, not refetched. +SRC="$(bash "$GLAMOR/fetch-mesa.sh" "$ROOT" | tail -1)" + +CROSS="$ROOT/cross-aarch64-linux-android.txt" +sed -e "s|@CCACHE@|${CCACHE:+'$CCACHE', }|g" \ + -e "s|@NDK_BIN@|$NDK_BIN|g" \ + -e "s|@BISON@|$BISON|g" \ + -e "s|@FLEX@|$FLEX|g" \ + -e "s|@DEPS@|$TERMUXFS|g" \ + -e "s|@OVERLAY@|$GLAMOR/overlay|g" \ + "$GLAMOR/cross.txt.in" > "$CROSS" +if grep -q '@[A-Z_]*@' "$CROSS"; then + echo "cross file still has unsubstituted placeholders: $CROSS" >&2 + exit 1 +fi + +# The glamor build looks only at the overlay's .pc files, because the prefix's +# add -I${includedir} and break C++. This build needs the prefix's real ones -- +# x11, xcb, xshmfence and the DRI protocol packages have no overlay copy -- and it +# compiles C only, so that hazard does not apply. Overlay stays first so libdrm +# still comes from it. +python3 - "$CROSS" "$TERMUXFS" <<'EOF' +import sys, re +path, deps = sys.argv[1], sys.argv[2] +text = open(path).read() +want = "pkg_config_libdir = ['%s/overlay/pkgconfig', '%s/lib/pkgconfig']" % ( + re.search(r"-I([^']*)/overlay/include", text).group(1), deps) +text = re.sub(r"pkg_config_libdir = \[[^\]]*\]", want, text) +open(path, "w").write(text) +print("pkg_config_libdir:", want) +EOF + +# platforms=x11 the GLX client talks X directly; this is what the glamor build +# turns off because glamor is EGL+GBM only +# glx=dri GLX with a DRI backend -- the frontend that carries kopper. +# 'disabled' means no GLX at all, 'xlib' would mean an indirect +# server-side path that presents by copy +# opengl=true build libGL; without it there is no client library +# glvnd=disabled one monolithic libGL.so.1.5.0, the shape the container image +# already has, so nothing has to learn about libGLX_mesa +# vulkan-drivers= zink dlopens the system ICD at runtime +# gbm/egl kept off: a GLX client needs neither, and every library the +# payload ships has to resolve inside it (check-payload-closure) +rm -rf "$BUILD_DIR" +meson setup "$BUILD_DIR" "$SRC" \ + --cross-file "$CROSS" \ + -Dprefix="$STAGE" \ + -Dbuildtype=release \ + -Dplatforms=x11 \ + -Dglx=dri \ + -Dopengl=true \ + -Dgles1=disabled -Dgles2=disabled \ + -Degl=disabled -Dgbm=disabled \ + -Dgallium-drivers=zink \ + -Dvulkan-drivers= \ + -Dshared-glapi=disabled \ + -Dglvnd=disabled \ + -Dllvm=disabled \ + -Dvalgrind=disabled \ + -Dzstd=disabled \ + -Dxmlconfig=disabled -Dexpat=disabled \ + -Dgallium-va=disabled \ + -Dgallium-rusticl=false \ + -Dgallium-d3d10umd=false \ + -Dtools= \ + -Dbuild-tests=false -Dlmsensors=disabled -Dperfetto=false \ + -Dandroid-libbacktrace=disabled + +ninja -C "$BUILD_DIR" install + +echo "staged: $STAGE" +ls -l "$STAGE/lib"/libGL.so* "$STAGE/lib/dri" 2>/dev/null || true From 6c89b6dafee1234e21d4e20ea9e3b0522b385463 Mon Sep 17 00:00:00 2001 From: Joshua Tam <297250+joshuatam@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:31:50 +0800 Subject: [PATCH 2/5] android: ship the guest's GL stack in the payload A GL guest loads libGL.so.1 through wine's opengl32. The container image's own library is Mesa 24.3's glx/xlib build, which presents with XShmPutImage: the frames are copied into the X server and never create a Vulkan surface, so the shim sees no swapchain, applies no acquire cap, generates nothing and never gets a release note. The mesa-gl stage is the same Mesa 26.2.6 source as the glamor stage built with -Dplatforms=x11 -Dglx=dri -Dopengl=true, so a GL guest presents through GLX/DRI3 (kopper) and rides the same ring and the same gate as a Vulkan guest. Staged in lib/gl rather than lib/: both stages emit libgallium-26.2.6.so and one would overwrite the other. The launcher puts lib/gl ahead of lib/ on LD_LIBRARY_PATH, so a GL guest resolves this libGL and this libgallium while gamescope and Xwayland keep the glamor stage's copies. Both are the same Mesa version, so no process can end up with two gallium APIs. libGL keeps its lib/dri pointer in lib/gl/dri because it needs the x11-platform module. glvnd is disabled and glapi is built in, so the imagefs's Mesa 24.3 libglapi.so.0 is untouched. --- android/package-gamescope.sh | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/android/package-gamescope.sh b/android/package-gamescope.sh index 4b968a73f..c1e5c5340 100755 --- a/android/package-gamescope.sh +++ b/android/package-gamescope.sh @@ -46,6 +46,9 @@ DEPS="${GAMESCOPE_TERMUX_PREFIX:-$HOME/termuxfs/aarch64/data/data/com.termux/fil # libxml2/libicu). libglvnd's loader/GLES libs and everything else still come # from the prefix. GN_MESA_GLAMOR_STAGE="${GN_MESA_GLAMOR_STAGE:-$GS_DIR/build-android-mesa-glamor/stage}" +# Second Mesa stage: the GL a *guest* loads (android/mesa-gl/build-mesa-gl.sh), +# GLX + DRI3 + kopper rather than the glamor stage's GLES/EGL. +GN_MESA_GL_STAGE="${GN_MESA_GL_STAGE:-$GS_DIR/build-android-mesa-gl/stage}" # macOS writes an AppleDouble "._name" sibling for every file it copies or # archives, which lands in the payload as a thousand extra members. BSD cp and # tar honour this; on Linux it is inert. @@ -279,8 +282,52 @@ mkdir -p "$STAGE/lib/gbm" cp -L "$GN_MESA_GLAMOR_STAGE/lib/gbm/dri_gbm.so" "$STAGE/lib/gbm/dri_gbm.so" resolve_libs "$STAGE/lib/gbm/dri_gbm.so" +# --- the guest's GL: GLX + DRI3 + kopper (android/mesa-gl) --------------------- +# A GL guest loads libGL.so.1 through wine's opengl32. The container image's own +# library is Mesa 24.3's glx/xlib build, which presents with XShmPutImage: the +# frames are copied into the X server and never create a Vulkan surface, so the +# shim sees no swapchain, applies no acquire cap, generates nothing and never gets +# a release note. This one presents through GLX/DRI3 (kopper), so the client +# creates a surface from its X window and rides the same ring and the same gate as +# a Vulkan guest. +# +# -Dglvnd=disabled means this is one monolithic library that dispatches nothing, +# so no libGLX_mesa vendor for glvnd to find is needed. glapi is built in +# (-Dshared-glapi=disabled), so the imagefs's Mesa 24.3 libglapi.so.0 is +# untouched: nothing at this path links it. +ensure_mesa_gl_stage() { + local want + want="$(ls "$GN_MESA_GL_STAGE"/lib/libGL.so.1.* 2>/dev/null | head -1)" + if [ -n "$want" ] && [ -z "$(find "$GS_DIR/android/mesa-gl" -type f -newer "$want" 2>/dev/null | head -1)" ]; then + return 0 + fi + echo "mesa-gl: building the guest GL stage at $GN_MESA_GL_STAGE" + bash "$GS_DIR/android/mesa-gl/build-mesa-gl.sh" +} +ensure_mesa_gl_stage +GL_LIB="$(ls "$GN_MESA_GL_STAGE"/lib/libGL.so.1.* 2>/dev/null | head -1)" +[ -f "$GL_LIB" ] || { echo "error: no libGL.so.1.* in $GN_MESA_GL_STAGE/lib" >&2; exit 1; } +GL_GALLIUM=("$GN_MESA_GL_STAGE"/lib/libgallium-*.so) +[ "${#GL_GALLIUM[@]}" = 1 ] && [ -f "${GL_GALLIUM[0]}" ] || { + echo "error: expected one libgallium-*.so in $GN_MESA_GL_STAGE/lib" >&2; exit 1; } +# Its own directory, because both Mesa stages emit the same megadriver soname +# (libgallium-26.2.6.so) and one would overwrite the other. lib/gl comes first on +# LD_LIBRARY_PATH (launcher), so a GL guest resolves this libGL and this gallium; +# the glamor stage's copies in lib/ stay what gamescope and Xwayland's EGL path +# use. Both are the same Mesa version, so the split cannot produce two different +# gallium APIs in one process. +mkdir -p "$STAGE/lib/gl/dri" +cp -L "$GL_LIB" "$STAGE/lib/gl/libGL.so.1.2.0" +ln -sfn libGL.so.1.2.0 "$STAGE/lib/gl/libGL.so.1" +ln -sfn libGL.so.1 "$STAGE/lib/gl/libGL.so" +cp -L "${GL_GALLIUM[0]}" "$STAGE/lib/gl/${GL_GALLIUM[0]##*/}" +cp -L "$GN_MESA_GL_STAGE/lib/dri/libdril_dri.so" "$STAGE/lib/gl/dri/libdril_dri.so" +ln -sfn libdril_dri.so "$STAGE/lib/gl/dri/zink_dri.so" +resolve_libs "$STAGE/lib/gl/libGL.so.1.2.0" "$STAGE/lib/gl/${GL_GALLIUM[0]##*/}" \ + "$STAGE/lib/gl/dri/libdril_dri.so" + # glvnd EGL vendor json (library_path: libEGL_mesa.so.0, resolved from -# LD_LIBRARY_PATH = filesDir/gamescope/lib on device). +# LD_LIBRARY_PATH = filesDir/gamescope/lib and .../lib/gl on device). mkdir -p "$STAGE/share/glvnd/egl_vendor.d" cp "$GN_MESA_GLAMOR_STAGE/share/glvnd/egl_vendor.d/50_mesa.json" \ "$STAGE/share/glvnd/egl_vendor.d/" From 8b083d8a352b69fcaeaf77f722a6a34af54b1748 Mon Sep 17 00:00:00 2001 From: Joshua Tam <297250+joshuatam@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:15:12 +0800 Subject: [PATCH 3/5] android: build EGL and GBM into the guest GL stage The GLX stack alone does not get a GL guest onto the shim: Xwayland's glamor is EGL-on-GBM, and with the glamor stage's EGL the server never got glamor. Xwayland logged "Failed to make EGL context current with GL" and "with GLES2", disabled glamor, fell back to software, and then every GL client reported "DRI3 not available" and stayed off the shim -- so the kopper libGL we ship was dead on arrival. That EGL is libglvnd's dispatch stub, and it was built for the termux prefix: its compiled-in vendor dirs are /data/data/com.termux/files/usr/{etc,share}/glvnd/ egl_vendor.d, which do not exist on device, so no vendor loads at all (the client extension list is empty) unless something sets __EGL_VENDOR_LIBRARY_DIRS. The launcher does set it, which is enough for glvnd to find 50_mesa.json, but the indirection is what failed and it is removable: this stage is glvnd=disabled, so its libEGL is the implementation. One stage now serves both sides of the socket -- the guest's GLX client and the server's EGL-on-GBM -- which is also why both galliums stay in lib/gl together: same tree, same version, same soname. -Dgles2=enabled comes with egl; the staged libGLESv2 is not shipped to the payload, which keeps the prefix's copy in front of everything else. --- android/mesa-gl/build-mesa-gl.sh | 33 +++++++++++++++++++++++--------- android/package-gamescope.sh | 29 +++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/android/mesa-gl/build-mesa-gl.sh b/android/mesa-gl/build-mesa-gl.sh index 2c9f11bb5..22a9950d6 100644 --- a/android/mesa-gl/build-mesa-gl.sh +++ b/android/mesa-gl/build-mesa-gl.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # NDK cross-build of the GL library a *guest* loads: Mesa zink with GLX + DRI3, -# i.e. the kopper path, as one monolithic libGL.so.1.5.0. +# i.e. the kopper path, as one monolithic libGL.so.1.2.0. # # Why this exists: the container image ships Mesa 24.3's classic libGL (glx/xlib # frontend on winsys/sw/xlib, presenting with XShmPutImage). A GL guest then @@ -17,8 +17,10 @@ # one version and one toolchain. # # Installs into a stage prefix: -# lib/libGL.so.1.5.0, libGL.so.1, libGL.so the GL/GLX client, glapi built in +# lib/libGL.so.1.2.0, libGL.so.1, libGL.so the GL/GLX client, glapi built in +# lib/libEGL.so.1, lib/libgbm.so.1, libgbm.so the server's glamor EGL + GBM # lib/dri/zink_dri.so the swrast-free DRI driver +# lib/gbm/dri_gbm.so libgbm's dri backend # share/glvnd/... absent: glvnd is disabled on purpose # # Env overrides are the same as build-mesa-glamor.sh: NDK, TERMUXFS, @@ -95,16 +97,28 @@ print("pkg_config_libdir:", want) EOF # platforms=x11 the GLX client talks X directly; this is what the glamor build -# turns off because glamor is EGL+GBM only +# turns off because glamor is EGL+GBM only. The GBM EGL platform +# is not a choice in `platforms` -- it comes with -Dgbm=enabled, +# which is why this stage builds both sides of the socket: the +# guest's GLX client and the server's EGL-on-GBM. # glx=dri GLX with a DRI backend -- the frontend that carries kopper. # 'disabled' means no GLX at all, 'xlib' would mean an indirect # server-side path that presents by copy # opengl=true build libGL; without it there is no client library -# glvnd=disabled one monolithic libGL.so.1.5.0, the shape the container image +# glvnd=disabled one monolithic libGL.so.1.2.0, the shape the container image # already has, so nothing has to learn about libGLX_mesa # vulkan-drivers= zink dlopens the system ICD at runtime -# gbm/egl kept off: a GLX client needs neither, and every library the -# payload ships has to resolve inside it (check-payload-closure) +# egl=gbm=enabled measured, not assumed: with the glamor stage's EGL the X server +# never got glamor. Xwayland logged "Failed to make EGL context +# current with GL/GLES2" then "EGL setup failed, disabling +# glamor", fell back to software, and every GL client then read +# "DRI3 not available" and stayed off the shim. That EGL is +# libglvnd's dispatch stub, built for the termux prefix: its +# compiled-in vendor dirs are /data/data/com.termux/files/usr/ +# {etc,share}/glvnd/egl_vendor.d, absent on device, so no vendor +# loads (client extension list empty) unless something sets +# __EGL_VENDOR_LIBRARY_DIRS. glvnd=disabled below removes the +# indirection: this libEGL IS the implementation rm -rf "$BUILD_DIR" meson setup "$BUILD_DIR" "$SRC" \ --cross-file "$CROSS" \ @@ -113,8 +127,8 @@ meson setup "$BUILD_DIR" "$SRC" \ -Dplatforms=x11 \ -Dglx=dri \ -Dopengl=true \ - -Dgles1=disabled -Dgles2=disabled \ - -Degl=disabled -Dgbm=disabled \ + -Dgles1=disabled -Dgles2=enabled \ + -Degl=enabled -Dgbm=enabled \ -Dgallium-drivers=zink \ -Dvulkan-drivers= \ -Dshared-glapi=disabled \ @@ -133,4 +147,5 @@ meson setup "$BUILD_DIR" "$SRC" \ ninja -C "$BUILD_DIR" install echo "staged: $STAGE" -ls -l "$STAGE/lib"/libGL.so* "$STAGE/lib/dri" 2>/dev/null || true +ls -l "$STAGE/lib"/libGL.so* "$STAGE/lib"/libEGL.so* "$STAGE/lib"/libgbm.so* \ + "$STAGE/lib/dri" "$STAGE/lib/gbm" 2>/dev/null || true diff --git a/android/package-gamescope.sh b/android/package-gamescope.sh index c1e5c5340..a74ccec0a 100755 --- a/android/package-gamescope.sh +++ b/android/package-gamescope.sh @@ -312,19 +312,38 @@ GL_GALLIUM=("$GN_MESA_GL_STAGE"/lib/libgallium-*.so) echo "error: expected one libgallium-*.so in $GN_MESA_GL_STAGE/lib" >&2; exit 1; } # Its own directory, because both Mesa stages emit the same megadriver soname # (libgallium-26.2.6.so) and one would overwrite the other. lib/gl comes first on -# LD_LIBRARY_PATH (launcher), so a GL guest resolves this libGL and this gallium; -# the glamor stage's copies in lib/ stay what gamescope and Xwayland's EGL path -# use. Both are the same Mesa version, so the split cannot produce two different +# LD_LIBRARY_PATH (launcher), so a GL guest resolves this libGL and this gallium. +# Both are the same Mesa version, so the split cannot produce two different # gallium APIs in one process. -mkdir -p "$STAGE/lib/gl/dri" +# +# The same directory also carries this build's EGL + GBM, and that is what the +# *server* side of the socket loads: Xwayland's glamor is EGL-on-GBM. With the +# glamor stage's EGL (libglvnd's dispatch stub, compiled for termux-prefix vendor +# dirs) Xwayland logged "Failed to make EGL context current with GL" and +# "with GLES2", then disabled glamor and fell back to software — and every GL +# client then reported "DRI3 not available" and stayed off the shim. This one is +# glvnd=disabled, so LIBEGL IS the implementation and there is no vendor lookup +# to get wrong. GBM comes with it because EGL's GBM platform is linked against +# it, and libgbm's dri backend must be the one built from the same tree. +mkdir -p "$STAGE/lib/gl/dri" "$STAGE/lib/gl/gbm" cp -L "$GL_LIB" "$STAGE/lib/gl/libGL.so.1.2.0" ln -sfn libGL.so.1.2.0 "$STAGE/lib/gl/libGL.so.1" ln -sfn libGL.so.1 "$STAGE/lib/gl/libGL.so" cp -L "${GL_GALLIUM[0]}" "$STAGE/lib/gl/${GL_GALLIUM[0]##*/}" cp -L "$GN_MESA_GL_STAGE/lib/dri/libdril_dri.so" "$STAGE/lib/gl/dri/libdril_dri.so" ln -sfn libdril_dri.so "$STAGE/lib/gl/dri/zink_dri.so" +GL_EGL=(libEGL.so.1 libgbm.so.1) +for n in "${GL_EGL[@]}"; do + src="$(ls "$GN_MESA_GL_STAGE/lib/$n".*.* 2>/dev/null | head -1)" + [ -f "$src" ] || { echo "error: no $n.*.* in $GN_MESA_GL_STAGE/lib" >&2; exit 1; } + cp -L "$src" "$STAGE/lib/gl/$n.0.0" + ln -sfn "$n.0.0" "$STAGE/lib/gl/$n" + ln -sfn "$n" "$STAGE/lib/gl/${n%.*}" +done +cp -L "$GN_MESA_GL_STAGE/lib/gbm/dri_gbm.so" "$STAGE/lib/gl/gbm/dri_gbm.so" resolve_libs "$STAGE/lib/gl/libGL.so.1.2.0" "$STAGE/lib/gl/${GL_GALLIUM[0]##*/}" \ - "$STAGE/lib/gl/dri/libdril_dri.so" + "$STAGE/lib/gl/dri/libdril_dri.so" "$STAGE/lib/gl/libEGL.so.1.0.0" \ + "$STAGE/lib/gl/libgbm.so.1.0.0" "$STAGE/lib/gl/gbm/dri_gbm.so" # glvnd EGL vendor json (library_path: libEGL_mesa.so.0, resolved from # LD_LIBRARY_PATH = filesDir/gamescope/lib and .../lib/gl on device). From 3738bbe92a77d3f29fa60f1a1b8ab506c4e0c9ee Mon Sep 17 00:00:00 2001 From: Joshua Tam <297250+joshuatam@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:41:41 +0800 Subject: [PATCH 4/5] android: ship a real libGLESv2, because glamor cannot use desktop GL here Mesa refuses EGL_OPENGL_API on Android: src/egl/main/eglcurrent.h gates it on `#if HAVE_OPENGL && !DETECT_OS_ANDROID` with the comment "OpenGL is not a valid/supported API on Android". So eglBindAPI(EGL_OPENGL_API) returns EGL_BAD_PARAMETER, the display advertises EGL_CLIENT_APIS="OpenGL_ES" only, and no config carries EGL_OPENGL_BIT. Measured on device, in one pass: GL 3.1 core -> EGL_BAD_ATTRIBUTE (the profile mask is rejected because the bound API was still ES), 2.1 -> EGL_BAD_MATCH, 1.0 -> EGL_BAD_ALLOC, GLES2/GLES3 -> SUCCESS. glamor's try_big_gl_api can never succeed, so try_gles_api is the only path -- which is also how Android Xwayland is normally configured. That path was handed libglvnd's dispatch stub from the termux prefix: its entry points resolve through libGLdispatch, whose vendor is registered by a glvnd EGL vendor library, and this stage is glvnd=disabled. glGetString returned NULL and glamor stopped at "your GL is broken", fell back to software, and every GL client then read "DRI3 not available" and stayed off the shim. Staging this stage's own libGLESv2 fixes it: glGetString reports "zink Vulkan 1.4(Turnip Adreno (TM) 740)", glamor initialises on GLES2, DRI3 appears, and a GL title (GLX + the kopper libGL) creates a swapchain through the shim for the first time -- SteamWorld Dig 2, 3 images for asked=3, declared=fifo, cap 60, acquire 60, 60.0 fps. --- android/mesa-gl/build-mesa-gl.sh | 27 ++++++++++++++++----------- android/package-gamescope.sh | 25 ++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/android/mesa-gl/build-mesa-gl.sh b/android/mesa-gl/build-mesa-gl.sh index 22a9950d6..e729cd1cf 100644 --- a/android/mesa-gl/build-mesa-gl.sh +++ b/android/mesa-gl/build-mesa-gl.sh @@ -108,17 +108,22 @@ EOF # glvnd=disabled one monolithic libGL.so.1.2.0, the shape the container image # already has, so nothing has to learn about libGLX_mesa # vulkan-drivers= zink dlopens the system ICD at runtime -# egl=gbm=enabled measured, not assumed: with the glamor stage's EGL the X server -# never got glamor. Xwayland logged "Failed to make EGL context -# current with GL/GLES2" then "EGL setup failed, disabling -# glamor", fell back to software, and every GL client then read -# "DRI3 not available" and stayed off the shim. That EGL is -# libglvnd's dispatch stub, built for the termux prefix: its -# compiled-in vendor dirs are /data/data/com.termux/files/usr/ -# {etc,share}/glvnd/egl_vendor.d, absent on device, so no vendor -# loads (client extension list empty) unless something sets -# __EGL_VENDOR_LIBRARY_DIRS. glvnd=disabled below removes the -# indirection: this libEGL IS the implementation +# egl=gbm=enabled with gles2 is what Xwayland's glamor actually runs on, and the +# reason is not a build preference. Mesa refuses desktop GL on +# Android outright -- src/egl/main/eglcurrent.h gates EGL_OPENGL_API +# on `#if HAVE_OPENGL && !DETECT_OS_ANDROID` -- so +# eglBindAPI(EGL_OPENGL_API) returns EGL_BAD_PARAMETER, the display +# advertises EGL_CLIENT_APIS="OpenGL_ES" only, and every config's +# RENDERABLE_TYPE carries no EGL_OPENGL_BIT. Measured on device: +# GL 3.1 core -> EGL_BAD_ATTRIBUTE (profile mask rejected because the +# bound API was still ES), 2.1 -> EGL_BAD_MATCH, 1.0 -> EGL_BAD_ALLOC, +# GLES2/GLES3 -> SUCCESS. glamor's try_big_gl_api can therefore +# never succeed here; try_gles_api is the only path, which is also +# how Android Xwayland is normally configured. +# glvnd=disabled additionally removes a vendor lookup that cannot +# work on device: libglvnd's stub has compiled-in vendor dirs under +# /data/data/com.termux/files/usr/{etc,share}/glvnd/egl_vendor.d, +# which do not exist there, so with that stub no vendor loads at all rm -rf "$BUILD_DIR" meson setup "$BUILD_DIR" "$SRC" \ --cross-file "$CROSS" \ diff --git a/android/package-gamescope.sh b/android/package-gamescope.sh index a74ccec0a..59776f142 100755 --- a/android/package-gamescope.sh +++ b/android/package-gamescope.sh @@ -341,9 +341,32 @@ for n in "${GL_EGL[@]}"; do ln -sfn "$n" "$STAGE/lib/gl/${n%.*}" done cp -L "$GN_MESA_GL_STAGE/lib/gbm/dri_gbm.so" "$STAGE/lib/gl/gbm/dri_gbm.so" +# The server's glamor runs on GLES2, not GL: Mesa's EGL refuses EGL_OPENGL_API +# under DETECT_OS_ANDROID ("OpenGL is not a valid/supported API on Android", +# src/egl/main/eglcurrent.h), so eglBindAPI(EGL_OPENGL_API) returns +# EGL_BAD_PARAMETER and the display advertises only EGL_OPENGL_ES. That leaves +# the GLES2 path as the only one Xwayland can take -- and it needs a real +# libGLESv2. The one in lib/ is libglvnd's dispatch stub from the termux prefix: +# it resolves entry points through libGLdispatch, whose vendor is registered by a +# glvnd EGL vendor library, and this stage is glvnd=disabled, so every GLES call +# came back NULL and glamor stopped at "glGetString() returned NULL, your GL is +# broken". This copy is the same Mesa, monolithic, so it needs no vendor. +# Measured after shipping it: glGetString reports "zink Vulkan 1.4(Turnip Adreno +# (TM) 740)", glamor initialises on GLES2, DRI3 appears, and a GL guest (GLX + +# kopper libGL above) reaches the shim -- the first GL title ever to create a +# swapchain through it. +GL_GLES=(libGLESv2.so.2) +for n in "${GL_GLES[@]}"; do + src="$(ls "$GN_MESA_GL_STAGE/lib/$n".*.* 2>/dev/null | head -1)" + [ -f "$src" ] || { echo "error: no $n.*.* in $GN_MESA_GL_STAGE/lib" >&2; exit 1; } + cp -L "$src" "$STAGE/lib/gl/$n.0.0" + ln -sfn "$n.0.0" "$STAGE/lib/gl/$n" + ln -sfn "$n" "$STAGE/lib/gl/${n%.*}" +done resolve_libs "$STAGE/lib/gl/libGL.so.1.2.0" "$STAGE/lib/gl/${GL_GALLIUM[0]##*/}" \ "$STAGE/lib/gl/dri/libdril_dri.so" "$STAGE/lib/gl/libEGL.so.1.0.0" \ - "$STAGE/lib/gl/libgbm.so.1.0.0" "$STAGE/lib/gl/gbm/dri_gbm.so" + "$STAGE/lib/gl/libgbm.so.1.0.0" "$STAGE/lib/gl/gbm/dri_gbm.so" \ + "$STAGE/lib/gl/libGLESv2.so.2.0.0" # glvnd EGL vendor json (library_path: libEGL_mesa.so.0, resolved from # LD_LIBRARY_PATH = filesDir/gamescope/lib and .../lib/gl on device). From 80992c5276aa99f87a53d5369d20ad3300b79bf3 Mon Sep 17 00:00:00 2001 From: Joshua Tam <297250+joshuatam@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:32:38 +0800 Subject: [PATCH 5/5] re enable A55 patch --- .../0051-A55-cursor-plane-on-gamenative-drm.patch | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename android/patches/{disabled => gamescope}/0051-A55-cursor-plane-on-gamenative-drm.patch (100%) diff --git a/android/patches/disabled/0051-A55-cursor-plane-on-gamenative-drm.patch b/android/patches/gamescope/0051-A55-cursor-plane-on-gamenative-drm.patch similarity index 100% rename from android/patches/disabled/0051-A55-cursor-plane-on-gamenative-drm.patch rename to android/patches/gamescope/0051-A55-cursor-plane-on-gamenative-drm.patch