Skip to content

feat: add GPU acceleration JVM parameters support#140

Merged
HsiangNianian merged 3 commits intomainfrom
feat/gpu-jvm-params
Apr 1, 2026
Merged

feat: add GPU acceleration JVM parameters support#140
HsiangNianian merged 3 commits intomainfrom
feat/gpu-jvm-params

Conversation

@hydroroll-bot
Copy link
Copy Markdown
Member

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

  • Add Prism rendering pipeline parameters when enable_gpu_acceleration is enabled
  • Windows: -Dprism.order=d3d,es2,sw (Direct3D priority)
  • Linux/macOS: -Dprism.order=es2,sw (OpenGL ES priority)
  • Add -Dprism.forcegpu=true to force hardware acceleration

Summary by Sourcery

Add optional GPU-accelerated JavaFX rendering configuration when launching the game JVM.

New Features:

  • Introduce configurable GPU acceleration JVM parameters based on the enable_gpu_acceleration setting.
  • Apply platform-specific JavaFX Prism rendering order defaults for Windows versus Unix-like systems.
  • Force hardware-accelerated rendering via a dedicated JVM flag when GPU acceleration is enabled.

- Add Prism rendering pipeline parameters when enable_gpu_acceleration is enabled
- Windows: -Dprism.order=d3d,es2,sw (Direct3D priority)
- Linux/macOS: -Dprism.order=es2,sw (OpenGL ES priority)
- Add -Dprism.forcegpu=true to force hardware acceleration
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 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 1, 2026 6:23am

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 1, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adds optional JavaFX Prism GPU acceleration JVM arguments to the Tauri game startup flow, enabling platform-specific hardware-accelerated rendering when the configuration flag is set.

Sequence diagram for game start with optional GPU-accelerated JVM parameters

sequenceDiagram
    actor User
    participant TauriApp
    participant Config
    participant JVM

    User->>TauriApp: click Play
    TauriApp->>Config: read enable_gpu_acceleration
    Config-->>TauriApp: enable_gpu_acceleration (bool)

    TauriApp->>TauriApp: build JVM args
    TauriApp->>TauriApp: add java.library.path

    alt enable_gpu_acceleration == true
        TauriApp->>TauriApp: detect target_os
        alt target_os == windows
            TauriApp->>TauriApp: args += -Dprism.order=d3d,es2,sw
        else target_os == linux or macos
            TauriApp->>TauriApp: args += -Dprism.order=es2,sw
        end
        TauriApp->>TauriApp: args += -Dprism.forcegpu=true
    else enable_gpu_acceleration == false
        TauriApp->>TauriApp: no Prism GPU args added
    end

    TauriApp->>JVM: start with args
    JVM-->>TauriApp: JavaFX game running (Prism pipeline configured)
Loading

File-Level Changes

Change Details Files
Conditionally append JavaFX Prism GPU acceleration JVM parameters based on configuration and target OS.
  • Introduce a check for config.enable_gpu_acceleration in the game startup argument construction
  • For Windows builds, append -Dprism.order=d3d,es2,sw to prefer Direct3D, then OpenGL ES, then software rendering
  • For non-Windows builds, append -Dprism.order=es2,sw to prefer OpenGL ES over software rendering
  • Always append -Dprism.forcegpu=true when GPU acceleration is enabled to force hardware usage over software fallback
src-tauri/src/main.rs

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Workspace change through: 551aab6

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 2 issues, and left some high level feedback:

  • Consider only appending -Dprism.order=... and -Dprism.forcegpu=true when they are not already present in args, so user- or config-specified JVM options aren’t silently overridden or duplicated.
  • Instead of using a bare else for non-Windows platforms, make the platform conditions explicit (e.g., cfg!(any(target_os = "linux", target_os = "macos"))) to avoid unintentionally applying the Linux/macOS settings to other targets in the future.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider only appending `-Dprism.order=...` and `-Dprism.forcegpu=true` when they are not already present in `args`, so user- or config-specified JVM options aren’t silently overridden or duplicated.
- Instead of using a bare `else` for non-Windows platforms, make the platform conditions explicit (e.g., `cfg!(any(target_os = "linux", target_os = "macos"))`) to avoid unintentionally applying the Linux/macOS settings to other targets in the future.

## Individual Comments

### Comment 1
<location path="src-tauri/src/main.rs" line_range="665-674" />
<code_context>

+    // Add GPU acceleration parameters if enabled
+    // JavaFX Prism rendering pipeline settings for hardware acceleration
+    if config.enable_gpu_acceleration {
+        // Platform-specific rendering order:
+        // - Windows: d3d (Direct3D) > es2 (OpenGL ES 2) > sw (software)
+        // - Linux/macOS: es2 > sw (no Direct3D available)
+        if cfg!(target_os = "windows") {
+            args.push("-Dprism.order=d3d,es2,sw".to_string());
+        } else {
+            args.push("-Dprism.order=es2,sw".to_string());
+        }
+        // Force GPU usage instead of software fallback
+        args.push("-Dprism.forcegpu=true".to_string());
+    }
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider not unconditionally forcing GPU usage to avoid crashes on problematic or missing GPU drivers.

