Repository navigation
GPU: marked pages go back to title memory on several threads (#2826) - #2914
kotekompotek wants to merge 1 commit into
Conversation
The copy-back of marked pages compared and wrote about 2,000 pages of 64 KiB a frame on the submitting thread, 55 to 80 us a page. Pages are now grouped by page index, so two buffers that cover the same page stay on one thread in their old order, and the groups are taken by up to six scoped threads, the submitting one among them. Fewer than sixteen pages stay on that thread. One run each at the same scene (medians, on a stack including Marvisak#2120, Marvisak#2130 and Marvisak#2280): marked pages 166 to 111 ms, copy-back 184 to 124 ms, frame 777 to 690 ms; same dropped draws and untranslated programs, no device removal. Ported to main from Machad3x/VIctory-nvidia-3080ti@7229f41 (Marvisak#2826), minus that fork's doc page. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 1c96dc2d cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).
Concurrency & Lock-Order Audit
- Same-page multi-Shadow serialization:
for_each_by_page(crates/victory-gpu/src/shadow.rs:901-925) sorts by virtual page and groups viachunk_by(|a, b| a.1 == b.1), ensuring multipleShadowbuffers overlapping the same 64 KiB title page run sequentially on one worker without data races. - Lock ordering & panic safety: Lock acquisition stays acyclic (
GUARDS->Changed.0->Changed.1), host-copy slices[from - start .. to - start]are disjoint per page, andstd::thread::scopepropagates worker panics cleanly without deadlock. - Minor observations (non-blocking):
watch::writing,Writing::drop, andt.takenstill serializeVirtualProtectunderGUARDS, so the parallel gain comes fromhost != title,read_into,merge_writeback, and memory copy work.- Theoretical edge case: if two distinct virtual pages alias the same physical page (
alias_of) and are both marked dirty via separate bufferShadows simultaneously, grouping by virtual page could process them on different threads (thoughalias_ofis primarily used for tiled texture heaps).
Local Verification (--features diagnostics, VICTORY_D3D12_DEBUG=1)
- RTX 5090:
shadow::+draw::tests31/31 (includingmany_marked_pages_all_go_back),watch::tests15/15. - WARP:
shadow::+draw::tests31/31. cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics) &cargo xtask policy(191 files ok): clean.
Looks clean and ready to merge.
|
Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval). In Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):
cargo test -p victory-gpu --lib shadow::tests: 10 passed, 0 failed (including newmany_marked_pages_all_go_back).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Parallelizing marked-page copy-back by page via for_each_by_page is clean and verified on hardware.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Independent AMD RDNA 4 / Ryzen 9 7950X verification of Setup: Windows 11 ( Checks:
Live title run (prison cell steady state, release build):
Notes:
Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity. |
|
A measurement for this one on an NVIDIA stack (RTX 4070 SUPER, Windows 11; main + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 + #2925 + #2958, prologue cell). Medians of the 5 s reports over the last 6 minutes of a 15-minute run:
On this machine the threads did not shorten the loop. Each page takes the guard lock three times ( |
|
Tested However, I reproduced an ordering issue with two virtual mappings of the same physical page. With the original mark order high-address then low-address:
This occurs with only two jobs, before parallel execution. Grouping by virtual address also appears insufficient to establish independence between workers when physical backing is shared. The temporary CPU-only reproduction is available if useful. Testing and analysis were performed with Codex assistance. |
Summary
Ports Machad3x/VIctory-nvidia-3080ti@
7229f41to main, per the #2826 triage invite ("PRs are open to everyone, so please open one with the commit and its test"). Authorship retained; that fork's doc page is left out.copy_back_marks' final loop runs throughfor_each_by_page: pages sorted and grouped by page index (copies covering one title page keep their order on one thread — thecopy_back_markedwrite/protection sequence stays single-writer per page), groups spread over up to six scoped threads including the submitting one.Tracked's changed/saved sets and arm bits (Mutex/atomics),watch::writing's guardsMutex,copystatcounters (AtomicU64);read_into/write_mappedtouch disjoint title ranges per group.The reporter's measurement (Ryzen 7 5700X, RTX 3080 Ti, medians, on a PR stack — #2120/#2130/#2280 — not main alone): marked pages 166→111 ms, copy-back 184→124 ms, frame 777→690 ms.
Test plan
cargo clippy -p victory-gpu --all-targets --locked -- -D warningscleanshadow::tests::many_marked_pages_all_go_back(96 marked pages over two overlapping copies) passes on GTX 1050mainalone (vs the PR stack) is still open — flagged in the issueGenerated with Devin