Skip to content

lighting: bound light occlusion grid visits (#4992) - #5042

Merged
jakildev merged 5 commits into
masterfrom
codex/4992-light-occlusion-domain
Nov 12, 2026
Merged

jakildev merged 5 commits into
masterfrom
codex/4992-light-occlusion-domain

Conversation

@jakildev

@jakildev jakildev commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • bound light-occlusion world-box refresh debt per chunk: refresh all before yaw/spatial world-bound frames and at most B = 64 oldest chunks on other frames
  • test current chunk boxes, conservatively admit stale chunks, clip every visited voxel to the shared local-light domain, and leave both caches untouched on the no-light fast path
  • compact consumed world-refresh queue prefixes under sustained re-dirtying so storage remains bounded while retaining oldest-first order
  • expose refresh, stale-admission, and rebuild counts in profile reports; add portable all-current, all-stale, mixed, debt-payment, sustained-queue, refresh-all, and pending-bit tests
  • retain the serial visitor: the measured sweep visit phase is 0.150 ms, below the 0.3 ms fan-out threshold

Test plan

  • fleet-build --target format-changed
  • fleet-build --target IrredenEngineTest
  • focused portable tests: 57 passed on the original head
  • final-tree LightVolumeBoundarySeedTest.*: 18 passed, including refresh-all from cold, fully re-marked, singly re-marked, and grown chunk-count states
  • MetalGpuComputeDispatchTest.*: 21 passed, including bounded/full equality after every iteration
  • final-tree python3 scripts/light-verify.py --if-changed: 46 passed
  • python3 scripts/render-verify.py --target IRPerfGrid: 21 passed
  • python3 scripts/render-verify.py --target IRCanvasStress: 59 passed
  • profile parser, header, comment-reference, formatting, and instruction-size checks passed
  • three interleaved M4 Max Release base/head rounds at sweep and static yaw 0
  • two-cell quick perf matrix across the queue-compaction amendment: frame average worst +2.4%, p99 worst +5.1%, both below regression thresholds

Acceptance evidence

Criterion Observed
Sweep performance Base combined phase: 6.181 / 6.268 / 6.510 ms; head: 4.733 / 4.698 / 5.675 ms. Improvements: 1.448 / 1.570 / 0.835 ms.
Static performance Base combined phase: 5.489 / 5.519 / 6.161 ms; head: 5.035 / 5.022 / 5.379 ms. Every head round is lower; base noise range is 0.672 ms.
Refresh-all currency The portable chunk-walk test reports 0 stale admissions and verifies every box current after refresh-all from a cold cache, after every chunk is re-marked, after one chunk is re-marked, and after the chunk count grows.
Sweep StaleVisit maximum 3843, equal to the A2 bound Total - B = 3907 - 64 = 3843.
Sweep StaleVisit average 51.2, below the A2 bound (Total - B) x C / Samples = 3843 x 4 / 300 = 51.24.
Sweep Visited average 423.3 of 3907 chunks, below half of Total (1953.5).
Static-yaw WorldRebuild maximum 64, equal to B = 64. Portable tests also prove <= B, stale rewrite at B = 0, debt payment after ceil(chunks/B), preservation of cardinal pending work, and bounded queue storage under sustained re-dirtying above B.
Domain visit Visit phase averages 0.150 ms, so the visitor remains serial.
No-light path 0 chunks visited, 0 stale admitted, 0 world boxes rebuilt; grid row averages 0.011 ms.
GPU equality 21 Metal compute tests passed, including the bounded/full buffer comparison after every iteration.
Lighting/render Lighting 46/46, IRPerfGrid 21/21, IRCanvasStress 59/59.

Plan departures and host evidence

  • The implementation was rebased onto current master, including engine/voxel: run voxel-set position updates once per rendered frame #5046's once-per-rendered-frame position update.
  • A2 classifies exact-cardinal frames reached during rotation by stage 1's branch on that frame. They remain budgeted frames and may admit unpaid chunks stale; the implementation and design document now state that contract, and the four replacement count clauses are graded above.
  • The dedicated nine-yaw IRCanvasStress capture produced no first shot after more than 14 minutes on the base arm and was manually stopped. The broader IRCanvasStress regression suite, including cardinal/inter-cardinal yaw coverage, passed 59/59.
  • IRShapeDebug previously completed with 129 passes, 19 tiny committed-reference mismatches, and 10 skips. A final rerun was environment-blocked with RESULT=NO-DISPLAY and Discovered 0 display monitors; it was not repeatedly retried.
  • The local attach-screenshots --two-ref origin/master HEAD helper is unavailable (command not found), so no comparison bundle was published.

Closes #4992

Authored with Codex (GPT-5 runtime).

@jakildev jakildev added fleet:wip Work in progress — not ready for review fleet:author-codex Implementation last authored by Codex; route review to Claude fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend labels Nov 11, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

NEEDS-DESIGN

The approved chunk-domain approach cannot currently satisfy acceptance criterion 6/8's static-yaw performance contract. At yaw 0, BUILD_LIGHT_OCCLUSION_GRID becomes the first reader to refresh every dirty chunk world bound. In preliminary clean guarded Release runs, the combined BuildLightOcclusionGrid + SingleVoxelToCanvasFirst sum moved from 6.316 ms on the instrumented base to 7.120 ms on the head (+0.804 ms), even though the voxel visit itself fell from 1.650 ms to 0.144 ms. The issue already identifies this cardinal-pose rebuild risk; the measured cost is larger than the saved visit.

  • Which contract should change: introduce a reusable/amortized world-bounds update before this system (my preference, but broader cache ownership), allow a cardinal-yaw full-pool visit instead of the locked per-chunk domain decision, or relax the static-yaw no-regression criterion?

Useful WIP is pushed: shared eligibility/domain math, no-light skip, chunk rejection, permanent phase/chunk stats, portable tests, and passing macOS lighting verification. The full three-round matrix and remaining acceptance checks are intentionally deferred until the architecture choice is resolved.

@jakildev jakildev added the fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond label Nov 11, 2026
@jakildev jakildev added fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… and removed fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond labels Nov 11, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Steward direction

Your NEEDS-DESIGN question went to the #4990 STEWARD PROPOSAL 2026-11-11, and the architect has answered it. The full decision and its criteria are in #4992's A1: #4992 (comment). Read A1 before resuming. It supersedes plan Decision 3 and the chunk-box Gotcha.

Q: Which contract changes: an amortized world-bounds update ahead of this system, a cardinal-pose full visit, or a relaxed static-yaw criterion?

A: Neither cache contract changes and the criterion stays as written. The grid build admits each chunk on its own and pays the world-box debt down in bounded steps:

  • A current world box is tested against the domain. A stale one is visited without a box test.
  • On a frame where stage 1 takes the world-bounds branch, refresh every stale box first, so the cost moves out of stage 1 instead of being added.
  • On any other frame, refresh at most B = 64 stale boxes, oldest first.

Cited: "Decision: (b), per chunk, with a bounded refresh. Criterion 8 stays as written on both arms and the two cull caches keep their contract." and "Rule 4 below is the amortized update they preferred, kept inside this system's own accessor." (architect answer, #4990 (comment)). Rejected there: (a) as a shared pass, which rewrites the voxel CLAUDE.md cache contract in the function #5010 changes; (c), which relaxes an approved criterion; (d), which parks the sweep saving.

Three things A1 adds that the answer did not have:

  1. Rule 3's yaw-frame predicate includes the spatial view. render: preserve trixel rendering through spatial camera rotation #4939 (374a361cc) merged after the answer's master read. Stage 1 now takes the world-bounds branch on IRRender::isSpatialViewEnabled() || residualYaw_ != 0 (system_voxel_to_trixel.hpp:1749, component_voxel_pool.hpp:557). The PR head merges cleanly with master 3734b2700.
  2. The voxel CLAUDE.md sentence must be net zero lines. That file sits at 210 lines, the instruction-size lint's hard wall.
  3. Executors on master: m_pendingWorldChunks is already oldest-first, and CullRebuildCounters::worldChunks_ is the rebuild count criterion 3 reads.

Next steps on this PR (A1 has the full list): five more grid-match checks under criterion 3, two new counts under criterion 5, a refresh phase row for criterion 9, the full three-round matrix for criterion 8 (if static yaw 0 still rises, lower B, and at B = 16 stop and post the table), then the render regression and the design-doc update you had deferred.

Host. The remaining gates are the Metal equality test, light-verify and the M4 Max matrix, so I added fleet:needs-macos-host.

Red checks on 98ad1b2d6. linux-build fails linking libjack on the ubuntu-26.04 image (undefined reference to __cxa_call_terminate@CXXABI_1.3.15). That is #5023, not this PR. fleet-tests fails in fleet-claim race cases, and this PR touches no scripts/fleet file.

@jakildev jakildev added fleet:needs-macos-host Remaining work needs a macOS host; non-mac panes skip (dispatch, claim, amending-claim) fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file and removed fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… labels Nov 12, 2026
@jakildev jakildev removed the fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file label Nov 12, 2026
Share local-light eligibility and seed-domain math with the gather, then
skip empty frames and rasterize only chunks that intersect the conservative
read domain. Add permanent phase and chunk-count evidence for the path.

Keep the change as WIP because refreshing chunk bounds at static yaw makes
the locked static performance gate regress despite the sweep improvement.
@jakildev
jakildev force-pushed the codex/4992-light-occlusion-domain branch from 98ad1b2 to c33013a Compare November 12, 2026 06:34
@jakildev jakildev removed fleet:wip Work in progress — not ready for review fleet:needs-macos-host Remaining work needs a macOS host; non-mac panes skip (dispatch, claim, amending-claim) labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

A1 addressed

  • Added per-chunk world-box currency and oldest-first bounded refresh. Yaw/spatial world-bound frames refresh all debt first; other frames refresh at most B = 64.
  • Current boxes are domain-tested, stale boxes are conservatively admitted, and every admitted voxel is clipped to the shared light-read domain. The no-light path touches neither cache.
  • Added portable all-current, all-stale, mixed, B = 0, ceil(chunks/B), <= B, and cardinal-pending tests.
  • Added refresh-phase timing plus stale-admitted/world-rebuilt counters to permanent reports.
  • Kept the voxel instruction update net-zero lines and updated the design document.
  • Rebased onto current master and fixed a simplify-audit finding: the pending queue now uses a read cursor instead of an erase(begin, ...) linear shift.

Validation is recorded in the updated PR body. Highlights: 57 focused portable tests, 21 Metal tests, 46 lighting captures, IRPerfGrid 21/21, IRCanvasStress 59/59, no-light zero cache activity, and three clean guarded interleaved M4 Max Release rounds. Sweep improves the combined phase by 0.835-1.570 ms; static is lower than base in every round, so B = 64 remains selected.

Two acceptance details need reviewer adjudication and are explicitly disclosed in the PR body:

  1. Exact-cardinal frames inside the sweep admit stale chunks because A1 locks the refresh-all decision to the current stage-1 predicate (spatial view or nonzero residual yaw). The sweep still visits 423.3/3907 chunks on average and meets the performance/correctness gates.
  2. The dedicated base-arm nine-yaw capture did not emit a first shot after more than 14 minutes and was manually stopped. The broader CanvasStress cardinal/inter-cardinal suite passed 59/59. A later ShapeDebug rerun was host-blocked with RESULT=NO-DISPLAY: Discovered 0 display monitors.

Blocked diagnostic operation, not retried as required: ps -axo pid,etime,%cpu,command | rg 'IRCanvasStress|ir-acquire gpu' | rg -v rg failed with /bin/ps: Operation not permitted. The comparison attachment helper was also unavailable: attach-screenshots --two-ref origin/master HEAD returned command not found.

Head: c33013a06. Pushed and stamped with fleet-pr-stamp 5042 --repo engine --runtime codex before returning the PR to review. Human merge authority is preserved.

— worker (pool-2), Codex

@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:amending-mac-pool-2 labels Nov 12, 2026
@jakildev jakildev added fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond fleet:wip Work in progress — not ready for review fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… and removed fleet:amending-mac-pool-6 fleet:design-blocked Worker escalated for architectural input mid-task; architect should respond labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Steward direction

Answers the NEEDS-DESIGN at #5042 (comment) (head a63e07940).

Q: Do exact-cardinal sweep frames refresh all debt (an exception to rules 3 and 4), or does criterion 5's zero-stale clause cover only frames where stage 1 takes the world-bounds branch?

A: the second (your option 2). The clause changes and the rules do not. The head's behaviour is the contract: an exact-cardinal frame reached during the sweep is a rule 4 frame. It refreshes at most B = 64 boxes and admits the rest stale. Rules 1 to 5, B, criterion 3's first five checks, criterion 8 and criterion 9 are unchanged, and criterion 8's three rounds stand.

What the head still owes:

  1. Criterion 3, sixth check (test). A refresh-all build admits no stale chunk and leaves no stale box in four states: a cold cache, every chunk re-marked after a refresh, one chunk re-marked, and a grown chunk count. ChunkWalkMatchesWithCurrentStaleAndMixedWorldBounds already covers the cold case. A2's executor notes show how a test reaches the other three, including the chunk-count growth.
  2. Docs. One sentence in the "Occlusion-grid read domain" section of docs/design/light-volume-propagation-domain.md: a frame's class is stage 1's branch on that frame, so an exact-cardinal frame reached during a rotation is a budgeted frame and admits its unpaid chunks stale. No CLAUDE.md change.
  3. Criterion 5, re-graded on the four clauses in A2. Quote the four rows of the sweep report's "Light occlusion chunk stats" table. The bounds are StaleVisit max ≤ Total − B and StaleVisit average ≤ (Total − B) × C / Samples, where C = 4 of 300, which gives 51.24. Visited average must be under half of Total, and WorldRebuild max at static yaw 0 must be at most B. The head's 3843 / 51.2 / 423.3 of 3907 / 64 meet all four. These are counts, so one sweep report from the head under review is enough.

The direction does not cover the review's other rows, such as the unrun nine-yaw IRCanvasStress capture under criterion 7. Those stay with the reviewer.

Siblings checked: no PR is stacked on this branch. #5039 (#4991) and #5050 (#4996) are approved and unchanged since the proposal. #5057 (#4993, opened 07:39Z) shares profile_report.{hpp,cpp} and world.cpp with this PR. git merge-tree of a63e07940 with e958ec19f is clean, and so is bbd6fe0eb with e958ec19f. The new test and docs touch neither shared file. No other #4990 child's plan or **Blocked by:** line moves.

Host: no fleet:needs-macos-host stamp. The remaining work is a portable IrredenEngineTest case, a design-doc sentence, and a re-grade from count rows. The Metal equality test, light-verify and the M4 Max rounds are already recorded on this head.

— epic-steward (pool-9)

@jakildev jakildev added fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file and removed fleet:design-proposed Epic-steward parked this design-blocked epic-child PR; its novel question(s) ride a STEWARD… labels Nov 12, 2026
@jakildev jakildev removed the fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file label Nov 12, 2026
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:wip Work in progress — not ready for review fleet:amending-mac-pool-4 labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback:

  • Added refresh-all coverage for cold, fully re-marked, singly re-marked, and grown chunk-count cache states; every state asserts zero stale admission and no stale world box remains.
  • Documented A2's per-frame classification: an exact-cardinal frame reached during rotation remains budgeted and may admit unpaid chunks stale.
  • Re-graded criterion 5 in the PR body: StaleVisit max 3843 <= 3843, average 51.2 <= 51.24, Visited average 423.3/3907 < half, and static WorldRebuild max 64 <= B.
  • Final-tree validation: IrredenEngineTest built; LightVolumeBoundarySeedTest.* passed 18/18; light-verify passed 46/46.

Head 48bc1c2 was pushed and stamped with fleet-pr-stamp 5042 --repo engine --runtime codex before review handoff. Human merge authority is preserved.

— worker (pool-4), Codex

@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 — light-occlusion grid: per-chunk domain admission with bounded world-box refresh (Closes #4992)

Verdict: approve

Re-review, delta-scoped to c33013a06..48bc1c2f4 (compaction, refresh-all test, docs sentence). Both prior needs-fix items are fixed and the plan-A2 re-grade matches the PR body.

Prior-review resolution

  • ✅ component_voxel_pool.hpp:541-550 (refreshOldestChunkWorldBounds) — unbounded m_pendingWorldChunks under sustained re-dirtying — verified fixed at 48bc1c2f4. The else if (cursor >= size()/2) branch erases [0, cursor) and resets the cursor. Oldest-first order is preserved because only the consumed prefix is dropped. Each live chunk is queued at most once (the pending bit gates markCullChunkPending and prepareChunkWorldBounds), so the unconsumed tail is at most chunkCount and storage stays near 2 × chunkCount. ensureChunkWorldBounds already starts from m_pendingWorldChunkRead_ and resets it, so the new erase does not disturb it. The new SustainedWorldDebtKeepsRefreshQueueStorageBounded test refreshes 2 per frame while re-dirtying 3 chunks for 1000 frames and asserts storage <= 2 × chunks. Without the compaction the queue would reach about 2000 entries, so the test discriminates.
  • ✅ Acceptance criterion 5 (sweep stale admission) — verified resolved under A2 on #4992 (## Plan corrections, 2026-11-12T07:53Z), which supersedes A1's sentence with four count clauses. The PR body quotes all four: StaleVisit max 3843 ≤ Total − B = 3843; average 51.2 ≤ 51.24; Visited average 423.3 of 3907 is under half; static-yaw WorldRebuild max 64 ≤ B. The A2 criterion-3 sixth check is covered by the extended ChunkWalkMatchesWithCurrentStaleAndMixedWorldBounds (cold, re-marked, singly re-marked, grown chunk count; asserts staleVisited_ == 0 and isChunkWorldBoundsCurrent for every chunk). The docs sentence A2 asked for is in docs/design/light-volume-propagation-domain.md.
  • ❌ (nit, follow-up, carried) system_build_light_occlusion_grid.hpp:387-389 — refreshAllWorldBounds still copies stage 1's branch condition. Unchanged and not blocking.

Checks and evidence

  • Green on 48bc1c2f4: format-check, header-checks, comment-refs, instruction-size, instruction-refs, closes-lint, whitespace, no-plan-files. linux-build, perf-gate and fleet-tests were still IN_PROGRESS when I read the rollup, so they are unread, not green. The author attributes the earlier reds to #5023 and fleet-claim races, and I did not re-verify that.
  • I did not build or run anything. The 18/18 LightVolumeBoundarySeedTest, 46/46 light-verify, Metal equality, IRPerfGrid and IRCanvasStress results and the sweep counts are the author's claims. I read the code and tests only. The counts are checked against A2's bounds arithmetic, not against a report I regenerated.
  • Disclosed and not penalized: IRShapeDebug final rerun RESULT=NO-DISPLAY (the earlier 19 reference mismatches stay open), the base-arm nine-yaw capture that was never completed, and no screenshot bundle.

Nits (follow-up)

  • component_voxel_pool.hpp:554 — worldBoundsRefreshQueueStorageSize() is a test-only accessor on a public component surface; a short note on its test-only intent would help.

Praise

  • The compaction threshold (cursor >= size()/2) is amortized O(1), keeps order, and has a regression test that fails without it.

Test plan the author should run before merge

  • Confirm linux-build, perf-gate and fleet-tests finish green on 48bc1c2f4 (or inherited-red for the stated reasons).

🤖 Reviewed by Claude Sonnet 5.5 (review-pr skill)

Escalation: none. Safe for merge.
Opus recheck not required.

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-codex Implementation last authored by Codex; route review to Claude 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.

lighting: build the light occlusion grid only where a local light can read it

1 participant