XMem: preserve overlapping source pages during GPU mapping copies #2199

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

@⁠Razdva122 on GitHub · 2026-11-25 07:32 UTC · original
Razdva122:fix/gpu-copy-page-mapping-sources → main · +114 −18 · 1 files · 1 commits · open

The GPU queue calls xmem::map_alias to copy physical page mappings. On main, it removes the destination range before looking up the source pages. On an overlapping move this can erase the source before it is read. A source range with a hole can also discard a valid destination before the copy reports failure.

This addresses one existing page-mapping case from #1905. The broader lifetime of host-imported GPU memory across protection changes remains open. Coordination thread

Resolve the entire source range while the physical mapping lock is held, retaining its section references and starting page indices. Only then replace the destination page mappings. A missing source page returns before any destination change. A single source view needs no temporary vector allocation. As before, an OS refusal while installing a destination mapping can interrupt a copy.

The regression uses real Windows placeholder reservations and physical sections with synthetic contents. It checks forward and backward overlap, a self-copy, a source with a hole and repeated physical pages. A write through one address verifies that the resulting mappings still share their backing page. With the previous implementation, a one-page forward shift mapped all five addresses to the first page: reading the sentinels returned [1, 1, 1, 1, 1]. The corrected code returned [1, 1, 2, 3, 4] on the same Windows runner. The full workspace suite and both Clippy configurations passed. Windows comparison and test log A run with the title has not been performed.

AI-assisted with Codex.

**@⁠Razdva122** on GitHub · 2026-11-25 07:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199) `Razdva122:fix/gpu-copy-page-mapping-sources` → `main` · +114 −18 · 1 files · 1 commits · open The GPU queue calls `xmem::map_alias` to copy physical page mappings. On main, it removes the destination range before looking up the source pages. On an overlapping move this can erase the source before it is read. A source range with a hole can also discard a valid destination before the copy reports failure. This addresses one existing page-mapping case from #1905. The broader lifetime of host-imported GPU memory across protection changes remains open. [Coordination thread](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Resolve the entire source range while the physical mapping lock is held, retaining its section references and starting page indices. Only then replace the destination page mappings. A missing source page returns before any destination change. A single source view needs no temporary vector allocation. As before, an OS refusal while installing a destination mapping can interrupt a copy. The regression uses real Windows placeholder reservations and physical sections with synthetic contents. It checks forward and backward overlap, a self-copy, a source with a hole and repeated physical pages. A write through one address verifies that the resulting mappings still share their backing page. With the previous implementation, a one-page forward shift mapped all five addresses to the first page: reading the sentinels returned `[1, 1, 1, 1, 1]`. The corrected code returned `[1, 1, 2, 3, 4]` on the same Windows runner. The full workspace suite and both Clippy configurations passed. [Windows comparison and test log](https://github.com/Razdva122/VIctory/actions/runs/45568944804/job/139050543733) A run with the title has not been performed. AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:10 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 08:52 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 365a2a49 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7157573080) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `365a2a49` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:28 UTC · original

Automated triage for the maintainers.

xmem::map_alias (crates/victory-hle/src/modules/xmem.rs) now resolves every source page under the physical lock before it unmaps the destination, so an overlapping copy no longer reads pages it has just erased; main's unmap-first order really does lose the source on a forward shift, and the new test covers forward/backward overlap, self-copy, a source hole and shared backing. Two smaller behaviour changes worth a glance: a source with a hole now leaves the destination mapped instead of unmapped, and unaligned addresses or lengths are refused (the only caller, copy_page_mappings in victory-gpu/src/queue.rs, always passes 64 KiB multiples). CI passes, and a tester reports the full suite passing on RDNA2.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7163837420) <!-- victory-triage v1 head=365a2a491ffde3629b57cceb3855e34565baa5ae verdict=merge-candidate at=2026-11-25T13:32:00Z --> Automated triage for the maintainers. `xmem::map_alias` (`crates/victory-hle/src/modules/xmem.rs`) now resolves every source page under the physical lock before it unmaps the destination, so an overlapping copy no longer reads pages it has just erased; main's `unmap`-first order really does lose the source on a forward shift, and the new test covers forward/backward overlap, self-copy, a source hole and shared backing. Two smaller behaviour changes worth a glance: a source with a hole now leaves the destination mapped instead of unmapped, and unaligned addresses or lengths are refused (the only caller, `copy_page_mappings` in `victory-gpu/src/queue.rs`, always passes 64 KiB multiples). CI passes, and a tester reports the full suite passing on RDNA2. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:51 UTC · original

