Skip to content

feat: add NVIDIA Prime environment variables for Linux hybrid graphics#155

Merged
HsiangNianian merged 2 commits intomainfrom
feat/linux-nvidia-prime-support
Apr 4, 2026
Merged

feat: add NVIDIA Prime environment variables for Linux hybrid graphics#155
HsiangNianian merged 2 commits intomainfrom
feat/linux-nvidia-prime-support

Conversation

@hydroroll-bot
Copy link
Copy Markdown
Member

@hydroroll-bot hydroroll-bot commented Apr 4, 2026

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.

- 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
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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 game

sequenceDiagram
    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)
Loading

Flow diagram for conditional GPU environment variable injection

flowchart 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)"]
Loading

File-Level Changes

Change Details Files
Inject Linux-only GPU-related environment variables before spawning the Java game process to force discrete GPU usage on hybrid systems.
  • Wrap new logic in a #[cfg(target_os = "linux")] block so it only compiles and runs on Linux
  • Set __NV_PRIME_RENDER_OFFLOAD=1 and __GLX_VENDOR_LIBRARY_NAME=nvidia on the Command used to start the game for NVIDIA Prime render offload
  • Set DRI_PRIME=1 on the Command to enable discrete AMD GPU usage on hybrid graphics systems
  • Emit a log message via emit_log! to indicate GPU environment variables were injected for Linux
src-tauri/src/main.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#154 When launching the Minecraft child process on Linux, inject NVIDIA hybrid-graphics environment variables (__NV_PRIME_RENDER_OFFLOAD=1 and __GLX_VENDOR_LIBRARY_NAME=nvidia) so Minecraft uses the discrete NVIDIA GPU.
#154 When launching the Minecraft child process on Linux, inject the AMD hybrid-graphics environment variable (DRI_PRIME=1) so Minecraft can use a discrete AMD GPU.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drop-out-docs Ready Ready Preview, Comment Apr 4, 2026 3:12pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

Workspace change through: 19f228a

1 changesets found

Planned changes to release
Package Bump Level Current Version Next Version
@dropout/docs patch 0.1.0-alpha.1 0.1.0-alpha.2

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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 HsiangNianian merged commit 0c77fd0 into main Apr 4, 2026
16 checks passed
@HsiangNianian HsiangNianian deleted the feat/linux-nvidia-prime-support branch April 4, 2026 15:21
@hydroroll-bot hydroroll-bot restored the feat/linux-nvidia-prime-support branch April 4, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux下支持NVIDIA独显环境变量注入

2 participants