`-Dprism.forcegpu=true` can cause startup failures on systems with buggy or unsupported GPU drivers (e.g., some Intel or virtualized setups). Since `enable_gpu_acceleration` already controls the pipeline order, consider either making `forcegpu` a separate config flag or only setting `prism.order` and letting JavaFX fall back to software if hardware acceleration fails.

Suggested implementation:

```rust
    // Add GPU acceleration parameters if enabled
    // JavaFX Prism rendering pipeline settings for hardware acceleration.
    // We configure the preferred pipeline order but do not force GPU usage,
    // so JavaFX can fall back to software rendering on problematic drivers.
    if config.enable_gpu_acceleration {
        // Platform-specific rendering order:
        // - Windows: d3d (Direct3D) > es2 (OpenGL ES 2) > sw (software)
        // - Linux/macOS: es2 > sw (no Direct3D available)
        if cfg!(target_os = "windows") {
            args.push("-Dprism.order=d3d,es2,sw".to_string());
        } else {
            args.push("-Dprism.order=es2,sw".to_string());
        }

```

If you later want an explicit `force_gpu` option, you can:
1. Add a boolean field like `force_gpu: bool` to your config struct.
2. Extend this block with:

```rust
if config.force_gpu {
    args.push("-Dprism.forcegpu=true".to_string());
}
```

This keeps the current safe default while allowing advanced users to opt-in to forcing GPU usage.
</issue_to_address>

### Comment 2
<location path="src-tauri/src/main.rs" line_range="670-672" />
<code_context>
+        // - Windows: d3d (Direct3D) > es2 (OpenGL ES 2) > sw (software)
+        // - Linux/macOS: es2 > sw (no Direct3D available)
+        if cfg!(target_os = "windows") {
+            args.push("-Dprism.order=d3d,es2,sw".to_string());
+        } else {
+            args.push("-Dprism.order=es2,sw".to_string());
+        }
+        // Force GPU usage instead of software fallback
</code_context>
<issue_to_address>
**suggestion:** Allow overriding the prism pipeline order when users need custom rendering preferences or debugging.

Hard-coding `prism.order` removes flexibility for users who need to force software rendering (e.g., for driver workarounds) or test different pipelines. Please only set this default when no `-Dprism.order` is already provided in `config.jvm_args` / equivalent, or expose a config option that can override this order while still defaulting to GPU acceleration.

Suggested implementation:

```rust
    // Add GPU acceleration parameters if enabled
    // JavaFX Prism rendering pipeline settings for hardware acceleration
    if config.enable_gpu_acceleration {
        // Only set a default prism.order if the user hasn't already provided one
        // via JVM args (e.g., in config.jvm_args). This allows overriding
        // the pipeline order for debugging or driver workarounds.
        let has_prism_order = args.iter().any(|a| a.starts_with("-Dprism.order="));

        if !has_prism_order {
            // Platform-specific rendering order:
            // - Windows: d3d (Direct3D) > es2 (OpenGL ES 2) > sw (software)
            // - Linux/macOS: es2 > sw (no Direct3D available)
            if cfg!(target_os = "windows") {
                args.push("-Dprism.order=d3d,es2,sw".to_string());
            } else {
                args.push("-Dprism.order=es2,sw".to_string());
            }
        }

        // Force GPU usage instead of software fallback
        args.push("-Dprism.forcegpu=true".to_string());
    }

```

If `config.jvm_args` (or similar) is not yet merged into `args` before this block, you should:
1. Ensure any user-provided JVM args (including `-Dprism.order=...`) are appended to `args` *before* this GPU-acceleration section.
2. Document for users (e.g., in config docs) that they can override the default Prism pipeline by adding a `-Dprism.order=...` entry to their JVM args.
</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.

@HsiangNianian HsiangNianian enabled auto-merge (squash) April 1, 2026 06:28
@HsiangNianian HsiangNianian disabled auto-merge April 1, 2026 06:29
@HsiangNianian HsiangNianian enabled auto-merge (squash) April 1, 2026 06:34
@HsiangNianian HsiangNianian disabled auto-merge April 1, 2026 06:38
@HsiangNianian HsiangNianian merged commit 2888c21 into main Apr 1, 2026
16 checks passed
@HsiangNianian HsiangNianian deleted the feat/gpu-jvm-params branch April 1, 2026 06:38
@hydroroll-bot hydroroll-bot restored the feat/gpu-jvm-params branch April 1, 2026 06:38
@fu050409 fu050409 deleted the feat/gpu-jvm-params branch April 4, 2026 13:27
@hydroroll-bot hydroroll-bot restored the feat/gpu-jvm-params branch April 4, 2026 13:27
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.

2 participants