Skip to content

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 7 commits into
trustno1-coder:mainfrom
banaanpapa:perf/unified-memory
Open

banaanpapa wants to merge 7 commits into
trustno1-coder:mainfrom
banaanpapa:perf/unified-memory

Conversation

@banaanpapa

@banaanpapa banaanpapa commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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.

🤖 Generated with Claude Code

banaanpapa and others added 4 commits November 29, 2026 22:04
An ignored test, no title files: a title buffer of 64 MiB whose copy is found, refreshed, read whole by a pass and written in part by shaders, sent as a flight and settled, with the copy in the PC's memory, with two sides, with two sides and its writes left on the card, and in card memory the CPU maps. Each placement in a process of its own, with the submitting thread's own account of its preparing beside the times.

RTX 5080, Ryzen 9 9950X3D, the title writing 16 MiB before each submission: 5.98 ms in the PC's memory, 4.52 with two sides, 3.97 with the writes left on the card, 1.25 in card memory the CPU maps. Of the two sides' 3.15 ms of preparing, 1.44 are the refresh (0.63 to 0.73 for one side) and 1.39 what goes to the card's side, 0.64 of that taking the bytes out of the CPU's side.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…and looks at landed pages with no lock

A refresh of more than a megabyte goes to the helpers (Shadow::take_all), a part to each. Of pages written here and there a part is a page or two: 14 MiB were 2,754 parts, and each told the card's side of its bytes under the lock of the copy's list of what is to go up (card_changed). With a copy whose shader writes come back, each also took the lock of the pages landings wrote (take_landed). The helpers waited for one another: 8 to 12 ms of their time in all at the first lock and 6.5 ms at the second, in one refresh.

The parts now go in tasks of about 256 KiB. A thread keeps what its task's parts would tell and tells it once, when the task's bytes are in (Shadow::telling_once). The landed pages are bits looked at and cleared with no lock.

What stays as it was: a byte is told of only after it is in the CPU's side, and before the refresh that took it returns; nothing reads the list in between for those bytes (what goes up is taken when the submission's refreshes are done, and a landing looks only at ranges flights declared, which no refresh takes). A landing and a refresh do not come to one whole page at once, for the same reason; a bit lost would only have the page copied and sent again, as before pages were noted.

Measured with host::placement (RTX 5080, Ryzen 9 9950X3D; a copy of 64 MiB with two sides, the title writing 16 MiB before each submission; three runs each, turn by turn):
- shader writes brought back: the refresh 1.37-1.44 ms -> 0.73-0.74, preparing and sending 3.11-3.27 -> 2.41-2.47, the submission 4.46-4.57 -> 3.76-3.85;
- shader writes left on the card (write-combined): the refresh 1.36-1.42 -> 0.59-0.61, preparing and sending 2.98-3.10 -> 2.14-2.26, the submission 3.87-3.95 -> 2.98-3.11.
A refresh of less than a megabyte is done on one thread and is not changed: frame_of_refreshes 14.8 ms before and 14.7 after (six runs each).

Test: a_refresh_on_several_threads_tells_the_cards_side_of_all_it_took, on write-watched memory, a view, and write-watched memory that landings write. It passes on the code as it was, and fails if what a task tells is dropped, if the bits are not set, or if they are not seen.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…of the card; how other layers hold one memory

host::bus::one_buffer_by_address makes a sparse buffer of 4 GiB, shows it
256 MiB of a heap at the address a title would name, in the card's memory
and in card memory the CPU maps, and checks and times both ways through
it. On an RTX 5080 (621.24): shaders read 939 GB/s and store 300 GB/s
through the sparse buffer, as through a buffer of its own; the CPU writes
the heap through a buffer placed in it at 31.8 GB/s and shaders read all
of it through the sparse one; 4 MiB is hidden or shown in 0.1 ms.

The audit's section 11 reads how Xenia, shadPS4, RPCS3, Ryujinx, yuzu,
Vita3K and Dolphin hold the console's one memory, from their source, and
what that asks of this tree. Section 3.6 had turned the sparse buffer
down because it cannot be mapped; the heap under it can.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e refresh bench, and one change tried and not kept

The figures of section 11.2 were counted from the bench's first frame,
which copies everything once; from the third frame on, the big copy's
second taking is 195 us and 3.5 MB a refresh, 5.9 ms a frame.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
JustOptimize added a commit to JustOptimize/VIctory-Enhanced that referenced this pull request Nov 29, 2026
…one lock (PR trustno1-coder#3268, shadow.rs part)

From trustno1-coder#3268 (banaanpapa): Shadow::take_all groups the
parts of a refresh into tasks of about 256 KiB; a task's marks are kept on its
thread and told once ([`Shadow::telling_once`]). The PR's host.rs/bus.rs/placement.rs
benches and audit text come with it. One conflict, in take_all: the PR's `wide_each`
with a pointer cast is replaced by this tree's `wide_each_scoped`.

Tried here (RTX 3080, Proton, native 1080p, pool at default, played): no Xid in
5:24; the user reports it is better. The logs do not show it clearly: frame rate
within noise of the build without it (15.7 fps / 73 ms against 14.6 fps / 74 ms);
texture refresh CPU per frame about 5 ms against about 24 ms in the run with trustno1-coder#2455
alone (4 ms in a baseline without trustno1-coder#2455, so scene or trustno1-coder#2455 may explain part). Put on
main at the user's call; a longer, repeated run has not been done.
One conflict, in `Shadow::take_all`: main now runs the parts on
`wide_each_scoped`; this branch groups them into tasks and tells the
card's side once a task. Kept both: the tasks run on `wide_each_scoped`
and each is told once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Foxhound, neonbyte1/VIctory and SlaktarnVI read against 41adb55 for four
things: bytes that come back from the card and nobody reads, memory looked
at that did not change, lists made anew every frame, and the card's own
ray tracing. Three pieces were taken over (pull requests of their own);
one was measured and left (a table's descriptors copied in one call are
slower here than one call each); the rest is here already in the same or
a stronger form, or needs a run of the title to judge.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant