GPU: page mapping copies wait for the submission that is running #2301
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2303"
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?
Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T10:05:46Z.
Summary
Remapping title pages under a submission's reads and copy-backs could fault it. The host's submission lock now covers the page mapping copies, so they wait for the submission that is running. Lock order is submitted then mapper, and no reverse order was found in
map_alias; otherxmemlocks were not audited. Cost: a remap waits up to a frame; not measured.Testing
Test
page_mappings_wait_for_a_running_submissionfails without the lock and passes with this change.cargo test --workspace --lockedpasses apart from known flakes:modules::dstorage::tests::a_page_list_filled_after_its_request_startsfails now and then onmaintoo, and so does a parallel-run flake invictory-gpu's lib tests (watch::anddescriptor::host::tests, 2 of 40 runs on pristinemain).Not tried: streaming throughput, or a run in the game.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:19Z.
Review: COMMENTED
Page mapping copies wait for the running submission (hold_submissions lock). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Race fix between remap and in-flight reads/writes.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:21:33Z.
Automated triage for the maintainers.
Merge candidate.
copy_page_mappings(crates/victory-gpu/src/queue.rs) now holdsHost::submitted(through the newHost::hold_submissionsinhost.rs) while it remaps pages, so a remap waits for the running submission instead of unmapping title memory under its reads and copy-backs. Theheld().holds_work(..)lock is taken and released before the new lock, andHost::executetakessubmittedfirst, so the order is the same on both sides. The items left open last time are done: the doc comment is updated, the test has#[cfg(windows)], and the lock order is stated.On your reply: the lock-order reasoning matches what I read in
executeandcopy_page_mappings. tumbubu's in-game samples in this thread show the race onmain(18 of 74 dumps) and show it turning into waits with this change, with no measurable frame-time cost. CI: passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by tumbubu on 2026-11-25T21:50:41Z.
Evidence for the race from a run in the game on an RX 7900 XT. Then this PR, cherry-picked onto
13f91ca, measured the same way: remaps and submissions no longer overlap, and frame time shows no cost within run-to-run spread.This answers the triage's first request: does the title call
CopyPageMappingsBatchXwhile a submission runs on another thread?--profile diag --features diagnostics) ofmain13f91ca, and of this PR cherry-picked onto it (clean,31416d0).VICTORY_STACKS, a dump every 0.25 s from 105 s to 175 s, which came to 74 dumps onmainand 82 here. I symbolisedvictory.exeframes and source lines from the build's PDB.On
main: the title remaps under running submissions.main, 74)Host::executecopy_page_mappings→xmem::map_alias→UnmapViewOfFile2/MapViewOfFile3watch::protect_notingandchanged,copy_mapped,write_mapped,texture::refresh_all,shadow::copy_back_marks,memory::Shared::rewrite. 12 of the 18 remaps were unmaps.VICTORY_STACKSsuspends one thread at a time, and a dump of 96 threads takes about 1 s, so two threads in a dump are not captured at the same instant. But with the submission thread insideHost::executein 70 of 74 dumps, a remap that does not overlap a submission would be the exception.With this PR: the overlaps become waits.
main(74)Host::executein the same dumphost.rs:1136(submitted)The 4 dumps left, where the submission seems to be working during a remap, are what the non-atomic dumps above allow.
executetakessubmittedat its first line.Cost.
main, 3 runsmainrun hadVICTORY_SHADER_LOOP_LIMIT=4096, which only changes shaders.xmemlocks.One more thing the samples show on
main. The title's mapping thread is already blocked atqueue.rs:636in 31 of 74 dumps, and in 35 of 82 with this PR. That line isheld().holds_work(..)for themappingscount of the held-work frame line.pumpholdsHELDfor each whole pump, and so for the submissions it runs, so this diagnostic already makes most page mappings wait for pumped submissions. That is why the race only shows up for some of them. Atry_lockthere would stop the title waiting for a counter, but this PR's lock would then have to carry the ordering alone.Tests.
cargo test --locked -p victory-gpu --lib -- --test-threads=1on31416d0: 196 passed, 0 failed, 1 ignored,page_mappings_wait_for_a_running_submissionincluded.AI-assisted (Claude Code); every run was on this machine. Only timings, counts and VIctory's own function names are posted, no game files.
Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T23:30:23Z.
Rebased onto current \main\ (\
842b0cb) and addressed the remaining triage items:\queue::tests\ and \clippy\ pass.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:51:54Z.
Review: APPROVED
Reviewed and verified
63f6881cebad990dcc00e881afa62c657b8659fcmerged ontoorigin/main(63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP,--features diagnosticswithVICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).Lock-Order & Code Audit
queue::copy_page_mappings(crates/victory-gpu/src/queue.rs:667-678),held().holds_work(...)drops theHELDguard beforeHost::hold_submissions(crates/victory-gpu/src/host.rs:1157-1159) acquiresHost::submitted.resource::page_mapper()andHost::submittedacrossvictory-gpuandvictory-hle:queue::pump:HELD->Host::submitted->watch::GUARDS.queue::copy_page_mappings:Host::submitted->xmem::PHYSICAL(map_alias) ->watch::GUARDS.page_mapper()is only invoked insidecopy_page_mappings, never insideHost::execute, and nothing inxmemacquiresHost::submittedorHELD. The global lock order (HELD->Host::submitted->xmem::PHYSICAL->watch::GUARDS) is cycle-free.Local Verification
cargo xtask policy— pass (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 page_mappings_wait_for_a_running_submission(RTX 5090 and WARP) — passed.Host::executesubmissions concurrently against tight-loopcopy_page_mappingscalls: completed cleanly with zero deadlock or debug-layer errors on both RTX 5090 (40 execs,35,565 maps) and WARP (40 execs,23,395 maps).Looks good to merge.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T21:49:31Z.
Review: APPROVED
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib queue:: -- --test-threads=1: 6 passed, 0 failed (includingpage_mappings_wait_for_a_running_submission).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.