From 5f48ba1a01da677a64dd92dd9d1b6d30afe9c339 Mon Sep 17 00:00:00 2001 From: teamnotus Date: Sun, 22 Nov 2026 23:54:20 -0300 Subject: [PATCH 1/2] fix(sdl): gate NVIDIA Wayland workaround to drivers below 590 --- .../java/com/cleanroommc/client/sdl/SDL.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java b/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java index 9bb0691c4..06e119477 100644 --- a/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java +++ b/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java @@ -47,6 +47,7 @@ import org.lwjgl.system.linux.DynamicLinkLoader; import java.awt.image.BufferedImage; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -56,6 +57,8 @@ public final class SDL { private static final Logger LOGGER = LoggerFactory.getLogger("SDL3"); + private static final Path NVIDIA_VERSION_FILE = Path.of("/sys/module/nvidia/version"); + private static final int FIRST_UNAFFECTED_NVIDIA_MAJOR = 590; /** * Every {@code com.cleanroommc.client.sdl.events} event is posted here, not on Forge's bus. * */ @@ -271,8 +274,8 @@ public static long checkHandle(long handle, String call) { * driver's application profile turns it on for anything that loads liblwjgl*.so before EGL is * initialized, which is why this is needed here at all. * - *

Only runs when PRIME offload was requested, so other Wayland and NVIDIA setups are left - * alone. Opt out with {@code -Dcleanroom.sdl.nvidiaWaylandWorkaround=false}. + *

Only runs on Linux/Wayland with PRIME offload and NVIDIA drivers below 590: the newer + * branches are not affected. Opt out with {@code -Dcleanroom.sdl.nvidiaWaylandWorkaround=false}. */ private static synchronized void applyNvidiaWaylandWorkaround() { if (nvidiaWaylandWorkaroundChecked) { @@ -288,10 +291,10 @@ private static synchronized void applyNvidiaWaylandWorkaround() { if (!"wayland".equals(SDLVideo.SDL_GetCurrentVideoDriver())) { return; } - if (!Files.isRegularFile(Path.of("/proc/driver/nvidia/version"))) { + if (!nvidiaOffloadRequested()) { return; } - if (!nvidiaOffloadRequested()) { + if (!needsNvidiaWorkaround()) { return; } String threaded = System.getenv("__GL_THREADED_OPTIMIZATIONS"); @@ -322,6 +325,17 @@ private static boolean nvidiaOffloadRequested() { return vendor != null && "nvidia".equalsIgnoreCase(vendor.trim()); } + private static boolean needsNvidiaWorkaround() { + try { + String version = Files.readString(NVIDIA_VERSION_FILE).trim(); + int major = Integer.parseInt(version.substring(0, version.indexOf('.'))); + return major < FIRST_UNAFFECTED_NVIDIA_MAJOR; + } catch (IOException | RuntimeException e) { + // Unknown version: keep the workaround rather than restore the swap failure. + return true; + } + } + /** * Calls SDL's {@code setenv} wrapper with overwrite enabled, so the driver sees the value when it * reads the environment. From 4af5adf60a0fcab8acdfecdce1781f3a4dccea4a Mon Sep 17 00:00:00 2001 From: teamnotus Date: Mon, 23 Nov 2026 08:48:17 -0300 Subject: [PATCH 2/2] fix(sdl): bump NVIDIA workaround cutoff to 600 and add /proc fallback Address review feedback: try /proc/driver/nvidia/version as a fallback for /sys/module/nvidia/version, keep the fail-safe when no major can be parsed, and raise the heuristic cutoff to < 600 given the 595.x report. --- .../java/com/cleanroommc/client/sdl/SDL.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java b/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java index 06e119477..1ad6d542f 100644 --- a/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java +++ b/module/cleanroom/src/main/java/com/cleanroommc/client/sdl/SDL.java @@ -50,6 +50,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * The way into SDL. Every device, subsystem and lifecycle call is exposed through here. @@ -57,8 +59,10 @@ public final class SDL { private static final Logger LOGGER = LoggerFactory.getLogger("SDL3"); - private static final Path NVIDIA_VERSION_FILE = Path.of("/sys/module/nvidia/version"); - private static final int FIRST_UNAFFECTED_NVIDIA_MAJOR = 590; + private static final Path NVIDIA_SYS_VERSION_FILE = Path.of("/sys/module/nvidia/version"); + private static final Path NVIDIA_PROC_VERSION_FILE = Path.of("/proc/driver/nvidia/version"); + private static final Pattern NVIDIA_MAJOR_PATTERN = Pattern.compile("(\\d+)\\.\\d+"); + private static final int NVIDIA_WORKAROUND_MAX_MAJOR_EXCLUSIVE = 600; /** * Every {@code com.cleanroommc.client.sdl.events} event is posted here, not on Forge's bus. * */ @@ -274,8 +278,9 @@ public static long checkHandle(long handle, String call) { * driver's application profile turns it on for anything that loads liblwjgl*.so before EGL is * initialized, which is why this is needed here at all. * - *

Only runs on Linux/Wayland with PRIME offload and NVIDIA drivers below 590: the newer - * branches are not affected. Opt out with {@code -Dcleanroom.sdl.nvidiaWaylandWorkaround=false}. + *

Only runs on Linux/Wayland with PRIME offload and NVIDIA drivers below 600. The cutoff is + * heuristic: 570.x/580.x are affected, 620.x was reported unaffected, and 590-599 have mixed/no + * confirmed fix data. Opt out with {@code -Dcleanroom.sdl.nvidiaWaylandWorkaround=false}. */ private static synchronized void applyNvidiaWaylandWorkaround() { if (nvidiaWaylandWorkaroundChecked) { @@ -326,14 +331,28 @@ private static boolean nvidiaOffloadRequested() { } private static boolean needsNvidiaWorkaround() { - try { - String version = Files.readString(NVIDIA_VERSION_FILE).trim(); - int major = Integer.parseInt(version.substring(0, version.indexOf('.'))); - return major < FIRST_UNAFFECTED_NVIDIA_MAJOR; - } catch (IOException | RuntimeException e) { - // Unknown version: keep the workaround rather than restore the swap failure. + Integer major = readNvidiaMajor(NVIDIA_SYS_VERSION_FILE); + if (major == null) { + major = readNvidiaMajor(NVIDIA_PROC_VERSION_FILE); + } + if (major == null) { + // Unknown version: keep the workaround rather than restore the EGL_BAD_DISPLAY swap failure. return true; } + return major < NVIDIA_WORKAROUND_MAX_MAJOR_EXCLUSIVE; + } + + private static Integer readNvidiaMajor(Path file) { + try { + String content = Files.readString(file); + Matcher matcher = NVIDIA_MAJOR_PATTERN.matcher(content); + if (matcher.find()) { + return Integer.parseInt(matcher.group(1)); + } + } catch (IOException | RuntimeException ignored) { + // Try next source / fail safe. + } + return null; } /**