Card steps: read fills through placed copies, gather reads, bound the pool #105

Open
SousaTrashBin wants to merge 1 commit from upstream-pr/105 into main
SousaTrashBin commented 2026-11-26 03:32:51 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by SousaTrashBin on 2026-11-26T03:32:51Z.


Card steps: fills read through copies at their place, reads gathered, a bounded pool

Three changes to host/card_steps.rs (VICTORY_CARD_STEPS=2 with the relay's second stage), measured on an RX 9070 XT.

1. Fills behind a copy at its place read the copy's source (VICTORY_PLACED_FORWARD, on by default)

Some 26 copies a frame write into the title's constant ring at their place in a list, out of what shaders wrote. A constant-buffer fill behind one of them that read what it had put made plan refuse the whole submission (BEHIND_PLACED), and the submitting thread stood 14–17 ms a frame until the flights had landed.

forward now gives such a fill (one that reads only bytes the copy put, through chains of such copies) the copy's source at the same offset. That is the value the CPU read after the old wait: there the copy is done in title memory at submission, in step order. A fill ahead of the copy is left alone, so the draw ahead of it still sees the old bytes. With the switch on, the steps ahead of a placed copy are planned in order, as VICTORY_PLACED_ORDER=1 does.

Measured: the refused submissions went from 0.9 a frame to 0, and the 14–17 ms waits for "a fill of upload memory" are gone.

2. Two holes where the card-steps path could let the CPU read stale bytes

The card-steps path skips late_blocked, so plan now refuses these itself:

  • a copy at its place whose source is taken on the CPU (Placed::waits is Yes, or a step on the card writes the source ahead of it): the CPU would copy stale bytes into upload memory (PLACED_ON_CPU);
  • a step left on the CPU that reads the destination of a copy at its place that title memory does not take at submission (not free, or its source is written on the card) (PLACED_STALE).

Neither showed up in the traces I have, so they should not add waits.

3. Reads gathered by one dispatch (VICTORY_CARD_GATHER, on by default)

A level's reads out of one buffer (8 or more, word-aligned) are copied into the buffer between by one compute dispatch, a group per read, instead of a CopyBufferRegion each. Measured: about 2,100 copy commands a frame became 66, plus about 18 dispatches. The frame-rate line now counts copy commands, gathered reads and dispatches.

4. The pool of lists of ours is bounded and sized

Each pooled list held a 4 MiB buffer, and as many were kept as were ever in the air. Buffers are now sized to the submission (a power of two from 128 KiB; a submission reads about 110 KB on average), a pooled one is taken only if it holds what is needed, and at most 32 are kept (the smallest goes first). Measured: 5.2 MB of these buffers alive.

Tests

  • plan and forward: the regression case from the trace (the draw ahead of the copy reads the old bytes, the one behind reads the new ones), edge cases (writes between copy and fill, partial overlap, chains, a copy onto itself, steps that run), and a randomized check over 20,000 step orders that every fill, copy and read sees what it would one step after the other.
  • On the card: the gather (40 reads gathered, a few copied, a second level gathering what the first wrote) and the bounded pool. These and the existing card-steps tests pass under the D3D12 debug layer, and so does the ignored end-to-end relay test (VICTORY_RELAY=2 VICTORY_CARD_STEPS=2).
  • cargo test -p victory-gpu --lib: everything passes except timeline::report::tests::real_waits_are_recorded_with_who_ended_them, which fails the same way on main.

Effect

The CPU waits went away, but frame time hardly moved (about 15 fps): the card was 96–97% busy, so the frame is bound by GPU work, not by these waits.

🤖 Generated with Claude Code

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6618907626 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/105). Originally posted by [SousaTrashBin](https://github.com/SousaTrashBin) on 2026-11-26T03:32:51Z. --- ## Card steps: fills read through copies at their place, reads gathered, a bounded pool Three changes to `host/card_steps.rs` (`VICTORY_CARD_STEPS=2` with the relay's second stage), measured on an RX 9070 XT. ### 1. Fills behind a copy at its place read the copy's source (`VICTORY_PLACED_FORWARD`, on by default) Some 26 copies a frame write into the title's constant ring at their place in a list, out of what shaders wrote. A constant-buffer fill behind one of them that read what it had put made `plan` refuse the whole submission (`BEHIND_PLACED`), and the submitting thread stood 14–17 ms a frame until the flights had landed. `forward` now gives such a fill (one that reads only bytes the copy put, through chains of such copies) the copy's source at the same offset. That is the value the CPU read after the old wait: there the copy is done in title memory at submission, in step order. A fill ahead of the copy is left alone, so the draw ahead of it still sees the old bytes. With the switch on, the steps ahead of a placed copy are planned in order, as `VICTORY_PLACED_ORDER=1` does. Measured: the refused submissions went from 0.9 a frame to 0, and the 14–17 ms waits for "a fill of upload memory" are gone. ### 2. Two holes where the card-steps path could let the CPU read stale bytes The card-steps path skips `late_blocked`, so `plan` now refuses these itself: - a copy at its place whose source is taken on the CPU (`Placed::waits` is `Yes`, or a step on the card writes the source ahead of it): the CPU would copy stale bytes into upload memory (`PLACED_ON_CPU`); - a step left on the CPU that reads the destination of a copy at its place that title memory does not take at submission (not `free`, or its source is written on the card) (`PLACED_STALE`). Neither showed up in the traces I have, so they should not add waits. ### 3. Reads gathered by one dispatch (`VICTORY_CARD_GATHER`, on by default) A level's reads out of one buffer (8 or more, word-aligned) are copied into the buffer between by one compute dispatch, a group per read, instead of a `CopyBufferRegion` each. Measured: about 2,100 copy commands a frame became 66, plus about 18 dispatches. The frame-rate line now counts copy commands, gathered reads and dispatches. ### 4. The pool of lists of ours is bounded and sized Each pooled list held a 4 MiB buffer, and as many were kept as were ever in the air. Buffers are now sized to the submission (a power of two from 128 KiB; a submission reads about 110 KB on average), a pooled one is taken only if it holds what is needed, and at most 32 are kept (the smallest goes first). Measured: 5.2 MB of these buffers alive. ### Tests - `plan` and `forward`: the regression case from the trace (the draw ahead of the copy reads the old bytes, the one behind reads the new ones), edge cases (writes between copy and fill, partial overlap, chains, a copy onto itself, steps that run), and a randomized check over 20,000 step orders that every fill, copy and read sees what it would one step after the other. - On the card: the gather (40 reads gathered, a few copied, a second level gathering what the first wrote) and the bounded pool. These and the existing card-steps tests pass under the D3D12 debug layer, and so does the ignored end-to-end relay test (`VICTORY_RELAY=2 VICTORY_CARD_STEPS=2`). - `cargo test -p victory-gpu --lib`: everything passes except `timeline::report::tests::real_waits_are_recorded_with_who_ended_them`, which fails the same way on `main`. ### Effect The CPU waits went away, but frame time hardly moved (about 15 fps): the card was 96–97% busy, so the frame is bound by GPU work, not by these waits. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
avatarmanz commented 2026-11-26 07:35:46 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by avatarmanz on 2026-11-26T07:35:46Z.


Left open: VICTORY_PLACED_FORWARD and VICTORY_CARD_GATHER are on by default and change the card-step plan on AMD; needs an in-game check on the 7900 XTX first.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185626320 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/105#issuecomment-7185626320). Originally posted by [avatarmanz](https://github.com/avatarmanz) on 2026-11-26T07:35:46Z. --- Left open: VICTORY_PLACED_FORWARD and VICTORY_CARD_GATHER are on by default and change the card-step plan on AMD; needs an in-game check on the 7900 XTX first.
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/105:upstream-pr/105'
git switch 'upstream-pr/105'

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