Skip to content

render: reset only listed per-axis store cells; skip the feeder raster and Hi-Z chain when nothing reads them (#4956) - #5064

Merged
jakildev merged 1 commit into
masterfrom
claude/4956-sparse-store-clear-feeder-hiz-gates
Nov 15, 2026
Merged

jakildev merged 1 commit into
masterfrom
claude/4956-sparse-store-clear-feeder-hiz-gates

Conversation

@jakildev

Copy link
Copy Markdown
Owner

Summary

Three pieces of per-frame GPU work in the voxel raster now run only when something uses their result. Each part was measured separately.

  • Per-axis store reset. After the first rotating frame, each frame resets the three per-axis stores only at the cells the previous frame's compaction listed. Each frame used to clear all nine textures whole.
    • A new kernel, c_per_axis_cell_clear, is dispatched indirectly over the occupied-cell list. It has GLSL and Metal twins. On Metal it also resets the distance's image-atomic scratch.
    • C_PerAxisTrixelCanvases::storeCellsListed_ decides which reset runs. compactPerAxisCells sets it. Allocation and unpark() drop it, so a fresh or unparked set still clears whole.
  • Feeder gate. Under finite face casting (the default), the voxel raster no longer widens its cull bounds by the sun sweep (IRPrefab::SunShadow::voxelRasterFeederParams). No feeder is classified or rasterized, and RESOLVE_PER_AXIS_SCREEN_DEPTH skips its scatter whenever the bake does not cast from canvas depth.
  • Hi-Z build gate. COMPUTE_DISTANCE_HIZ builds the chain only on frames with the occlusion cull on (IRPrefab::OcclusionCull::buildsDistanceHiZ). A new pure helper, IRPrefab::OcclusionCull::LagSource, holds every staleness trigger. It adds one new trigger: the frame after a cull-off frame is stale.
  • scripts/feeder-margin-verify.py now runs with --legacy-depth-shadows. That is the only path that still rasterizes feeders.
  • The new contracts are documented in per-axis-trixel-canvas-rotation.md, voxel-feeder-split.md, voxel-occlusion-culling.md, prefab-render-surface.md and engine/render/CLAUDE.md. The CLAUDE.md edit changes no line count.

Test plan

  • fleet-run IrredenEngineTest --gtest_filter='*PerAxis*:*OcclusionLag*:*SunShadowFeeder*:MetalGpuComputeDispatchTest.*': 91 passed.
    • The new OcclusionLagSource.* suite has 4 tests.
    • The new Metal test is PerAxisCellClearResetsListedCellsAndTheirScratch. It fails when the scratch atomic_store is deleted from the kernel (mutation check, then restored).
  • Frozen-wave yaw sweep, base vs head Release IRPerfGrid. Command: --wave-freeze --yaw 0 --yaw-step 0.05235987756, so frame 31 lands on the 90° cardinal.
    • Frames 31, 32, 33 and 60 are byte-identical in a single run.
    • Frames 2, 3 and 10 vary run to run on master itself. Across 5 runs per arm, the modal image is byte-identical between base and head (method under Notes).
  • Interleaved Release A/B with the benchmark lease, QUIET=guarded on all 22 runs (criterion 4).
  • render-verify on five targets, the nine-yaw set and the 28 default IRShapeDebug shots, each against a master control run in the same session (criterion 3).
  • python3 scripts/light-verify.py --if-changed: [light-verify] all checks PASS
  • cmake -DPROJECT_ROOT=$PWD -P cmake/run_header_checks_standalone.cmake: exit 0 (Metal scratch-consumer check: 56 kernels, 12 declare the scratch).

Acceptance evidence

Criterion Check run Observed
1. Phase 0 readings posted small-fixture base runs; render-verify with the gate applied Posted on #4956 (issuecomment-6818874340). Base voxelPerAxisStore mean 0.651 ms (0.536 to 0.829), above the 0.3 ms bail. All five render-verify sets unchanged vs master.
2. Sparse clear is exact (frames 2, 3, 10, 60; first rotated frame after a cardinal crossing; first rotated frame of a run) --capture-frame N base vs head, render-compare.py --per-pixel-tol 0 --threshold-max-delta 0 Frame 2 is the first rotated frame of the run. Frame 32 is the first rotated frame after the 90° crossing. Frame 33 is the first sparse reset after the unpark. Frames 31, 32, 33 and 60: PASS, max_delta 0. Frames 2, 3 and 10 vary on master alone (base vs base max_delta 38). Over 5 runs per arm the modal hash is identical on both arms (f2 fec2125782, f3 360149faea, f10 37ab56f5ad). Each arm has one outlier run (base 1 at f2, f3 and f10; head 1 at f3).
3. No committed row moves; nine-yaw set identical; occlusion-fire and feeder-margin pass render-verify.py --target … ×5; nine-yaw IRCanvasStress --sweep-yaw 0 6.2831853 9; occlusion-fire-verify.py; feeder-margin-verify.py IRCanvasStress 59/59, IRFogDemo 69/69, IRLightingSdfBlocker 5/5, IRPerfGrid 21/21. IRShapeDebug 19/148 FAIL, row-identical in metrics to a same-session master control, all #5051's yaw-180/270 rows (tables under Notes). Nine-yaw set: 9/9 max_delta 0 vs master. Default IRShapeDebug pass: 28/28 max_delta 0. occlusion-fire: PASS: per-voxel marginal reduction 11034.7 >= 1.0. feeder-margin: PASS — the shipped classify margin is adequate, ring non-empty, run on --legacy-depth-shadows (see departures).
4. Store row falls by at least half on the 8³ fixture (≥5 pairs, lower 95% bound > 0); no regression at 64³ zoom 1, 45° repeat_profile.py interleaved ABBA, Release, QUIET=guarded 8³ zoom 4, 45°, 6 pairs: base 0.651 ms (0.536 to 0.829), head 0.159 ms (0.135 to 0.179). Reduction 0.491 ms (76%), one-sided 95% lower bound 0.380 ms. 64³ zoom 1, 45°, 5 pairs: base 0.724 (0.696 to 0.751), head 0.340 (0.338 to 0.342), a 53% fall (bound 0.363 ms), so the dense scene improves rather than regresses.
5. Feeder 0 at 0° with shadows on, > 0 with --legacy-depth-shadows; 45° Visible and AxisEntries below base million control (configs/perf/million.lua), Release 0°: base 110,916 → head 0. 0° legacy: head 110,916 (base 110,916). 45°: Visible 909,358 → 808,564, AxisEntries 2,728,074 → 2,425,692 (both −11.1%).
6. Headless test: chain not dispatched with the cull off, dispatched with it on; the frame after a re-enable is stale IrredenEngineTest --gtest_filter='*OcclusionLag*' ChainIsBuiltOnlyWhileTheCullIsOn and FrameAfterAReEnableIsStale pass. COMPUTE_DISTANCE_HIZ::beginTick reads buildsDistanceHiZ, and stage 1 reads LagSource::advance.
7. Twins, shader_names.hpp, Metal registries, header checks run_header_checks_standalone.cmake Added: c_per_axis_cell_clear.glsl and metal/c_per_axis_cell_clear.metal, kFileCompPerAxisCellClear, threadgroupSizeForFunctionName (16,16,1), functionUsesImageAtomicScratch. Header checks: exit 0 (Metal scratch-consumer check: 56 kernels, 12 declare the scratch).

Plan departures

  • feeder-margin-verify flag. The plan expected feeder-margin-verify.py to pass unchanged. Under the gate, the default path has no feeder ring, and the script's own vacuity guard failed it ("vacuous adequacy arm"). It now passes --legacy-depth-shadows, the configuration where the classify margin still matters, and it passes there with the ring non-empty.
  • Store-reset bookkeeping. The plan said "whatever marks a set as needing a whole clear" lives in per_axis_canvas.hpp or the component. It is one component field set by the compaction. No lifecycle code changed beyond unpark().
  • Phase 0 reading. The plan expected about 1 ms on the small fixture; this host reads 0.65 ms. That is still above the 0.3 ms bail.

Notes for reviewer

Screenshots

Base vs head at rotated yaws. Every pair is byte-identical; the change has no visual effect.

IRPerfGrid frame 3 — first sparse reset of a run (yaw 6°)
Before After
IRPerfGrid frame 33 — first sparse reset after a cardinal unpark (yaw 96°)
Before After
IRCanvasStress nine-yaw pose 2 (yaw 45°)
Before After

Closes #4956

🤖 Generated with Claude Code

A rotating frame now resets the three per-axis stores only at the cells
the previous frame's compaction listed (c_per_axis_cell_clear, GLSL and
Metal twins; Metal also resets the distance's image-atomic scratch). A
fresh or unparked set still clears whole. The store row on the 8^3
rotating fixture falls from 0.65 to 0.16 ms, and the dense 64^3 scene
improves too.

Under finite face casting the voxel raster no longer widens its cull
bounds by the sun sweep, so no feeder is classified or rasterized, and
RESOLVE_PER_AXIS_SCREEN_DEPTH skips when the bake does not read canvas
depth. COMPUTE_DISTANCE_HIZ builds only while the occlusion cull is on,
and IRPrefab::OcclusionCull::LagSource treats the frame after a cull-off
frame as stale. feeder-margin-verify runs on --legacy-depth-shadows,
the only path that still rasterizes feeders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:wip Work in progress — not ready for review fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend and removed fleet:wip Work in progress — not ready for review labels Nov 12, 2026

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review — render: reset only listed per-axis store cells; skip the feeder raster and Hi-Z chain when nothing reads them (#4956)

Verdict: approve

The implementation matches the planned three-part optimization. The sparse reset consumes the previous frame's finalized occupied-cell list before that list is rebuilt, preserves the whole-clear path for fresh and unparked stores, and resets Metal's R32I atomic scratch alongside the texture. The feeder and Hi-Z gates are conservative: the former retains the canvas-depth path for legacy/particle coverage, while the latter suppresses culling for the first frame after any build gap or view discontinuity.

Acceptance (issue #4956)

Criterion Grade Basis
Phase 0 readings met The issue thread records the six-pair 0.651 ms small-fixture baseline above the 0.3 ms bail and same-session master controls for all five render targets.
Sparse clear exactness met Evidence covers startup, steady, and cardinal-crossing frames; deterministic frames are byte-identical and the pre-existing nondeterministic frames have identical modal hashes across five runs per arm.
Render/yaw/occlusion/feeder validation met The five target rows match the same-session master control, the nine-yaw and default-shot sets are identical, and both positive-fire validators report PASS.
Store cost and dense guard met Six interleaved pairs show a 76% reduction with a positive 0.380 ms lower bound; the five-pair dense arm improves by 53%.
Feeder gate met Default 0-degree feeder count falls from 110,916 to 0, legacy depth retains 110,916, and both required 45-degree counters fall by 11.1%.
Hi-Z gate and re-enable staleness met The real system dispatch reads buildsDistanceHiZ; the new tests exercise both gate states and the post-gap stale frame.
Backend twins and registries met GLSL/Metal twins, shader name, Metal threadgroup/scratch registrations, and the header-check audit are all present and green.

Verification

  • fleet-build --detach --target IrredenEngineTest: terminal success (fleet-jobs: 20261112T084953Z-build-d74c5b succeeded exit=0).
  • fleet-run IrredenEngineTest --gtest_filter='*OcclusionLag*:*PerAxisCellClear*:*SunShadowFeeder*': 10/10 passed, including the real Metal texture-and-scratch clear.
  • git diff --check origin/master...HEAD: clean.
  • fleet-pr-overlap --base claude/4956-sparse-store-clear-feeder-hiz-gates: VERDICT: clean.
  • The red perf-gate is inherited infrastructure: this head and the current master runs both fail while linking IRPerfGrid against the Ubuntu 26.04 runner's libjack.so (__cxa_call_terminate@CXXABI_1.3.15), before measurement. Header, format, shader-parity, Python, comment, instruction, whitespace, and closes checks are green; the still-running checks are unread rather than green.

No blocking findings or amend-worthy nits.

🤖 Reviewed by Codex (GPT-5, opus-class final pass)

Opus recheck not required (reviewed at opus class).

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge fleet:needs-windows-smoke PR needs windows-debug build + smoke-run validation and removed fleet:reviewing-mac-pool-2 labels Nov 12, 2026
@jakildev
jakildev added this pull request to stack #5071 November 12, 2026 09:46
@jakildev
jakildev merged commit fdec08e into master Nov 15, 2026
11 of 17 checks passed
jakildev added a commit that referenced this pull request Nov 16, 2026
The stack below this branch (#5064, #5070) has merged, so the branch is
rebased onto master and every reading is retaken against it: the interleaved
timing series (now series-3, replacing series-1 and series-2, which measured
the old stack base), the 45-degree stage profiles, the census and rejection
counts, the base/head capture identity, and the late-pose GUI fixtures
(criteria 10-13).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakildev added a commit that referenced this pull request Nov 17, 2026
…aw (#4954) (#5084)

* render: reject hidden overflow-lane faces before sort, relight and draw

The per-axis overflow lane held every exposed face that lost its
cardinal store cell, and the sort, the relight, the fog pass and the
scatter draw all sized their work from it. On the million control at
45 degrees that is 2.36 million records, of which about 1,500 own a
framebuffer pixel.

Stage 1 now draws the faces that won their store cells into the main
framebuffer's depth, reduces that depth to a block-maximum pyramid, and
tests each overflow candidate's whole projected footprint against it
before appending. A face is rejected only when no pixel centre falls in
its footprint, or every occluder over it is nearer by more than one tie
band, so the image is unchanged. The append is its own compiled variant
of the stage-1 body; the store kernel no longer carries it.

The test and the draw must project a face at the same place, so the
scatter placement is computed by one function. Stage 1 derives it ahead
of the composite; a frame that rejected is drawn with that value. When a
system writes the camera between the two, or a glitch subject can blank
a store cell, the append keeps every candidate.

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

* docs: record the overflow-lane rejection counts and timings

Adds the measurement document for the overflow-lane rejection: how many
lane faces own a pixel, what the append rejects, two series of
interleaved base/head timing pairs with their reports and manifests,
the per-stage split at 45 degrees, and the capture comparison. Adds the
matching row to the optimize skill's big-wins reference.

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

* render: opt the late-pose GUI fixtures out of overflow rejection

The GUI-test cyclers that IRShapeDebug splices ahead of the composite write
each shot's pose between VOXEL_TO_TRIXEL_STAGE_1 and TRIXEL_TO_FRAMEBUFFER,
outside the camera ordering contract. --gui-test, --continuous-zoom-gui-test
and --rotation-pick-test gui now keep the full overflow lane for the whole
run, so the frame a pose lands on draws as the base does.

- setOverflowRejectionEnabled returns whether it took effect; the demo
  asserts it, because the setter changes nothing before the voxel system
  exists.
- Stage 1 logs the first rotating frame's rejection verdict once per run.
- GuiTestConfig::capturePoseWriteFrame_ (IRShapeDebug
  --capture-pose-write-frame) adds a capture of each pose-write frame.
- IRShapeDebug --late-camera-write-test writes the yaw in that slot on
  scheduled frames and checks the latch, a refill inside the stand-down and
  a second latch after it expires.
- The camera row of the render ordering table now puts camera controls
  before VOXEL_PICKING / VOXEL_TO_TRIXEL_STAGE_1; the design doc states the
  contract, the fixture opt-outs and the recovery boundary.

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

* docs: retake the overflow-lane rejection evidence on master 345dbbf

The stack below this branch (#5064, #5070) has merged, so the branch is
rebased onto master and every reading is retaken against it: the interleaved
timing series (now series-3, replacing series-1 and series-2, which measured
the old stack base), the 45-degree stage profiles, the census and rejection
counts, the base/head capture identity, and the late-pose GUI fixtures
(criteria 10-13).

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

* docs: grade the perf-HUD pose-write frame with its graph masked

The --gui-test perf_hud_closed pose-write frame differs between any
two runs, base against base included, only inside the HUD's
frame-time graph, which plots wall-clock timings. Record the graph's
opaque rectangle and the masked max-delta-0 comparison that passes on
two independent base/head run pairs (#4954 criterion 10).

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

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet:approved Fleet reviewer approved — ready for human merge fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend fleet:needs-windows-smoke PR needs windows-debug build + smoke-run validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render: clear only written per-axis store cells and skip the feeder raster and Hi-Z chain when nothing reads them

1 participant