feat: add NVIDIA Prime environment variables for Linux hybrid graphics#155
Merged
HsiangNianian merged 2 commits intomainfrom Apr 4, 2026
Merged
feat: add NVIDIA Prime environment variables for Linux hybrid graphics#155HsiangNianian merged 2 commits intomainfrom
HsiangNianian merged 2 commits intomainfrom
Conversation
- 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
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds Linux-only environment variable injection to enable discrete GPU usage (NVIDIA Prime and AMD DRI_PRIME) when launching Minecraft, along with logging for visibility. Sequence diagram for Linux GPU env injection when starting gamesequenceDiagram
actor User
participant TauriApp
participant StartGameFunction as start_game
participant Command as JavaCommand
participant JavaProcess as JavaMinecraft
participant GPUDriver
User->>TauriApp: Click Play / start game
TauriApp->>StartGameFunction: start_game(window, config, ...)
StartGameFunction->>Command: build JavaCommand
alt target_os_linux
StartGameFunction->>Command: env __NV_PRIME_RENDER_OFFLOAD=1
StartGameFunction->>Command: env __GLX_VENDOR_LIBRARY_NAME=nvidia
StartGameFunction->>Command: env DRI_PRIME=1
StartGameFunction->>TauriApp: emit_log Injected GPU environment variables
else non_linux
StartGameFunction-->>Command: no GPU env injection
end
StartGameFunction->>Command: spawn()
Command->>JavaProcess: launch JVM with env
JavaProcess->>GPUDriver: initialize rendering using discrete GPU
GPUDriver-->>JavaProcess: provide accelerated rendering
JavaProcess-->>User: Game running on discrete GPU (Linux hybrid systems)
Flow diagram for conditional GPU environment variable injectionflowchart TD
A[Start start_game] --> B[Build Java command]
B --> C{target_os is linux}
C -- Yes --> D[Set env __NV_PRIME_RENDER_OFFLOAD=1]
D --> E[Set env __GLX_VENDOR_LIBRARY_NAME=nvidia]
E --> F[Set env DRI_PRIME=1]
F --> G[emit_log Injected GPU environment variables for Linux]
G --> H[Spawn Java process]
C -- No --> H[Spawn Java process]
H --> I["Game runs (discrete GPU used on Linux hybrid systems)"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Workspace change through: 19f228a1 changesets found Planned changes to release
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The Linux-specific GPU environment variables are injected unconditionally; consider only setting them when they are not already present in the environment so you don’t override user/system configuration.
- You may want to gate the NVIDIA/AMD offload vars behind a configuration flag or a runtime detection of hybrid GPU availability, to avoid unexpected behavior on systems without PRIME/DRI_PRIME setups.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The Linux-specific GPU environment variables are injected unconditionally; consider only setting them when they are not already present in the environment so you don’t override user/system configuration.
- You may want to gate the NVIDIA/AMD offload vars behind a configuration flag or a runtime detection of hybrid GPU availability, to avoid unexpected behavior on systems without PRIME/DRI_PRIME setups.
## Individual Comments
### Comment 1
<location path="src-tauri/src/main.rs" line_range="865-879" />
<code_context>
+ #[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!(
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider not unconditionally overriding GPU-related env vars if they’re already set.
This will clobber any existing `__NV_PRIME_RENDER_OFFLOAD`, `__GLX_VENDOR_LIBRARY_NAME`, and `DRI_PRIME` values, which can break custom GPU setups. Consider only setting them when unset, or making this behavior configurable (e.g., via a flag or config option) so advanced users can opt in or override it.
```suggestion
// 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()
);
}
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
HsiangNianian
approved these changes
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Test Plan
Closes #154
Summary by Sourcery
Inject GPU-related environment variables when launching the game on Linux to support hybrid graphics configurations.
New Features:
Enhancements: