GPU: parallelize marked page copy-backs across disjoint pages #3341
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!3341
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3341"
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?
@danielibabet on GitHub · 2026-11-26 19:16 UTC · original
danielibabet:pr/parallel-copyback-marks→main· +134 −19 · 2 files · 2 commits · openSummary
Shadow::copy_back_marksacross up to 8 worker threads (std::thread::scope) over disjoint 64 KiB title memory pages (uniquesorted by page, with any aliased duplicate page addresses handled sequentially).pooled(PAGE)scratch buffer per worker thread instead of allocating/zeroingvec![0u8; n]per page, and batchTracked::taken(&list)once perShadowafter the parallel pass.parallel_marked_pages_go_back_and_retake_guardsexercisingcopy_back_marksacross 20 marked pages.Motivation
In GTA VI open-world frames,
copy_back_marksprocesses ~1,800–1,900 marked 64 KiB pages (~118 MB/frame) sequentially on the submission thread (~38–40 ms/frame), doing per-page 64 KiB heap allocations, comparisons, merges, andVirtualProtectsyscalls. Parallelizing disjoint page writebacks and batchingTracked::takenremoves that single-thread CPU bottleneck.Verification
cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views:230 passed; 0 failed; 1 ignored; 2 filtered out(includingparallel_marked_pages_go_back_and_retake_guards)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warningscargo run -p xtask --locked -- policy:asset policy: 191 files ok@AurumCarlos on GitHub · 2026-11-26 19:18 UTC · original · reviewed
This is the same change as #2914 (kotekompotek, "marked pages go back to title memory on several threads", from issue #2826), which is still open with reviews and a changes-requested. It would be worth linking it, checking whether that review's points apply here too, and agreeing which one goes forward.
One question on the batching: on
main,copy_back_markedcallst.taken(&[page])right after each page's writeback. Here every page'stakenwaits until the whole parallel pass is done. What keeps a title write that lands on an already-written page during that window from being dropped when the page is then marked equal to title memory? If the guard makes that impossible, a short comment saying so would help, since the window is now the whole pass instead of one page.@danielibabet on GitHub · 2026-11-26 19:27 UTC · original
Good catch @AurumCarlos (and thanks for pointing out #2914)! Updated #3341 to address both:
t.taken(&[page / PAGE])back insidecopy_back_marked_withright afterwrite_mapped(matchingmain's per-page window instead of deferringtakenacross the whole parallel pass).watch::has_aliasesso any marked page with physical-memory aliases (alias_of) is routed to the sequential path alongside duplicate virtual pages, preventing concurrent writebacks to different virtual mappings of the same physical page (the issue raised in #2914).Re-ran
victory-gputests (230 passed, 0 failed; 2 skipped), strict clippy (--all-targets --all-features -- -D warnings), andxtask policy(191 files ok).@cloph-dsp on GitHub · 2026-11-26 19:55 UTC · original
Independent local verification of PR #3341 (
GPU: parallelize marked page copy-backs across disjoint pages), head586102fb60.cargo test --locked,CARGO_BUILD_JOBS=2, per-worktreeCARGO_TARGET_DIR(D:\Victory-Contrib\target-3341).cargo test --locked -p victory-gpu --lib -- --exact shadow::tests::parallel_marked_pages_go_back_and_retake_guards --test-threads=1-> 1 passed, 0 failed, 232 filtered, exit 0.git diff --check origin/main HEAD-> clean.63bcca43..., so it is genuinely added by this PR.AI-assisted (Hy4 flash). GPU/driver: N/A for this CPU test. No game data used.
@fuzeofficlal on GitHub · 2026-11-26 20:24 UTC · original · approved these changes
Verified locally merged onto
origin/main(63bcca43) at PR head586102fb(Windows 11 x64, Ryzen 9 9950X, NVIDIA RTX 5090 + Microsoft WARP,VICTORY_D3D12_DEBUG=1):crates/victory-gpu/src/{shadow.rs, watch.rs}:copy_back_marks(shadow.rs:957-1052) sorts marked entries by 64 KiB-alignedpage, routes all physically aliased pages (viawatch::has_aliases,watch.rs:298-304) and duplicate virtual-page entries toseq, and only runsseqafterstd::thread::scopejoins. Disjoint pages inuniqueyield strictly non-overlapping&mut [u8]slices intoShadow::data,host::read_into/write_mappeduse stack-localReadProcessMemorycalls (thread-safe), and lock ordering (GUARDS->changed.0->changed.1,POOLindependent) is deadlock-free.t.taken(&[page / PAGE])immediately afterwrite_mappedinsidecopy_back_marked_with(shadow.rs:549-551) preservesmain's race window for concurrent title writes, and reusing a per-workerpooled(PAGE)scratch buffer sliced to&mut title_buf[..n](1 <= n <= PAGE) avoids per-page allocations without stale-byte leaks.cargo xtask policy: 191 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features): 0 warnings.cargo test --locked -p victory-gpu --features diagnostics --lib -- shadow:: watch:: --test-threads=1: 26/26 passed on both RTX 5090 (0.38s) and WARP (0.08s), includingparallel_marked_pages_go_back_and_retake_guards.merge_writeback): completed in 9.61 ms on Ryzen 9 9950X with 100% byte-exact shader + title merge and all 256 pages re-armed (copy.clean()).start = p + 0x100,len = 20 * PAGE - 0x200) plus a second overlappingShadowon page 0: verified clean serialization of page 0, exact partial-page bounds, and untouched bytes past the shadow end.#3343(both touchwatch.rs): 0 clippy warnings and 26/26watch::+shadow::tests passing.Synthetic tests only; looks ready to merge.
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.