Skip to content

render: bound sun-face bake to feeder chunks - #5070

Merged
jakildev merged 2 commits into
masterfrom
codex/4962-sun-face-caster-mask
Nov 16, 2026
Merged

jakildev merged 2 commits into
masterfrom
codex/4962-sun-face-caster-mask

Conversation

@jakildev

@jakildev jakildev commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Preserve a dedicated sun-face chunk mask while the optional occlusion pre-pass mutates the raster mask in place.
  • Build that mask from the full sun-swept shadow-feeder viewport, while the finite-casting raster keeps its visible-only viewport.
  • Reject non-admitted pool chunks in both finite sun-face kernels before per-voxel loads; detached and revoxelized domains remain all-visible.
  • Report the finite-bake admitted slot count as SunFaceAdmit, with direct profile-row and off-screen-caster controls.
  • Rebase the change onto master's deterministic three-pass sun-record admission while preserving its workgroup barriers and prefix allocation.

Performance

The original head measured 2.105 ms at 764,480 / 1,000,000 admitted slots, but review found that mask was too narrow and excluded valid off-screen casters. Those figures are superseded and are not evidence for this head. A fresh runtime matrix is host-unverifiable: light-verify --if-changed reached Metal capture setup and then exited 69 with RESULT=NO-DISPLAY (Discovered 0 display monitors), the open macOS verification instability tracked by #5052.

Static hot-path review: the amendment resolves the sun direction once per frame, adds no per-voxel CPU work or GPU dispatch, reuses the existing chunk-bounds cache and mask staging storage, and performs the additional mask construction only while finite face casting is active. After the semantic-conflict rebase, the mask predicate participates in master's existing activeVoxel lane predicate so rejected lanes still reach the deterministic admission pass's workgroup barriers with zero records.

