From 96cad1ac999b7d6e288a681ce53a23044bc23127 Mon Sep 17 00:00:00 2001 From: krypton Date: Sat, 4 Apr 2026 21:37:16 +0800 Subject: [PATCH 1/2] feat: add NVIDIA Prime environment variables for Linux hybrid graphics - Inject __NV_PRIME_RENDER_OFFLOAD=1 and __GLX_VENDOR_LIBRARY_NAME=nvidia - Enables discrete GPU usage on Linux systems with hybrid graphics - Only applies on Linux via #[cfg(target_os = "linux")] - Closes #154 --- src-tauri/src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7f7c4c0..5109182 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -862,6 +862,22 @@ async fn start_game( ); } + // On Linux, inject GPU environment variables for hybrid graphics support + #[cfg(target_os = "linux")] + { + // NVIDIA Prime Render Offload - enables discrete NVIDIA GPU on hybrid systems + command.env("__NV_PRIME_RENDER_OFFLOAD", "1"); + command.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); + + // AMD DRI_PRIME - enables discrete AMD GPU on hybrid systems + command.env("DRI_PRIME", "1"); + + emit_log!( + window, + "Injected GPU environment variables for Linux (NVIDIA Prime & AMD DRI_PRIME)".to_string() + ); + } + // Spawn and handle output let mut child = command .spawn() From 19f228a324e7462d3e3a6ec3921c30f0cb2a5415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E5=BE=8B=E7=BA=AF?= Date: Sat, 4 Apr 2026 23:11:39 +0800 Subject: [PATCH 2/2] Update src-tauri/src/main.rs Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- src-tauri/src/main.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5109182..952d250 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -863,19 +863,34 @@ async fn start_game( } // On Linux, inject GPU environment variables for hybrid graphics support + // but do not override values that are already set in the environment. #[cfg(target_os = "linux")] { + let mut injected_any = false; + // NVIDIA Prime Render Offload - enables discrete NVIDIA GPU on hybrid systems - command.env("__NV_PRIME_RENDER_OFFLOAD", "1"); - command.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); - + if std::env::var_os("__NV_PRIME_RENDER_OFFLOAD").is_none() { + command.env("__NV_PRIME_RENDER_OFFLOAD", "1"); + injected_any = true; + } + + if std::env::var_os("__GLX_VENDOR_LIBRARY_NAME").is_none() { + command.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia"); + injected_any = true; + } + // AMD DRI_PRIME - enables discrete AMD GPU on hybrid systems - command.env("DRI_PRIME", "1"); - - emit_log!( - window, - "Injected GPU environment variables for Linux (NVIDIA Prime & AMD DRI_PRIME)".to_string() - ); + if std::env::var_os("DRI_PRIME").is_none() { + command.env("DRI_PRIME", "1"); + injected_any = true; + } + + if injected_any { + emit_log!( + window, + "Injected default GPU environment variables for Linux (NVIDIA Prime & AMD DRI_PRIME, only where unset)".to_string() + ); + } } // Spawn and handle output