diff options
| author | 2026-04-04 23:21:36 +0800 | |
|---|---|---|
| committer | 2026-04-04 23:21:36 +0800 | |
| commit | 0c77fd0c210f0f7578b94f8f177b40471b28e721 (patch) | |
| tree | f3b575df1d6afe23ec6c5fee4852c71bccd0b7de | |
| parent | e5f94912615e69c32c353fd6a63790e9b16685e4 (diff) | |
| download | DropOut-main.tar.gz DropOut-main.zip | |
## Summary
- Inject __NV_PRIME_RENDER_OFFLOAD=1 and
__GLX_VENDOR_LIBRARY_NAME=nvidia environment variables when launching
Minecraft on Linux
- Enables discrete GPU usage on Linux systems with hybrid graphics
(NVIDIA + Intel/AMD)
- Only applies on Linux via #[cfg(target_os = "linux")]
## Changes
- Modified src-tauri/src/main.rs to inject NVIDIA Prime environment
variables before spawning the Java process
## Test Plan
- On a Linux system with hybrid graphics (NVIDIA + Intel/AMD), launch
the game and verify the discrete GPU is being used
- Can check with nvidia-smi or glxinfo to confirm GPU usage
Closes #154
## Summary by Sourcery
Inject GPU-related environment variables when launching the game on
Linux to support hybrid graphics configurations.
New Features:
- Enable discrete GPU usage on Linux hybrid graphics systems by setting
NVIDIA Prime and AMD DRI_PRIME environment variables before starting the
game process.
Enhancements:
- Log when GPU environment variables are injected on Linux to aid
debugging of hybrid graphics setups.
---------
Co-authored-by: 简律纯 <i@jyunko.cn>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
| -rw-r--r-- | src-tauri/src/main.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7f7c4c0..952d250 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -862,6 +862,37 @@ 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 + 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 + 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 let mut child = command .spawn() |