GPU: a refresh on several threads without its two contended locks; benches of placements and of one sparse buffer by address; audit section 11 #3268

Open
banaanpapa wants to merge 22 commits from upstream-pr/3268 into main
banaanpapa commented 2026-11-29 21:11:01 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by banaanpapa on 2026-11-29T21:11:01Z.


Four commits, on f72cec77. One changes what the layer does; the others are two benches, one probe of the card, and a section of the audit. No game was run: every figure is from a synthetic bench on one PC (Ryzen 9 9950X3D, RTX 5080 16 GB, driver 621.24, Windows 11 26300).

The change: a refresh on several threads (shadow.rs)

A refresh of 1 MiB or more is cut into parts for the helper threads (Shadow::take_all). For 14 MiB of scattered pages that was 2,754 parts, and each took two locks of the copy:

  • card.dirty, to tell the card's side of its bytes: 8 to 12 ms of the helpers' summed time a refresh, waiting;
  • landings, to look at the pages a landing noted: 6.5 ms.

(Timers added for the measurement and taken out.) Now the parts are grouped into tasks of 256 KiB, a task's marks are kept on its thread and told under one lock when it ends (telling_once), and the noted pages are an atomic bitmap. A mark still appears only after its bytes are in the copy and before the refresh returns.

host::placement::placements, 64 MiB copy, the title writes 16 MiB before each submission, three alternating runs each:

Two sides Before After
Shader writes landed refresh 1.37-1.44 ms 0.73-0.74 ms
prepared and sent 3.11-3.27 ms 2.41-2.47 ms
Shader writes left on the card refresh 1.36-1.42 ms 0.59-0.61 ms
prepared and sent 2.98-3.10 ms 2.14-2.26 ms

With 1 MiB written, and in frame_of_refreshes, nothing changes (14.8 against 14.7 ms): a refresh under 1 MiB stays on one thread.

Test: a_refresh_on_several_threads_tells_the_cards_side_of_all_it_took (write-watched memory, a view, and write-watched memory that landings write too). It passes on the code as it was, and fails if the kept marks are dropped, if the noted bits are never set, or if they are never read.

Benches and the probe (all #[ignore])

  • host::placement::placements: what one submission costs by where a title buffer's copy lies (one side in the PC's memory, two sides, two sides with writes left on the card, one side in card memory the CPU maps), through the real paths (shadow::register, refresh, gpu_writes, execute_own, settle_now), with the host's own SPLIT and send::STATS. At 16 MiB written: prepared and sent 1.23 / 2.42 / 2.27 / 0.89 ms, run and landed 4.57 / 1.17 / 0.63 / 0.18 ms.
  • host::bus::one_buffer_by_address: a sparse buffer of 4 GiB whose tiles lie in a GPU_UPLOAD heap, written by the CPU through a buffer placed in the same heap. On this card: shaders read 939 GB/s and store 300 GB/s through it (as through a buffer of its own), the CPU copies in at 31.8 GB/s, all 16,384 threads read what the CPU wrote and the CPU reads what they stored, and 4 MiB is hidden or shown in 0.1 ms. Direct3D's documents neither allow nor forbid tiles in such a heap; this is one driver, without the debug layer.

The audit, section 11

How Xenia, shadPS4, RPCS3, Ryujinx, yuzu, Vita3K and Dolphin hold the console's one memory, read from their source; what they have in common that this tree has not (most leave shader writes on the card unless asked; the two nearest in kind hold one sparse buffer by address; books by page); what the probe above means for section 3.6, which had turned the sparse buffer down because it cannot be mapped; a PC of 16 GB with a card of 8 GB; and one change tried and not kept.

