metal: VICTORY_PASS_TIMING=draw — per-draw/per-dispatch GPU timing (#600, stacks on #594) #606

Open
github-bot wants to merge 2 commits from github-bot/gh-602 into main AGit
Owner

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

What this changes

Refs #604. Stacks on PR #598 (branch vibe/pass-timing-55a8d1); once #598 merges, this PR's diff narrows to just this change. Adds a draw mode to VICTORY_PASS_TIMING: =draw (or =draw,<n>) samples at each draw/dispatch boundary inside a render/compute pass (one sample per draw between the pass's start and end samples), and each logged pass then names its 3 slowest draws as pass time draw frame=<f> rank=<r> kind=.. pipe=.. draw=<j> ms=<ms>. Blit passes get no mid samples. The per-command-buffer sample buffer is sized for the submission's passes plus their draws/dispatches/ops (also across VICTORY_PASSES_PER_BUFFER pieces).

One finding baked into the gate: the switch is enabled by the per-boundary supportsCounterSampling points (draw/dispatch/blit), not AtStageBoundary. Probed on this Mac (AGXG15X, M4 Pro): AtStageBoundary=true but sampleCountersInBuffer:atSampleIndex:withBarrier: asserts on compute, render and blit encoders (SIGABRT) — so on that GPU family the switch stays off and the tests skip. On GPUs reporting draw/dispatch/blit support it is on. Documented in docs/native-host.md.

How it was tested

  • cargo test -p victory-metal -- --test-threads=1: 85+ tests pass, including metal::tests::draw_mode_samples_each_dispatch_inside_a_pass (two dispatches of the test compute shader in one pass → one pass sample with two per-dispatch intervals; skips cleanly on this Mac's GPU, which rejects counter sampling) and the #598 pass-mode test
  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (host arm64, serialized per #552): 709 passed, 0 failed
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean; host clippy on victory-metal adds no new warnings
  • cargo xtask policy: clean
  • Ran the game: not possible yet — the game download on the external drive is still incomplete (no game_*master.exe); a watcher runs the headless VICTORY_PASS_TIMING=draw measurement as soon as it lands

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • The GPU-family sampling-support finding is marked in the module doc and docs/native-host.md
  • Off by default behind VICTORY_PASS_TIMING, documented in docs/native-host.md
**@⁠AnastasisKon** on GitHub · 2026-11-28 11:45 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/602) `AnastasisKon:vibe/pass-timing-draw-55a8d1` → `main` · +625 −17 · 6 files · 2 commits · open ## What this changes Refs #604. Stacks on PR #598 (branch `vibe/pass-timing-55a8d1`); once #598 merges, this PR's diff narrows to just this change. Adds a `draw` mode to `VICTORY_PASS_TIMING`: `=draw` (or `=draw,<n>`) samples at each draw/dispatch boundary inside a render/compute pass (one sample per draw between the pass's start and end samples), and each logged pass then names its 3 slowest draws as `pass time draw frame=<f> rank=<r> kind=.. pipe=.. draw=<j> ms=<ms>`. Blit passes get no mid samples. The per-command-buffer sample buffer is sized for the submission's passes plus their draws/dispatches/ops (also across `VICTORY_PASSES_PER_BUFFER` pieces). One finding baked into the gate: the switch is enabled by the per-boundary `supportsCounterSampling` points (draw/dispatch/blit), **not** `AtStageBoundary`. Probed on this Mac (AGXG15X, M4 Pro): `AtStageBoundary=true` but `sampleCountersInBuffer:atSampleIndex:withBarrier:` asserts on compute, render *and* blit encoders (SIGABRT) — so on that GPU family the switch stays off and the tests skip. On GPUs reporting draw/dispatch/blit support it is on. Documented in `docs/native-host.md`. ## How it was tested - [x] `cargo test -p victory-metal -- --test-threads=1`: 85+ tests pass, including `metal::tests::draw_mode_samples_each_dispatch_inside_a_pass` (two dispatches of the test compute shader in one pass → one pass sample with two per-dispatch intervals; skips cleanly on this Mac's GPU, which rejects counter sampling) and the #598 pass-mode test - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (host arm64, serialized per #552): 709 passed, 0 failed - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings`: clean; host clippy on victory-metal adds no new warnings - [x] `cargo xtask policy`: clean - [ ] Ran the game: not possible yet — the game download on the external drive is still incomplete (no `game_*master.exe`); a watcher runs the headless `VICTORY_PASS_TIMING=draw` measurement as soon as it lands ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] The GPU-family sampling-support finding is marked in the module doc and `docs/native-host.md` - [x] Off by default behind `VICTORY_PASS_TIMING`, 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.
A finer mode of #460's switch: =draw (or =draw,<n>) also samples at each
draw/dispatch boundary inside a render/compute pass (one sample per
draw, between the pass's start and end samples), and each logged pass then
names its 3 slowest draws (pass time draw ... draw=<j> ms=<ms>). Blit
passes get no mid samples (no draw boundary). The sample buffer is sized
for the submission's passes plus their draws/dispatches/ops.

The sampling gate stays on the per-boundary supportsCounterSampling points
(draw/dispatch/blit), not AtStageBoundary: an AGXG15X (M4 Pro) reports the
stage boundary yet every encoder asserts on sampleCountersInBuffer
(SIGABRT), so on that GPU family the switch stays off and the tests skip.
Documented in docs/native-host.md. Test: draw_mode_samples_each_dispatch_inside_a_pass
(two dispatches of the test compute shader in one pass yield one pass
sample with two per-dispatch intervals).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 11:46:02 +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/606/head:github-bot/gh-602'
git switch 'github-bot/gh-602'

Merge

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