GPU diagnostics: pipeline statistics per noted command with VICTORY_GPU_TIMING #1722

Open
LarryBebou wants to merge 2 commits from upstream-pr/1723 into main
LarryBebou commented 2026-11-24 21:19:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LarryBebou on 2026-11-24T21:19:09Z.


Why

VICTORY_GPU_TIMING=1 says which commands of a slow list took longest, but not what they did on the GPU. In #71 that left a question open for the slow world mesh draws: are they slow because they rasterize a huge area, or before rasterization?

What

With timing on, each noted command also gets a D3D12_QUERY_TYPE_PIPELINE_STATISTICS query: begun at its note, ended at the next note or at close, and resolved next to the timestamps. The slow-command lines then start with four of its counters:

slow list command, 98.7 ms: [primitives to the rasterizer 128, rasterized 128, pixel shader runs 48, compute runs 0] mesh 1 [mesh …, pixel …] | …
  • Diagnostics builds only, and only with VICTORY_GPU_TIMING set: without it no query heap is made and nothing is recorded.
  • One query is open at a time (stats_open), so queries never nest; reset clears it.
  • Same limit as the timestamps (STAMPS commands per list).
  • README: the VICTORY_GPU_TIMING row mentions the counters.

What it showed here (RTX 5060, driver 32.0.16.2124, ffe310e + #1349)

World mesh draws of 128 to 1,920 primitives and fewer than 1,500 pixel shader runs take about 100 ms each, so their time is not overdraw. Details in my comment on #71.

Since then, one more run with VICTORY_SHADER_LOOP_LIMIT=64 (as a measurement, not a fix): GPU time per world frame fell from seconds to about 0.2 s and the slowest mesh draw from about 100 ms to 1.2 ms, although the native code of the pair I looked at (51ff151f75cd5759 / 7fe75645c406cac6) has no backward branch. The device was still removed after 62 s, at an indirect mesh draw in a 0.57 s submission.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
  • cargo test --workspace --locked: passed
  • cargo xtask policy: passed (154 files)
  • Run on the title with VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1 on the RTX 5060: counters logged for every slow command.

Limits

  • Not run on AMD or Intel.
  • The counters of a list are lost if the device is removed while it runs, like its timestamps.
  • Mesh-shader counters (PIPELINE_STATISTICS1) are not used: the plain query works on every host.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5480513928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723). Originally posted by [LarryBebou](https://github.com/LarryBebou) on 2026-11-24T21:19:09Z. --- ## Why `VICTORY_GPU_TIMING=1` says which commands of a slow list took longest, but not what they did on the GPU. In #71 that left a question open for the slow world mesh draws: are they slow because they rasterize a huge area, or before rasterization? ## What With timing on, each noted command also gets a `D3D12_QUERY_TYPE_PIPELINE_STATISTICS` query: begun at its note, ended at the next note or at `close`, and resolved next to the timestamps. The slow-command lines then start with four of its counters: ``` slow list command, 98.7 ms: [primitives to the rasterizer 128, rasterized 128, pixel shader runs 48, compute runs 0] mesh 1 [mesh …, pixel …] | … ``` - Diagnostics builds only, and only with `VICTORY_GPU_TIMING` set: without it no query heap is made and nothing is recorded. - One query is open at a time (`stats_open`), so queries never nest; `reset` clears it. - Same limit as the timestamps (`STAMPS` commands per list). - README: the `VICTORY_GPU_TIMING` row mentions the counters. ## What it showed here (RTX 5060, driver 32.0.16.2124, `ffe310e` + #1349) World mesh draws of 128 to 1,920 primitives and fewer than 1,500 pixel shader runs take about 100 ms each, so their time is not overdraw. Details in [my comment on #71](https://github.com/Marvisak/VIctory/issues/71#issuecomment-7144548769). Since then, one more run with `VICTORY_SHADER_LOOP_LIMIT=64` (as a measurement, not a fix): GPU time per world frame fell from seconds to about 0.2 s and the slowest mesh draw from about 100 ms to 1.2 ms, although the native code of the pair I looked at (`51ff151f75cd5759` / `7fe75645c406cac6`) has no backward branch. The device was still removed after 62 s, at an indirect mesh draw in a 0.57 s submission. ## Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo test --workspace --locked`: passed - `cargo xtask policy`: passed (154 files) - Run on the title with `VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1` on the RTX 5060: counters logged for every slow command. ## Limits - Not run on AMD or Intel. - The counters of a list are lost if the device is removed while it runs, like its timestamps. - Mesh-shader counters (`PIPELINE_STATISTICS1`) are not used: the plain query works on every host.
DenRakEiw commented 2026-11-24 21:26:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T21:26:22Z.

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu — 50 passed, 0 failed (1 ignored) on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean opt-in pipeline statistics query heap and readback under VICTORY_GPU_TIMING with clear documentation in README.md. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047682206 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#pullrequestreview-6047682206). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T21:26:22Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu` — 50 passed, 0 failed (1 ignored) on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean opt-in pipeline statistics query heap and readback under `VICTORY_GPU_TIMING` with clear documentation in `README.md`. Looks good. AI-assisted (Gemini 4 Neon).
LarryBebou commented 2026-11-24 21:28:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LarryBebou on 2026-11-24T21:25:05Z.


Correction to my report above, from two more runs on the same RTX 5060 (ffe310e + #1349, diag build, VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1, with the per-command pipeline statistics of #1723).

AI-assisted (Claude Code); measured on my own machine.

What I got wrong

I wrote that the slow world mesh draws are not slow because of overdraw. That holds for the small draws I had counters for, but not for the draw I had named as the 12.7 s one: its counters were lost with the device in that run. Now measured:

Command CPrimitives PSInvocations GPU time
mesh 3 [mesh 51ff151f75cd5759, pixel 7fe75645c406cac6] 184 51,119,928 387.8 ms (with the cap below)

184 rasterized primitives give 51 million pixel shader runs: about six full 3840×2160 screens. So this draw does cover the screen many times over with a handful of primitives, which is what wrong vertex positions would look like.

Also, the per-command times are less reliable than I implied: on this card a draw seems to be charged the wait for work queued before it. I would trust the counters (primitives, shader runs) and the per-submission times, not a single command's milliseconds.

Two runs with loop caps (as measurements, not fixes)

Run Device removed Longest submission GPU time per world frame
no cap yes, after 60–100 s 12–17 s 1–15 s
VICTORY_SHADER_LOOP_LIMIT=64 (every stage) yes, after 62 s, at an indirect mesh draw (db4835a364449a45 / c10e7d95d8266d2a) in a 0.57 s submission 0.57 s about 0.2 s
cap of 64 on every stage but compute (local switch) no, in 83 s (stopped by my watchdog) 0.43 s 0.4–0.9 s

One run each, so the difference between the last two rows may be chance. What the third row does say: with compute loops left alone and only pixel/mesh/vertex loops capped, the longest submission stays under half a second here, which fits @HenriqueSBueno's result on the RTX 3080 above.

The compute 8bbcbda6008eaa37 (CSInvocations 122,944) takes 0.32–0.39 s per dispatch uncapped and is not what hangs.

What I think it points to (not shown)

Draws like the one above rasterize screen-sized primitives, and every covered pixel then runs a pixel program with data-bounded loops. A cap hides the cost; the cause to look for is why the mesh stage gets such positions (the stream that draw reads is filled by an earlier pass).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144903005 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7144903005). Originally posted by [LarryBebou](https://github.com/LarryBebou) on 2026-11-24T21:25:05Z. --- Correction to my report above, from two more runs on the same RTX 5060 (`ffe310e` + #1349, diag build, `VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1`, with the per-command pipeline statistics of #1723). *AI-assisted (Claude Code); measured on my own machine.* ## What I got wrong I wrote that the slow world mesh draws are not slow because of overdraw. That holds for the small draws I had counters for, but not for the draw I had named as the 12.7 s one: its counters were lost with the device in that run. Now measured: | Command | CPrimitives | PSInvocations | GPU time | |---|---:|---:|---:| | `mesh 3 [mesh 51ff151f75cd5759, pixel 7fe75645c406cac6]` | 184 | 51,119,928 | 387.8 ms (with the cap below) | 184 rasterized primitives give 51 million pixel shader runs: about six full 3840×2160 screens. So this draw does cover the screen many times over with a handful of primitives, which is what wrong vertex positions would look like. Also, the per-command times are less reliable than I implied: on this card a draw seems to be charged the wait for work queued before it. I would trust the counters (primitives, shader runs) and the per-submission times, not a single command's milliseconds. ## Two runs with loop caps (as measurements, not fixes) | Run | Device removed | Longest submission | GPU time per world frame | |---|---|---:|---:| | no cap | yes, after 60–100 s | 12–17 s | 1–15 s | | `VICTORY_SHADER_LOOP_LIMIT=64` (every stage) | yes, after 62 s, at an indirect mesh draw (`db4835a364449a45` / `c10e7d95d8266d2a`) in a 0.57 s submission | 0.57 s | about 0.2 s | | cap of 64 on every stage but compute (local switch) | no, in 83 s (stopped by my watchdog) | 0.43 s | 0.4–0.9 s | One run each, so the difference between the last two rows may be chance. What the third row does say: with compute loops left alone and only pixel/mesh/vertex loops capped, the longest submission stays under half a second here, which fits @HenriqueSBueno's result on the RTX 3080 above. The compute `8bbcbda6008eaa37` (CSInvocations 122,944) takes 0.32–0.39 s per dispatch uncapped and is not what hangs. ## What I think it points to (not shown) Draws like the one above rasterize screen-sized primitives, and every covered pixel then runs a pixel program with data-bounded loops. A cap hides the cost; the cause to look for is why the mesh stage gets such positions (the stream that draw reads is filled by an earlier pass).
catminou4 commented 2026-11-24 21:37:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:37:05Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Pipeline statistics per noted command: a query heap + readback buffer are created lazily (stats() -> Option), and VICTORY_GPU_TIMING gates the per-command notes. README updated to say the timing switch needs DRED for the notes. Small, well-scoped diagnostics addition. The interplay with DRED (GPU-based validation removal) is the risky part — worth a Windows run with an actual title before merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047812520 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#pullrequestreview-6047812520). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:37:05Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Pipeline statistics per noted command: a query heap + readback buffer are created lazily (stats() -> Option), and VICTORY_GPU_TIMING gates the per-command notes. README updated to say the timing switch needs DRED for the notes. Small, well-scoped diagnostics addition. The interplay with DRED (GPU-based validation removal) is the risky part — worth a Windows run with an actual title before merge.
aycow commented 2026-11-24 22:02:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T21:58:53Z.


A bounded native control held 64 authored triangles, draw shape and viewport fixed and varied only clip W. AMD pixel invocations rose from 17,664 at W=1 to 65,536 at W=.125. WARP covered the same pixels while reporting different PSInvocations and CPrimitives. CInvocations stayed at 64 for both positive-W runs. For the reported title draw, an authored primitive count and projected-bounds distribution would complement the clipping counters.

I checked compatibility with #509 at bfc60cf. The branches conflict in host.rs and README, and census mode suppresses the legacy timing path. Paired runs use #509 for pipeline identity, spans and CPU build cost, and #1723 for invocation counters, with the same scene and whole-submission timing. This keeps per-command wait attribution out of the estimate.

AI-assisted using Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145643489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7145643489). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T21:58:53Z. --- A [bounded native control](https://github.com/aycow/VIctory/blob/669987461b4f696b30c8d5df6c42ef8eb8e73562/docs/mesh-projection-overdraw-control.md) held 64 authored triangles, draw shape and viewport fixed and varied only clip W. AMD pixel invocations rose from 17,664 at W=1 to 65,536 at W=.125. WARP covered the same pixels while reporting different PSInvocations and CPrimitives. CInvocations stayed at 64 for both positive-W runs. For the reported title draw, an authored primitive count and projected-bounds distribution would complement the clipping counters. I checked compatibility with #509 at bfc60cf. The branches conflict in host.rs and README, and census mode suppresses the legacy timing path. Paired runs use #509 for pipeline identity, spans and CPU build cost, and #1723 for invocation counters, with the same scene and whole-submission timing. This keeps per-command wait attribution out of the estimate. AI-assisted using Codex.
Marvisak commented 2026-11-25 04:06:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:36:06Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in README.md). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge candidate) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152066657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7152066657). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:36:06Z. --- <!-- victory-triage v1 head=5542340831d31c486953b9cb6a8c0c326056213e verdict=needs-rebase at=2026-11-25T15:58:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `README.md`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-26 08:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T07:50:54Z.


