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

Open
AnastasisKon wants to merge 2 commits from upstream-pr/602 into main
AnastasisKon commented 2026-11-28 11:45:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T11:45:05Z.


What this changes

Refs #600. Stacks on PR #594 (branch vibe/pass-timing-55a8d1); once #594 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 #594 pass-mode test
  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (host arm64, serialized per #548): 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
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5539781340 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/602). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T11:45:05Z. --- ## What this changes Refs #600. Stacks on PR #594 (branch `vibe/pass-timing-55a8d1`); once #594 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 #594 pass-mode test - [x] `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (host arm64, serialized per #548): 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`
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/602:upstream-pr/602'
git switch 'upstream-pr/602'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/602'
git switch 'upstream-pr/602'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/602'
git switch 'upstream-pr/602'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/602'
git switch 'main'
git merge --squash 'upstream-pr/602'
git switch 'main'
git merge --ff-only 'upstream-pr/602'
git switch 'main'
git merge 'upstream-pr/602'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!602
No description provided.