Test plan

  • fleet-build --target IRShapeDebug (rebased head 2b9acadd6, exit 0)
  • python3 scripts/tests/test_render_fog_cut_voxel_faces.py (GLSL + Metal; 40,296 retained-solid rays per dialect, including ignored_chunk_mask mutation)
  • python3 scripts/shader_parity_audit.py (149 GLSL, 138 Metal, 5 allowlisted)
  • Pre-rebase: fleet-build --target IrredenEngineTest (detached job 20261112T112107Z-build-93d784, exit 0)
  • Pre-rebase: fleet-run --timeout 180 IrredenEngineTest '--gtest_filter=ChunkBoundsEvictionTest.*:ProfileReport*.*' (39 passed)
  • Pre-rebase: fleet-build --target header-checks
  • python3 scripts/light-verify.py --if-changed (unverifiable on this host: detached job 20261112T111952Z-light-verify-3a83bf exited 69, RESULT=NO-DISPLAY; render: run #4959's base/head render rows and sort-cost pairs, unverified at PR #5020's merge #5052)

Acceptance evidence

Criterion Check run Observed
1. Admitted counter fires below live and equals live for all-visible input ChunkBoundsEvictionTest.SunFaceMaskAdmitsCasterInsideShadowThrow; ProfileReportVoxelCull.SunFaceAdmittedRowCarriesAverageMaximumAndSamples; runtime matrix The positive control proves a chunk outside raster visible+margin but inside the 64-voxel sun throw is rejected by the raster mask and admitted by the sun-face mask. The profile report row is pinned directly. Fresh live counts are unverifiable on this host because the display-backed run exits 69 (#5052).
2. Tight-pose record demand is lower than parent test_render_fog_cut_voxel_faces.py; live index probe Both dialect adapters prove a rejected chunk emits no faces and the named mask-ignored mutation fails. Fresh live CSV evidence remains unverifiable on this host (#5052).
3. Tight-pose cost follows admitted fraction Current-head benchmark matrix Unverifiable on this host: the previous 0.734 ratio used the defective too-narrow mask and is withdrawn; display-backed execution exits 69 (#5052).
4. Zoom-4 yaw 0/45 controls do not regress Detached parent/head benchmark setup Unverifiable on this host: display-backed execution exits 69 (#5052).
5. Same-session captures and occlusion validators light-verify --if-changed The pre-rebase job built IRLightingEmissive, saved 23 captures, then exited 69 with RESULT=NO-DISPLAY; no visual verdict is claimed. #5052 tracks the host instability.
6. Both kernel dialects reject a non-admitted chunk; mutation and conventions pass Fog-cut suite on rebased head; three kernel suites on the original head; shader parity; header checks The rebased fog-cut suite passed GLSL and Metal with ignored_chunk_mask; parity passed. The new C++ positive control distinguishes the correct sun-swept mask from the raster viewport.

Plan departures

  • The implementation and executable mask-domain controls are complete, but current-head display-backed counts, performance pairs, and visual comparisons are recorded as host-unverifiable rather than carrying forward measurements from the superseded narrow mask.
  • Master gained deterministic three-pass sun-record admission after review. The rebased kernels fold the chunk gate into the lane-active predicate instead of returning early, preserving the new count/scan/bake barriers while still avoiding rejected lanes' per-voxel loads.

Closes #4962

@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 12, 2026
@jakildev
jakildev added this pull request to stack #5071 November 12, 2026 09:46
@jakildev jakildev removed the fleet:wip Work in progress — not ready for review label 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: bound sun-face bake to feeder chunks

Verdict: approve

Stacked on #5064 (claude/4956-sparse-store-clear-feeder-hiz-gates, fleet:approved, open). Reviewing the child diff only — upstream is approved separately.

Big picture: this does what #4962 asks. The finite sun-face bake gets its own copy of the frustum-only chunk mask (SunFaceChunkVisibilityBuffer), so the occlusion pre-pass that mutates ChunkVisibilityBuffer in place can no longer narrow it. Both kernels drop a rejected chunk before any per-voxel load, and the admitted-slot count is reported next to Visible and Total.

What I checked

  • Mask sizing and tail math. In the non-detached branch buildChunkVisibilityMask returns getChunkCount() entries. That is ceil(liveVoxelCount/256), and effectiveVoxelCount == liveVoxelCount there because revoxInverse takes the first branch. So uploadMask.back() is the chunk holding the tail slot, and the sunFaceAdmittedCount tail subtraction is correct. The tailSlots != 0 && guard also protects back() on an empty mask.
  • Detached and revoxelized domains. They upload the all-visible scratch to the new buffer and report effectiveVoxelCount. That matches the doc paragraph and the PR body.
  • Kernel index bound. chunkVisible[index / VOXEL_CHUNK_SIZE] only runs after the index >= dispatch.x bound check. The buffer holds maxVoxelPoolChunks words, the same as the original.
  • Binding hygiene. bakeVoxelFaces binds the new buffer at kBufferIndex_ChunkVisibility (24). chunkVisBuf_ is rebound at 24 right after the bake, so later stage-1 consumers see their own mask again. The two shader declarations (GLSL binding = 24, Metal buffer(24)) match, and ir_constants.{glsl,metal} both define VOXEL_CHUNK_SIZE = 256.
  • GLSL/Metal parity. The two kernels carry the identical early-out in the same position. shader-parity is green.
  • Test. I re-ran python3 scripts/tests/test_render_fog_cut_voxel_faces.py on this head. It passes for glsl and metal, and the ignored_chunk_mask mutation is in the variant list. The adapter extracts the real gate line from the shader source rather than restating it, so the control tracks the shipped kernels.

CI state (head 1640336ab)

  • perf-gate: FAILURE, inherited. It fails at the link step of the IRPerfGrid build: libjack.so: undefined reference to __cxa_call_terminate@CXXABI_1.3.15. That is a runner toolchain issue unrelated to this diff. The parent #5064 shows the same red perf-gate and all-checks. I do not hold it against this PR.
  • linux-build, render-harness-tests, fleet-tests: still IN_PROGRESS. These are unread, not green.
  • Green: format-check, header-checks, shader-parity, comment-refs, instruction-refs, instruction-size, closes-lint, python-lint, no-plan-files, whitespace.

Acceptance (issue #4962), graded from the PR's evidence table

I did not dispatch review-acceptance. I graded from the PR's own table, so the per-criterion reading below is mine.

# Criterion Reading
1 Admitted counter fires below live, equals live when all-visible Met. Tight pose: 764,480 of 1,000,000. All-visible pose: 512 of 512.
2 Tight-pose record demand lower than parent Unverifiable on this host. The probe produced no CSV. The executable kernel control covers "rejected chunk emits zero faces".
3 Cost follows admitted fraction Partially evidenced. The ratio is 0.734 against a 0.914 bound, but it rests on one 120-frame head run against a 3×300 parent. The requested five interleaved pairs were not obtained.
4 Zoom-4 yaw 0/45 controls do not regress Unverifiable on this host (#5052).
5 Same-session captures and occlusion validators Unverifiable on this host (#5052).
6 Both dialects reject a non-admitted chunk; mutation and conventions pass Met. Reproduced above.

Each unverifiable row is attributed to the open #5052 display and lease instability rather than silently claimed, which is the honest shape. Criteria 4 and 5 are the ones that would catch a visual or perf regression on the default control poses, so the cross-host smoke lanes need to cover them.

Nits (follow-up)

  • engine/profile/src/profile_report.cpp:442 — the new SunFaceAdmit row has no direct assertion. The *ProfileReport* gtests pass, but none of them pins the row. A one-line check in the next test touch on that file would lock it.
  • engine/prefabs/irreden/render/systems/system_voxel_to_trixel.hpp:1830 — the two if (voxelFaceBaker_ != nullptr) blocks repeat the guard. Nothing is wrong, since the buffer is only read when the baker exists. Folding the mask upload into a small helper would remove the duplicated subData pair on the next pass over this function.

Test plan the author should run before merge

  • Let linux-build, render-harness-tests, and fleet-tests finish green on this head.
  • On a stable-display host, run the criterion 4 and 5 captures (zoom-4 yaw 0/45 controls, render-verify, light-verify) that were host-unverifiable.

Escalation: please Opus-recheck before merge (touches: engine/render, engine/prefabs/irreden/render).

🤖 Reviewed by Claude Sonnet (review-pr skill)

Opus recheck required: engine/render GPU path. A new GPU buffer is bound at the shared ChunkVisibility slot 24 and restored afterwards, and two compute kernels gained an early-out. I confirmed the binding handoff, the tail math, and the kernel parity by reading. The cross-frame buffer-binding lifetime and the sun-caster coverage argument need an Opus-class read: does the frustum-only feeder mask ever drop a chunk that casts into a visible receiver? Criteria 2 to 5 have no same-host evidence, so I am not confident enough to stamp this final.

@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.

Opus recheck — render: bound sun-face bake to feeder chunks

Verdict: needs-fix

Stacked on #5064 (fleet:approved, open). Reviewing the child diff only; the upstream is approved separately. Head 1640336ab.

Sonnet asked: "does the frustum-only feeder mask ever drop a chunk that casts into a visible receiver?" On closer read, yes. In the default render path the mask this PR gates on is not widened toward the sun, so off-screen casters within the shadow throw stop casting.

Blocker: the gate mask has no sun sweep exactly when the gate is active

The chain, all at this head:

  1. system_voxel_to_trixel.hpp:2549, beginTick: shadowFeederParams_ = voxelRasterFeederParams(voxelFaceBaker_ != nullptr);
  2. sun_shadow_constants.hpp:85 (added by the parent #5064): voxelRasterFeederParams(true) returns ShadowFeederParams{}, so sweepDistance_ == 0. Its comment gives the reason: "Under finite face casting the sun bake reads pool faces and never the canvas depth an off-screen feeder deposits, so the raster admits no feeder ring at all."
  3. system_voxel_to_trixel.hpp:1795: chunkVp = shadowFeederCullViewport(kCullChunkMargin, shadowFeederParams_). With a zero sweep, IRMath::shadowFeederIsoBounds returns the visible viewport unchanged (ir_math.hpp:1480). So chunkVp is the visible cull viewport plus kCullChunkMargin = 8 iso units.
  4. This PR copies that same mask into SunFaceChunkVisibilityBuffer and the bake kernels return on it. The copy happens only under voxelFaceBaker_ != nullptr, the same condition that zeroed the sweep in step 1.
  5. Finite coverage is the default: voxelFaceCoverage_ = true (system_bake_sun_shadow_map.hpp:199). It turns off only when a particle-to-trixel system is registered.

So whenever this gate runs, it admits visible+8 chunks, not visible widened by kSunShadowMaxDistance = 64 voxels along the sun. A caster up to 64 voxels toward the sun casts onto on-screen receivers, but at a typical sun its iso shift is far larger than 8 units. Any chunk in that band is now rejected before its faces reach the face index or the sampled layer. The visible symptom: shadows from casters just off-screen on the sun side vanish, and they pop in as the camera pans those casters into the margin.

The parent's zero-sweep decision was sound only because the bake read the whole pool. This PR removes that, so the parent's comment in step 2 becomes false once the two compose. The issue's own Scope defines the domain this needs: "the visible iso viewport widened along the sun by the shadow throw, kSunShadowMaxDistance". The plan's "Verified current state" bullet ("built from chunk iso bounds against the shadow-feeder viewport") describes master, where the sweep is live. #5064 changed that on this tree, and the issue's Dependencies section flagged #5064 for exactly this reason. The new paragraph in docs/design/sun-shadow-bake-coverage.md ("admits source slots through the frustum-only chunk mask built from the shadow-feeder viewport") has the same mismatch.

The criterion that would have caught this is 5: a same-session RGB-identical parent/head capture set. It is recorded as host-unverifiable. Criteria 1, 3 and 6 all pass on a too-narrow mask, because a narrower mask admits fewer slots and costs less.

Fix (mechanical, in scope): build the sun-face mask from the widened viewport, shadowFeederCullViewport(kCullChunkMargin, IRPrefab::SunShadow::frameShadowFeederParams()). Resolve those params once in beginTick beside shadowFeederParams_, not per canvas. The raster mask keeps its zero-sweep viewport. buildChunkVisibilityMask returns a reference to one thread_local vector, so a second call overwrites the first result. Either upload chunkVisBuf_ before the second call, or test both viewports in one bounds pass so rebuildChunkBounds runs once. Then:

  • Recompute sunFaceAdmittedCount from the widened mask. That is the number criterion 1 reports.
  • Re-take criteria 1 and 3. The admitted fraction will rise, and the 0.914 bound moves with it.
  • Correct the design-doc paragraph so it names the sun-swept viewport and says it differs from the raster's.

Positive-fire control to add: extend an existing render gtest, or the kernel adapter suite, with a case that fails on this head. Put a chunk outside the visible+margin viewport, within the 64-voxel throw on the sun side, and assert the sun-face mask admits it. Then mutate the sun-face viewport back to shadowFeederParams_ and confirm the case fails by name. The ignored_chunk_mask mutation only proves the kernel reads the mask. It cannot see which mask was built.

Confirmed from the Sonnet pass

  • Tail math and the back() guard: correct for the mask length getChunkCount() == divCeil(effectiveVoxelCount, 256) in the world branch. It stays correct once the widened mask replaces the current one, since that mask has the same length.
  • Binding handoff: the bake binds SunFaceChunkVisibilityBuffer at 24 inside bakeVoxelFaces, and chunkVisBuf_ is rebound at 24 right after (:2134), before the compact and the occlusion pre-pass bind their own inputs. The plan's Metal gotcha (bindings don't persist across program switches) is honored. Per-canvas subData into one shared buffer follows the same pattern chunkVisBuf_ already uses, so it adds no new cross-canvas hazard.
  • The two upload and bake sites share one voxelFaceBaker_ != nullptr guard. voxelFaceBaker_ is assigned only in beginTick, so a bake never reads a mask that was skipped for this canvas.
  • Detached and revoxelized canvases stay all-visible. GLSL and Metal gates are identical. VOXEL_CHUNK_SIZE matches kVoxelChunkSize.

Nits (carry forward from Sonnet, unchanged)

  • profile_report.cpp:442: the SunFaceAdmit row has no direct test assertion.
  • system_voxel_to_trixel.hpp:1830/1853: the duplicated voxelFaceBaker_ guard and upload pair. This is worth folding into one helper when the widened-mask build lands there.

CI

perf-gate red at the IRPerfGrid link step (libjack.so __cxa_call_terminate@CXXABI_1.3.15), inherited from the parent. Not held against this PR.

🤖 Reviewed by Claude Opus (review-pr skill, Opus recheck)

@jakildev jakildev added fleet:needs-fix Fleet reviewer found issues — author must address and removed fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge fleet:reviewing-mac-pool-3 labels Nov 12, 2026
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:needs-fix Fleet reviewer found issues — author must address fleet:amending-mac-pool-3 labels Nov 12, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback:

  • Built the finite sun-face mask from once-per-frame full sun-swept feeder params while leaving the raster mask visible-only under finite casting.
  • Added a positive control proving a caster outside visible+margin but inside the 64-voxel throw is admitted, plus a direct SunFaceAdmit report assertion.
  • Updated the design contract and withdrew the superseded too-narrow performance figures from the PR body.
  • Validation: IrredenEngineTest build clean; 39 focused gtests passed; GLSL/Metal fog-cut suite, shader parity, and header checks passed. Current-head light verification remains host-unverifiable: exit 69, RESULT=NO-DISPLAY (render: run #4959's base/head render rows and sort-cost pairs, unverified at PR #5020's merge #5052).

— Codex worker (GPT-5)

@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.

Re-review — render: bound sun-face bake to feeder chunks

Verdict: approve (Opus recheck required, see the footer)

Stacked on #5064 (fleet:approved, open). Reviewing the child diff only — upstream is approved separately. Delta-scoped re-review of 1640336ab..441c79b63 against the Opus needs-fix on 1640336ab.

Prior-review resolution

  • ✅ Blocker, gate mask had no sun sweep (system_voxel_to_trixel.hpp, chunkVp from shadowFeederParams_) — verified fixed at 441c79b. beginTick (:2576) now resolves sunFaceFeederParams_ = frameShadowFeederParams() once per frame, and shadowFeederParams_ is zero-sweep only under voxelFaceBaker_ != nullptr. That matches the old voxelRasterFeederParams(voxelFaceBaker_ != nullptr) for the raster. The per-canvas tick builds sunFaceChunkVp from sunFaceFeederParams_ (:1817) and a second buildChunkVisibilityMask call from it (:1874). The raster mask and its chunkVisBuf_ upload keep the visible-only viewport.
  • ✅ thread_local mask overwrite hazard — verified safe. uploadMask is last read at :1871, before the second call returns the same vector. sunFaceMask is consumed immediately by uploadSunFaceChunkMask. The identical-args second call hits the rebuildChunkBounds dirty check, so bounds are not rebuilt.
  • ✅ sunFaceAdmittedCount recomputed from the widened mask (:1883). The all-visible branch now goes through the same helper, and the tail math gives effectiveVoxelCount there (admittedChunkCount == chunkWords, last word is 1). That is the same value as before.
  • ✅ Design doc paragraph — now names the sun-swept viewport and says it differs from the raster's (docs/design/sun-shadow-bake-coverage.md).
  • ✅ Nit profile_report.cpp:442 (no SunFaceAdmit assertion) — ProfileReportVoxelCull.SunFaceAdmittedRowCarriesAverageMaximumAndSamples pins the row.
  • ✅ Nit, duplicated guard/upload pair — folded into uploadSunFaceChunkMask. The back()-on-empty hazard stays covered: tailSlots != 0 implies a non-empty mask.
  • ↗ Criteria 1, 3, 4, 5 (same-session captures and perf pairs) — still host-unverifiable (RESULT=NO-DISPLAY, #5052). The PR body withdraws the superseded narrow-mask figures, so no stale numbers carry forward. Step-5c smoke labels cover the lane.

Nits (follow-up)

  • test/ecs/chunk_bounds_eviction_test.cpp:137 — SunFaceMaskAdmitsCasterInsideShadowThrow exercises buildChunkVisibilityMask with two hand-built viewports, so it would also pass on the pre-amend head. Reverting the sun-face mask to shadowFeederParams_ in the system tick would not fail it by name, which is the mutation the prior review asked the control to catch. It proves the widened viewport admits the caster, not that the tick feeds that viewport to the sun-face mask. Extracting the choice into a small helper that the test and the tick both call (for example sunFaceChunkViewport(margin, params)) would close it. I left this for Opus to judge as nit or needs-fix, since it decides whether the prescribed control is met.
  • engine/prefabs/irreden/render/sun_shadow_constants.hpp:85 — voxelRasterFeederParams now has no caller (beginTick open-codes the ternary). Either call it, or drop it and update the docs/design/voxel-feeder-split.md:249 reference.

CI state (head 441c79b63)

  • Green: format-check, header-checks, shader-parity, comment-refs, instruction-refs, instruction-size, closes-lint, python-lint, no-plan-files, whitespace.
  • linux-build, render-harness-tests, fleet-tests and perf-gate: pending on this head, so unread, not green. The parent's perf-gate was red at the libjack.so link step on the earlier head, a runner-toolchain issue unrelated to this diff.
  • I did not run a build or test myself. The author's IrredenEngineTest build and 39 focused gtests, the fog-cut suite, parity and header checks are cited from the PR body only.

Escalation: please Opus-recheck before merge (touches: engine/prefabs/irreden/render, sun-shadow bake, GPU chunk-mask binding).

🤖 Reviewed by Claude Sonnet (review-pr skill)

Opus recheck required: this amend answers an Opus needs-fix on the render sun-shadow gate. I confirmed the wiring and mask lifetime by reading, but the display-backed criteria are unverifiable. Also needs a judgement on whether the unit control meets the mutation requirement (nit above).

@jakildev jakildev added fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge and removed fleet:changes-made Agent addressed human feedback — ready for human re-review fleet:reviewing-mac-pool-5 labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

Perf gate

Head host slug: linux-x86_64-xeon-platinum-8370c-unknown

perf comparison: 7c08741 → eac8b2f-ci

baseline: /home/runner/work/_temp/perf-baseline/history/linux-x86_64-xeon-platinum-8370c-unknown/7c087414203d0c2baf53b05fb7a0dca285f29615
head: /home/runner/work/IrredenEngine/IrredenEngine/save_files/perf/eac8b2f44-ci

host calibration

  • host: linux-x86_64-xeon-platinum-8370c-unknown (matches baseline)
  • ref_ms: head 115.63 vs baseline 116.12 (load_factor 1.00×)
  • calibration target: 50.00 ms (informational)
  • baseline capture: perf-baseline@7c0874142 (branch tip); master 2b1d20122, finished 2026-11-10T06:57:14Z, 5.8 d before the head run, ref_ms 116.12
  • weighting: raw (class-matched capture; load_factor 1.00×; no calibration-scaling entry)
  • attribution: no measured master improvement between capture master 2b1d20122 and merge base 2455e3240 (52 commits)

thresholds: regress ≥ 10%, improve ≥ 5%

voxel cull effectiveness

cell ratio (base→head) avg visible total avg feeder
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 1.000 → 1.000 (+0.0pp) 262144 → 262144 262144 → 1024 0 → 0
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.788 → 0.598 (-19.1pp) 156630 → 156630 262144 → 1024 50080 → 0 (0.000×)
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 1.000 → 1.000 (+0.0pp) 262144 → 262144 262144 → 1024 0 → 0
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.990 → 0.975 (-1.5pp) 255592 → 255592 262144 → 1024 3862 → 0 (0.000×)

frame timing (ms)

cell avg p99
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 548.57 → 565.79 (+3.1%) 1782.55 → 1629.01 (-8.6%) ↓
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 1400.63 → 1295.89 (-7.5%) ↓ 2541.77 → 2402.71 (-5.5%) ↓
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 644.61 → 666.75 (+3.4%) 8996.10 → 9064.94 (+0.8%)
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 1853.06 → 1836.77 (-0.9%) 2873.31 → 2923.15 (+1.7%)

GPU frame timing (ms; separate from stage samples)

cell envelope (base→head) buffer spans (base→head) coverage (base→head)
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable

GPU stage timing (avg ms per sampled invocation)

Window rows on one side and exclusive rows on the other measure different things, so these cells carry no stage marks: target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1, target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1, target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1, target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1.

cell canvasClear voxelCompact voxelStage1 voxelCardinalElect voxelStage2 voxelSunFaces textToTrixel buildLightOcclusionGrid computeVoxelAO bakeSunShadowMap computeSunShadow computeLightVolume lightingToTrixel fogToTrixel trixelToFb resolvePerAxisScreenDepth fbToScreen
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 71.90→20.33 62.27→61.87 55.07→54.67 1.44→1.01 58.09→59.80 6.39→91.70 — 0.00→0.00 2.48→2.47 16.98→34.06 20.11→20.77 22.51→23.18 4.13→4.05 1.28→1.28 0.26→0.21 — 9.62→9.11
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 137.15→21.40 430.94→320.10 261.46→248.63 4.58→4.31 260.85→251.45 5.42→152.81 — 0.00→0.00 2.19→2.08 31.54→55.94 19.15→19.11 20.96→21.38 8.96→9.26 1.30→1.25 0.25→0.20 — 9.07→8.50
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 64.31→19.39 74.86→76.26 59.76→60.34 9.37→8.69 51.25→52.85 7.98→88.01 1.55→1.57 0.00→0.00 1.04→6.33 50.12→59.11 19.23→19.81 46.09→45.73 6.82→6.61 1.78→1.72 0.23→0.25 0.00→0.00 10.46→10.23
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 150.17→20.31 545.14→517.29 418.10→400.58 6.86→6.79 407.88→392.19 6.20→167.10 1.56→1.51 0.00→0.00 0.95→2.17 27.72→77.94 18.08→20.31 20.68→23.94 7.22→7.53 1.49→1.46 0.24→0.18 0.00→0.00 9.21→8.62

top CPU systems by avg ms (head)

target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 258.186 → 290.566 (+12.5%) ⚠
RENDER ComputeLightVolume 42.093 → 43.514 (+3.4%)
RENDER ComputeSunShadow 8.886 → 26.379 (+196.9%) ⚠
RENDER CanvasToFramebuffer 21.871 → 20.573 (-5.9%) ↓
RENDER BakeSunShadowMap 10.411 → 9.960 (-4.3%)
UPDATE PropagateTransform 5.175 → 5.769 (+11.5%) ⚠
UPDATE FogRevealEval 5.008 → 4.813 (-3.9%)
RENDER ComputeVoxelAO 3.926 → 4.248 (+8.2%)

target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1099.483 → 994.315 (-9.6%) ↓
RENDER ComputeSunShadow 24.535 → 49.562 (+102.0%) ⚠
RENDER ComputeLightVolume 39.483 → 40.009 (+1.3%)
RENDER CanvasToFramebuffer 20.548 → 19.480 (-5.2%) ↓
RENDER ComputeVoxelAO 8.641 → 9.515 (+10.1%) ⚠
RENDER LightingToTrixel 9.023 → 9.458 (+4.8%)
RENDER BakeSunShadowMap 9.093 → 8.622 (-5.2%) ↓
UPDATE PropagateTransform 4.869 → 5.816 (+19.4%) ⚠

target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 276.966 → 318.572 (+15.0%) ⚠
RENDER ComputeSunShadow 42.505 → 51.549 (+21.3%) ⚠
RENDER ComputeLightVolume 40.970 → 42.574 (+3.9%)
RENDER LightingToTrixel 25.716 → 24.308 (-5.5%) ↓
RENDER CanvasToFramebuffer 21.682 → 21.408 (-1.3%)
RENDER BakeSunShadowMap 13.045 → 13.016 (-0.2%)
UPDATE PropagateTransform 6.438 → 6.744 (+4.8%)
RENDER FogToTrixel 5.843 → 5.625 (-3.7%)

target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1535.741 → 1501.700 (-2.2%)
RENDER ComputeSunShadow 20.850 → 71.196 (+241.5%) ⚠
RENDER ComputeLightVolume 38.296 → 43.675 (+14.0%) ⚠
RENDER CanvasToFramebuffer 20.398 → 19.005 (-6.8%) ↓
RENDER BakeSunShadowMap 9.056 → 8.539 (-5.7%) ↓
RENDER ComputeVoxelAO 7.156 → 7.903 (+10.4%) ⚠
RENDER LightingToTrixel 7.408 → 7.717 (+4.2%)
UPDATE PropagateTransform 6.497 → 6.451 (-0.7%)

@github-actions github-actions Bot added the perf:improved Performance comparison detected an improvement label Nov 16, 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.

Opus recheck: render: bound sun-face bake to feeder chunks (semantic-conflict rebase)

Verdict: approve

The PR is standalone on master (parent #5064 merged). Head 2b9acadd6 rebases the two PR-only commits onto master's deterministic three-pass sun-record admission (#5063). The last Opus approval was on 441c79b63. This recheck covers the one new piece of executable logic: how the chunk gate composes with count → scan → bake. The C++ mask construction is the code the last Opus pass approved, carried over by the rebase.

Sonnet's open item: count/bake mismatch at runtime

Sonnet confirmed barrier reach and the single binding by reading. It flagged that no runtime run exists to catch a count/bake mismatch. On closer read I confirm the mismatch cannot happen, and the reason is structural, so it does not depend on a runtime run:

  • Same predicate, same inputs, every pass. Passes 0 and 2 are the same kernel. activeVoxel folds the chunk test in right after the range test (c_bake_voxel_sun_faces.glsl:103, .metal:92). recordMask depends only on activeVoxel, the voxel loads, the fog window and FrameDataSun, and none of those change between pass 0 and pass 2. chunkVisibility is bound once at slot 24 before pass 0 (system_bake_sun_shadow_map.hpp:1253). Nothing writes sunFaceChunkVisBuf_ between the three dispatchCompute calls: its only subData runs in the per-canvas tick before bakeVoxelFaces. So pass 2 writes exactly the records pass 0 counted, and the prefix allocation stays exact.
  • Barrier uniformity. A rejected lane is inactive, not returned, so every lane reaches both barrier() / threadgroup_barrier calls. Pass 0 still writes admissionScratch[group] for every group, zero for a fully rejected group. That meets the steward's A1 rule that pass 1 sums every slot and nothing clears it between frames. The only early returns, the admission.x == 1 scan and the pass-0 tail, are uniform across the workgroup.
  • Cross-canvas buffer reuse on Metal. I checked this beyond the last recheck. sunFaceChunkVisBuf_ is patched per canvas while the previous canvas's bake may still be queued in the same uncommitted command buffer. MetalBufferImpl::subDataRanges (metal_buffer.cpp:97-117) sends a write to an already-encoded buffer through replaceBacking (full size) or stagePatch (a GPU-timeline blit). Either way the earlier encoder reads its own canvas's bytes. GL orders glBufferSubData against prior reads implicitly. The buffer is shader read-only, so the NVIDIA "subData into a buffer a queued shader wrote" stall in engine/render/CLAUDE.md does not apply.
  • Index bound. chunkVisible[index / 256] is reached only for index < dispatch.x == effectiveVoxelCount. The upload covers divCeil(effectiveVoxelCount, 256) words in both branches, and the buffer holds maxVoxelPoolChunks. That is the same bound chunkVisBuf_ already relies on for the same count.

Run here (macOS, head 2b9acadd6)

  • fleet-build --target IrredenEngineTest: exit 0.
  • fleet-run IrredenEngineTest --gtest_filter=ChunkBoundsEvictionTest.*:ProfileReport*.*: 39 passed, RESULT=CLEAN. This includes SunFaceMaskAdmitsCasterInsideShadowThrow and ProfileReportVoxelCull.SunFaceAdmittedRowCarriesAverageMaximumAndSamples on the rebased tree. The PR body listed these as pre-rebase only.
  • python3 scripts/tests/test_render_sun_record_capacity.py: OK. Each dialect passed 12 retention orders and 6 grown-capacity controls.
  • python3 scripts/tests/test_render_fog_cut_voxel_faces.py: OK, 40,296 retained-solid rays per dialect, ignored_chunk_mask mutation included.
  • python3 scripts/shader_parity_audit.py: clean (149 GLSL / 138 Metal).

CI (head 2b9acadd6)

  • Green: linux-build, perf-gate, fleet-tests, format-check, header-checks, shader-parity, comment-refs, instruction-refs, instruction-size, closes-lint, python-lint, no-plan-files, whitespace, gate.
  • Red: render-harness-tests (and all-checks), inherited. The one failing suite is test_harness_dependency_contract.py (130/131 pass). It fails on scripts/verify_common.py importing fleet, which master 7944324d2 (#5078) added. render-harness-tests fails on that master commit too, and #5088 tracks it. This PR's only script change is the fog-cut adapter, which adds no import. Not held against this PR.

Acceptance (#4962)

My reading matches Sonnet's table. Criterion 6 is met, now including the record-capacity suite that A1 added. Criteria 1 and 2 have their domain and kernel halves met. Criteria 3–5 are host-unverifiable (#5052), and the superseded narrow-mask figures are correctly withdrawn. fleet:needs-windows-smoke carries the off-screen sun-side caster capture and the zoom-4 yaw 0/45 pair.

Nits (follow-up)

  • engine/prefabs/irreden/render/sun_shadow_constants.hpp:85: voxelRasterFeederParams is still uncalled now that #5064 is on master, because beginTick open-codes the ternary. Either call it (shadowFeederParams_ = voxelRasterFeederParams(voxelFaceBaker_ != nullptr)) or drop it and fix the docs/design/voxel-feeder-split.md:249 reference. Carried from the last recheck.
  • scripts/tests/test_render_sun_record_capacity.py does not model the lane predicate, so the count/bake agreement under the chunk gate is pinned by structure, not by a control. A future adapter that runs pass 0 and pass 2 over one lane set with a half-rejected workgroup would lock it. Not needed for this PR.
  • On Metal, the per-canvas sun-face mask write to an already-encoded buffer costs one extra blit encoder per canvas per frame, the same as chunkVisBuf_ already does. It is small, but the PR body's "adds no GPU dispatch" claim leaves it out. The criterion-3/4 perf pair on a display host will show whether it matters.

🤖 Reviewed by Claude Opus (review-pr skill, Opus recheck)

@jakildev jakildev added fleet:reviewing-mac-pool-2 fleet:approved Fleet reviewer approved — ready for human merge and removed fleet:needs-opus-recheck Sonnet flagged this PR for Opus recheck before merge fleet:reviewing-mac-pool-2 labels Nov 16, 2026
@jakildev
jakildev merged commit edf66e3 into master Nov 16, 2026
17 of 19 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-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 perf:improved Performance comparison detected an improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render: bound the voxel sun-face bake to casters that can reach the view

1 participant