@LarryBebou I tested 5542340 and the same fixture with the fix and regression test in c66d2f2 on codex2/pr1723-timing-stats.

WARP run Expected CSInvocations in recording order PR head, DRED off PR head, DRED on Patch, both DRED modes
First recording 16, 56, 24 0 rows 16, 56, 24 16, 56, 24
Same list after Reset 40, 8 0 rows 40, 8 40, 8

The fixture submits one list and reads the production slow-command formatter after the fence. For each label it checks the expected counter and the exact delta of the corresponding GPU timestamp pair, even when the rows are sorted by time. The final dispatch is included in both recordings, and the second report contains only its two new labels.

The fix enables queries when timing is on, keeps DRED markers conditional, and closes the final statistics query before resolving the samples. It also lets the slow-list warning run for a single submitted list. The app-local WARP diagnostics suite passed 81 tests and the timing fixture passed separately in both DRED modes. The full system WARP suite had one placed-texture test failure that passed with app-local WARP.

To rerun on Windows, set VICTORY_GPU_TIMING=1 and VICTORY_D3D12_WARP=1, then run this once with VICTORY_D3D12_DRED unset and once with it set.

cargo test --locked -p victory-gpu --features diagnostics --lib host::timing_stats_warp::timing_stats_follow_commands_through_close_and_reset -- --ignored --exact --nocapture --test-threads=1

