metal: VICTORY_PASS_TIMING — per-pass GPU timing at each encoder boundary (#460 step 1) #598

Open
github-bot wants to merge 1 commit from github-bot/gh-594 into main AGit
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 11:04 UTC · original
AnastasisKon:vibe/pass-timing-55a8d1 → main · +463 −17 · 6 files · 1 commits · open

What this changes

Refs #464 (step 1 only; step 2 record/replay stays open). Adds VICTORY_PASS_TIMING=1 (or =<n>): per-pass GPU time on the native Metal path. An MTLCounterSampleBuffer of the timestamp counter set is sampled at each pass encoder's start and end, resolved when the command buffer completes, and at each present the frame's n most expensive passes (10 for =1) are logged most-expensive-first by pipeline (shader hash) and work (draws / thread groups / blit ops), then the frame total (pass time frame=<f> ... lines).

Implementation notes:

  • New module crates/victory-metal/src/pass_timing.rs; sampling hooks in gfx.rs's submit path (one sample buffer per command buffer, one per piece of a split submission) and in both completion handlers; the frame boundary is each present in present.rs.
  • Only encoder kinds the device reports as sampling at their own boundary are sampled (AtDispatchBoundary / AtDrawBoundary / AtBlitBoundary): Metal asserts (SIGABRT) on sampleCountersInBuffer for an unsupported kind, and support differs per GPU family — an AGXG15X (this Mac) samples dispatch and draw boundaries but not blit. Passes of an unsampled kind get no label, keeping sample indices aligned with labels.
  • A render pass with indirect draws starts its sample pair on its gate compute encoder when compute boundaries are sampled, so the gate's time is inside the pass's.
  • Pipeline names are now kept without VICTORY_TRACE_GPU_FAILS so the log can name passes by shader hash.
  • Off by default; documented in docs/native-host.md under "Bring-up diagnostics".

How it was tested

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (host arm64, run with -- --test-threads=1 per #552): 708 passed, 0 failed
  • cargo test -p victory-metal -- --test-threads=1: 85 passed, 0 failed, including the new pass_timing::tests::each_pass_of_a_command_buffer_is_sampled_and_a_frame_reports_them — a synthetic two-pass command buffer (blit fills, or a zero-draw render pass when the device samples no blit boundary, as here) yields one resolved sample per pass, with sane durations
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean
  • cargo xtask policy: clean
  • Ran the game: not needed for this change — the switch is off by default and touches no game data; the unit test exercises the sampling/resolve path on a real device

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented behaviour are marked: per-GPU-family sampling support is noted in the module doc and docs/native-host.md (G15X: no blit boundary)
  • The new diagnostic is behind VICTORY_PASS_TIMING, off by default, and documented in docs/native-host.md
**@⁠AnastasisKon** on GitHub · 2026-11-28 11:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/594) `AnastasisKon:vibe/pass-timing-55a8d1` → `main` · +463 −17 · 6 files · 1 commits · open ## What this changes Refs #464 (step 1 only; step 2 record/replay stays open). Adds `VICTORY_PASS_TIMING=1` (or `=<n>`): per-pass GPU time on the native Metal path. An `MTLCounterSampleBuffer` of the timestamp counter set is sampled at each pass encoder's start and end, resolved when the command buffer completes, and at each present the frame's `n` most expensive passes (10 for `=1`) are logged most-expensive-first by pipeline (shader hash) and work (draws / thread groups / blit ops), then the frame total (`pass time frame=<f> ...` lines). Implementation notes: - New module `crates/victory-metal/src/pass_timing.rs`; sampling hooks in `gfx.rs`'s submit path (one sample buffer per command buffer, one per piece of a split submission) and in both completion handlers; the frame boundary is each present in `present.rs`. - Only encoder kinds the device reports as sampling at their own boundary are sampled (`AtDispatchBoundary` / `AtDrawBoundary` / `AtBlitBoundary`): Metal asserts (SIGABRT) on `sampleCountersInBuffer` for an unsupported kind, and support differs per GPU family — an AGXG15X (this Mac) samples dispatch and draw boundaries but not blit. Passes of an unsampled kind get no label, keeping sample indices aligned with labels. - A render pass with indirect draws starts its sample pair on its gate compute encoder when compute boundaries are sampled, so the gate's time is inside the pass's. - Pipeline names are now kept without `VICTORY_TRACE_GPU_FAILS` so the log can name passes by shader hash. - Off by default; documented in `docs/native-host.md` under "Bring-up diagnostics". ## How it was tested - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (host arm64, run with `-- --test-threads=1` per #552): 708 passed, 0 failed - [x] `cargo test -p victory-metal -- --test-threads=1`: 85 passed, 0 failed, including the new `pass_timing::tests::each_pass_of_a_command_buffer_is_sampled_and_a_frame_reports_them` — a synthetic two-pass command buffer (blit fills, or a zero-draw render pass when the device samples no blit boundary, as here) yields one resolved sample per pass, with sane durations - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: clean - [x] `cargo xtask policy`: clean - [ ] Ran the game: not needed for this change — the switch is off by default and touches no game data; the unit test exercises the sampling/resolve path on a real device ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented behaviour are marked: per-GPU-family sampling support is noted in the module doc and `docs/native-host.md` (G15X: no blit boundary) - [x] The new diagnostic is behind `VICTORY_PASS_TIMING`, off by default, and documented in `docs/native-host.md`
The whole command buffer's GPUEndTime - GPUStartTime cannot tell a slow pass
in a world frame from the others. With VICTORY_PASS_TIMING=1 (or =<n>), an
MTLCounterSampleBuffer of the timestamp counter set is sampled at each pass
encoder's start and end (stage-boundary sampling), resolved when the command
buffer completes, and at each present the frame's n most expensive passes
(10 for =1) are logged most-expensive-first by pipeline (shader hash) and work
(draws, thread groups, blit ops), then the frame total.

Only encoder kinds the device reports as sampling at their own boundary are
sampled (dispatch/draw/blit): Metal asserts on sampleCountersInBuffer for an
unsupported kind, and support differs per GPU family (a G15X samples dispatch
and draw boundaries, not blit). A render pass with indirect draws starts its
sample pair on its gate encoder when compute boundaries are sampled, so the
gate's time is inside the pass's. Split submissions (VICTORY_PASSES_PER_BUFFER)
get one sample buffer per piece. Passes whose kind is not sampled are not
labelled, keeping sample indices aligned with labels.

Off by default; needs a device with the timestamp counter set. New module
pass_timing.rs; sampling hooks in gfx.rs's submit path and completion
handlers; frame boundary at each present in present.rs; pipeline names are
now kept without VICTORY_TRACE_GPU_FAILS so the log can name them. Documented
in docs/native-host.md. Test: a synthetic two-pass command buffer (blit fills
or a zero-draw render pass, whichever the device samples) yields one resolved
sample per pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 11:18:37 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/598/head:github-bot/gh-594'
git switch 'github-bot/gh-594'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'main'
git merge --squash 'github-bot/gh-594'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'main'
git merge 'github-bot/gh-594'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.