GPU diagnostics: count copy-back waits by fill caller and write declarations by binding #136

Open
SamuelHaleDev wants to merge 1 commit from upstream-pr/136 into main
SamuelHaleDev commented 2026-11-27 17:40:26 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by SamuelHaleDev on 2026-11-27T17:40:26Z.


Hardware

  • GPU: AMD Radeon RX 6650 XT, 8 GB (driver 32.0.21045.5002)
  • CPU: AMD Ryzen 5 5600X3D
  • RAM: 32 GB
  • OS: Windows 11 Pro
  • Profile: victory-play.exe --1080p-to-1440p, no --rt, retail Series X image, shader cache warmed

Problem statement

In the opening interior scene, about 400 ms of each 520–650 ms frame is the CPU waiting for the card. The settle line said "title memory read by a fill of upload memory", but couldn't tell which caller's fills, or which declared writes they overlapped.

Solution

Diagnostics only, with no behaviour change. Three counters that answer that question from an ordinary run.

What changed

  • host.rs
    • Fill carries a FillBy tag: texture copy, root CBV, dynamic CBV slot, or other.
    • Settles caused by a fill are also counted per caller (FILL_SETTLES), printed as "settles for a fill of upload memory per frame, by caller".
    • defer_fill is replaced by defer_fill_by, so every caller names itself.
  • shadow.rs: Shadow::gpu_writes becomes gpu_writes_by with a Declarer tag (root UAV, table buffer UAV, page-directory ranges, page-directory pages). Per frame and per binding it prints declared ranges, bytes, and ranges of 64 MiB or more (DECLARED): "shader write ranges declared per frame, by binding".
  • host/card_steps_probe.rs: with VICTORY_CARD_STEPS_PROBE=1, sampled blocked fills also log the declared write spans they met and the host copy each lies in: "blocked upload fill, the declared writes it met".
  • Call sites tagged: list.rs, draw.rs, memory.rs, and a test in host.rs / resource.rs.

Design decisions

  • Tags at the call sites, not inferred later.
    • Trade-off: a few call sites change their signature.
    • Why: a caller can't be recovered from a merged written span afterwards. Removing defer_fill and gpu_writes makes every future caller name itself instead of silently counting as "other".
  • Counts, not per-event logs, for the always-on lines.
    • Trade-off: they say how much, not which shader.
    • Why: thousands of declarations per frame. An atomic add each is cheap; a log line each is not.
  • The span detail stays behind the existing probe switch, sampled.
    • Trade-off: you only see some of the blocked fills.
    • Why: same sampling and gating as the probe already uses.
  • No pipeline or shader identity.
    • Trade-off: the counters can't name which shaders bind the big views.
    • Why: Flight/Declared carry none, and adding it is new plumbing better left to a separate change.

Baseline

Before these counters, the settle line only showed totals. Minute 3–4, still camera at a window:

  • waiting for the card in settles: ~750 ms/frame
  • synchronous submission or present: ~358 ms
  • title memory read: ~392 ms, of which "a fill of upload memory" was 1–2 settles per frame

After change

The same scene and window, read from the new lines:

Question Answer
Which caller's fills settle? Dynamic CBV slots (defer_table_constant): 1.0–2.0 per frame. Texture copy, root CBV and other: 0.
What did they overlap? Each sampled blocked fill was 480 bytes. It met a declared write span covering the whole 0xAE00000-byte (174 MB) host copy.
Who declares that span? Table buffer UAVs: ~7,900 ranges per frame, ~542 of 64 MiB or more. Root UAVs and the page directory: 0.

What it means: the game binds near-whole-heap UAV views of a 174 MB heap that also holds its constants. Any CPU read of those constants therefore waits on every flight in the air. The declaration matches the views; it isn't a runtime over-estimate.

What I tried: pointing aligned table CBVs at the shadow, as root_view does. It rendered correctly, but only ~7% of slots are 256-byte aligned. Total waiting didn't change (467 → 465 ms per frame), so it isn't included.

What would fix it: this points at the GPU-side written-page mask that Shadow::gpu_writes already notes as a shortcut.

