Repository navigation
render: skip the main-canvas sun-shadow dispatch on cardinal surfaces - #5176
Conversation
On a cardinal surface-lit frame lighting reads no sun-shadow texel of a main canvas whose occupied texels are all cardinal voxel surfaces, yet COMPUTE_SUN_SHADOW still visited every texel of it. C_TriangleCanvasTextures now records whether its distance content needs a query: every distance writer binds through one chokepoint with a content kind (voxel stage 2 reports cardinal surfaces only under its own cardinal-bit gate), and only the device clear back to the empty sentinel resets the record. The pass skips the main-canvas grid dispatch when the surface variant is selected and the record is clear. When the dispatch runs, empty single-canvas texels and cardinal voxel surfaces are left unwritten, in both shader twins. Debug asserts check that the producer's and the reader's skip sets agree on each frame and that the surface variant never runs at a non-zero residual yaw. On Metal Debug, cardinal-zoom4-overlap8-subdiv4, computeSunShadow drops from 0.308 ms to no GPU sample; captures are unchanged. Evidence: docs/perf/main-canvas-sun-shadow-skip/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakildev
left a comment
There was a problem hiding this comment.
Review — render: skip the main-canvas sun-shadow dispatch on cardinal surfaces
Verdict: needs-fix
The whole-dispatch approach and its Metal evidence are sound, but the current head does not yet uphold its writer-chokepoint invariant and turns a required CI validator red.
Needs-fix
engine/render/include/irreden/render/trixel_rect.hpp:76andengine/render/include/irreden/render/mask_grid_painter.hpp:97— both CPU helpers still writetextureTriangleDistances_directly withsubImage2D, bypassingC_TriangleCanvasTextures::recordDistanceContent. After an empty reset, either helper can introduce queried content whileholdsQueriedContent_remains false, allowingCOMPUTE_SUN_SHADOWto skip and leave stale shadow texels. Route both uploads throughwriteDistances(or the same recording chokepoint) and add a census/test that covers direct CPU texture writes; the current R32IbindAsImagesweep cannot see these two sites.scripts/tests/test_render_canvas_shape_geometry.py::test_geometry_writers_invalidate_and_shading_preserves— the PR movedclearTexImagebehindclearDistancesToEmpty()without updating this contract test. Both CI and a local run error at line 269 withValueError: substring not found, sorender-harness-testsandall-checksare red. Update the assertion to verify invalidation precedes the device clear insideclearDistancesToEmpty, then run the render-harness suite.
Acceptance (issue #5102)
4 of 5 met. Cost, capture parity/route transitions, parent-vs-head render verification, and the named shader/cardinal tests have credible positive-fire evidence. Criterion 4 (writer census) is unmet because the two direct CPU subImage2D writers above bypass the new content record and are invisible to the stated sweep.
Praise
- The skip is scoped to the main-canvas grid dispatch rather than returning from the whole tick, preserving per-axis and shape-receiver work exactly as the reviewed plan required.
- The evidence includes the skip-firing fixture, cardinal-to-rotating transitions, parent/head render-manifest replay, and a paired upper bound well beyond the required reduction.
Checked
- Read the complete PR/issue thread, including both plans, both correction rounds, the refuted store-only premise, and the replacement premise probe.
- Reviewed current head
71ab22ed9977bb44933d67d24872f976ac43d292and all changed code/shader paths in context. python3 scripts/tests/test_render_cardinal_surface_lighting.py: 4 tests passed.python3 scripts/shader_parity_audit.py: clean, 171 GLSL and 158 Metal files.python3 scripts/tests/test_render_canvas_shape_geometry.py: 3 tests run, 1 error at the staleclearTexImageassertion.- Current GitHub checks:
render-harness-testsfailed for the same error;linux-buildandperf-gatewere still pending when reviewed; the remaining completed checks passed.
Test plan the author should run before merge
- Route both external CPU distance uploads through the recording mutator and add a regression census for direct
textureTriangleDistances_writes outside the owner component. - Update
test_render_canvas_shape_geometry.pyfor the extracted clear helper and runbash scripts/tests/run_all.shto a clean terminal result.
🤖 Reviewed by Codex GPT-5 (opus-class; review-pr skill)
Opus recheck not required (reviewed at opus class).
Perf gateHead host slug: perf comparison: b309c9f → 59c5e51-cibaseline: host calibration
thresholds: regress ≥ 10%, improve ≥ 5% voxel cull effectiveness
frame timing (ms)
GPU frame timing (ms; separate from stage samples)
GPU stage timing (avg ms per sampled invocation)
top CPU systems by avg ms (head)
|
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
221.593 → 219.673 (-0.9%) |
| RENDER | ComputeLightVolume |
26.250 → 27.102 (+3.2%) |
| RENDER | CanvasToFramebuffer |
14.773 → 14.828 (+0.4%) |
| RENDER | ComputeSunShadow |
13.119 → 12.464 (-5.0%) |
| UPDATE | FogRevealEval |
8.618 → 8.329 (-3.4%) |
| RENDER | BakeSunShadowMap |
6.145 → 6.064 (-1.3%) |
| UPDATE | PropagateTransform |
3.668 → 3.659 (-0.2%) |
| UPDATE | LuaWaveStateToOffset |
3.274 → 3.081 (-5.9%) ↓ |
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
729.250 → 723.246 (-0.8%) |
| RENDER | ComputeSunShadow |
26.492 → 25.872 (-2.3%) |
| RENDER | ComputeLightVolume |
22.641 → 22.754 (+0.5%) |
| RENDER | CanvasToFramebuffer |
14.167 → 13.760 (-2.9%) |
| UPDATE | FogRevealEval |
7.354 → 8.151 (+10.8%) ⚠ |
| RENDER | ComputeVoxelAO |
6.886 → 6.929 (+0.6%) |
| RENDER | BakeSunShadowMap |
5.002 → 5.154 (+3.0%) |
| RENDER | LightingToTrixel |
5.192 → 4.998 (-3.7%) |
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
235.817 → 237.672 (+0.8%) |
| RENDER | ComputeSunShadow |
34.222 → 35.665 (+4.2%) |
| RENDER | ComputeLightVolume |
23.624 → 24.525 (+3.8%) |
| RENDER | LightingToTrixel |
18.734 → 19.189 (+2.4%) |
| RENDER | CanvasToFramebuffer |
14.799 → 14.642 (-1.1%) |
| RENDER | BakeSunShadowMap |
8.113 → 8.060 (-0.7%) |
| UPDATE | FogRevealEval |
7.265 → 7.397 (+1.8%) |
| UPDATE | PropagateTransform |
4.769 → 4.746 (-0.5%) |
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
1101.999 → 1102.722 (+0.1%) |
| RENDER | ComputeSunShadow |
34.622 → 34.600 (-0.1%) |
| RENDER | ComputeLightVolume |
24.498 → 25.288 (+3.2%) |
| RENDER | CanvasToFramebuffer |
13.496 → 13.612 (+0.9%) |
| UPDATE | FogRevealEval |
7.735 → 7.453 (-3.6%) |
| RENDER | ComputeVoxelAO |
5.662 → 5.871 (+3.7%) |
| RENDER | BakeSunShadowMap |
5.175 → 5.272 (+1.9%) |
| UPDATE | PropagateTransform |
4.747 → 4.756 (+0.2%) |
fillRect/blitRect and the mask-grid painter wrote the canvas distance texture with subImage2D directly, so a CPU upload after an empty reset left holdsQueriedContent() false and COMPUTE_SUN_SHADOW could skip a canvas that now held queried content. Both go through writeDistances, and the distance texture is private (m_textureTriangleDistances), so a direct CPU write no longer compiles: getTextureDistances() hands out a const texture, and Texture2D's CPU writers are non-const. test_render_cardinal_surface_lighting gains the census: the member is private, the accessor is const, Texture2D::subImage2D/clear take no const receiver, and no other tracked source names the member, with one mutation control per arm. test_render_canvas_shape_geometry checks the invalidate-then-clear order inside clearDistancesToEmpty, now that canvas_clear.hpp calls it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Addressed feedback:
New head: 070b033. Evidence rows 4 and 5 and the census plan departure are updated in the body. |
jakildev
left a comment
There was a problem hiding this comment.
Review — render: skip the main-canvas sun-shadow dispatch on cardinal surfaces
Verdict: approve
The amended head resolves both prior findings: every external CPU distance upload now crosses the recording mutator, and the clear-order contract test follows the extracted reset helper.
Acceptance (issue #5102)
5 of 5 met. The cost, capture parity and route-transition, parent/head render-verification, complete writer census, and required-test criteria all have credible positive-fire evidence on the amended head.
Checked
- Read the complete PR and issue thread, including the superseded plan, both correction rounds, the refuted store-only premise, the replacement premise probe, the prior review, and the author's amendment response.
- Reviewed the complete delta from
71ab22ed9977bb44933d67d24872f976ac43d292to current head070b033eaee110cb2f6df33e51edd557ab2f239f; no files changed beyond the two requested fixes and their tests/docs. python3 scripts/tests/test_render_cardinal_surface_lighting.py: 5 tests passed, including the private-member/const-accessor CPU-writer census and mutation controls.python3 scripts/tests/test_render_canvas_shape_geometry.py: 3 tests passed, including invalidate-before-device-clear andclearCanvasAndDistancesdelegation.python3 scripts/shader_parity_audit.py: clean, 171 GLSL and 158 Metal files, 5 allowlisted.- Current GitHub checks completed green where concluded;
linux-build,render-harness-tests,perf-gate,fleet-tests, andall-checkswere still pending or in progress when reviewed and are unread, not green.
🤖 Reviewed by Codex GPT-5 (opus-class; review-pr skill)
Opus recheck not required (reviewed at opus class).
Perf gateHead host slug: perf comparison: c03fe48 → 08aff6d-cibaseline: host calibration
thresholds: regress ≥ 10%, improve ≥ 5% voxel cull effectiveness
frame timing (ms)
GPU frame timing (ms; separate from stage samples)
GPU stage timing (avg ms per sampled invocation)
top CPU systems by avg ms (head)
|
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
298.046 → 298.701 (+0.2%) |
| RENDER | ComputeLightVolume |
35.887 → 34.906 (-2.7%) |
| RENDER | ComputeSunShadow |
19.925 → 19.409 (-2.6%) |
| RENDER | CanvasToFramebuffer |
18.227 → 17.809 (-2.3%) |
| RENDER | BakeSunShadowMap |
10.420 → 10.034 (-3.7%) |
| UPDATE | FogRevealEval |
6.578 → 6.721 (+2.2%) |
| UPDATE | PropagateTransform |
4.948 → 5.056 (+2.2%) |
| RENDER | ComputeVoxelAO |
4.434 → 4.392 (-0.9%) |
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
992.838 → 987.179 (-0.6%) |
| RENDER | ComputeSunShadow |
40.580 → 39.667 (-2.2%) |
| RENDER | ComputeLightVolume |
32.529 → 31.054 (-4.5%) |
| RENDER | CanvasToFramebuffer |
17.101 → 16.210 (-5.2%) ↓ |
| RENDER | ComputeVoxelAO |
11.089 → 10.933 (-1.4%) |
| RENDER | LightingToTrixel |
9.445 → 9.089 (-3.8%) |
| RENDER | BakeSunShadowMap |
8.988 → 8.642 (-3.8%) |
| UPDATE | FogRevealEval |
6.633 → 6.496 (-2.1%) |
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
346.948 → 342.429 (-1.3%) |
| RENDER | ComputeSunShadow |
67.001 → 65.961 (-1.6%) |
| RENDER | LightingToTrixel |
38.626 → 37.344 (-3.3%) |
| RENDER | ComputeLightVolume |
35.479 → 33.596 (-5.3%) ↓ |
| RENDER | BakeSunShadowMap |
23.074 → 22.822 (-1.1%) |
| RENDER | CanvasToFramebuffer |
18.942 → 18.050 (-4.7%) |
| RENDER | FogToTrixel |
7.359 → 7.186 (-2.4%) |
| UPDATE | PropagateTransform |
6.053 → 6.362 (+5.1%) |
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
1504.717 → 1503.493 (-0.1%) |
| RENDER | ComputeSunShadow |
53.380 → 54.373 (+1.9%) |
| RENDER | ComputeLightVolume |
33.333 → 33.817 (+1.5%) |
| RENDER | CanvasToFramebuffer |
16.508 → 16.488 (-0.1%) |
| RENDER | BakeSunShadowMap |
9.077 → 8.996 (-0.9%) |
| RENDER | ComputeVoxelAO |
8.784 → 8.870 (+1.0%) |
| RENDER | LightingToTrixel |
7.400 → 7.609 (+2.8%) |
| UPDATE | PropagateTransform |
6.169 → 6.405 (+3.8%) |
|
Cross-host smoke OK on windows (fresh checkout + IRShapeDebug --auto-screenshot 10 — build clean, exit 0, no log warnings). |
Summary
On a cardinal surface-lit frame,
COMPUTE_SUN_SHADOWnow skips the main-canvas grid dispatch when every occupied texel is a cardinal voxel surface. Lighting never samples the shadow texture there.C_TriangleCanvasTexturesrecords whether its distance content needs a query. Every distance writer binds through one chokepoint with a content kind, and only the device clear to the empty sentinel resets the record.m_textureTriangleDistances), so a CPU write outside the component's mutators does not compile.Screenshots
No visual change: 14 of 14 pairs identical, IRCanvasStress (
--debug-overlay shadow, plus the skip-firing fixture; published tomediaat7ab6843a7).Acceptance evidence
computeSunShadowrow absent with the skip, upper bound −94.8% (issue comment)repeat_profile.pyparent/head pairs,cardinal-zoom4-overlap8-subdiv4, Metal Debug,QUIET=guardeddocs/perf/main-canvas-sun-shadow-skip/comparison.json)commandBufferSpans1.005×IRCanvasStress,IRShapeDebugtable,--debug-overlay shadowrender-compare.py --per-pixel-tol 0--probe-floor-mode gridresumedon 4 rotatingIRPerfGrid/IRFogDemorender-verify failures--ceiling-shadow) replayed on parent and headFOG-SHADOW-PROBElines identical (see notes)fleet-rules-sweep --pattern 'TextureAccess::(WRITE_ONLY|READ_WRITE),\s*(IRRender::)?TextureFormat::R32I' …test_cpu_distance_writes_record_canvas_contentinscripts/tests/test_render_cardinal_surface_lighting.pyTexture2D::subImage2D/clearnon-const, 0 other tracked sources name the member; 4 of 4 mutation controls fire (public member, mutable accessor, const CPU writer, outside writer)python3 scripts/tests/test_render_cardinal_surface_lighting.py;python3 scripts/tests/test_render_canvas_shape_geometry.py;bash scripts/tests/run_all.sh;IrredenEngineTest --gtest_filter='CanvasBackingResizeTest.*';python3 scripts/shader_parity_audit.pyRan 5 tests … OK;Ran 3 tests … OK; 134 of 135 suites (the miss istest_render_verify_demo_args.py: 6 failures from its run mock catching the macOSdisplay_preflightprobe; subject and test are byte-identical to master); 3 of 3 passed;clean, 171 glsl and 158 metal filesIRCanvasStressnine-yaw sweeps (SDF and grid floor) and every capture run aboveReviewer notes
Plan departures
READ_ONLY(atomic writes) and stay off the chokepoint. Stage 2's bind in the same tick records the content for both, because both cover the same texels apart from off-screen shadow feeders.clearDistancesToEmpty()(deviceclearTexImage) resets the record.canvas_clear.hppandShapeOnlyCanvasClearnow call it.clear(),clearWithColor(),clearWithColorData(),clearDistances()andsetTrixel()recordQUERIEDinstead of resetting:Texture2D::clearis unreliable for R32I on Metal, andclearDistanceTexturestores 65534, which lighting reads as occupied.font_maker,trixel_rect.hpp(fillRect/blitRect) andmask_grid_painter.hppwrote the distance texture directly withsubImage2D. They now go through a newwriteDistancesmutator, which recordsQUERIED. The GPU-bind sweep cannot see a CPU write, so the member is now private and the CPU census runs as a test.CARDINAL_VOXEL_SURFACEonly whenperAxisRoute_ == 0, the canvas is not detached,residualYaw_ == 0, there is no cut-section fog and no source-face display. Any fog canvas therefore keeps its dispatch. That covers the--ceiling-shadowprobe and the lighting: fog-pass pipelines take the one sun-shadow receiver model by default (stage 2 of #4965) #5123 ordering gotcha.System<COMPUTE_SUN_SHADOW>::cardinalSurfaceLightingEligible_throughfindSystemin lighting'sbeginTick. It asserts equality only when the producer is registered.engine/prefabs/irreden/render/CLAUDE.mdis not edited. It is over its byte budget on master (21050 against 20823). The chokepoint contract lives in the component and system header comments.render-verify.pytherefore fails on shape alone for parent and head alike (21/35IRPerfGridon both). The replay keeps the manifest's arguments and warmup per run.Notes for reviewer
system_bake_sun_shadow_map.hpp:505,:759(worldPlacedResolveDepth_);system_build_distance_hiz.hpp:68(Hi-Z mip);system_resolve_per_axis_screen_depth.hpp:165(resolveDepth_);system_shapes_to_trixel.hpp:577(casterDepth);system_voxel_to_trixel.hpp:1371,:1524(per-axis stage 2 / stage 1 textures),:1756(occluder pyramid). The rest use the chokepoint:bindDistancesForWrite(stage 2, shapes ×2, both particle passes, text, GUI text batch, canvas draw),bindAsCompositeTarget(TRIXEL_TO_TRIXEL's texture-unit bind), and the CPU mutators.18a91f694against this head, in separate Debug trees. The pre-rebase set on6236f5854read the same (−95.8%, all pairs identical).fleet-pr-overlap:VERDICT: overlap. render: size per-axis stores from content height (#4960) #5101, docs: capture overflow-rejection camera ordering in docs/design/per-axis-trixel-canvas-rotation.md (#5086) #5124, render: give the per-axis list walks their own one-entry kernels #5131 and render: align sun-face culling with raster yaw (#5106) #5148 sharesystem_voxel_to_trixel.hpp, and each trial merge is clean.Closes #5102
🤖 Generated with Claude Code