What was run

  • cargo test -p victory-gpu --release --lib --locked, on this branch and on main beside it: the same tests fail on both. Deterministically, shader_cache::tests::every_switch_of_the_translator_is_in_the_key: 1b4b6cd4 put VICTORY_SCALAR_SPLITS (and the four VICTORY_ORACLE_* names) back into shader_cache.rs while what read them stays reverted (a1fe8350). This branch leaves that to you: the name is hashed into every key whether it is set or not. In the full run only, on both: three of pipeline::host::tests (out of memory making a pipeline) and one or two of texback::tests; and now and then card_steps::tests::places_written_after_sending_are_learned and uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue. Each of those passes run alone.
  • cargo clippy -p victory-gpu --all-targets --locked: nothing in the lines this branch writes.

The check

check fails here at the Clippy step, at crates\victory-loader\src\crash.rs:804 (unwind_copy is never used without diagnostics). This branch does not touch victory-loader. The same step fails at the same line on every push to main today (f72cec77, this branch's base, among them) and on the other pull requests that ran it. Run here without -D warnings, the step has 36 findings on main, none in a line this branch writes. #2792 and #2682 put that line right (and the key test above); this branch leaves the gate to them so as not to be a third.

Limits

  • The change only reaches refreshes of 1 MiB or more.
  • The card's-side half of a two-sided send is as it was: 0.6 ms copying out of the CPU's side and 0.7 to 1.0 ms recording some 2,750 CopyBufferRegion calls for 14 MiB.

Merged with main again (2026-11-30, c71899d9)

The branch holds two merges of main (no rewrite of what was pushed): the first resolved the one conflict there was, in Shadow::take_all (main's wide_each_scoped and this branch's tasks told once, both kept); the second, with the 494 commits since, was clean.

Measured again on that main with the same bench, the binary with main's shadow.rs and the one with this branch's run in turn three times, 16 MiB written before each submission to a copy with two sides: a submission 4.62 to 4.78 ms before and 3.72 to 3.79 after; of it the preparing 3.24 to 3.34 ms before and 2.31 to 2.39 after. With 1 MiB written nothing changes, as intended (such a refresh does not take the path).

cargo test -p victory-gpu --release --lib on the merged branch: 1,115 pass; the two that fail are main's (list::thin::tests::bindings_record_no_work, shader_cache's key test). The crate's tests compile only with #4115 (two calls on main miss an argument card_pass gained); they were run with it applied and not committed here.

The audit has a new section, 11.8: what the public forks (Foxhound, neonbyte1, SlaktarnVI) have that this tree has not, what was taken over from them, and what was measured and left.

Measured in play (2026-11-30)

VICTORY_TELL_ONCE is new in this pull request: the grouping of a refresh into tasks of about 256 KiB, which used to be always on, can now be turned off (=0, as before) and so weighed in play. The refresh tests pass both ways. The branch is merged with e1251c31.

One session in the title's world on an RTX 5080 with a Ryzen 9 9950X3D (driver 621.40, Series X profile, 1440p, DLSS Quality, about 4,800 draws a frame), built on e1251c31. VICTORY_AB=10,VICTORY_SUBMIT_SPLIT,VICTORY_TELL_ONCE,VICTORY_UNDER_FUSED flipped the three switches every 10 s through all eight combinations. Each switch's effect is the mean of its four "on" phases minus its four "off" phases, within each full 80-second cycle, over 5 cycles:

