GPU: page mapping copies wait for the submission that is running #2303

Open
github-bot wants to merge 1 commit from github-bot/gh-2303 into main AGit
Owner

@⁠denkencar-sketch on GitHub · 2026-11-25 10:05 UTC · original
denkencar-sketch:fix/queue-002 → main · +39 −1 · 2 files · 1 commits · open

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; other xmem locks were not audited. Cost: a remap waits up to a frame; not measured.

Testing

Test page_mappings_wait_for_a_running_submission fails without the lock and passes with this change. cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

Not tried: streaming throughput, or a run in the game.

AI-assisted.

**@⁠denkencar-sketch** on GitHub · 2026-11-25 10:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303) `denkencar-sketch:fix/queue-002` → `main` · +39 −1 · 2 files · 1 commits · open ## 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`; other `xmem` locks were not audited. Cost: a remap waits up to a frame; not measured. ## Testing Test `page_mappings_wait_for_a_running_submission` fails without the lock and passes with this change. `cargo test --workspace --locked` passes apart from known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). Not tried: streaming throughput, or a run in the game. AI-assisted.
Remapping title pages under a submission's reads and copy-backs could
fault it; the host's submission lock now covers the remap.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:01:36 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:21 UTC · original · edited 2026-11-26 00:20 UTC

Automated triage for the maintainers.

Merge candidate. copy_page_mappings (crates/victory-gpu/src/queue.rs) now holds Host::submitted (through the new Host::hold_submissions in host.rs) while it remaps pages, so a remap waits for the running submission instead of unmapping title memory under its reads and copy-backs. The held().holds_work(..) lock is taken and released before the new lock, and Host::execute takes submitted first, 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 execute and copy_page_mappings. tumbubu's in-game samples in this thread show the race on main (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

**@⁠Marvisak** on GitHub · 2026-11-25 15:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303#issuecomment-7166717174) · edited 2026-11-26 00:20 UTC <!-- victory-triage v1 head=63f6881cebad990dcc00e881afa62c657b8659fc verdict=merge-candidate at=2026-11-26T00:20:13Z --> Automated triage for the maintainers. **Merge candidate.** `copy_page_mappings` (`crates/victory-gpu/src/queue.rs`) now holds `Host::submitted` (through the new `Host::hold_submissions` in `host.rs`) while it remaps pages, so a remap waits for the running submission instead of unmapping title memory under its reads and copy-backs. The `held().holds_work(..)` lock is taken and released before the new lock, and `Host::execute` takes `submitted` first, 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 `execute` and `copy_page_mappings`. tumbubu's in-game samples in this thread show the race on `main` (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](https://claude.ai/code)_
Author
Owner

@⁠tumbubu on GitHub · 2026-11-25 21:50 UTC · original

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 CopyPageMappingsBatchX while a submission runs on another thread?

  • Setup: AMD Radeon RX 7900 XT, driver 32.0.31036.15, Windows 11 Pro 26300.
  • Builds: diag builds (--profile diag --features diagnostics) of main 13f91ca, and of this PR cherry-picked onto it (clean, 31416d0).
  • Runs: warm shader cache and pipeline library, 180 s each, Enter every 3 s from 8 s to 47 s.
  • Sampling: VICTORY_STACKS, a dump every 0.25 s from 105 s to 175 s, which came to 74 dumps on main and 82 here. I symbolised victory.exe frames and source lines from the build's PDB.

On main: the title remaps under running submissions.

per dump (main, 74) count
submission thread inside Host::execute 70
a title thread inside copy_page_mappings → xmem::map_alias → UnmapViewOfFile2 / MapViewOfFile3 19
both at once 18
  • In those 18 dumps the submission thread was working on title memory: watch::protect_noting and changed, copy_mapped, write_mapped, texture::refresh_all, shadow::copy_back_marks, memory::Shared::rewrite. 12 of the 18 remaps were unmaps.
  • Caveat: VICTORY_STACKS suspends 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 inside Host::execute in 70 of 74 dumps, a remap that does not overlap a submission would be the exception.

With this PR: the overlaps become waits.

per dump main (74) this PR (82)
remap and Host::execute in the same dump 18 17
…of which the submission thread is waiting at host.rs:1136 (submitted) 0 13
submission thread blocked on any lock 1 14

