Skip to content

Draw custom opaque materials inside the main HDR pass - #206

Merged
proggeramlug merged 1 commit into
mainfrom
perf/materials-in-main-pass
Nov 11, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
perf/materials-in-main-pass

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

What

Game-compiled opaque materials (compileMaterial + drawMeshWithMaterial) were drawn in bloom_material_pass, a render pass of their own with Load/Store on all four G-buffer targets and depth. The main HDR pass now dispatches them before it ends (dispatch_opaque_materials). The separate pass stays as the fallback for frames whose main pass is skipped by BLOOM_SKIP=hdr_pass.

Why

A second pass over the same targets costs nothing on an immediate-mode GPU. A tile-based GPU reloads and stores every attachment for it.

Measured (The Deep: a water material on 12 sea tiles and a sky dome)

before after
iPad Pro (A12Z), 2049×1536 render, BLOOM_GPU_TIME 62.0 ms 58.7 ms
macOS, 3200×1800, frame time 15.3 ms 14.5 ms

I found it by elimination on the device: simplifying the shader, sorting draws front to back and turning SSR off each left the 62 ms unchanged.

Checks

  • cargo test --release in native/shared: golden suite unchanged; only visibility_shading_matches_forward_reference fails, as on main.
  • The game's frame looks the same before and after (custom materials still draw after the scene nodes, with the same pipelines and depth state).

Not covered

Planar-reflection dispatch used to run between the scene and the material pass and now runs after both. Materials sample the previous frame's reflection target, so I expect no change, but no golden test exercises a planar reflection with a custom material.

Game-compiled opaque materials were drawn in a render pass of their own, with
Load and Store on all four G-buffer targets and depth. An immediate-mode GPU
does not notice; a tile-based one reloads and stores every target for it. The
main HDR pass now dispatches them before it ends. The separate pass remains
only for frames whose main pass is skipped by a diagnostic.

Measured with The Deep (a water material on 12 sea tiles plus a sky dome):
- iPad Pro A12Z, 2049x1536 render: GPU time 62.0 -> 58.7 ms a frame
- macOS, 3200x1800: 15.3 -> 14.5 ms a frame

Golden suite unchanged; the game's frame is pixel-equivalent before and after.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c39e1f41-0100-4742-a35a-27d9b5e2fe54
Commits

Reviewing files that changed from the base of the PR and between d0417b2 and 1e1b4b2.

Files selected for processing: 2

  • native/shared/src/renderer/opaque_material_pass.rs
  • native/shared/src/renderer/scene_pass.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@proggeramlug
proggeramlug merged commit 49cf675 into main Nov 11, 2026
26 checks passed
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.

1 participant