If you fold the changes or fixture into another commit, please retain Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185900749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7185900749). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T07:50:54Z. --- @LarryBebou I tested `5542340` and the same fixture with the fix and regression test in [`c66d2f2`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/c66d2f213c0b6e1b96695f2cb5e1be9cf3c331d2) on `codex2/pr1723-timing-stats`. | WARP run | Expected `CSInvocations` in recording order | PR head, DRED off | PR head, DRED on | Patch, both DRED modes | | --- | --- | --- | --- | --- | | First recording | `16, 56, 24` | 0 rows | `16, 56, 24` | `16, 56, 24` | | Same list after `Reset` | `40, 8` | 0 rows | `40, 8` | `40, 8` | The fixture submits one list and reads the production slow-command formatter after the fence. For each label it checks the expected counter and the exact delta of the corresponding GPU timestamp pair, even when the rows are sorted by time. The final dispatch is included in both recordings, and the second report contains only its two new labels. The fix enables queries when timing is on, keeps DRED markers conditional, and closes the final statistics query before resolving the samples. It also lets the slow-list warning run for a single submitted list. The app-local WARP diagnostics suite passed 81 tests and the timing fixture passed separately in both DRED modes. The full system WARP suite had one placed-texture test failure that passed with app-local WARP. To rerun on Windows, set `VICTORY_GPU_TIMING=1` and `VICTORY_D3D12_WARP=1`, then run this once with `VICTORY_D3D12_DRED` unset and once with it set. ```sh cargo test --locked -p victory-gpu --features diagnostics --lib host::timing_stats_warp::timing_stats_follow_commands_through_close_and_reset -- --ignored --exact --nocapture --test-threads=1 ``` If you fold the changes or fixture into another commit, please retain `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted.
andrewpozdnakov7-jpg commented 2026-11-28 04:11:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T04:11:09Z.


I combined the pipeline statistics from #1723 with the peak and note coverage from #3534, #3651 and #3661 in 9f64e98. The integration keeps statistics in the slow-command rows, so the aggregate command and pipeline keys stay intact. A command list resolves at most 4,095 intervals and keeps a separate count of the omitted notes.

On app-local WARP 1.0.22 with Agility 1.620.2, a generated dispatch through ExecuteIndirect reported 56 compute shader invocations between direct dispatches with 16 and 24. After a list reset, the new dispatches reported 40 and 8. At 4,097 notes, the list reported 4,095 intervals and two omitted notes. The last measured dispatch had 32 invocations, including when the first omitted interval contained another dispatch. The normal multi-list aggregate kept the expected pipeline key, peak and omission count. Both DRED settings passed, as did strict GPU Clippy and the asset policy.

This is an integration branch for testing. LarryBebou or a maintainer can pick up the resolution. The separate hardware timing check remains in #3590.

Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding this resolution into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7233781570 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7233781570). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T04:11:09Z. --- I combined the pipeline statistics from **#1723** with the peak and note coverage from #3534, #3651 and #3661 in [9f64e98](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/9f64e984d08065a28a59b14816092e502af570b0). The integration keeps statistics in the slow-command rows, so the aggregate command and pipeline keys stay intact. A command list resolves at most 4,095 intervals and keeps a separate count of the omitted notes. On app-local WARP 1.0.22 with Agility 1.620.2, a generated dispatch through `ExecuteIndirect` reported 56 compute shader invocations between direct dispatches with 16 and 24. After a list reset, the new dispatches reported 40 and 8. At 4,097 notes, the list reported 4,095 intervals and two omitted notes. The last measured dispatch had 32 invocations, including when the first omitted interval contained another dispatch. The normal multi-list aggregate kept the expected pipeline key, peak and omission count. Both DRED settings passed, as did strict GPU Clippy and the asset policy. This is an integration branch for testing. LarryBebou or a maintainer can pick up the resolution. The separate hardware timing check remains in #3590. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding this resolution into another commit. AI-assisted with OpenAI Codex.
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/1723:upstream-pr/1723'
git switch 'upstream-pr/1723'

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/1723'
git switch 'upstream-pr/1723'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1723'
git switch 'upstream-pr/1723'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1723'
git switch 'main'
git merge --squash 'upstream-pr/1723'
git switch 'main'
git merge --ff-only 'upstream-pr/1723'
git switch 'main'
git merge 'upstream-pr/1723'
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
Marvisak/VIctory!1722
No description provided.