Skip to content

perf: report exclusive gpu stage time beside the stage window - #5030

Merged
jakildev merged 1 commit into
claude/4947-metal-pacer-late-framefrom
claude/4948-exclusive-gpu-stage-time
Nov 12, 2026
Merged

jakildev merged 1 commit into
claude/4947-metal-pacer-late-framefrom
claude/4948-exclusive-gpu-stage-time

Conversation

@jakildev

Copy link
Copy Markdown
Owner

Summary

  • Metal samples every encoder of a stage separately. Each stage keeps its one MTL::CounterSampleBuffer, grown to 128 start/end pairs. Every compute, blit and render encoder writes its own pair. The new pure resolveGpuEncoderIntervals (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::pollTimestampSample returns both figures (GpuTimestampSample). By default it wraps pollTimestampPairMs, so OpenGL writes its pair in both columns unchanged. GpuTimestampRing, the observer and the sub-stage scopes pass the sample through. GpuStageAccumulator keeps exclusive statistics at top level and the window in window_. The live GpuStageTiming fields (overlay, Lua pass timing) carry exclusive time only.
  • The profile report's stage cost column is exclusive. Window(ms) and WindowOnly columns sit beside it, a Format: exclusive+window marker identifies the layout, and a row whose every invocation was window-only prints - and window-only. An Exclusive sum: … ms; commandBufferSpans: … ms (…%) line sits under the table.
  • scripts/perf/ reads the exclusive figure and still reads old reports. parse_report keeps gpu_stages[*].avg_ms as the stage cost and adds window_ms, window_only, gpu_stage_format (exclusive+window or window) and gpu_exclusive_sum_ms. Window-only rows go to gpu_window_only_stages, out of gpu_stages. compare_perf_runs.py prints the stage deltas of a cell whose reports differ in format without marks. repeat_profile.py and profile_matrix.py label old-format rows (window), and repeat_profile.py summarizes the exclusive sum.
  • Docs: docs/design/gpu-stage-timing-cost-model.md §1 and reading rule 1, the registry comment in gpu_stage_timing.hpp, and a scripts/perf/README.md section describe both figures.

Test plan

  • fleet-build --target IrredenEngineTest, then fleet-run IrredenEngineTest --gtest_filter='GpuEncoderIntervals.*:ProfileReport*:GpuTimestamp*' → [ PASSED ] 37 tests.
  • python3 scripts/perf/test_profile_parser.py → Ran 24 tests … OK. Every other scripts/perf/test_*.py and scripts/perf/tests/*.py suite 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. The cmake/run_header_checks_standalone.cmake gate passes. fleet-build --target format-changed was 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 at d5f23eb3f (separate worktree, own macos-debug build) reports the same 19 rows; all 149 result rows match line for line, metrics included.

Acceptance evidence

Criterion Check run Observed
1. The phase 0 table is posted on the issue Per-encoder intervals logged by a local build at million 45° and yaw 0 (log removed before commit) Posted at #4948 (comment). Premise holds. computeLightVolume union: 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 + computeVoxelAoPerAxis union: 0.122 ms at 45°
2. Million control, Release, stage profiling on, yaw 0 and 45°, 3 interleaved rounds, QUIET=guarded: the exclusive sum is within 15% of the mean commandBufferSpans at both poses; computeLightVolume exclusive ≤ 1.0 ms at both python3 scripts/perf/million_controls.py --tree build-release --rounds 3 --output /tmp/pool2-acc/million; each report read with parse_report Every run QUIET=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%); computeLightVolume 0.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%); computeLightVolume 0.677 / 0.695 / 0.484 ms (windows 9.14 / 10.28 / 9.84). No window-only rows. Met
3. Positive control: million 45°, default against --render-env IR_PERAXIS_OVERFLOW_DISABLE=1, five interleaved pairs: the drop in exclusive perAxisScatter equals the commandBufferSpans drop 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 ms repeat_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, ×5 All 10 runs QUIET=guarded, RESULT=CLEAN. Span A 31.036 → B 23.283 ms (drop 7.752). perAxisScatter A 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 are voxelPerAxisOverflow 0.423 (bound 1.526), voxelPerAxisStore 0.109 (0.227), voxelPerAxisFinalize 0.078 (0.240), computeLightVolume 0.019 (0.150). Met
4. 64³ 45° cell, three runs: exclusive lightingOverflow ≤ 0.3 ms with its window still reported repeat_profile.py --release --repeats 3 -- --auto-profile 300 --grid-size 64 --zoom 4 --yaw 0.785398163 --wave-freeze --no-overlay --pivot-origin All 3 runs RESULT=CLEAN. lightingOverflow exclusive 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
5. --gtest_filter='<interval suite>.*' and 'ProfileReport*' pass, including a stage over its sample capacity reading window-only fleet-run IrredenEngineTest --gtest_filter='GpuEncoderIntervals.*:ProfileReport*:GpuTimestamp*' [ PASSED ] 37 tests. These include GpuEncoderIntervals.MoreEncodersThanCapacityReadsWindowOnly, …DisjointIntervalsSumTheirLengths, …NestedIntervalCountsOnce, …OverlappingIntervalsMergeInAnyOrder, ProfileReportGpuStages.RowsCarryExclusiveTimeAndTheWindowBesideIt (window-only row and sum line) and GpuTimestampPollTest.WindowOnlyInvocationFeedsTheWindowButNotTheCost. Met
6. test_profile_parser.py passes with new-format, old-format and mixed-comparison cases; ruff check scripts/ is clean python3 scripts/perf/test_profile_parser.py; ruff check scripts/ Ran 24 tests … OK. The new ExclusiveStageFormatTest cases: 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! Met
7. render-verify.py --target IRShapeDebug and --target IRCanvasStress pass with no reference change python3 scripts/render-verify.py --target IRShapeDebug; … --target IRCanvasStress IRCanvasStress (stage timing on): [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 base d5f23eb3f (fresh worktree and macos-debug build, 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 (diff of 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. Met
8. perf-gate.yml is green on the PR perf-gate.yml on this PR (hosted runner, OpenGL build, parses the new report) Pending: the workflow runs once this PR opens. It is not run by the author; the reviewer grades it from the PR's checks
9. The cost-model document, the registry comment and scripts/perf/README.md describe both figures git diff origin/master -- docs/design/gpu-stage-timing-cost-model.md engine/prefabs/irreden/render/gpu_stage_timing.hpp scripts/perf/README.md §1 has a new "Each row reports two figures" bullet and a rewritten Metal sampling bullet. Reading rule 1 says to rank by the exclusive column. The registry comment gains a "Every row carries two figures" paragraph. The README has a new "Read GPU stage rows as exclusive time" section. Met

Plan departures

  • Stacked on render/metal: stop the offscreen frame pacer sleeping after a late frame #5018 (render/metal: stop the offscreen frame pacer sleeping after a late frame #4947, an approved epic sibling). fleet-pr-overlap blocked on conflicts in metal_render_impl.cpp and test/CMakeLists.txt, so this branch is rebased onto claude/4947-metal-pacer-late-frame; both conflicts were additive. The acceptance runs above were taken on the pre-rebase head fd9a993ce (base d5f23eb3f); 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) and test_profile_parser.py pass. A spot check of the rebased head: the million yaw-0 run is RESULT=CLEAN, exclusive sum 19.339 / span 18.261 (105.9%), computeLightVolume 0.723 ms. Two 45° runs were QUIET=breach from fleet load (101.1% and 101.1%, computeLightVolume 0.525 / 0.484 ms); they are not counted as evidence.
  • Window semantics. The plan's window was first-encoder start to last-encoder end in creation order. With every encoder sampled, the window is the earliest sampled start to the latest sampled end, so it no longer depends on the GPU running encoders in creation order.
  • Unexecuted encoders (found in phase 0). Three voxelPerAxisOverflow encoders 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.
  • Capacity (the plan's implementer's call): 128 pairs. The largest stage at the million 45° control (voxelPerAxisOverflow) creates 72 encoders; the next largest creates 28. All 24 stage handles still allocate their buffers.
  • Positive-control pair 1. The first run of arm B was 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

Closes #4948

🤖 Generated with Claude Code

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 jakildev added fleet:wip Work in progress — not ready for review fleet:author-claude Implementation last authored by Claude; route review to Codex labels Nov 11, 2026
@jakildev
jakildev added this pull request to stack #5031 November 11, 2026 21:37
@jakildev jakildev added fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend and removed fleet:wip Work in progress — not ready for review labels Nov 11, 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 — 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

  • resolveGpuEncoderIntervals isolates 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, and fleet-tests were 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: report exclusive GPU stage time in the profile report

1 participant