The 4 dumps left, where the submission seems to be working during a remap, are what the non-atomic dumps above allow. execute takes submitted at its first line.

Cost.

  • The waits move onto the submission thread, which is the critical path here: 14 of 82 dumps against 1 of 74.
  • In the frame lines it does not show beyond the spread. World lines are frame-rate lines under 10 fps with at least 500 draws:
run fps ms/frame preparing on the GPU copying back draws/frame
main, 3 runs 1.53 / 1.54 / 1.66 918 / 760 / 712 379 / 414 / 409 199 / 202 / 178 93 / 107 / 86 3913 / 3535 / 4370
this PR, 2 runs 1.45 / 1.47 783 / 824 411 / 399 222 / 191 90 / 100 3740 / 3661
  • Two of the runs above were sampled. One main run had VICTORY_SHADER_LOOP_LIMIT=4096, which only changes shaders.
  • Neither run of this PR hung or removed the device. I did not audit the lock order against the other xmem locks.

One more thing the samples show on main. The title's mapping thread is already blocked at queue.rs:636 in 31 of 74 dumps, and in 35 of 82 with this PR. That line is held().holds_work(..) for the mappings count of the held-work frame line. pump holds HELD for 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. A try_lock there 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=1 on 31416d0: 196 passed, 0 failed, 1 ignored, page_mappings_wait_for_a_running_submission included.

AI-assisted (Claude Code); every run was on this machine. Only timings, counts and VIctory's own function names are posted, no game files.

**@⁠tumbubu** on GitHub · 2026-11-25 21:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303#issuecomment-7175610687) **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 `CopyPageMappingsBatchX` while a submission runs on another thread? - **Setup:** AMD Radeon RX 7900 XT, driver 32.0.31036.15, Windows 11 Pro 26300. - **Builds:** diag builds (`--profile diag --features diagnostics`) of `main` `13f91ca`, and of this PR cherry-picked onto it (clean, `31416d0`). - **Runs:** warm shader cache and pipeline library, 180 s each, Enter every 3 s from 8 s to 47 s. - **Sampling:** `VICTORY_STACKS`, a dump every 0.25 s from 105 s to 175 s, which came to 74 dumps on `main` and 82 here. I symbolised `victory.exe` frames and source lines from the build's PDB. **On `main`: the title remaps under running submissions.** | per dump (`main`, 74) | count | |---|---:| | submission thread inside `Host::execute` | 70 | | a title thread inside `copy_page_mappings` → `xmem::map_alias` → `UnmapViewOfFile2` / `MapViewOfFile3` | 19 | | both at once | 18 | - In those 18 dumps the submission thread was working on title memory: `watch::protect_noting` and `changed`, `copy_mapped`, `write_mapped`, `texture::refresh_all`, `shadow::copy_back_marks`, `memory::Shared::rewrite`. 12 of the 18 remaps were unmaps. - **Caveat:** `VICTORY_STACKS` suspends 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 inside `Host::execute` in 70 of 74 dumps, a remap that does not overlap a submission would be the exception. **With this PR: the overlaps become waits.** | per dump | `main` (74) | this PR (82) | |---|---:|---:| | remap and `Host::execute` in the same dump | 18 | 17 | | …of which the submission thread is waiting at `host.rs:1136` (`submitted`) | 0 | **13** | | submission thread blocked on any lock | 1 | 14 | The 4 dumps left, where the submission seems to be working during a remap, are what the non-atomic dumps above allow. `execute` takes `submitted` at its first line. **Cost.** - The waits move onto the submission thread, which is the critical path here: 14 of 82 dumps against 1 of 74. - In the frame lines it does not show beyond the spread. World lines are frame-rate lines under 10 fps with at least 500 draws: | run | fps | ms/frame | preparing | on the GPU | copying back | draws/frame | |---|---:|---:|---:|---:|---:|---:| | `main`, 3 runs | 1.53 / 1.54 / 1.66 | 918 / 760 / 712 | 379 / 414 / 409 | 199 / 202 / 178 | 93 / 107 / 86 | 3913 / 3535 / 4370 | | this PR, 2 runs | 1.45 / 1.47 | 783 / 824 | 411 / 399 | 222 / 191 | 90 / 100 | 3740 / 3661 | - Two of the runs above were sampled. One `main` run had `VICTORY_SHADER_LOOP_LIMIT=4096`, which only changes shaders. - Neither run of this PR hung or removed the device. I did not audit the lock order against the other `xmem` locks. **One more thing the samples show on `main`.** The title's mapping thread is already blocked at `queue.rs:636` in 31 of 74 dumps, and in 35 of 82 with this PR. That line is `held().holds_work(..)` for the `mappings` count of the held-work frame line. `pump` holds `HELD` for 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. A `try_lock` there 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=1` on `31416d0`: 196 passed, 0 failed, 1 ignored, `page_mappings_wait_for_a_running_submission` included. AI-assisted (Claude Code); every run was on this machine. Only timings, counts and VIctory's own function names are posted, no game files.
Author
Owner

@⁠denkencar-sketch on GitHub · 2026-11-25 23:30 UTC · original

Rebased onto current \main\ (\842b0cb) and addressed the remaining triage items:

  • Updated the doc comment on \copy_page_mappings.
  • Added #[cfg(windows)]\ on the new test.
  • Checked lock ordering against \xmem: \copy_page_mappings\ takes \Host::submitted\ → \xmem::PHYSICAL\ (\map_alias) → \watch::GUARDS. \Host::execute\ takes \Host::submitted\ → \watch::GUARDS\ and nothing in \xmem\ ever acquires \Host::submitted, so \Host::submitted\ stays strictly outermost.

\queue::tests\ and \clippy\ pass.

**@⁠denkencar-sketch** on GitHub · 2026-11-25 23:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303#issuecomment-7177654107) Rebased onto current \main\ (\842b0cb\) and addressed the remaining triage items: - Updated the doc comment on \copy_page_mappings\. - Added \#[cfg(windows)]\ on the new test. - Checked lock ordering against \xmem\: \copy_page_mappings\ takes \Host::submitted\ → \xmem::PHYSICAL\ (\map_alias\) → \watch::GUARDS\. \Host::execute\ takes \Host::submitted\ → \watch::GUARDS\ and nothing in \xmem\ ever acquires \Host::submitted\, so \Host::submitted\ stays strictly outermost. \queue::tests\ and \clippy\ pass.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 10:19 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 10:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303#pullrequestreview-6055713891) · **reviewed** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 19:51 UTC · original · approved these changes

Reviewed and verified 63f6881cebad990dcc00e881afa62c657b8659fc merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, --features diagnostics with VICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).

Lock-Order & Code Audit

  • In queue::copy_page_mappings (crates/victory-gpu/src/queue.rs:667-678), held().holds_work(...) drops the HELD guard before Host::hold_submissions (crates/victory-gpu/src/host.rs:1157-1159) acquires Host::submitted.
  • Audited all callers of resource::page_mapper() and Host::submitted across victory-gpu and victory-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 inside copy_page_mappings, never inside Host::execute, and nothing in xmem acquires Host::submitted or HELD. 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.
  • Additional multi-threaded stress probe racing 40 Host::execute submissions concurrently against tight-loop copy_page_mappings calls: 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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 19:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2303#pullrequestreview-6079792478) · **approved these changes** Reviewed and verified `63f6881cebad990dcc00e881afa62c657b8659fc` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (RTX 5090 + Microsoft WARP, `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1 MSVC). ### Lock-Order & Code Audit - In `queue::copy_page_mappings` (`crates/victory-gpu/src/queue.rs:667-678`), `held().holds_work(...)` drops the `HELD` guard before `Host::hold_submissions` (`crates/victory-gpu/src/host.rs:1157-1159`) acquires `Host::submitted`. - Audited all callers of `resource::page_mapper()` and `Host::submitted` across `victory-gpu` and `victory-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 inside `copy_page_mappings`, never inside `Host::execute`, and nothing in `xmem` acquires `Host::submitted` or `HELD`. 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. - Additional multi-threaded stress probe racing 40 `Host::execute` submissions concurrently against tight-loop `copy_page_mappings` calls: 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2303/head:github-bot/gh-2303'
git switch 'github-bot/gh-2303'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2303'
git switch 'github-bot/gh-2303'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2303'
git switch 'github-bot/gh-2303'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2303'
git switch 'main'
git merge --squash 'github-bot/gh-2303'
git switch 'main'
git merge --ff-only 'github-bot/gh-2303'
git switch 'main'
git merge 'github-bot/gh-2303'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2303
No description provided.