Switch Frame, mean Frame, p90 Submitting thread
VICTORY_SUBMIT_SPLIT (upstream's, off by default) ±0.00 ms -0.93 ms -2.68 ms (17.0 to 14.4)
VICTORY_TELL_ONCE (#3268) -0.25 ms, faster in 4 of 5 cycles -0.18 ms -0.20 ms
VICTORY_UNDER_FUSED (#3582) -0.15 ms, faster in 4 of 5 cycles -0.05 ms -0.03 ms

The card was 99 to 100 % busy throughout, so in this scene the frame waits on the card, not on the submitting thread. Where the frame is bound by that thread, these gains should show more; this session can't say how much more. Five cycles of one scene is a small sample.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555160761 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3268). Originally posted by [banaanpapa](https://github.com/banaanpapa) on 2026-11-29T21:11:01Z. --- Four commits, on `f72cec77`. One changes what the layer does; the others are two benches, one probe of the card, and a section of the audit. No game was run: every figure is from a synthetic bench on one PC (Ryzen 9 9950X3D, RTX 5080 16 GB, driver 621.24, Windows 11 26300). ## The change: a refresh on several threads (`shadow.rs`) A refresh of 1 MiB or more is cut into parts for the helper threads (`Shadow::take_all`). For 14 MiB of scattered pages that was 2,754 parts, and each took two locks of the copy: - `card.dirty`, to tell the card's side of its bytes: 8 to 12 ms of the helpers' summed time a refresh, waiting; - `landings`, to look at the pages a landing noted: 6.5 ms. (Timers added for the measurement and taken out.) Now the parts are grouped into tasks of 256 KiB, a task's marks are kept on its thread and told under one lock when it ends (`telling_once`), and the noted pages are an atomic bitmap. A mark still appears only after its bytes are in the copy and before the refresh returns. `host::placement::placements`, 64 MiB copy, the title writes 16 MiB before each submission, three alternating runs each: | Two sides | | Before | After | |---|---|---|---| | Shader writes landed | refresh | 1.37-1.44 ms | 0.73-0.74 ms | | | prepared and sent | 3.11-3.27 ms | 2.41-2.47 ms | | Shader writes left on the card | refresh | 1.36-1.42 ms | 0.59-0.61 ms | | | prepared and sent | 2.98-3.10 ms | 2.14-2.26 ms | With 1 MiB written, and in `frame_of_refreshes`, nothing changes (14.8 against 14.7 ms): a refresh under 1 MiB stays on one thread. Test: `a_refresh_on_several_threads_tells_the_cards_side_of_all_it_took` (write-watched memory, a view, and write-watched memory that landings write too). It passes on the code as it was, and fails if the kept marks are dropped, if the noted bits are never set, or if they are never read. ## Benches and the probe (all `#[ignore]`) - `host::placement::placements`: what one submission costs by where a title buffer's copy lies (one side in the PC's memory, two sides, two sides with writes left on the card, one side in card memory the CPU maps), through the real paths (`shadow::register`, `refresh`, `gpu_writes`, `execute_own`, `settle_now`), with the host's own `SPLIT` and `send::STATS`. At 16 MiB written: prepared and sent 1.23 / 2.42 / 2.27 / 0.89 ms, run and landed 4.57 / 1.17 / 0.63 / 0.18 ms. - `host::bus::one_buffer_by_address`: a sparse buffer of 4 GiB whose tiles lie in a `GPU_UPLOAD` heap, written by the CPU through a buffer placed in the same heap. On this card: shaders read 939 GB/s and store 300 GB/s through it (as through a buffer of its own), the CPU copies in at 31.8 GB/s, all 16,384 threads read what the CPU wrote and the CPU reads what they stored, and 4 MiB is hidden or shown in 0.1 ms. Direct3D's documents neither allow nor forbid tiles in such a heap; this is one driver, without the debug layer. ## The audit, section 11 How Xenia, shadPS4, RPCS3, Ryujinx, yuzu, Vita3K and Dolphin hold the console's one memory, read from their source; what they have in common that this tree has not (most leave shader writes on the card unless asked; the two nearest in kind hold one sparse buffer by address; books by page); what the probe above means for section 3.6, which had turned the sparse buffer down because it cannot be mapped; a PC of 16 GB with a card of 8 GB; and one change tried and not kept. ## What was run - `cargo test -p victory-gpu --release --lib --locked`, on this branch and on `main` beside it: the same tests fail on both. Deterministically, `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`: `1b4b6cd4` put `VICTORY_SCALAR_SPLITS` (and the four `VICTORY_ORACLE_*` names) back into `shader_cache.rs` while what read them stays reverted (`a1fe8350`). This branch leaves that to you: the name is hashed into every key whether it is set or not. In the full run only, on both: three of `pipeline::host::tests` (out of memory making a pipeline) and one or two of `texback::tests`; and now and then `card_steps::tests::places_written_after_sending_are_learned` and `uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue`. Each of those passes run alone. - `cargo clippy -p victory-gpu --all-targets --locked`: nothing in the lines this branch writes. ## The check `check` fails here at the Clippy step, at `crates\victory-loader\src\crash.rs:804` (`unwind_copy` is never used without `diagnostics`). This branch does not touch `victory-loader`. The same step fails at the same line on every push to `main` today (`f72cec77`, this branch's base, among them) and on the other pull requests that ran it. Run here without `-D warnings`, the step has 36 findings on `main`, none in a line this branch writes. #2792 and #2682 put that line right (and the key test above); this branch leaves the gate to them so as not to be a third. ## Limits - The change only reaches refreshes of 1 MiB or more. - The card's-side half of a two-sided send is as it was: 0.6 ms copying out of the CPU's side and 0.7 to 1.0 ms recording some 2,750 `CopyBufferRegion` calls for 14 MiB. ## Merged with `main` again (2026-11-30, `c71899d9`) The branch holds two merges of `main` (no rewrite of what was pushed): the first resolved the one conflict there was, in `Shadow::take_all` (main's `wide_each_scoped` and this branch's tasks told once, both kept); the second, with the 494 commits since, was clean. Measured again on that `main` with the same bench, the binary with `main`'s `shadow.rs` and the one with this branch's run in turn three times, 16 MiB written before each submission to a copy with two sides: a submission 4.62 to 4.78 ms before and 3.72 to 3.79 after; of it the preparing 3.24 to 3.34 ms before and 2.31 to 2.39 after. With 1 MiB written nothing changes, as intended (such a refresh does not take the path). `cargo test -p victory-gpu --release --lib` on the merged branch: 1,115 pass; the two that fail are `main`'s (`list::thin::tests::bindings_record_no_work`, `shader_cache`'s key test). The crate's tests compile only with #4115 (two calls on `main` miss an argument `card_pass` gained); they were run with it applied and not committed here. The audit has a new section, 11.8: what the public forks (Foxhound, neonbyte1, SlaktarnVI) have that this tree has not, what was taken over from them, and what was measured and left. ## Measured in play (2026-11-30) `VICTORY_TELL_ONCE` is new in this pull request: the grouping of a refresh into tasks of about 256 KiB, which used to be always on, can now be turned off (`=0`, as before) and so weighed in play. The refresh tests pass both ways. The branch is merged with `e1251c31`. One session in the title's world on an RTX 5080 with a Ryzen 9 9950X3D (driver 621.40, Series X profile, 1440p, DLSS Quality, about 4,800 draws a frame), built on `e1251c31`. `VICTORY_AB=10,VICTORY_SUBMIT_SPLIT,VICTORY_TELL_ONCE,VICTORY_UNDER_FUSED` flipped the three switches every 10 s through all eight combinations. Each switch's effect is the mean of its four "on" phases minus its four "off" phases, within each full 80-second cycle, over 5 cycles: | Switch | Frame, mean | Frame, p90 | Submitting thread | |---|---|---|---| | `VICTORY_SUBMIT_SPLIT` (upstream's, off by default) | ±0.00 ms | -0.93 ms | -2.68 ms (17.0 to 14.4) | | `VICTORY_TELL_ONCE` (#3268) | -0.25 ms, faster in 4 of 5 cycles | -0.18 ms | -0.20 ms | | `VICTORY_UNDER_FUSED` (#3582) | -0.15 ms, faster in 4 of 5 cycles | -0.05 ms | -0.03 ms | The card was 99 to 100 % busy throughout, so in this scene the frame waits on the card, not on the submitting thread. Where the frame is bound by that thread, these gains should show more; this session can't say how much more. Five cycles of one scene is a small sample. 🤖 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/3268:upstream-pr/3268'
git switch 'upstream-pr/3268'

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