A frame chain: line per frame, and refreshed bytes by backing (VICTORY_BACKING_STATS=1) #4377

Closed
IRennie74 wants to merge 12 commits from upstream-pr/4377 into main
IRennie74 commented 2026-11-30 19:26:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-11-30T19:26:32Z.


Fixes #

What it changes

Two diagnostics, both compiled only into diagnostics builds; release builds are unchanged.

frame chain: (crates/victory-gpu/src/chain.rs): one line per frame, written three presents later when the card and the relay are done with it, of the frame's way from the title's calls to the card and back to what the title is told. Times are milliseconds since the title's present of the frame before:

  • the title's submit calls (first, last, how many), its present call and how long it stood at the line's gate (queue::behind::present), and when it began the next frame (frame::wait);
  • our submitting thread: first and last job of the frame, busy time and job count, time standing with the line empty and at a head not free to go, and when the present was sent;
  • the card: how many flights ran and when the relay saw the first and last done;
  • what the title was told (fence values, bottom-of-pipe writes): first, last, how many, and the longest any came after the relay took its flight.

It is on in diagnostics builds; VICTORY_FRAME_CHAIN=0 turns it off. The hooks are an atomic stamp or two each (queue.rs, queue/behind.rs, frame.rs, and the relay's landing and flight sends in host.rs); chain::on() is false in release builds, so they cost a branch there.

Why: on a 5600X with an RTX 3060 nothing looked saturated by itself in the sampling profile, yet the frame was about 56 ms. The frame was a chain of stages with too little overlap, and every saving on one stage was taken up by another. The timeline shows that chain for three frames; this line shows it for every frame of a benchmark run. Reconstructed from the profile, the logs and the timeline, the chain was:

  • what the title waits on of ours is the present gate (11-17 ms a frame), nothing else measurable: no title wait over 50 us in the timeline was ended by the relay or the card, and fence values and bottom-of-pipe writes reach it 0.03 ms a frame after their landing;
  • the gate waits for our submitting thread, which is busy 44-54 ms of a 55-58 ms frame. It stood about 5 ms a frame with the line empty and 6 ms at a head not free to go; the card is idle 14-21 ms a frame, all of it while that thread was preparing;
  • VICTORY_SUBMIT_FRAMES=2 took the gate's 11-17 ms to 0.0, but the submitting thread's work grew by about as much (refreshes 11-16 -> 13-19 ms), so the critical path is that thread, not the gate.

Refreshed bytes by backing (crates/victory-gpu/src/backing.rs, VICTORY_BACKING_STATS=1): every 10 s beside the frame-rate line, the bytes refreshes copy and the bytes copies in the card's memory send up, split by what backs them on the host (a view of a page-pool section from the views' book; xmem's private allocations; other private memory; other mapped memory; the image; free or reserved, found with a cached VirtualQuery), the allocations behind them by size class, which allocations hold 90% of the bytes, and how often each was freed or, for a section, had views made (its remaps). Hooks: shadow.rs (refresh and card-dirty sends), watch.rs (allocations and frees), inplace.rs (section gone, view made, and a view_shares lookup). Off unless asked: thousands of refreshes a frame each take two locks there.

Why: reading title memory in place on the card ("one memory") has two openings on native D3D12, and which fits depends on where the hot bytes live: a page-pool section can be opened whole as one heap and addressed by section offset, while private memory opens by address and is then pinned until the heap goes. This says which allocations those bytes are in.

Left out on purpose: VICTORY_TELL_EARLY (from the same source commit) was never measured, so it is not in this pull request.

How it was tested

  • GPU and profile: RTX 3060 12 GB, Ryzen 5 5600X, 32 GB, Series S, 960x540 internal, DLSS Performance, frame generation off, ray tracing default. Diagnostics builds, standing at the opening.

  • Before: no per-frame view of the chain; the submitting thread's busy time was known only as a frame average.

  • After, frame chain: (with the sampling profile and timeline it was read beside): the submitting thread busy 44-54 ms of a 55-58 ms frame, the title at the gate 11-17 ms a frame, the card idle 14-21 ms a frame while that thread prepared.

  • After, VICTORY_BACKING_STATS=1, standing: refreshed 32.5-33.5 MB a frame (pool views 25.6, private 6.9); sent up 22.3 (17.3, 4.9). Three allocations hold 90%, none ever freed:

    Allocation Refreshed + sent, MB a frame Views made
    page-pool section, 185 MB (the ring of constants) 15.0 + 13.5 5
    page-pool section, 3,977 MB 9.5-10.3 + 2.9 about 300,000
    private XMemVirtualAlloc, 1,277 MB 6.6 + 4.9 0

    The first and the third could be opened once and read in place; the second is remapped constantly and would need a table of pages.

  • These figures were measured on the working branch these commits come from. On this branch, rebased on current main, the code was built and its tests run, but it was not run in game again.

  • For shader changes, the wave sizes tested: not applicable (no shader changes).

  • cargo test passed for the crates it touches: yes for this change. cargo test -p victory-gpu --lib --features diagnostics: 1211 passed, 69 ignored, 5 failed, all in files this does not touch (compose, list::thin, shader_cache, watch::ask_holds, rangelock); the new chain and backing tests pass. cargo build --locked --profile diag -p victory --features diagnostics builds. cargo clippy -p victory-gpu --all-targets -- -D warnings stops only on lints already in main (shadow.rs ranged unused, copystat.rs mb unused, host.rs:5092 manual is_multiple_of).

Checked for overlap

  • I searched the open and merged pull requests for "frame chain", "chain.rs", "backing", "BACKING_STATS", "refreshed bytes" and "critical path". None adds a per-frame chain line or a census of refreshed bytes by backing. Related: #1545 (merged, traces the lifetimes of physical page backing; it does not count refreshed bytes), #3869 (open, host buffers alive by heap), #3271 (open, a refresh census by cause, not by backing).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5572231120 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4377). Originally posted by [IRennie74](https://github.com/IRennie74) on 2026-11-30T19:26:32Z. --- Fixes # ## What it changes Two diagnostics, both compiled only into diagnostics builds; release builds are unchanged. **`frame chain:` (`crates/victory-gpu/src/chain.rs`)**: one line per frame, written three presents later when the card and the relay are done with it, of the frame's way from the title's calls to the card and back to what the title is told. Times are milliseconds since the title's present of the frame before: - the title's submit calls (first, last, how many), its present call and how long it stood at the line's gate (`queue::behind::present`), and when it began the next frame (`frame::wait`); - our submitting thread: first and last job of the frame, busy time and job count, time standing with the line empty and at a head not free to go, and when the present was sent; - the card: how many flights ran and when the relay saw the first and last done; - what the title was told (fence values, bottom-of-pipe writes): first, last, how many, and the longest any came after the relay took its flight. It is on in diagnostics builds; `VICTORY_FRAME_CHAIN=0` turns it off. The hooks are an atomic stamp or two each (`queue.rs`, `queue/behind.rs`, `frame.rs`, and the relay's landing and flight sends in `host.rs`); `chain::on()` is false in release builds, so they cost a branch there. Why: on a 5600X with an RTX 3060 nothing looked saturated by itself in the sampling profile, yet the frame was about 56 ms. The frame was a chain of stages with too little overlap, and every saving on one stage was taken up by another. The timeline shows that chain for three frames; this line shows it for every frame of a benchmark run. Reconstructed from the profile, the logs and the timeline, the chain was: - what the title waits on of ours is the present gate (11-17 ms a frame), nothing else measurable: no title wait over 50 us in the timeline was ended by the relay or the card, and fence values and bottom-of-pipe writes reach it 0.03 ms a frame after their landing; - the gate waits for our submitting thread, which is busy 44-54 ms of a 55-58 ms frame. It stood about 5 ms a frame with the line empty and 6 ms at a head not free to go; the card is idle 14-21 ms a frame, all of it while that thread was preparing; - `VICTORY_SUBMIT_FRAMES=2` took the gate's 11-17 ms to 0.0, but the submitting thread's work grew by about as much (refreshes 11-16 -> 13-19 ms), so the critical path is that thread, not the gate. **Refreshed bytes by backing (`crates/victory-gpu/src/backing.rs`, `VICTORY_BACKING_STATS=1`)**: every 10 s beside the frame-rate line, the bytes refreshes copy and the bytes copies in the card's memory send up, split by what backs them on the host (a view of a page-pool section from the views' book; `xmem`'s private allocations; other private memory; other mapped memory; the image; free or reserved, found with a cached `VirtualQuery`), the allocations behind them by size class, which allocations hold 90% of the bytes, and how often each was freed or, for a section, had views made (its remaps). Hooks: `shadow.rs` (refresh and card-dirty sends), `watch.rs` (allocations and frees), `inplace.rs` (section gone, view made, and a `view_shares` lookup). Off unless asked: thousands of refreshes a frame each take two locks there. Why: reading title memory in place on the card ("one memory") has two openings on native D3D12, and which fits depends on where the hot bytes live: a page-pool section can be opened whole as one heap and addressed by section offset, while private memory opens by address and is then pinned until the heap goes. This says which allocations those bytes are in. Left out on purpose: `VICTORY_TELL_EARLY` (from the same source commit) was never measured, so it is not in this pull request. ## How it was tested - GPU and profile: RTX 3060 12 GB, Ryzen 5 5600X, 32 GB, Series S, 960x540 internal, DLSS Performance, frame generation off, ray tracing default. Diagnostics builds, standing at the opening. - Before: no per-frame view of the chain; the submitting thread's busy time was known only as a frame average. - After, `frame chain:` (with the sampling profile and timeline it was read beside): the submitting thread busy 44-54 ms of a 55-58 ms frame, the title at the gate 11-17 ms a frame, the card idle 14-21 ms a frame while that thread prepared. - After, `VICTORY_BACKING_STATS=1`, standing: refreshed 32.5-33.5 MB a frame (pool views 25.6, private 6.9); sent up 22.3 (17.3, 4.9). Three allocations hold 90%, none ever freed: | Allocation | Refreshed + sent, MB a frame | Views made | |---|---|---| | page-pool section, 185 MB (the ring of constants) | 15.0 + 13.5 | 5 | | page-pool section, 3,977 MB | 9.5-10.3 + 2.9 | about 300,000 | | private `XMemVirtualAlloc`, 1,277 MB | 6.6 + 4.9 | 0 | The first and the third could be opened once and read in place; the second is remapped constantly and would need a table of pages. - These figures were measured on the working branch these commits come from. On this branch, rebased on current `main`, the code was built and its tests run, but it was not run in game again. - For shader changes, the wave sizes tested: not applicable (no shader changes). - `cargo test` passed for the crates it touches: yes for this change. `cargo test -p victory-gpu --lib --features diagnostics`: 1211 passed, 69 ignored, 5 failed, all in files this does not touch (`compose`, `list::thin`, `shader_cache`, `watch::ask_holds`, `rangelock`); the new `chain` and `backing` tests pass. `cargo build --locked --profile diag -p victory --features diagnostics` builds. `cargo clippy -p victory-gpu --all-targets -- -D warnings` stops only on lints already in `main` (`shadow.rs` `ranged` unused, `copystat.rs` `mb` unused, `host.rs:5092` manual `is_multiple_of`). ## Checked for overlap - [x] I searched the open and merged pull requests for "frame chain", "chain.rs", "backing", "BACKING_STATS", "refreshed bytes" and "critical path". None adds a per-frame chain line or a census of refreshed bytes by backing. Related: #1545 (merged, traces the lifetimes of physical page backing; it does not count refreshed bytes), #3869 (open, host buffers alive by heap), #3271 (open, a refresh census by cause, not by backing).
trustno1-coder commented 2026-12-01 18:42:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:42:09Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321376119 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4377#issuecomment-7321376119). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:42:09Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!4377
No description provided.