GPU: a submission's refreshes copy on several threads #2051
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2051
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2051"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xkn0wh3r3 on GitHub · 2026-11-25 04:08 UTC · original
0xkn0wh3r3:gpu/parallel-refresh→main· +532 −17 · 4 files · 3 commits · openThe problem
At each submission, host copies of title memory are brought up to date. That is a plain memory copy, and the submitting thread made every one of them alone.
On the world's shape (#400: a 174 MB heap, ~8,800 scattered 64 KiB pages a frame, about 525 MB), this is now most of what a frame's copies cost. Marked pages already took snapshots and copy-back down to a few milliseconds. One thread moves far less than the memory can:
The fix
Batch::flushnow collects its refreshes' copies and makes them together at the end, on several threads (new modulecopy_pool):copy_pool::queued).copy_pool::runmakes them. Copies are cut to 1 MiB. From 4 MiB in all, they are taken by index by three persistent workers and the submitting thread. Below that, one thread copies.Only copies no snapshot reads back are queued:
Where a snapshot covers a run,
update_trackedstill copies at once and takes the bytes into the snapshot. Once the queued copies are made, what they took goes into the saved bytes of armed pages (Shadow::queued_made, the sameTracked::refreshedthatShadow::copycalls). Outside a flush every copy is made at once, as before.Testing
New test
copy_pool::tests::queued_copies_are_made_on_the_workers: queued copies are made byrun, on the workers past the threshold, a big copy is cut into pieces, and every byte is in place.New test
copy_pool::tests::the_workers_take_the_pieces_past_the_threshold: with the submitting thread leaving every piece to the workers, they copy all of them and every byte lands in place.New ignored benchmark
host::batch::world_frame_refreshes(cargo test --release -p victory-gpu -- --ignored --nocapture world_frame_refreshes). It replays a world frame's refreshes throughBatchasHost::executedoes: title writes to 256 random pages, 24 declared ranges armed as marked, one flush, 36 submissions. It also asserts every title write reached the copy. RTX 5070 Ti host, release build, median of 6 frames, about 525 MB copied either way. Re-measured on13f91ca:13f91cacargo test -p victory-gpuon an RTX 5070 Ti (driver 621.24): all pass exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views. Those fail the same way onmain(the NVIDIA 1,000,000-descriptor heap cap, #1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Not covered / Related
copy_mapped.Rebased onto
13f91ca280b150limits change tracking to the runtime's memory and copies the parts outside it whole (Tracked::untracked).update_freequeues those whole copies too, so they also run on the workers.Rebased onto
f3578e35319366mergedupdate_busyandupdate_freeintoupdate_tracked(oneTracked::takeper range, so a page under a written range is still guarded). The queueing now lives there: a run with a snapshot over it is copied at once and the snapshot takes the bytes; any other run, and the untracked parts, are queued.106377dmakesShadow::copyhand what it copied toTracked::refreshed, so a partial refresh of an armed page updates the bytes saved of it. A queued copy has no bytes untilcopy_pool::runmakes it, so each copy records the ranges it queued, andBatch::flushcallsShadow::queued_madeon every copy it updated once the run is done.copy_pool::copynow returns whether it queued.shadow::tests::queued_partial_refresh_under_marked_range_updates_saved_bytes: upstream's partial-refresh test with the refreshes queued. Withoutqueued_madeit fails (copy-back puts a refreshed byte back over a later title write).world_frame_refreshesstill checks every title write reached the copy (release build, under load from other builds: 80.6 ms on one thread, 53.6 ms with the workers).cargo test -p victory-gpu --lib: the same two failures as on upstreammainhere.cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Measured in the title
@imjustprism ran
9ff67b2in the title (RX 9070 XT, diagnostics build, world, medians per frame, 47 to 74 frame lines per run), with timers around the phases of a submission:Batch::flushwithout the write-watch take, msScenes drift between runs, so ms per MB is the row to compare: 20 to 53% lower with this PR, no errors and no device removed. On the threshold: 77% of the bytes refreshed (76 to 88% by draw bucket) were in flushes of 4 MiB or more, so they already reach the workers; lowering
PARALLEL_FROMcan only win on the rest, which sits in many small flushes.Review follow-ups (
b55f5c6)Batch::flushcallsShadow::queued_madeonly on the copies that flush updated, instead of on every copy current in the submission (in run 3 above: 31,000 visits a frame against 3,600 copies updated).SAFETYcomment onShadow'sSend/Syncsays the workers writedataonly insidecopy_pool::run, which the flush waits for.Batch::flushsays that withdiagnosticsthe copied-whole time (WholeUs) counts only queueing, and that the copies count in the flush time and, summed over the threads, in the move time.github-bot referenced this pull request2026-11-26 04:55:46 +00:00
@jeremygold02 on GitHub · 2026-11-25 04:19 UTC · original
Triage verdict — Keep the parallel refresh path, verify worker participation explicitly (
cda7548)Evidence
Checks and limits
Next step
This verification was AI-assisted.
@0xkn0wh3r3 on GitHub · 2026-11-25 05:27 UTC · original
Thanks for the triage. Added in e004f35:
copy_pool::tests::the_workers_take_the_pieces_past_the_threshold. A test-only switch makes the submitting thread leave every piece to the workers, and a test-only count of the pieces they copy shows they copied all 128 of an 8 MiB run, each byte where it belongs. Nothing outside tests changes.Also measured on the same benchmark and dropped: handing copies to the workers while the submitting thread is still finding dirty pages. It made refresh slower (median 49 -> 70 ms per frame, slower in all 20 alternating runs), as finding resets write watches and page protections, which contends with the workers'
ReadProcessMemory.@Marvisak on GitHub · 2026-11-25 09:22 UTC · original · edited 2026-11-26 01:20 UTC
Automated triage for the maintainers.
Merge candidate (unchanged). The head is still
9ff67b2, which merges cleanly onto currentmain. The latest reply only answers @MeMako's in-title numbers. Its explanation fits the code:copy_pool::runuses one thread belowPARALLEL_FROM(4 MiB per flush), andShadow::update_trackedstill copies snapshot-covered runs at once. So nothing in the earlier reading ofBatch::flush,Shadow::queued_madeand thePool::run/Pool::workerhandshake changes.One minor, non-blocking point from the comments:
copy_pool::queueddoesn't clear its thread-local queue when the closure panics. A drop guard would make it robust ifupdate_allever gains a panic path.CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code
@xndbogdan on GitHub · 2026-11-25 23:33 UTC · original
Results from #2134's
world_frame_preparingon two quite different CPUs, against the same benchmark onmain.Builds:
main842b0cbwith #2134 merged, and the same with this PR merged on top (6a3296f).diagprofile withdiagnostics, hardware adapter. #2134 doesn't build on currentmainas it is:Shadow::mark_writtencallsbitmap(), which now takesmemory: bool. I changed it tobitmap(false)locally in both builds, which is the only change. Three runs per build, interleaved with the other builds, each the benchmark's median of 5 frames.mainmainmainAll 30 runs passed the benchmark's checks.
AI-assisted (Claude Code). Synthetic benchmark only, no game data.
@0xkn0wh3r3 on GitHub · 2026-11-25 23:35 UTC · original
@xndbogdan thanks for running it on two very different machines. Identical work counters (1,325 checks, 6,657.8 MB checked, 243.7 MB copied) with the "GPU writes" step down 25–34% on the 9800X3D and about 18% on the Xeon is the cleanest evidence that the same copies just run in parallel. Copy-back not moving is expected too: this PR only parallelises the refresh copies.
@fuzeofficlal on GitHub · 2026-11-26 00:44 UTC · original
Code review (lifetime/concurrency audit) and RTX 5090 + WARP verification at head
9ff67b2aa8bbmerged cleanly ontomain(63bcca43c6a0):Batch::flush(host.rs:2442-2455) collects pieces viacopy_pool::queued(|| self.update_all()), executescopy_pool::run(pieces), and then callsshadow.queued_made()overself.current.values(). SinceBatch::adddeduplicates byShadowpointer andself.currentholdsArc<Shadow>across both parallel copy andqueued_made()(Batch::title_written()flushes before clearingcurrent), every backing buffer outlives its copy work.Shadow::update_tracked(shadow.rs:611-680) keeps snapshot-overlapping (before) andunmappedranges synchronous, queuing only disjoint non-overlappingruns/untrackedspans for parallel copy beforequeued_madecallsTracked::refreshed.Pool::run(copy_pool.rs:138-182) serializes batches underrunning, publishes jobs underself.job, and re-acquiresself.jobbeforefinished.notify_all()(no lost wakeup). Minor non-blocking note:copy_pool::queued(lines 24-29) does not use aDropguard on TLSQUEUE, so a panic inside the closure would leaveSomeinstalled (currentlyupdate_allhas no panic path).VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:192 files ok;cargo clippy -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warningscopy_pool:: shadow:: host::tests:: --skip descriptor::host: 29/29 passed on both RTX 5090 and WARP (--features diagnostics)--releasehost::batch::world_frame_refreshes: passed (all title writes observed on host copies; first 3 frames dropped from 85.3–102.9 ms single-threaded to 52.5–73.9 ms with workers).Clean concurrency design; LGTM.
@MeMako on GitHub · 2026-11-26 00:56 UTC · original
Independent verification of
9ff67b2on AMD Ryzen 9 7950X + AMD Radeon RX 9070 XT (adapter 0, driver32.0.32029.2010, Windows 1110.0.26200x64).CI checks & synthetic benchmark:
cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings(and--all-features): passcargo test -p victory-gpu --locked: 234 passed, 0 failed (all newcopy_pool/shadowtests pass on RX 9070 XT)world_frame_refreshes(release build, median of 6 frames, ~518 MB/frame):Live title run (release build, warm shader & pipeline cache):
(Note: merged cleanly onto
842b0cb+ a local RDNA 4 separate-handle workaround equivalent to #2122 andDYNAMIC = 1 << 19, since plainmaincrashesamdxc64.dllon this card; before/after compared against the exact same local branch without #2051.)draws >= 200, excluding menus/pause)n=104vsn=29) —copiesavg153.1 ms(560.1 MB)123.4 ms(549.2 MB)copiesthroughput (med / agg)4.08/3.66 GB/s4.74/4.45 GB/s>2,500draws,n=73vsn=22) —copiesavg161.0 ms(585.3 MB)122.5 ms(530.6 MB)00One observation from the live run: real-world copy throughput reached ~4.45 GB/s vs ~15.9 GB/s in the synthetic benchmark (~550 MB/frame copied), likely because smaller submissions (
< 4 MiB), snapshot-covered ranges, or unmapped-hole fallbacks still run single-threaded —#2051is a clear win either way with zero regressions.No game data, shader names, or screenshots are included, per
docs/asset-policy.md. Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.@0xkn0wh3r3 on GitHub · 2026-11-26 00:59 UTC · original
@MeMako thanks for the 7950X / RX 9070 XT numbers, especially the in-title buckets: copies down 19% across the world and 24% in heavy scenes, with no errors. Your reading of the gap to the synthetic 15.9 GB/s fits the code. Submissions under 4 MiB in all stay on one thread (
PARALLEL_FROM), and pages a snapshot covers are copied at once so the snapshot can take their bytes. So a frame of many small submissions keeps part of its copying serial. Lowering the threshold, or batching across submissions, would be the next step if that share turns out large.@catminou4 on GitHub · 2026-11-25 04:17 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Submission refreshes copy on several threads — parallel copy of refresh data; check the threading invariants on the copy sources.
@DenRakEiw on GitHub · 2026-11-25 04:49 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib copy_pool::— 1 passed, 0 failedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (184 files ok)Clean multithreaded copy pool for parallelizing submission shadow-buffer refreshes. Looks good.
AI-assisted (Gemini 4 Neon).
@Xvania7 on GitHub · 2026-11-25 11:43 UTC · original · approved these changes
Verified
e004f35on Windows 10 + NVIDIA GeForce RTX 5060:copy_pool::tests::(2 passed:queued_copies_are_made_on_the_workers,the_workers_take_the_pieces_past_the_threshold)shadow::tests::(4 passed)cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warningscargo xtask policy: 183 files okApproving.
@imjustprism on GitHub · 2026-11-26 18:16 UTC · original · reviewed
ran
9ff67b2in the title with timers around the phases of a submission, to split out what this pr changes and to answer the open question about the 4 MiB threshold. rx 9070 xt, world, medians per frame:Batch::flushwithout the write-watch take, ms63bcca4plus #2122 (this card needs it) plus local timers, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 74 world frame lines per run. no errors and no device removed in any run. scenes drift between runs, so ms per MB is the row to compare: 20 to 53% less before rounding, and every run with the pr is below both runs without. the copy alone goes from 4.9 and 7.1 GB/s on one thread to 9.5 GB/s (run 3, time insidecopy_pool::run). the whole frame was 195 and 213 ms without and 155 to 182 ms with; i would read that only as "not slower".run 3 had one more timer and three counters in
Batch::flush:copy_pool::runqueued_madeloopso on the threshold: about three quarters of the bytes already reach the workers here, though there are 150 to 180 flushes a frame. the other quarter sits in the many small flushes; lowering
PARALLEL_FROMcan only win on that part.what i checked from the description:
world_frame_refreshes, release, two runs: 50.3 and 51.4 ms on one thread, 26.7 and 30.0 ms with the workers, about 520 MB (10 GB/s against 17 to 19). matches.small points from reading the diff, none blocking:
host.rs:2450: after every flush the loop callsqueued_madeon every copy incurrent, and each tracked one takes itsqueuedlock, whether or not that flush queued anything for it. run 3 counted 31,000 visits a frame against 3,600 copies updated, so about nine in ten find nothing. it costs 0.6 ms a frame here and 3.1 ms in the heaviest scenes.update_allalready knows which copies it updated in this flush; visiting only those removes it.shadow.rs:138: theSAFETYcomment onunsafe impl Send for Shadowsaysdatais "written only on the submitting thread". with this pr the workers write it too. the code holds because the flush waits forrun; the comment should say that instead.shadow.rs:669andshadow.rs:691: with thediagnosticsfeature,WholeUsnow times queueing, so the "copied whole" time in the frame line reads near zero while the copy itself is counted elsewhere. the doc onBatch::flushsays this for the per-range time but not for this one.i agree with the audit above on
Pool::runandPool::worker: i looked for a lost wakeup and for a copy outliving its buffer and found neither.@0xkn0wh3r3 on GitHub · 2026-11-26 18:26 UTC · original
@imjustprism thanks for the in-title runs and the phase timers. ms per MB down 20 to 53%, with no errors, is the figure I could not get here. I added your table to the description. All three points are addressed in
b55f5c6:queued_madeloop:Batch::flushnow visits only the copies that flush updated.update_allleaves them inrefreshes, and the flush drains that list aftercopy_pool::run. Before, it went through every copy current in the submission. Nothing else changes: onlyupdate_allcallsupdateinsidecopy_pool::queued, so only those copies can have queued ranges.SAFETYonShadow'sSend/Sync: it now says the refresh workers writedataonly insidecopy_pool::run, and the flush waits for that before it goes on.WholeUs: doc only. TheBatch::flushdoc now says that withdiagnostics, both the per-range time and the copied-whole time count only finding and queueing. The copies themselves count in the flush time (FlushUs) and, summed over the threads, in the move time (MoveUs). I left the counter alone: putting the pool's time under "copied whole" would mean tagging each queued piece by its kind, and the threads overlap, so a summed time would not be wall time anyway.On the threshold: 77% of the bytes were in flushes of 4 MiB or more, so about three quarters already reach the workers. Lowering
PARALLEL_FROMcan only win on the remaining quarter, the many small flushes. I've left the threshold as it is in this PR.@imjustprism on GitHub · 2026-11-26 19:24 UTC · original
checked
b55f5c6the same way as before (same base, same timers and counters, one 12-minute world run):9ff67b2, run 3b55f5c6queued_madeloop visitsBatch::flushwithout the write-watch take, ms per MBthe loop now visits exactly the copies the flush updated, on every frame line. no errors and no device removed, 70 world frame lines. the three tests pass at this head, and
world_frame_refreshesgives 59.5 ms on one thread and 29.7 ms with the workers (one run). the newSAFETYtext matches the code, and leavingWholeUsas a documented limit is fine by me. nothing open from my side.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.