Repository navigation
Conversation
Metal stage rows were first-encoder-start to last-encoder-end windows that overlap other stages' work, so they summed to about twice the frame's GPU time and ranked the wrong stages. Each encoder of a stage now samples its own start/end pair in the stage's one (larger) counter buffer, and the union of those intervals is the stage's exclusive time. Encoders past the capacity make that invocation window-only; encoders the GPU never ran are skipped. The profile report's cost column is exclusive time, with the window, a window-only count, a format marker and an exclusive-sum line against commandBufferSpans. scripts/perf reads exclusive rows, still parses old reports as windows, and drops stage marks across formats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakildev
left a comment
There was a problem hiding this comment.
Review — perf: report exclusive gpu stage time beside the stage window
Verdict: approve
Stacked on #5018 (cross-author). Reviewing the child diff only — upstream is approved separately.
The implementation consistently carries the new exclusive/window distinction from Metal counter sampling through RenderDevice, the timing ring, live stage values, accumulated report rows, and the Python report readers. The interval resolver is conservative at both failure boundaries: incomplete or invalid pairs discard the invocation, while capacity overflow produces a window-only sample that cannot enter cost statistics. The OpenGL compatibility adapter preserves the old pair semantics in both columns.
Praise
resolveGpuEncoderIntervalsisolates the interval-union and stale-sample rules into a pure, well-covered surface instead of embedding them in the Metal readback path.- Window-only invocations remain visible without contaminating live timing values, exclusive averages, or downstream stage rankings.
- Mixed old/new report comparisons deliberately suppress regression marks, avoiding comparisons between window and exclusive measurements.
Acceptance (issue #4948)
| Criterion | Grade | Evidence |
|---|---|---|
| 1. Phase 0 reading posted | Met | The issue thread contains the required per-encoder interval table before the report-format change. |
| 2. Million controls | Met | Six guarded, clean runs stay within 15% of commandBufferSpans; computeLightVolume remains at or below 1.0 ms at both poses. |
| 3. Positive control | Met | perAxisScatter drops 6.839 ms against a 7.752 ms span drop, within the 1.163 ms tolerance; all other rows stay within their stated bounds. |
| 4. 64-cubed control | Met | Three clean runs report lightingOverflow at 0.100–0.101 ms with 1.952–2.052 ms windows. |
| 5. C++ tests | Met | Reviewer build succeeded and all 37 filtered interval, profile-report, and timestamp tests passed, including capacity overflow/window-only coverage. |
| 6. Parser tests and lint | Met | Reviewer run: 24 parser tests passed; PR CI reports python-lint green. Cases cover new, old, mixed, and window-only formats. |
| 7. Render regression | Met with inherited failures documented | IRCanvasStress passes. The reported IRShapeDebug failures match the same-session merge-base control row for row and are tracked by #4904. |
8. perf-gate.yml green |
Blocked by inherited CI failure | The current run fails at link time on libjack.so requiring __cxa_call_terminate@CXXABI_1.3.15, exactly the hosted-runner baseline failure tracked in #5023 and called out by the epic steward. This is not attributable to this diff. |
| 9. Documentation | Met | The cost model, registry comment, and perf README describe exclusive time, windows, window-only rows, and old-report compatibility. |
Validation
fleet-build --detach --target IrredenEngineTest— succeeded (fleet-jobs: 20261111T214139Z-build-eadbbe succeeded exit=0).fleet-run IrredenEngineTest --gtest_filter='GpuEncoderIntervals.*:ProfileReport*:GpuTimestamp*'— 37 tests passed.python3 scripts/perf/test_profile_parser.py— 24 tests passed.- At review time
linux-build,render-harness-tests, andfleet-testswere still pending and therefore unread, not green. The completed formatting, header, Python, comment-reference, instruction-size, closes, whitespace, and plan-file checks were green.
🤖 Reviewed by Codex GPT-5 (opus-class; review-pr skill)
Opus recheck not required (reviewed at opus class).
Summary
MTL::CounterSampleBuffer, grown to 128 start/end pairs. Every compute, blit and render encoder writes its own pair. The new pureresolveGpuEncoderIntervals(engine/render/include/irreden/render/gpu_encoder_intervals.hpp) reports the length of the union of those intervals as exclusive time, and earliest start to latest end as the window. Encoders beyond the capacity share the last pair, so that invocation is window-only. A pair with no sample newer than the previous invocation is an encoder the GPU never ran, and is skipped. A pair with one zero, stale, error or reversed sample discards the whole invocation, as before.RenderDevice::pollTimestampSamplereturns both figures (GpuTimestampSample). By default it wrapspollTimestampPairMs, so OpenGL writes its pair in both columns unchanged.GpuTimestampRing, the observer and the sub-stage scopes pass the sample through.GpuStageAccumulatorkeeps exclusive statistics at top level and the window inwindow_. The liveGpuStageTimingfields (overlay, Lua pass timing) carry exclusive time only.Window(ms)andWindowOnlycolumns sit beside it, aFormat: exclusive+windowmarker identifies the layout, and a row whose every invocation was window-only prints-andwindow-only. AnExclusive sum: … ms; commandBufferSpans: … ms (…%)line sits under the table.scripts/perf/reads the exclusive figure and still reads old reports.parse_reportkeepsgpu_stages[*].avg_msas the stage cost and addswindow_ms,window_only,gpu_stage_format(exclusive+windoworwindow) andgpu_exclusive_sum_ms. Window-only rows go togpu_window_only_stages, out ofgpu_stages.compare_perf_runs.pyprints the stage deltas of a cell whose reports differ in format without marks.repeat_profile.pyandprofile_matrix.pylabel old-format rows(window), andrepeat_profile.pysummarizes the exclusive sum.docs/design/gpu-stage-timing-cost-model.md§1 and reading rule 1, the registry comment ingpu_stage_timing.hpp, and ascripts/perf/README.mdsection describe both figures.Test plan
fleet-build --target IrredenEngineTest, thenfleet-run IrredenEngineTest --gtest_filter='GpuEncoderIntervals.*:ProfileReport*:GpuTimestamp*'→[ PASSED ] 37 tests.python3 scripts/perf/test_profile_parser.py→Ran 24 tests … OK. Every otherscripts/perf/test_*.pyandscripts/perf/tests/*.pysuite also passes.ruff check scripts/→All checks passed!fleet-build --release --target IRPerfGrid, then the acceptance runs below (M4 Max, Metal, Release, AC power, fleet live).python3 scripts/lint_comment_refs.py→ok. Thecmake/run_header_checks_standalone.cmakegate passes.fleet-build --target format-changedwas applied.python3 scripts/render-verify.py --target IRCanvasStress→all 59 checks PASS. That demo turns stage timing on, so it exercises the new sampling.python3 scripts/render-verify.py --target IRShapeDebug(stage timing off) →19 of 148 checks FAIL (10 skipped — references pending). A same-session master control atd5f23eb3f(separate worktree, ownmacos-debugbuild) reports the same 19 rows; all 149 result rows match line for line, metrics included.Acceptance evidence
computeLightVolumeunion: 0.445 ms (45°) and 0.73–1.02 ms (yaw 0, 30-frame windows); 0.86 / 0.92 ms over 150-frame windows.perAxisCellCompact+computeVoxelAoPerAxisunion: 0.122 ms at 45°QUIET=guarded: the exclusive sum is within 15% of the meancommandBufferSpansat both poses;computeLightVolumeexclusive ≤ 1.0 ms at bothpython3 scripts/perf/million_controls.py --tree build-release --rounds 3 --output /tmp/pool2-acc/million; each report read withparse_reportQUIET=guarded,RESULT=CLEAN. yaw 0: sum/span 19.578/18.412 (106.3%), 20.542/19.340 (106.2%), 19.719/18.543 (106.3%);computeLightVolume0.763 / 0.934 / 0.853 ms (windows 17.15 / 17.79 / 17.15). 45°: 29.912/29.989 (99.7%), 34.345/34.614 (99.2%), 32.754/33.155 (98.8%);computeLightVolume0.677 / 0.695 / 0.484 ms (windows 9.14 / 10.28 / 9.84). No window-only rows. Met--render-env IR_PERAXIS_OVERFLOW_DISABLE=1, five interleaved pairs: the drop in exclusiveperAxisScatterequals thecommandBufferSpansdrop within max(0.5 ms, 15%) and is ≥ 3 ms; every other exclusive row moves by no more than its five-run arm-A spread, floor 0.15 msrepeat_profile.py --release --repeats 1 [--render-env IR_PERAXIS_OVERFLOW_DISABLE=1] -- --wave-freeze --no-overlay --pivot-origin --auto-profile 300 --config-preset configs/perf/million.lua --yaw 0.785398163, A then B, ×5QUIET=guarded,RESULT=CLEAN. Span A 31.036 → B 23.283 ms (drop 7.752).perAxisScatterA 7.294 → B 0.455 ms (drop 6.839). |6.839 − 7.752| = 0.914 ≤ 1.163, and 6.839 ≥ 3. Every other row is within its bound; the largest moves arevoxelPerAxisOverflow0.423 (bound 1.526),voxelPerAxisStore0.109 (0.227),voxelPerAxisFinalize0.078 (0.240),computeLightVolume0.019 (0.150). MetlightingOverflow≤ 0.3 ms with its window still reportedrepeat_profile.py --release --repeats 3 -- --auto-profile 300 --grid-size 64 --zoom 4 --yaw 0.785398163 --wave-freeze --no-overlay --pivot-originRESULT=CLEAN.lightingOverflowexclusive 0.100 / 0.101 / 0.101 ms (299 samples each); windows 1.952 / 1.991 / 2.052 ms. Exclusive sum 8.95–8.98 against spans of 9.07–9.15 ms. Met--gtest_filter='<interval suite>.*'and'ProfileReport*'pass, including a stage over its sample capacity reading window-onlyfleet-run IrredenEngineTest --gtest_filter='GpuEncoderIntervals.*:ProfileReport*:GpuTimestamp*'[ PASSED ] 37 tests.These includeGpuEncoderIntervals.MoreEncodersThanCapacityReadsWindowOnly,…DisjointIntervalsSumTheirLengths,…NestedIntervalCountsOnce,…OverlappingIntervalsMergeInAnyOrder,ProfileReportGpuStages.RowsCarryExclusiveTimeAndTheWindowBesideIt(window-only row and sum line) andGpuTimestampPollTest.WindowOnlyInvocationFeedsTheWindowButNotTheCost. Mettest_profile_parser.pypasses with new-format, old-format and mixed-comparison cases;ruff check scripts/is cleanpython3 scripts/perf/test_profile_parser.py;ruff check scripts/Ran 24 tests … OK. The newExclusiveStageFormatTestcases:test_new_format_reads_exclusive_as_the_cost_and_keeps_the_window,test_old_format_still_parses_and_is_identified_as_windows,test_comparing_across_formats_prints_deltas_without_marks, plus window-only, within-format-marks and writer-literal locks.All checks passed!Metrender-verify.py --target IRShapeDebugand--target IRCanvasStresspass with no reference changepython3 scripts/render-verify.py --target IRShapeDebug;… --target IRCanvasStress[render-verify] all 59 checks PASS, no reference change. IRShapeDebug (stage timing off):19 of 148 checks FAIL (10 skipped — references pending). A same-session master control at the merge based5f23eb3f(fresh worktree andmacos-debugbuild,render-verify.py --target IRShapeDebug --no-build --build-dir <control>/build) gives the identical summary. All 149 PASS/FAIL rows, match percentages and max deltas are equal between head and control (diffof the sorted result rows: 0 lines). The 19 failing yaw180/yaw270 rows (max_delta 109–120 > 64) and 10 missing references are the stale macOS reference set tracked by open #4904. No reference changed. Metperf-gate.ymlis green on the PRperf-gate.ymlon this PR (hosted runner, OpenGL build, parses the new report)scripts/perf/README.mddescribe both figuresgit diff origin/master -- docs/design/gpu-stage-timing-cost-model.md engine/prefabs/irreden/render/gpu_stage_timing.hpp scripts/perf/README.mdPlan departures
fleet-pr-overlapblocked on conflicts inmetal_render_impl.cppandtest/CMakeLists.txt, so this branch is rebased ontoclaude/4947-metal-pacer-late-frame; both conflicts were additive. The acceptance runs above were taken on the pre-rebase headfd9a993ce(based5f23eb3f); render/metal: stop the offscreen frame pacer sleeping after a late frame #5018 changes only the offscreen pacer's CPU sleep. After the rebase, the 43-test filtered suite (pacer tests included) andtest_profile_parser.pypass. A spot check of the rebased head: the million yaw-0 run isRESULT=CLEAN, exclusive sum 19.339 / span 18.261 (105.9%),computeLightVolume0.723 ms. Two 45° runs wereQUIET=breachfrom fleet load (101.1% and 101.1%,computeLightVolume0.525 / 0.484 ms); they are not counted as evidence.voxelPerAxisOverflowencoders never write a sample. A pair with no fresh sample is therefore skipped as an encoder the GPU never ran, instead of discarding the invocation. The Gotcha "a zero, reversed or stale sample is discarded, never recorded as 0 ms" still holds for any pair with exactly one such sample, and for an invocation with no executed encoder.voxelPerAxisOverflow) creates 72 encoders; the next largest creates 28. All 24 stage handles still allocate their buffers.QUIET=breach(fleet activity), so pair 1 was rerun as a fresh A-then-B pair after pairs 2–5. Interleaving within each pair is preserved.Notes for reviewer
fleet-pr-overlap --base claude/4947-metal-pacer-late-frame→VERDICT: overlap. Rows: render: configure LOD zoom thresholds and hysteresis per camera #4921 / editor: add upright spatial orbit and cursor-anchored zoom #4940 / editor: add shape erasing and live Shift roll #4944test/CMakeLists.txtclean; render/metal: stop the offscreen frame pacer sleeping after a late frame #5018metal_render_impl.cpp,scripts/perf/README.md,test/CMakeLists.txtupstream (the stack parent); render: show sun record loss under pool pressure varies frame to frame #5025scripts/perf/README.mdclean (separate sections).computeLightVolumemargin under criterion 2 is thin (0.76–0.93 ms against 1.0). One early encoder of that stage runs alongsidevoxelStage1, and its interval stretches from about 0.5 to 1.6 ms frame to frame; the union counts it. This is also why the yaw-0 exclusive sum reads 106% rather than 100%: two stages sharing the GPU both count the shared time. The phase 0 comment has the per-encoder detail.pollTimestampPairMsstays on the device interface; Metal's returns exclusive time, or the window for a window-only invocation, for any out-of-tree caller.Closes #4948
🤖 Generated with Claude Code