Tests:

  • cargo test -p victory-gpu --features diagnostics passes (239 passed, 4 ignored).
  • One run hit the known WARP decommit race in inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset (see #80). Three reruns passed.
  • Release builds with and without diagnostics build cleanly.
  • cargo xtask policy passes.

Notes

  • AI-assisted (Claude Code). The runs and observations are mine, on the hardware above.
  • No game data, frames or logs are included. The numbers are the runtime's own counters.
  • Independent of #135; based on main.

🤖 Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5530806622 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/136). Originally posted by [SamuelHaleDev](https://github.com/SamuelHaleDev) on 2026-11-27T17:40:26Z. --- ## Hardware - GPU: AMD Radeon RX 6650 XT, 8 GB (driver 32.0.21045.5002) - CPU: AMD Ryzen 5 5600X3D - RAM: 32 GB - OS: Windows 11 Pro - Profile: `victory-play.exe --1080p-to-1440p`, no `--rt`, retail Series X image, shader cache warmed ## Problem statement In the opening interior scene, about 400 ms of each 520–650 ms frame is the CPU waiting for the card. The settle line said "title memory read by a fill of upload memory", but couldn't tell which caller's fills, or which declared writes they overlapped. ## Solution Diagnostics only, with no behaviour change. Three counters that answer that question from an ordinary run. ## What changed - **`host.rs`** - `Fill` carries a `FillBy` tag: texture copy, root CBV, dynamic CBV slot, or other. - Settles caused by a fill are also counted per caller (`FILL_SETTLES`), printed as "settles for a fill of upload memory per frame, by caller". - `defer_fill` is replaced by `defer_fill_by`, so every caller names itself. - **`shadow.rs`**: `Shadow::gpu_writes` becomes `gpu_writes_by` with a `Declarer` tag (root UAV, table buffer UAV, page-directory ranges, page-directory pages). Per frame and per binding it prints declared ranges, bytes, and ranges of 64 MiB or more (`DECLARED`): "shader write ranges declared per frame, by binding". - **`host/card_steps_probe.rs`**: with `VICTORY_CARD_STEPS_PROBE=1`, sampled blocked fills also log the declared write spans they met and the host copy each lies in: "blocked upload fill, the declared writes it met". - **Call sites tagged:** `list.rs`, `draw.rs`, `memory.rs`, and a test in `host.rs` / `resource.rs`. ## Design decisions - **Tags at the call sites, not inferred later.** - Trade-off: a few call sites change their signature. - Why: a caller can't be recovered from a merged `written` span afterwards. Removing `defer_fill` and `gpu_writes` makes every future caller name itself instead of silently counting as "other". - **Counts, not per-event logs, for the always-on lines.** - Trade-off: they say how much, not which shader. - Why: thousands of declarations per frame. An atomic add each is cheap; a log line each is not. - **The span detail stays behind the existing probe switch, sampled.** - Trade-off: you only see some of the blocked fills. - Why: same sampling and gating as the probe already uses. - **No pipeline or shader identity.** - Trade-off: the counters can't name which shaders bind the big views. - Why: `Flight`/`Declared` carry none, and adding it is new plumbing better left to a separate change. ## Baseline Before these counters, the settle line only showed totals. Minute 3–4, still camera at a window: - waiting for the card in settles: ~750 ms/frame - synchronous submission or present: ~358 ms - title memory read: ~392 ms, of which "a fill of upload memory" was 1–2 settles per frame ## After change The same scene and window, read from the new lines: | Question | Answer | | --- | --- | | Which caller's fills settle? | Dynamic CBV slots (`defer_table_constant`): 1.0–2.0 per frame. Texture copy, root CBV and other: 0. | | What did they overlap? | Each sampled blocked fill was 480 bytes. It met a declared write span covering the whole 0xAE00000-byte (174 MB) host copy. | | Who declares that span? | Table buffer UAVs: ~7,900 ranges per frame, ~542 of 64 MiB or more. Root UAVs and the page directory: 0. | **What it means:** the game binds near-whole-heap UAV views of a 174 MB heap that also holds its constants. Any CPU read of those constants therefore waits on every flight in the air. The declaration matches the views; it isn't a runtime over-estimate. **What I tried:** pointing aligned table CBVs at the shadow, as `root_view` does. It rendered correctly, but only ~7% of slots are 256-byte aligned. Total waiting didn't change (467 → 465 ms per frame), so it isn't included. **What would fix it:** this points at the GPU-side written-page mask that `Shadow::gpu_writes` already notes as a shortcut. **Tests:** - `cargo test -p victory-gpu --features diagnostics` passes (239 passed, 4 ignored). - One run hit the known WARP decommit race in `inplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset` (see #80). Three reruns passed. - Release builds with and without `diagnostics` build cleanly. - `cargo xtask policy` passes. ## Notes - AI-assisted (Claude Code). The runs and observations are mine, on the hardware above. - No game data, frames or logs are included. The numbers are the runtime's own counters. - Independent of #135; based on `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/136:upstream-pr/136'
git switch 'upstream-pr/136'

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