Code review and Windows 11 verification at head 365a2a491ffd merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-hle/src/modules/xmem.rs:773-837):
    • Snapshotting (Slice { index, section: Arc<Section> }, run_bytes) across [from, from + len) before mutating [to, to + len) cleanly fixes both forward/backward overlapping mapping copies and source holes (returning false without touching the destination), while self-copy (from == to) returns true after source validation and title_memory_remapped/title_memory_aliased keep GPU page watches and physical.shown coherent.
    • Minor note (matches prior behavior): if host map() fails partway through remapping the destination after unmap, earlier destination runs remain mapped (only reachable under host commit exhaustion / non-placeholder target).
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-hle --tests -- -D warnings: 0 warnings
    • cargo test --locked -p victory-hle -- xmem: 15/15 passed (including gpu_page_copies_keep_the_source_mappings).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7179183987) Code review and Windows 11 verification at head `365a2a491ffd` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-hle/src/modules/xmem.rs:773-837`)**: - Snapshotting `(Slice { index, section: Arc<Section> }, run_bytes)` across `[from, from + len)` before mutating `[to, to + len)` cleanly fixes both forward/backward overlapping mapping copies and source holes (returning `false` without touching the destination), while self-copy (`from == to`) returns `true` after source validation and `title_memory_remapped`/`title_memory_aliased` keep GPU page watches and `physical.shown` coherent. - Minor note (matches prior behavior): if host `map()` fails partway through remapping the destination after `unmap`, earlier destination runs remain mapped (only reachable under host commit exhaustion / non-placeholder target). - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-hle --tests -- -D warnings`: 0 warnings - `cargo test --locked -p victory-hle -- xmem`: **15/15 passed** (including `gpu_page_copies_keep_the_source_mappings`). LGTM.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 07:42 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-hle --lib xmem:: — 11 passed, 0 failed (including gpu_page_copies_keep_the_source_mappings)
  • cargo clippy -p victory-hle --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean preservation of overlapping source pages during GPU mapping copies in xmem.rs. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 07:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6053615479) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-hle --lib xmem::` — **11 passed, 0 failed** (including `gpu_page_copies_keep_the_source_mappings`) - `cargo clippy -p victory-hle --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean preservation of overlapping source pages during GPU mapping copies in `xmem.rs`. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:03 UTC · original · reviewed

Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.

XMem overlapping source pages preserved during GPU mapping copy — memmove-overlap fix; relates to #2213's xmem page-run coalescing.

**@⁠catminou4** on GitHub · 2026-11-25 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6053836805) · **reviewed** Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff. XMem overlapping source pages preserved during GPU mapping copy — memmove-overlap fix; relates to #2213's xmem page-run coalescing.
Author
Owner

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

Reviewed and verified 365a2a49 merged locally onto origin/main (63bcca43) on Windows 11 x64 (Rust 1.98.1 MSVC; synthetic tests only, no game files).

Verification

  • git merge-tree against origin/main (63bcca43): clean.
  • cargo xtask policy (PR head): 182 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings (default and --all-features, PR head and merged): 0 warnings.
  • Dev tests (merged): cargo test --locked -p victory-hle --lib -- xmem:: — 15 passed, 0 failed (including gpu_page_copies_keep_the_source_mappings); full cargo test --locked -p victory-hle --lib — 153 passed, 0 failed.
  • Release tests (merged): cargo test --locked --release -p victory-hle --lib -- xmem:: — 15 passed, 0 failed.
  • Extra edge-case checks (dev & --release): verified len == 0, unaligned to/from/len, u64 overflow in to + len and from + len, self-copy spanning an unmapped hole returning false, and forward overlapping copies across multiple distinct non-contiguous source views.

Review Notes

  • Resolving and snapshotting (Slice { index, section: Arc<Section> }, run_bytes) across [from, from + len) under physical() (crates/victory-hle/src/modules/xmem.rs:769-792) before unmapping [to, to + len) (:796) fixes both overlapping forward copies and source holes leaving the destination unmapped, while keeping the single-view hot path allocation-free.
  • Validating the source range before the from == to early return (:793-795) preserves the contract that a self-copy containing an unmapped source page returns false.
  • Note for maintainers: merging alongside #1935 has a trivial test-only hunk conflict in crates/victory-hle/src/modules/xmem.rs (mod tests), with no production-code overlap.

Looks good to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 13:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6074798358) · **approved these changes** Reviewed and verified `365a2a49` merged locally onto `origin/main` (`63bcca43`) on Windows 11 x64 (Rust `1.98.1` MSVC; synthetic tests only, no game files). ### Verification - `git merge-tree` against `origin/main` (`63bcca43`): clean. - `cargo xtask policy` (PR head): `182 files ok`. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` (default and `--all-features`, PR head and merged): 0 warnings. - **Dev tests (merged):** `cargo test --locked -p victory-hle --lib -- xmem::` — **15 passed, 0 failed** (including `gpu_page_copies_keep_the_source_mappings`); full `cargo test --locked -p victory-hle --lib` — **153 passed, 0 failed**. - **Release tests (merged):** `cargo test --locked --release -p victory-hle --lib -- xmem::` — **15 passed, 0 failed**. - **Extra edge-case checks (dev & `--release`):** verified `len == 0`, unaligned `to`/`from`/`len`, `u64` overflow in `to + len` and `from + len`, self-copy spanning an unmapped hole returning `false`, and forward overlapping copies across multiple distinct non-contiguous source views. ### Review Notes - Resolving and snapshotting `(Slice { index, section: Arc<Section> }, run_bytes)` across `[from, from + len)` under `physical()` (`crates/victory-hle/src/modules/xmem.rs:769-792`) before unmapping `[to, to + len)` (`:796`) fixes both overlapping forward copies and source holes leaving the destination unmapped, while keeping the single-view hot path allocation-free. - Validating the source range before the `from == to` early return (`:793-795`) preserves the contract that a self-copy containing an unmapped source page returns `false`. - Note for maintainers: merging alongside `#1935` has a trivial test-only hunk conflict in `crates/victory-hle/src/modules/xmem.rs` (`mod tests`), with no production-code overlap. 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/2199/head:github-bot/gh-2199'
git switch 'github-bot/gh-2199'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2199'
git switch 'github-bot/gh-2199'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2199'
git switch 'github-bot/gh-2199'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2199'
git switch 'main'
git merge --squash 'github-bot/gh-2199'
git switch 'main'
git merge --ff-only 'github-bot/gh-2199'
git switch 'main'
git merge 'github-bot/gh-2199'
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!2199
No description provided.