From 915591aea962beb60da2e96ac0f57307f646f675 Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Sat, 14 Mar 2026 15:15:53 -0400 Subject: [PATCH] perf: auto-detect NVIDIA+Wayland for DMABuf workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of disabling DMABuf for all users (hurting AMD/Intel/X11 performance), detect NVIDIA GPU + Wayland session at startup and only apply WEBKIT_DISABLE_DMABUF_RENDERER=1 for that combo. Detection checks /proc/driver/nvidia/version first (fast, no subprocess), falls back to scanning /proc/modules for nvidia. GPU policy remains Always for everyone — the DMABuf workaround only affects buffer sharing between WebKitGTK and the display server, not GPU-accelerated CSS/layout/paint. --- main.go | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index f0b2e7e..6f01470 100644 --- a/main.go +++ b/main.go @@ -29,9 +29,11 @@ var ( var frontendDistAssets embed.FS func main() { - // Work around WebKitGTK DMABuf rendering crashes on certain - // Wayland compositor / GPU-driver combinations. - if os.Getenv("WEBKIT_DISABLE_DMABUF_RENDERER") == "" { + // WebKitGTK's DMABuf renderer crashes on NVIDIA GPUs under Wayland. + // Only disable it for that specific combo so AMD/Intel and X11 users + // keep full hardware-accelerated buffer sharing. Users can also + // force the workaround with WEBKIT_DISABLE_DMABUF_RENDERER=1. + if os.Getenv("WEBKIT_DISABLE_DMABUF_RENDERER") == "" && isNVIDIAWayland() { _ = os.Setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "1") } @@ -89,7 +91,7 @@ func main() { MaxWidth: 0, MaxHeight: 0, Linux: &linux.Options{ - WebviewGpuPolicy: linux.WebviewGpuPolicyOnDemand, + WebviewGpuPolicy: linux.WebviewGpuPolicyAlways, }, }) @@ -124,3 +126,29 @@ func resolveLogLevel(_ bool) slog.Level { // Default: Info for both dev and prod. return slog.LevelInfo } + +// isNVIDIAWayland returns true when running under a Wayland session with +// an NVIDIA GPU. This combination triggers DMABuf rendering crashes in +// WebKitGTK, so we need to disable the DMABuf renderer for it. +func isNVIDIAWayland() bool { + // Not Wayland → safe. + if os.Getenv("WAYLAND_DISPLAY") == "" && os.Getenv("XDG_SESSION_TYPE") != "wayland" { + return false + } + + // Check for NVIDIA kernel modules (works even without nvidia-smi). + if data, err := os.ReadFile("/proc/driver/nvidia/version"); err == nil { + _ = data + + return true + } + + // Fallback: check if the nvidia module is loaded. + if data, err := os.ReadFile("/proc/modules"); err == nil { + if strings.Contains(string(data), "nvidia") { + return true + } + } + + return false +}