From dcbd140b8c38bc513ef9758e798817aa98467c44 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 02:25:31 +0900 Subject: [PATCH] docs: a Slint window on Linux needs a GL vendor; tools/check_display/ diagnoses a machine where it does not libglvnd is only a dispatcher, so the default OpenGL renderer aborts with "argument does not name a valid config" on an X server whose GL vendor (for example NVIDIA's) nothing wired in. compat.slint now depends on compat.glx-runtime for that (mcpp-index #871). tools/check_display/ is the dlopen-only probe (library loads, EGL devices, EGL and GLX on X11, with a distinct exit code per failure) plus scripts to check the xlings homes' nvidia-gl-host-link and to run a Slint project's binary six ways. No release: documentation and a tool only. --- README.md | 10 ++ README.zh.md | 9 + docs/usage.md | 2 +- tools/check_display/README.md | 44 +++++ tools/check_display/check-homes.sh | 31 ++++ tools/check_display/make-overlay.sh | 13 ++ tools/check_display/mcpp.toml | 17 ++ tools/check_display/run.sh | 18 ++ tools/check_display/slint-variants.sh | 29 ++++ tools/check_display/src/main.cpp | 228 ++++++++++++++++++++++++++ 10 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 tools/check_display/README.md create mode 100755 tools/check_display/check-homes.sh create mode 100755 tools/check_display/make-overlay.sh create mode 100644 tools/check_display/mcpp.toml create mode 100755 tools/check_display/run.sh create mode 100755 tools/check_display/slint-variants.sh create mode 100644 tools/check_display/src/main.cpp diff --git a/README.md b/README.md index ff3c50b..63f6da0 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,16 @@ fontconfig (xim:fontconfig) and the C runtime only; X11, Wayland and GL are load when used. `mcpplibs::mwrap::slint::macros::SLINT_FEATURE_RENDERER_SKIA` and the others say which features are present. +### A window on Linux needs a GL vendor + +libglvnd is only a dispatcher: a window on the default OpenGL renderer also needs the +vendor library (Mesa, or NVIDIA's on an NVIDIA X server). `compat.slint` depends on +`compat.glx-runtime` (the same package `compat.glfw` uses) for it, so a project needs +nothing extra; an older descriptor needs `compat.glx-runtime = "2026.09.11"` in +`[dependencies]`. If a window still aborts with `argument does not name a valid config`, +[`tools/check_display/`](tools/check_display/README.md) shows which part is missing; +`SLINT_BACKEND=winit-software` runs without GL meanwhile. + ## Build and testing Linux, macOS and Windows CI build the modules with GCC and Clang and run the tests: diff --git a/README.zh.md b/README.zh.md index d47c1b0..4868e43 100644 --- a/README.zh.md +++ b/README.zh.md @@ -73,6 +73,15 @@ int main() { Linux 上该库只依赖 fontconfig(xim:fontconfig)和 C 运行时;X11、Wayland 与 GL 在用到时 动态加载。`mcpplibs::mwrap::slint::macros::SLINT_FEATURE_RENDERER_SKIA` 等常量说明哪些功能存在。 +### Linux 上的窗口需要 GL 厂商库 + +libglvnd 只是分发器:默认的 OpenGL 渲染器开窗口还需要厂商库(Mesa;NVIDIA 的 X 服务器上是 +NVIDIA 的)。`compat.slint` 依赖 `compat.glx-runtime`(`compat.glfw` 用的同一个包)来提供它, +项目不需要额外写什么;更早的描述符则需要在 `[dependencies]` 里加 +`compat.glx-runtime = "2026.09.11"`。窗口仍以 `argument does not name a valid config` 中止时, +[`tools/check_display/`](tools/check_display/README.md) 能指出缺的是哪一环; +期间可用 `SLINT_BACKEND=winit-software` 不经 GL 运行。 + ## 构建与测试 Linux、macOS 与 Windows 的 CI 用 GCC 和 Clang 构建模块并运行测试:经模块使用运行时类型, diff --git a/docs/usage.md b/docs/usage.md index 3383078..2ad8299 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -32,4 +32,4 @@ import mcpplibs.mwrap.slint; ## The SDK's features -Upstream CMake's desktop defaults: `interpreter`, `backend-winit`, `renderer-femtovg`, `renderer-software`, `accessibility`, `system-tray`, `testing`, and the compiler. `SLINT_FEATURE_RENDERER_SKIA`, `BACKEND_QT`, `EXPERIMENTAL`, `FREESTANDING`, `LIVE_PREVIEW` and the image pixel formats are `false`; `slint::testing` is declared only with `EXPERIMENTAL`, so it is not here. On Linux the library NEEDs `libfontconfig.so.1` (xim:fontconfig) and the C runtime; X11, Wayland and GL are loaded when a window needs them. +Upstream CMake's desktop defaults: `interpreter`, `backend-winit`, `renderer-femtovg`, `renderer-software`, `accessibility`, `system-tray`, `testing`, and the compiler. `SLINT_FEATURE_RENDERER_SKIA`, `BACKEND_QT`, `EXPERIMENTAL`, `FREESTANDING`, `LIVE_PREVIEW` and the image pixel formats are `false`; `slint::testing` is declared only with `EXPERIMENTAL`, so it is not here. On Linux the library NEEDs `libfontconfig.so.1` (xim:fontconfig) and the C runtime; X11, Wayland and GL are loaded when a window needs them. A window on the OpenGL renderer needs a GL vendor library (Mesa, or NVIDIA's on an NVIDIA X server) that libglvnd dispatches to: `compat.slint` brings it through `compat.glx-runtime`, as `compat.glfw` does; `tools/check_display/` diagnoses a machine where the window still aborts (`argument does not name a valid config`), and `SLINT_BACKEND=winit-software` runs without GL. diff --git a/tools/check_display/README.md b/tools/check_display/README.md new file mode 100644 index 0000000..32bf412 --- /dev/null +++ b/tools/check_display/README.md @@ -0,0 +1,44 @@ +# check_display: does a window's GPU path work on this machine? + +A Slint window needs an X11 or Wayland session and, for the default OpenGL renderer, a GL vendor +library (Mesa, or NVIDIA's). The headless build and `mcpp test` never touch any of that, so a machine +where the window dies shows no sign of it until a person runs the program. This directory is how to +find out which part is missing. Run it from a **desktop terminal** (`DISPLAY` or `WAYLAND_DISPLAY` set). + +``` +cd tools/check_display +./check-homes.sh # read-only: which xlings homes hold nvidia-gl-host-link, and is it current +./run.sh # build and run the probe: as an mcpp program runs, with an NVIDIA overlay, through `mcpp run` +./slint-variants.sh # run a Slint project's binary six ways, 8 s each +``` + +`slint-variants.sh` takes the project directory (default: the current one) and, if it differs from +the directory name, the binary name. Each variant opens a window for up to 8 seconds: exit **124** = +the window came up, **134** = it aborted. + +## The probe (`src/main.cpp`) + +It uses only `dlopen`/`dlsym`, so it sees exactly what a toolkit's own `dlopen()` sees under mcpp's +loader. + +- `0.` the environment (glvnd and Mesa variables choose the vendor). +- `1.` which of the libraries a toolkit loads at run time resolve, including the NVIDIA vendor libraries. +- `2.` EGL devices (no X needed). +- `3.` EGL on X11 and how many configurations each template gets. +- `4.` GLX on X11: the server's GLX vendor and the configuration count. glutin tries GLX and then + EGL, and reports GLXBadFBConfig as `argument does not name a valid config`. On an NVIDIA X server + the GLX vendor is NVIDIA's, so `libGLX_nvidia.so.0` must load. +- `SUMMARY` and the exit code: 0 fine, 2 EGL on X11 gave nothing, 7 GLX gave nothing or an X error, + 6 the host has NVIDIA but the program gets no NVIDIA EGL device, 3/4 could not get that far. + +## Reading the result + +| what you see | meaning | what to do | +|---|---|---| +| Slint default aborts with `glutin: argument does not name a valid config`; probe part 4 says `client vendor: (null)` or `libGLX_nvidia.so.0` is not found | libglvnd is only a dispatcher and nothing wired a vendor into it: the GL provider (`xim:graphics`, through `compat.glx-runtime`) is not in the project's dependency closure | `compat.slint` carries that dependency (index PR #871); with an older descriptor, add `compat.glx-runtime = "2026.09.11"` to `[dependencies]` | +| the same, with `compat.glx-runtime` present | the `nvidia-gl-host-link` copy is stale (a driver upgrade leaves its version-named links dangling), `check-homes.sh` shows it: "links named for the live driver: 0 of N", "dangling" > 0 | reinstall `nvidia-gl-host-link`, or run `xlings-gl-doctor` | +| `SLINT_BACKEND=winit-software` works and the default does not | the software renderer needs no GL; the failure is in the GL path above | use it as a stop-gap | +| no window and a different error | an X11 or Wayland library is missing (`libX11.so.6`, `libxkbcommon-x11.so.0` ...): probe part 1 | add the library's xim package | + +Wayland is not covered: the index has no package that provides `opengl.egl.driver`, and the probe +only exercises X11. diff --git a/tools/check_display/check-homes.sh b/tools/check_display/check-homes.sh new file mode 100755 index 0000000..1eddfe7 --- /dev/null +++ b/tools/check_display/check-homes.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Which copy of nvidia-gl-host-link is stale? No build needed; read-only. +live=$(cat /sys/module/nvidia/version 2>/dev/null) +[ -n "$live" ] || live=$(grep -o '[0-9][0-9][0-9]\.[0-9]*\.[0-9]*' /proc/driver/nvidia/version 2>/dev/null | head -1) +echo "host driver now: ${live:-none loaded}" +for home in "$HOME/.xlings" "$HOME/.mcpp/registry"; do + echo + echo "== $home" + found=0 + for p in "$home"/data/xpkgs/xim-x-nvidia-gl-host-link/*/; do + [ -d "$p" ] || continue + found=1 + stamp=$(tr -d '\n' < "$p/.host-driver-version" 2>/dev/null) + total=$(ls "$p/lib" 2>/dev/null | grep -c '\.so\.[0-9][0-9][0-9]\.[0-9]*\.[0-9]*') + cur=$(ls "$p/lib" 2>/dev/null | grep -c "$live") + dang=$(find "$p/lib" -xtype l 2>/dev/null | wc -l) + echo " $(basename "$p") stamp=${stamp:-none} links named for the live driver: $cur of $total dangling: $dang" + done + [ "$found" = 0 ] && echo " (no nvidia-gl-host-link here)" + for g in "$home"/data/xpkgs/xim-x-libglvnd/*/lib/glx-vendor; do + [ -d "$g" ] || continue + echo " glvnd GLX vendors ($(basename "$(dirname "$(dirname "$g")")")): $(ls "$g" | grep -v '^\.' | tr '\n' ' ')" + done + for lib in "$home"/subos/*/lib; do + [ -d "$lib" ] || continue + echo " subos $(basename "$(dirname "$lib")"): nvidia links dangling: $(find "$lib" -maxdepth 1 -xtype l -name '*nvidia*' 2>/dev/null | wc -l)" + done +done +echo +echo "Reading: a copy whose 'links named for the live driver' is 0 and whose 'dangling' is > 0 is stale." +echo "mcpp uses ~/.mcpp/registry; the global ~/.xlings is a different copy." diff --git a/tools/check_display/make-overlay.sh b/tools/check_display/make-overlay.sh new file mode 100755 index 0000000..ab91765 --- /dev/null +++ b/tools/check_display/make-overlay.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Prints the path of a directory of symlinks to the host's NVIDIA user-space libraries, built by +# globbing the host for the driver that is loaded NOW. No list of file names; nothing is copied. +live=$(cat /sys/module/nvidia/version 2>/dev/null) +[ -n "$live" ] || live=$(grep -o '[0-9][0-9][0-9]\.[0-9]*\.[0-9]*' /proc/driver/nvidia/version 2>/dev/null | head -1) +[ -n "$live" ] || { echo "no NVIDIA driver is loaded" >&2; exit 1; } +libdir=${HOST_LIBDIR:-/usr/lib/x86_64-linux-gnu} +dir=${TMPDIR:-/tmp}/gl-overlay-$live +rm -rf "$dir"; mkdir -p "$dir" +for f in "$libdir"/libnvidia-*.so* "$libdir"/libEGL_nvidia.so* "$libdir"/libGLX_nvidia.so* "$libdir"/libGLESv*_nvidia.so*; do + [ -e "$f" ] && ln -s "$f" "$dir/" +done +echo "$dir" diff --git a/tools/check_display/mcpp.toml b/tools/check_display/mcpp.toml new file mode 100644 index 0000000..1a0d81c --- /dev/null +++ b/tools/check_display/mcpp.toml @@ -0,0 +1,17 @@ +[package] +name = "glprobe" +version = "0.1.0" +description = "Minimal probe: can a program built by mcpp load the host's GL driver libraries, and does EGL on X11 give it a configuration?" +license = "Apache-2.0" + +[language] +standard = "c++23" +modules = true +import_std = false + +[build] +sources = ["src/*.cpp"] + +[targets.glprobe] +kind = "bin" +main = "src/main.cpp" diff --git a/tools/check_display/run.sh b/tools/check_display/run.sh new file mode 100755 index 0000000..78fb554 --- /dev/null +++ b/tools/check_display/run.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# Build the probe with mcpp, run it as mcpp programs run today (A), then again with an +# overlay generated from the live driver version on the search path (B). +# B runs the built binary directly: LD_LIBRARY_PATH holds only NVIDIA libraries, so it cannot +# pull in a second libc, and it does not depend on what `mcpp run` does with the environment. +cd "$(dirname "$0")" || exit 1 +mcpp build || exit 1 +bin=$(find target -type f -path '*/bin/glprobe' -printf '%T@ %p\n' | sort -nr | head -1 | cut -d' ' -f2-) +[ -x "$bin" ] || { echo "glprobe was not built" >&2; exit 1; } +echo; echo "################ A: as an mcpp-built program runs today" +"$bin"; a=$? +echo; echo "################ B: plus an overlay of the live driver's NVIDIA libraries" +ov=$(./make-overlay.sh) || { echo "(no NVIDIA driver: B skipped)"; echo; echo "A exit=$a"; exit "$a"; } +echo "overlay: $ov ($(ls "$ov" | wc -l) links)" +LD_LIBRARY_PATH="$ov" "$bin"; b=$? +echo; echo "################ C: through mcpp run (mcpp's own environment, not your shell's)" +mcpp run; c=$? +echo; echo "A exit=$a B exit=$b C exit=$c (0 fine; 2 EGL on X11 gave no configuration; 7 GLX gave none or an X error; 6 the host has NVIDIA but this program gets no NVIDIA EGL device; 3/4 could not get that far)" diff --git a/tools/check_display/slint-variants.sh b/tools/check_display/slint-variants.sh new file mode 100755 index 0000000..5a6ebfc --- /dev/null +++ b/tools/check_display/slint-variants.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Run a Slint project's own binary in several ways and say what each does. +# Each run opens a window for up to 8 seconds, then is stopped: exit 124 means it was still +# running when stopped, i.e. the window came up; 134 means it aborted (SIGABRT). +# usage: ./slint-variants.sh [project-dir] [binary-name] (default: the current directory; the binary is named after the project directory) +here=$(cd "$(dirname "$0")" && pwd) +proj=${1:-.} +cd "$proj" || { echo "no such project: $proj" >&2; exit 1; } +name=${2:-$(basename "$(pwd)")} +mcpp build >/dev/null 2>&1 || mcpp build || exit 1 +bin=$(find target -type f -path "*/bin/$name" -printf '%T@ %p\n' | sort -nr | head -1 | cut -d' ' -f2-) +[ -x "$bin" ] || { echo "no $name binary under $proj/target (pass its name as the second argument)" >&2; exit 1; } +out=$(mktemp) +run() { + label=$1; shift + env "$@" timeout 8 "$bin" >"$out" 2>&1; rc=$? + case $rc in 124) verdict="window stayed up (stopped by the 8 s timeout)";; 134) verdict="ABORTED (SIGABRT)";; 0) verdict="exited normally";; *) verdict="exit $rc";; esac + echo; echo "=== $label"; echo " -> $verdict" + grep -vE '^\s*$|Fontconfig|RUST_BACKTRACE|note: run with' "$out" | head -4 | cut -c1-220 | sed 's/^/ /' +} +ov=$("$here/make-overlay.sh" 2>/dev/null) +mesa=/usr/share/glvnd/egl_vendor.d/50_mesa.json +run "default" +run "software renderer: SLINT_BACKEND=winit-software" SLINT_BACKEND=winit-software +run "OpenGL renderer, explicit: SLINT_BACKEND=winit-femtovg" SLINT_BACKEND=winit-femtovg +run "OpenGL, GLX vendor forced to mesa" SLINT_BACKEND=winit-femtovg __GLX_VENDOR_LIBRARY_NAME=mesa +[ -f "$mesa" ] && run "OpenGL, EGL and GLX both forced to mesa" SLINT_BACKEND=winit-femtovg __GLX_VENDOR_LIBRARY_NAME=mesa __EGL_VENDOR_LIBRARY_FILENAMES=$mesa +[ -n "$ov" ] && run "default + overlay of the live NVIDIA driver (LD_LIBRARY_PATH=$ov)" LD_LIBRARY_PATH="$ov" +rm -f "$out" diff --git a/tools/check_display/src/main.cpp b/tools/check_display/src/main.cpp new file mode 100644 index 0000000..67a0dd1 --- /dev/null +++ b/tools/check_display/src/main.cpp @@ -0,0 +1,228 @@ +// glprobe -- three questions, no dependencies beyond libdl: +// 1. which of the libraries a GUI toolkit dlopen()s can this program (under mcpp's loader) load? +// 2. which EGL devices/vendors answer, and how many configurations does each give? (no X needed) +// 3. if DISPLAY is set: what EGL on X11 gives, for the configuration templates a toolkit asks for. +// 4. if DISPLAY is set: what GLX gives -- glutin tries EGL, then GLX, and "argument does not name a +// valid config" is how it spells GLXBadFBConfig, so GLX is the other half of Slint's failure. +// Everything is resolved with dlopen/dlsym, so nothing here depends on how the ecosystem +// provides headers or libraries: it sees exactly what a toolkit's own dlopen() would see. +#include +#include +#include +#include +#include +#include +#include + +using EGLint = int; +using EGLBoolean = unsigned; +using EGLDisplay = void*; +using EGLConfig = void*; +using EGLDeviceEXT = void*; + +namespace { +constexpr EGLint kNone = 0x3038, kSurfaceType = 0x3033, kWindowBit = 0x0004, kPbufferBit = 0x0001, + kRenderableType = 0x3040, kEs2Bit = 0x0004, kOpenGlBit = 0x0008, + kVendor = 0x3053, kVersion = 0x3054, kOpenGlApi = 0x30A2, kEsApi = 0x30A0; +constexpr unsigned kPlatformX11 = 0x31D5, kPlatformDevice = 0x313F; + +struct Egl { + void* lib = nullptr; + void* (*getProc)(const char*) = nullptr; + EGLint (*getError)() = nullptr; + const char* (*queryString)(EGLDisplay, EGLint) = nullptr; + EGLBoolean (*initialize)(EGLDisplay, EGLint*, EGLint*) = nullptr; + EGLBoolean (*terminate)(EGLDisplay) = nullptr; + EGLBoolean (*chooseConfig)(EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*) = nullptr; + EGLBoolean (*bindApi)(unsigned) = nullptr; + EGLDisplay (*platformDisplay)(unsigned, void*, const EGLint*) = nullptr; + EGLBoolean (*queryDevices)(EGLint, EGLDeviceEXT*, EGLint*) = nullptr; +}; + +bool g_nvidiaDevice = false; // an EGL display whose vendor is NVIDIA initialised + +template void sym(F& f, void* lib, const char* name) { f = reinterpret_cast(dlsym(lib, name)); } + +// How many configurations does `d` offer for the given API / surface kind. +int configs(const Egl& e, EGLDisplay d, unsigned api, EGLint renderable, EGLint surface) { + e.bindApi(api); + const EGLint attrs[] = {kSurfaceType, surface, kRenderableType, renderable, kNone}; + EGLConfig cfg[64]; + EGLint n = 0; + if (!e.chooseConfig(d, attrs, cfg, 64, &n)) return -static_cast(e.getError()); + return n; +} + +// Count configurations for an API and a list of EGL attribute/value pairs. +int configsWith(const Egl& e, EGLDisplay d, unsigned api, std::initializer_list pairs) { + e.bindApi(api); + std::vector attrs(pairs); + attrs.push_back(kNone); + EGLConfig cfg[256]; + EGLint n = 0; + if (!e.chooseConfig(d, attrs.data(), cfg, 256, &n)) return -static_cast(e.getError()); + return n; +} + +struct XErrorEvent { int type; void* display; unsigned long resourceid; unsigned long serial; + unsigned char error_code, request_code, minor_code; }; +int g_xErrors = 0, g_lastXError = 0, g_lastXRequest = 0; +int xErrorHandler(void*, XErrorEvent* ev) { ++g_xErrors; g_lastXError = ev->error_code; g_lastXRequest = ev->request_code; return 0; } + +void printEnv() { + std::puts("== 0. environment this program runs in"); + for (const char* n : {"DISPLAY", "WAYLAND_DISPLAY", "XDG_SESSION_TYPE", "LD_LIBRARY_PATH", "LD_PRELOAD", + "__EGL_VENDOR_LIBRARY_DIRS", "__EGL_VENDOR_LIBRARY_FILENAMES", "__GLX_VENDOR_LIBRARY_NAME", + "LIBGL_DRIVERS_PATH", "LIBGL_ALWAYS_SOFTWARE", "MESA_LOADER_DRIVER_OVERRIDE", + "GBM_BACKENDS_PATH", "VK_ICD_FILENAMES", "VK_DRIVER_FILES", "SLINT_BACKEND", "SLINT_HEADLESS"}) { + const char* v = std::getenv(n); + if (v && *v) std::printf(" %s=%s\n", n, v); + } +} + +// Initialise a display and report what it is and what it offers. Returns the window-capable +// ES2 configuration count (negative: an EGL error code), or -1 when the display did not initialise. +int report(const Egl& e, const char* label, EGLDisplay d) { + if (!d) { std::printf(" %-26s no display (eglGetError=0x%x)\n", label, e.getError()); return -1; } + EGLint major = 0, minor = 0; + if (!e.initialize(d, &major, &minor)) { + std::printf(" %-26s eglInitialize failed (eglGetError=0x%x)\n", label, e.getError()); + return -1; + } + const char* vendor = e.queryString(d, kVendor); + if (vendor && std::strstr(vendor, "NVIDIA")) g_nvidiaDevice = true; + const int es2 = configs(e, d, kEsApi, kEs2Bit, kWindowBit); + const int gl = configs(e, d, kOpenGlApi, kOpenGlBit, kWindowBit); + const int pb = configs(e, d, kEsApi, kEs2Bit, kPbufferBit); + std::printf(" %-26s EGL %d.%d vendor=%s configs: ES2/window=%d GL/window=%d ES2/pbuffer=%d\n", + label, major, minor, vendor ? vendor : "?", es2, gl, pb); + e.terminate(d); + return es2; +} +} // namespace + +int main() { + printEnv(); + std::puts("\n== 1. libraries a toolkit dlopen()s, loaded by this program"); + bool nvidiaLibLoads = false; + for (const char* n : {"libX11.so.6", "libXcursor.so.1", "libXi.so.6", "libxcb.so.1", "libxkbcommon.so.0", + "libwayland-client.so.0", "libEGL.so.1", "libGL.so.1", + "libEGL_mesa.so.0", "libEGL_nvidia.so.0", "libGLX_nvidia.so.0"}) { + void* h = dlopen(n, RTLD_NOW); + std::printf(" %-24s %s\n", n, h ? "loaded" : dlerror()); + if (h && std::strcmp(n, "libEGL_nvidia.so.0") == 0) nvidiaLibLoads = true; + } + const bool hostNvidia = access("/proc/driver/nvidia", F_OK) == 0; + + Egl e; + e.lib = dlopen("libEGL.so.1", RTLD_NOW); + if (!e.lib) { std::puts("\nlibEGL.so.1 does not load: nothing more to probe"); return 3; } + sym(e.getProc, e.lib, "eglGetProcAddress"); + sym(e.getError, e.lib, "eglGetError"); + sym(e.queryString, e.lib, "eglQueryString"); + sym(e.initialize, e.lib, "eglInitialize"); + sym(e.terminate, e.lib, "eglTerminate"); + sym(e.chooseConfig, e.lib, "eglChooseConfig"); + sym(e.bindApi, e.lib, "eglBindAPI"); + e.platformDisplay = reinterpret_cast(e.getProc("eglGetPlatformDisplayEXT")); + e.queryDevices = reinterpret_cast(e.getProc("eglQueryDevicesEXT")); + + std::puts("\n== 2. EGL devices (no display server needed)"); + if (!e.queryDevices || !e.platformDisplay) { + std::puts(" EGL_EXT_device_enumeration is not available"); + } else { + EGLDeviceEXT dev[16]; + EGLint n = 0; + if (!e.queryDevices(16, dev, &n)) n = 0; + std::printf(" %d device(s)\n", n); + for (int i = 0; i < n; ++i) { + char label[32]; + std::snprintf(label, sizeof label, "device %d", i); + report(e, label, e.platformDisplay(kPlatformDevice, dev[i], nullptr)); + } + } + + auto summary = [&](const char* x11) { + std::printf("\nSUMMARY: host NVIDIA driver: %s | libEGL_nvidia.so.0 loads: %s | NVIDIA EGL device initialised: %s | EGL on X11: %s\n", + hostNvidia ? "yes" : "no", nvidiaLibLoads ? "yes" : "no", g_nvidiaDevice ? "yes" : "no", x11); + if (hostNvidia && !g_nvidiaDevice) + std::puts("PROBLEM: the host has an NVIDIA driver, but this program gets no NVIDIA EGL device (the host-link package is absent or stale)."); + return hostNvidia && !g_nvidiaDevice ? 6 : 0; + }; + + std::puts("\n== 3. EGL on X11 (what Slint's glutin does)"); + const char* display = std::getenv("DISPLAY"); + if (!display || !*display) { std::puts(" DISPLAY is not set: skipped. Run this from a desktop terminal."); return summary("skipped (no DISPLAY)"); } + void* x11 = dlopen("libX11.so.6", RTLD_NOW); + using OpenDisplay = void* (*)(const char*); + OpenDisplay xopen = x11 ? reinterpret_cast(dlsym(x11, "XOpenDisplay")) : nullptr; + void* xd = xopen ? xopen(nullptr) : nullptr; + if (!xd) { std::printf(" XOpenDisplay(%s) failed (libX11 %s)\n", display, x11 ? "loaded" : "did not load"); summary("could not open the display"); return 4; } + EGLDisplay xegl = e.platformDisplay ? e.platformDisplay(kPlatformX11, xd, nullptr) : nullptr; + const int n = report(e, "X11", xegl); + if (xegl && e.initialize(xegl, nullptr, nullptr)) { + constexpr EGLint kRed = 0x3024, kGreen = 0x3023, kBlue = 0x3022, kAlpha = 0x3021, kStencil = 0x3026, + kCaveat = 0x3027, kDepth = 0x3025; + std::puts(" configuration templates (window surface):"); + std::printf(" %-46s %d\n", "ES2", configsWith(e, xegl, kEsApi, {kSurfaceType, kWindowBit, kRenderableType, kEs2Bit})); + std::printf(" %-46s %d\n", "ES2 + RGBA8888", configsWith(e, xegl, kEsApi, {kSurfaceType, kWindowBit, kRenderableType, kEs2Bit, kRed, 8, kGreen, 8, kBlue, 8, kAlpha, 8})); + std::printf(" %-46s %d\n", "ES2 + RGBA8888 + stencil 8", configsWith(e, xegl, kEsApi, {kSurfaceType, kWindowBit, kRenderableType, kEs2Bit, kRed, 8, kGreen, 8, kBlue, 8, kAlpha, 8, kStencil, 8})); + std::printf(" %-46s %d\n", "ES2 + RGBA8888 + stencil 8 + depth 24", configsWith(e, xegl, kEsApi, {kSurfaceType, kWindowBit, kRenderableType, kEs2Bit, kRed, 8, kGreen, 8, kBlue, 8, kAlpha, 8, kStencil, 8, kDepth, 24})); + std::printf(" %-46s %d\n", "ES2 + caveat NONE (hardware only)", configsWith(e, xegl, kEsApi, {kSurfaceType, kWindowBit, kRenderableType, kEs2Bit, kCaveat, kNone})); + std::printf(" %-46s %d\n", "OpenGL + RGBA8888 + stencil 8", configsWith(e, xegl, kOpenGlApi, {kSurfaceType, kWindowBit, kRenderableType, kOpenGlBit, kRed, 8, kGreen, 8, kBlue, 8, kAlpha, 8, kStencil, 8})); + } + std::printf("\nRESULT 3: EGL on X11 offers %d window configuration(s) -> %s\n", n, n > 0 ? "ok" : "NONE"); + + std::puts("\n== 4. GLX on X11 (glutin's fallback; what an NVIDIA X server makes it ask)"); + int glxFb = -1; + void* glx = dlopen("libGLX.so.0", RTLD_NOW); + if (!glx) glx = dlopen("libGL.so.1", RTLD_NOW); + if (!glx) { + std::puts(" neither libGLX.so.0 nor libGL.so.1 loads"); + } else { + using QueryExt = int (*)(void*, int*, int*); + using GetStr = const char* (*)(void*, int); + using ServerStr = const char* (*)(void*, int, int); + using Choose = void** (*)(void*, int, const int*, int*); + using SetHandler = int (*(*)(int (*)(void*, XErrorEvent*)))(void*, XErrorEvent*); + using Sync = int (*)(void*, int); + using Free = int (*)(void*); + auto queryExt = reinterpret_cast(dlsym(glx, "glXQueryExtension")); + auto clientStr = reinterpret_cast(dlsym(glx, "glXGetClientString")); + auto serverStr = reinterpret_cast(dlsym(glx, "glXQueryServerString")); + auto choose = reinterpret_cast(dlsym(glx, "glXChooseFBConfig")); + auto setHandler = reinterpret_cast(dlsym(x11, "XSetErrorHandler")); + auto xsync = reinterpret_cast(dlsym(x11, "XSync")); + auto xfree = reinterpret_cast(dlsym(x11, "XFree")); + if (!queryExt || !choose || !setHandler || !xsync) { + std::puts(" GLX entry points are missing"); + } else { + setHandler(xErrorHandler); + int errBase = 0, evBase = 0; + if (!queryExt(xd, &errBase, &evBase)) { + std::puts(" the X server has no GLX extension"); + } else { + std::printf(" GLX client vendor: %s | server vendor: %s\n", + clientStr ? clientStr(xd, 1) : "?", serverStr ? serverStr(xd, 0, 1) : "?"); + const int attrs[] = {0x8010 /*DRAWABLE_TYPE*/, 0x1 /*WINDOW_BIT*/, 0x8011 /*RENDER_TYPE*/, 0x1 /*RGBA_BIT*/, + 0x8012 /*X_RENDERABLE*/, 1, 5 /*DOUBLEBUFFER*/, 1, 0x8 /*RED*/, 8, 0x9, 8, 0xA, 8, 0xB /*ALPHA*/, 8, + 0xD /*STENCIL*/, 8, 0}; + int count = 0; + void** fb = choose(xd, 0, attrs, &count); + xsync(xd, 0); + glxFb = fb ? count : 0; + if (fb && xfree) xfree(fb); + std::printf(" glXChooseFBConfig: %d configuration(s)", glxFb); + if (g_xErrors) std::printf(", X error %d (GLX error base %d => GLX error %d; 9 is GLXBadFBConfig), request %d", + g_lastXError, errBase, g_lastXError - errBase, g_lastXRequest); + std::puts(""); + } + } + } + std::printf("\nRESULT 4: GLX on X11 offers %d framebuffer configuration(s) -> %s\n", glxFb, + glxFb > 0 ? "ok" : "NONE or an X error: glutin would report \"argument does not name a valid config\""); + const int rc = summary(n > 0 ? (glxFb > 0 ? "EGL ok, GLX ok" : "EGL ok, GLX NONE") : "EGL NONE"); + if (n <= 0) return 2; + if (glxFb <= 0) return 7; + return rc; +}