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

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

@⁠LarryBebou on GitHub · 2026-11-24 21:19 UTC · original
LarryBebou:diag/timing-pipeline-statistics → main · +118 −2 · 2 files · 2 commits · open

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.
**@⁠LarryBebou** on GitHub · 2026-11-24 21:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723) `LarryBebou:diag/timing-pipeline-statistics` → `main` · +118 −2 · 2 files · 2 commits · open ## 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://git.gtahub.st/github/Marvisak--VIctory/issues/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.
With timing on, each noted command also gets a pipeline-statistics query
(begun at its note, ended at the next one or at close, resolved with the
timestamps). The slow-command lines then say how many primitives reached
the rasterizer, how many were rasterized and how often the pixel and
compute shaders ran, so a slow draw can be told from one that rasterizes
a large area.

On an RTX 5060 this showed world mesh draws of 128 to 1,920 primitives
and fewer than 1,500 pixel shader runs taking about 100 ms each (#71).
Two conflicts, both kept from each side: the README row for
VICTORY_GPU_TIMING (the counters, and main's device-removal sentence),
and HostList::reset (the open statistics query, and main's targets).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:42:46 +00:00
Author
Owner

@⁠LarryBebou on GitHub · 2026-11-24 21:25 UTC · original

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).

**@⁠LarryBebou** on GitHub · 2026-11-24 21:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7144903005) 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).
Author
Owner

@⁠aycow on GitHub · 2026-11-24 21:58 UTC · original

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.

**@⁠aycow** on GitHub · 2026-11-24 21:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7145643489) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 15:55 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7152066657) · edited 2026-11-25 15:55 UTC <!-- 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)_
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-24 21:26 UTC · original · approved these changes

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).

**@⁠DenRakEiw** on GitHub · 2026-11-24 21:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#pullrequestreview-6047682206) · **approved these changes** 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 21:37 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-24 21:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#pullrequestreview-6047812520) · **reviewed** 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.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 07:50 UTC · original

@⁠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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 07:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1723#issuecomment-7185900749) @⁠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.
This pull request has changes conflicting with the target branch.
  • README.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1723'
git switch 'github-bot/gh-1723'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1723'
git switch 'github-bot/gh-1723'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1723'
git switch 'main'
git merge --squash 'github-bot/gh-1723'
git switch 'main'
git merge --ff-only 'github-bot/gh-1723'
git switch 'main'
git merge 'github-bot/gh-1723'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1723
No description provided.