Skip to content

Mesh-card capture: one render pass per frame instead of one per axis - #198

Merged
proggeramlug merged 1 commit into
mainfrom
perf/card-capture-one-pass
Nov 11, 2026
Merged

proggeramlug merged 1 commit into
mainfrom
perf/card-capture-one-pass

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Loading a scene with SSGI on spiked the process footprint by about 1 GB for the first seconds. Part of that is mesh-card capture.

Cause

Each captured axis had its own render pass into a 64×64 scratch target plus two texture copies into the atlases. At the per-frame budget (20 meshes × 6 axes) that is 120 render passes and 120 blit encoders in one command buffer. On Metal each encoder holds about 1 MB of driver memory until the frame retires: vmmap showed 413 one-megabyte IOAccelerator regions at the peak against 40 at steady state.

Change

The scratch targets become a grid, one row per captured mesh and one column per axis (384×1280). All captures of a frame draw into their cells in a single render pass, with a viewport and scissor per draw, and the cells are then copied to their atlas slots in one run of copies. The pass lives in renderer/card_capture_pass.rs.

Result

The Deep (85 static nodes), peak memory footprint from launch to frame 200, three runs each, same game source:

Peak footprint
main 2913–2935 MB
This PR 2354–2406 MB

One run on main reported 847 MB; I treated it as an outlier and left it out.

Output with deterministic autoplay: frame 20 identical apart from 2 LSB on a handful of pixels; frames 60 and 300 differ on under 0.01% of pixels, max channel delta 8.

Not addressed

About 700 MB of load-time spike remains above the steady footprint. I have not attributed it yet.

Tests

cargo test --release in native/shared: same result as main (only visibility_shading_matches_forward_reference fails, as on main). ci-check.sh --quick lint and contracts pass locally.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Card captures can now be processed in larger batches, including multiple viewing angles per capture.
    • Rendering and updating capture images are handled together, with each capture’s image and metadata kept associated.

Each captured axis had its own render pass into a 64x64 scratch plus two texture copies
into the atlases: 120 render passes and 120 blit encoders per frame at the capture budget.
On Metal every encoder holds about 1 MB of driver memory until the frame retires, which
showed as ~400 x 1 MB IOAccelerator regions while a scene loaded.

The scratch targets are now a grid (one row per captured mesh, one column per axis). All
captures of a frame draw into their cells in a single pass with a viewport and scissor
per draw, then the cells are copied to their atlas slots in one run.

The Deep, peak memory footprint through load: about 2920 MB -> 2400 MB (3 runs each).
Output: under 0.01% of pixels differ, max channel delta 8.

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

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Card captures are now collected as per-axis draw descriptors. The renderer records the batch into a scratch grid, then copies each capture’s albedo and emissive regions to its atlas slot.

Changes: Card capture batching

Layer / File(s) Summary
Scratch grid and batched pass
native/shared/src/renderer/card_capture_pass.rs, native/shared/src/renderer/mod.rs
Capture scratch textures now hold a grid for batched draws. The new pass renders each capture into its scratch cell, then copies its albedo and emissive regions to the corresponding atlas slot.
Capture collection and recording
native/shared/src/renderer/mod.rs
The renderer collects per-axis draw descriptors and records them after the capture loop. The descriptors include uniform offsets, bindings, geometry, scratch-cell coordinates, and atlas slots.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Renderer
  participant CommandEncoder
  participant ScratchTextures
  participant AtlasTextures
  Renderer->>CommandEncoder: Record rendering and texture-copy commands
  CommandEncoder->>ScratchTextures: Render captures into scratch cells
  CommandEncoder->>AtlasTextures: Copy cell albedo and emissive regions to atlas slots
Loading

Possibly related PRs

  • Bloom-Engine/engine#117: It documents the mesh-card configuration and drained capture queue that this change batches.
Merge Risk: Minimal · up to a7955

This change batches mesh-card capture into one render pass per frame and lowers memory use. No merge-blocking issues were found in the reviewed code.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title clearly identifies the main change: batching mesh-card capture into one render pass per frame instead of one per axis.
Description check Passed The description provides the change summary, motivation, implementation details, measured results, test results, and reviewer notes. It does not use the template headings or test-plan checkboxes, and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description provides the change summary, motivation, implementation details, measured results, test results, and reviewer notes. It does not use the template headings or test-plan checkboxes, and it does not identify tested platforms, but the required information is mostly present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: b4f41d17-a781-49a3-969b-f7f40dd8333b
Commits

Reviewing files that changed from the base of the PR and between 36b95e8 and a7955f5.

Files selected for processing: 2

  • native/shared/src/renderer/card_capture_pass.rs
  • native/shared/src/renderer/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@proggeramlug
proggeramlug merged commit 39ccc64 into main Nov 11, 2026
47 of 48 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