Shader counters: VICTORY_SHADER_COUNTERS=<hash> counts what named programs do per draw and dispatch (diagnostics builds) #4939

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

@⁠bentsignal on GitHub · 2026-12-01 14:45 UTC · original
bentsignal:diag-shader-counters → main · +1422 −5 · 12 files · 1 commits · open

What it changes

The card meter and the timing runs say how long a program takes, not what it does in that time: whether its loops run away, how many lanes stop at a loop's limit, how much title memory it reads by address and whether those pages had a copy. This adds counters to the programs one names, and leaves every other program as it is.

  • VICTORY_SHADER_COUNTERS=<hash>[,<hash>...] (the 16-digit hashes the logs name programs by; diagnostics builds only). Those programs alone are translated with counters (victory_shader::emit::tally, a raw root UAV at u249, a register no other root view of ours takes, so nothing is shared with SLOT_SAMPLED at u251 or the others at 250-255). The shader cache keys the counted translations apart; every other program's translation is byte for byte as before (a test checks the same program translates to the same bytes without the switch).
  • What a counted program adds up, per host lane, summed over each wave by a wave operation and added by its first lane (one atomic a wave):
    • lanes that began, ended, and were stopped at a loop's iteration limit;
    • per loop (numbered by its header's place in the program): header runs (iterations), entries, the longest entry, entries cut at the loop's limit, and entries of 2^k iterations or more;
    • ray-tracing node tests by kind (boxes, triangles, other) and those of nodes in pages without a copy (read as zeros);
    • accesses to title memory by address, and the directory looks among them by what held the page: no copy, a title buffer's copy or an arena, on the card or in PC memory.
  • Host side (crates/victory-gpu/src/host/counters.rs): each draw, dispatch, mesh dispatch and indirect execution of a named program gets a block of 18 KiB of the list's own, cleared before the command and copied back after it in the same list (three barriers), and read when the list is reset after its last submission has run, as the timing stamps are: nothing waits for the card. Every VICTORY_SHADER_COUNTERS_EVERY s (10; 0 = every frame) one line per program, target victory_gpu::host::counters: a frame's average and the window's heaviest command.
  • Unset (and in release builds), nothing changes: no translation differs, the hooks in draw.rs and HostList::reset are compiled only with diagnostics and are one cached load each. The counted programs themselves run slower (a wave operation and an atomic at each loop header, node test and access by address).
  • What it does not see: commands past 32 of one list, a list let go without a run, commands no lane began, and indirect executions joined with ones before them count as one.
  • README: both switches in "Logs and diagnostics".

How it was tested

  • GPU and profile: RTX 5070 Ti (16 GB), Ryzen 9 9900X; Series X, 2560x1440, DLSS Quality, frame generation off, ray tracing at bench.ps1's default (on). Diagnostics build of this branch (e29c1c1d, on 5fabb46e), the open-world save standing at the player's house, started with scripts\bench.ps1; numbers from the run's log (every frame from the frame log, 30-150 s after the first frame line with 3,000+ draws).
  • With VICTORY_SHADER_COUNTERS=f22a76fcb967ee59,6d7fe7745ab9c6d8 (two of the title's ray-tracing compute programs), one line per program every 10 s. A real excerpt (the heaviest command's part of the second line cut):
INFO victory_gpu::host::counters: shader counters [compute 6d7fe7745ab9c6d8]: 2.8 commands a frame; a frame: lanes 8.8 k (ended 8.8 k, stopped at a loop's limit 0.0); loop 0: 155.2 iterations, 0.02 a lane, 1.00 an entry, the longest 1, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; loop 7: 34.2 k iterations, 3.91 a lane, 1.03 an entry, the longest 2, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; accesses by address 15.8 k, looks 15.8 k (100.0%): no copy 0.00%, title buffers on the card 49.5%, in PC memory 0.0%, arenas on the card 0.0%, in PC memory 50.5%; the heaviest command: lanes 14.0 k (ended 14.0 k, stopped at a loop's limit 0.0); loop 7: 55.1 k iterations, 3.95 a lane, 1.02 an entry, the longest 2, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; accesses by address 25.9 k, looks 25.9 k (100.0%): no copy 0.00%, title buffers on the card 50.0%, in PC memory 0.0%, arenas on the card 0.0%, in PC memory 50.0% uncounted=0
INFO victory_gpu::host::counters: shader counters [compute f22a76fcb967ee59]: 0.8 commands a frame; a frame: lanes 43.1 k (ended 43.1 k, stopped at a loop's limit 0.0); loop 0: 47.2 k iterations, 1.09 a lane, 1.11 an entry, the longest 5, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; loop 1: 513.6 iterations, 0.01 a lane, 1.00 an entry, the longest 1, ...; accesses by address 44.5 k, looks 44.5 k (100.0%): no copy 0.00%, title buffers on the card 94.7%, in PC memory 4.1%, arenas on the card 0.0%, in PC memory 1.2%; the heaviest command: lanes 117.8 k ...

(In this build neither program runs long loops or reads pages without a copy. On our fork in November the first one's far-trace loop ran 330-360 iterations a lane, many of them over nodes read as zeros: that is what the counters were made to find.) In that run (another view of the house: 8,900 draws a frame against 6,400 in the runs below, so not comparable) the frames came at 25.0 fps.

  • Cost with the switch off (same scene and settings, back to back; one run each, so within run-to-run noise only):
build, run order fps median ms p95 p99 frames over 50 ms over 100 ms draws a frame (median)
main (5fabb46e), 1st 27.3 35.4 48.3 85.6 138 8 6420
this branch, switch unset, 4th 27.6 35.1 48.3 83.8 132 3 6422
main, 6th (last) 26.9 36.3 50.0 86.8 164 6 6439

About 3,300-3,400 frames each (120 s). The two main runs, first and last of the six, differ by as much as any branch does from them: no cost is seen.

  • cargo test -p victory-shader --lib -- tally: 2 passed (new: the counters are only in a counted translation and the plain one is unchanged; a loop of known counts per lane, one lane cut at the limit, run on WARP and every counter checked, validated by dxil.dll when present).
  • cargo test -p victory-gpu --lib --features diagnostics -- counters:: shader_cache::: 14 passed (2 new: the switch's parsing, a block read as the shader wrote it).
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings, with and without --features victory-gpu/diagnostics: nothing in the files this touches. The 5 errors left are on main already (host/font.rs 213 and 260, host/menu.rs 667, host/panel.rs 602 and 668).
  • cargo build --locked --release -p victory and --profile diag --features diagnostics: both build.
  • Wave sizes: the host runs 32-lane waves here (VICTORY_HOST_WAVE=32); the WARP test is a wave32 program. Not tested with 64-lane host waves, nor on AMD.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches (shader counters, loop iterations, per-dispatch instrumentation). Related: none found. VICTORY_SHADER_LOOP_LIMIT (main) changes the limit; this counts what reaches it.

This change and its testing were done with an AI assistant (Claude Code), and the results were checked on my machine.

🤖 Generated with Claude Code

**@⁠bentsignal** on GitHub · 2026-12-01 14:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4938) `bentsignal:diag-shader-counters` → `main` · +1422 −5 · 12 files · 1 commits · open ## What it changes The card meter and the timing runs say how long a program takes, not what it does in that time: whether its loops run away, how many lanes stop at a loop's limit, how much title memory it reads by address and whether those pages had a copy. This adds counters to the programs one names, and leaves every other program as it is. - `VICTORY_SHADER_COUNTERS=<hash>[,<hash>...]` (the 16-digit hashes the logs name programs by; diagnostics builds only). Those programs alone are translated with counters (`victory_shader::emit::tally`, a raw root UAV at **u249**, a register no other root view of ours takes, so nothing is shared with `SLOT_SAMPLED` at u251 or the others at 250-255). The shader cache keys the counted translations apart; every other program's translation is byte for byte as before (a test checks the same program translates to the same bytes without the switch). - What a counted program adds up, per host lane, summed over each wave by a wave operation and added by its first lane (one atomic a wave): - lanes that began, ended, and were stopped at a loop's iteration limit; - per loop (numbered by its header's place in the program): header runs (iterations), entries, the longest entry, entries cut at the loop's limit, and entries of 2^k iterations or more; - ray-tracing node tests by kind (boxes, triangles, other) and those of nodes in pages without a copy (read as zeros); - accesses to title memory by address, and the directory looks among them by what held the page: no copy, a title buffer's copy or an arena, on the card or in PC memory. - Host side (`crates/victory-gpu/src/host/counters.rs`): each draw, dispatch, mesh dispatch and indirect execution of a named program gets a block of 18 KiB of the list's own, cleared before the command and copied back after it in the same list (three barriers), and read when the list is reset after its last submission has run, as the timing stamps are: nothing waits for the card. Every `VICTORY_SHADER_COUNTERS_EVERY` s (10; `0` = every frame) one line per program, target `victory_gpu::host::counters`: a frame's average and the window's heaviest command. - Unset (and in release builds), nothing changes: no translation differs, the hooks in `draw.rs` and `HostList::reset` are compiled only with `diagnostics` and are one cached load each. The counted programs themselves run slower (a wave operation and an atomic at each loop header, node test and access by address). - What it does not see: commands past 32 of one list, a list let go without a run, commands no lane began, and indirect executions joined with ones before them count as one. - README: both switches in "Logs and diagnostics". ## How it was tested - GPU and profile: RTX 5070 Ti (16 GB), Ryzen 9 9900X; Series X, 2560x1440, DLSS Quality, frame generation off, ray tracing at bench.ps1's default (on). Diagnostics build of this branch (`e29c1c1d`, on `5fabb46e`), the open-world save standing at the player's house, started with `scripts\bench.ps1`; numbers from the run's log (every frame from the frame log, 30-150 s after the first frame line with 3,000+ draws). - With `VICTORY_SHADER_COUNTERS=f22a76fcb967ee59,6d7fe7745ab9c6d8` (two of the title's ray-tracing compute programs), one line per program every 10 s. A real excerpt (the heaviest command's part of the second line cut): ``` INFO victory_gpu::host::counters: shader counters [compute 6d7fe7745ab9c6d8]: 2.8 commands a frame; a frame: lanes 8.8 k (ended 8.8 k, stopped at a loop's limit 0.0); loop 0: 155.2 iterations, 0.02 a lane, 1.00 an entry, the longest 1, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; loop 7: 34.2 k iterations, 3.91 a lane, 1.03 an entry, the longest 2, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; accesses by address 15.8 k, looks 15.8 k (100.0%): no copy 0.00%, title buffers on the card 49.5%, in PC memory 0.0%, arenas on the card 0.0%, in PC memory 50.5%; the heaviest command: lanes 14.0 k (ended 14.0 k, stopped at a loop's limit 0.0); loop 7: 55.1 k iterations, 3.95 a lane, 1.02 an entry, the longest 2, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; accesses by address 25.9 k, looks 25.9 k (100.0%): no copy 0.00%, title buffers on the card 50.0%, in PC memory 0.0%, arenas on the card 0.0%, in PC memory 50.0% uncounted=0 INFO victory_gpu::host::counters: shader counters [compute f22a76fcb967ee59]: 0.8 commands a frame; a frame: lanes 43.1 k (ended 43.1 k, stopped at a loop's limit 0.0); loop 0: 47.2 k iterations, 1.09 a lane, 1.11 an entry, the longest 5, at the limit 0.0, of 64+ 0.0, 256+ 0.0, 1024+ 0.0; loop 1: 513.6 iterations, 0.01 a lane, 1.00 an entry, the longest 1, ...; accesses by address 44.5 k, looks 44.5 k (100.0%): no copy 0.00%, title buffers on the card 94.7%, in PC memory 4.1%, arenas on the card 0.0%, in PC memory 1.2%; the heaviest command: lanes 117.8 k ... ``` (In this build neither program runs long loops or reads pages without a copy. On our fork in November the first one's far-trace loop ran 330-360 iterations a lane, many of them over nodes read as zeros: that is what the counters were made to find.) In that run (another view of the house: 8,900 draws a frame against 6,400 in the runs below, so not comparable) the frames came at 25.0 fps. - Cost with the switch off (same scene and settings, back to back; one run each, so within run-to-run noise only): | build, run order | fps | median ms | p95 | p99 | frames over 50 ms | over 100 ms | draws a frame (median) | |---|---|---|---|---|---|---|---| | `main` (`5fabb46e`), 1st | 27.3 | 35.4 | 48.3 | 85.6 | 138 | 8 | 6420 | | this branch, switch unset, 4th | 27.6 | 35.1 | 48.3 | 83.8 | 132 | 3 | 6422 | | `main`, 6th (last) | 26.9 | 36.3 | 50.0 | 86.8 | 164 | 6 | 6439 | About 3,300-3,400 frames each (120 s). The two `main` runs, first and last of the six, differ by as much as any branch does from them: no cost is seen. - `cargo test -p victory-shader --lib -- tally`: 2 passed (new: the counters are only in a counted translation and the plain one is unchanged; a loop of known counts per lane, one lane cut at the limit, run on WARP and every counter checked, validated by `dxil.dll` when present). - `cargo test -p victory-gpu --lib --features diagnostics -- counters:: shader_cache::`: 14 passed (2 new: the switch's parsing, a block read as the shader wrote it). - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`, with and without `--features victory-gpu/diagnostics`: nothing in the files this touches. The 5 errors left are on `main` already (`host/font.rs` 213 and 260, `host/menu.rs` 667, `host/panel.rs` 602 and 668). - `cargo build --locked --release -p victory` and `--profile diag --features diagnostics`: both build. - Wave sizes: the host runs 32-lane waves here (`VICTORY_HOST_WAVE=32`); the WARP test is a wave32 program. Not tested with 64-lane host waves, nor on AMD. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches (shader counters, loop iterations, per-dispatch instrumentation). Related: none found. `VICTORY_SHADER_LOOP_LIMIT` (main) changes the limit; this counts what reaches it. This change and its testing were done with an AI assistant (Claude Code), and the results were checked on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The named programs (by the 16-digit hash the logs give) are translated with
counters (victory_shader::emit::tally, a root UAV at u249, a register no
other root view of ours takes): lanes started, ended and stopped at a loop's
limit; per loop its header runs, entries, longest entry, entries cut at the
loop's iteration limit and entries of 2^k+ iterations; ray-tracing node
tests by kind and those of nodes in pages without a copy; accesses by
address and directory looks by the copy that held the page. Wave sums are
added by one lane a wave. The shader cache keys counted translations apart;
every other program is byte for byte as before.

Each draw, dispatch and indirect execution of a named program gets a block
of the list's own, cleared before it and copied back after it in the same
list, read when the list is reset after its last run (no waits). Every
VICTORY_SHADER_COUNTERS_EVERY s (default 10, 0 = each frame) a line per
program (target victory_gpu::host::counters): a frame's average and the
window's heaviest command. WARP tests: a loop of known counts and the limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:50:54 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/4939/head:github-bot/gh-4938'
git switch 'github-bot/gh-4938'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4938'
git switch 'github-bot/gh-4938'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4938'
git switch 'github-bot/gh-4938'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4938'
git switch 'main'
git merge --squash 'github-bot/gh-4938'
git switch 'main'
git merge --ff-only 'github-bot/gh-4938'
git switch 'main'
git merge 'github-bot/gh-4938'
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/trustno1-coder--VIctory-NVIDIA!4939
No description provided.