GPU/HLE: import committed physical-page sections in place for title memory (#1905) #2494

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

@⁠nathanbzrr on GitHub · 2026-11-25 14:48 UTC · original
nathanbzrr:proto/issue-1905-inplace-remap → main · +707 −38 · 4 files · 1 commits · open

Addresses #1905.

Summary

Wires zero-reimport in-place physical-page section views directly into the runtime GPU title-memory page table (crates/victory-gpu/src/memory.rs) and xmem physical-page mappings (crates/victory-hle/src/modules/xmem.rs):

  • crates/victory-hle/src/modules/xmem.rs:
    • Commits physical-page sections up to 512 MiB (a raw buffer view's limit) whole with SEC_COMMIT on Windows as on Wine (falling back to SEC_RESERVE for multi-gigabyte reservations or if SEC_COMMIT fails).
    • Reports mapped committed section views (victory_gpu::title_memory_mapped) in xmem::map and section closure (victory_gpu::title_memory_section_freed) in Section::drop, while leaving xmem::map's placeholder splitting unchanged (avoiding overlap with #76 / #1224 / #2425).
  • crates/victory-gpu/src/memory.rs & crates/victory-gpu/src/watch.rs:
    • Imports each committed section handle once via ID3D12Device3::OpenExistingHeapFromFileMapping + CreatePlacedResource (ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER) and keeps one persistent raw (SRV, UAV) descriptor pair per view heap (Shared::rewrite).
    • Maps 64 KiB physical-page views in write_table to [pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)] (IN_PLACE owner), and trims/clears mappings on watch::title_memory_remapped.
    • Remaps, aliases, unmaps, and CPU VirtualProtect guard pages (PAGE_GUARD / PAGE_NOACCESS) update only the two-level GPU page table with 0 heap re-imports and 0 new resources.

Empirical D3D12/Win32 notes and remap benchmarks remain in #1905.

Verification

  • cargo run -p xtask -- policy: 191 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings
  • cargo test -p victory-gpu --lib memory --locked: 22/22 passed (including section_views_resolve_offsets_and_aliases_in_place and section_views_survive_guards_and_remaps_with_one_import)
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib memory --locked: 22/22 passed (0 D3D12 debug errors)
  • cargo test -p victory-hle --lib xmem --locked: 15/15 passed (including a_live_range_survives_a_guard_page_and_subrange_remaps)

AI-assisted; synthetic tests only, no game files used.

**@⁠nathanbzrr** on GitHub · 2026-11-25 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2494) `nathanbzrr:proto/issue-1905-inplace-remap` → `main` · +707 −38 · 4 files · 1 commits · open Addresses #1905. ## Summary Wires zero-reimport in-place physical-page section views directly into the runtime GPU title-memory page table (`crates/victory-gpu/src/memory.rs`) and `xmem` physical-page mappings (`crates/victory-hle/src/modules/xmem.rs`): - **`crates/victory-hle/src/modules/xmem.rs`**: - Commits physical-page sections up to 512 MiB (a raw buffer view's limit) whole with `SEC_COMMIT` on Windows as on Wine (falling back to `SEC_RESERVE` for multi-gigabyte reservations or if `SEC_COMMIT` fails). - Reports mapped committed section views (`victory_gpu::title_memory_mapped`) in `xmem::map` and section closure (`victory_gpu::title_memory_section_freed`) in `Section::drop`, while leaving `xmem::map`'s placeholder splitting unchanged (avoiding overlap with #76 / #1224 / #2425). - **`crates/victory-gpu/src/memory.rs` & `crates/victory-gpu/src/watch.rs`**: - Imports each committed section handle once via `ID3D12Device3::OpenExistingHeapFromFileMapping` + `CreatePlacedResource` (`ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER`) and keeps one persistent raw `(SRV, UAV)` descriptor pair per view heap (`Shared::rewrite`). - Maps 64 KiB physical-page views in `write_table` to `[pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)]` (`IN_PLACE` owner), and trims/clears mappings on `watch::title_memory_remapped`. - Remaps, aliases, unmaps, and CPU `VirtualProtect` guard pages (`PAGE_GUARD` / `PAGE_NOACCESS`) update only the two-level GPU page table with 0 heap re-imports and 0 new resources. Empirical D3D12/Win32 notes and remap benchmarks remain in #1905. ## Verification - `cargo run -p xtask -- policy`: `191 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: 0 warnings - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings - `cargo test -p victory-gpu --lib memory --locked`: 22/22 passed (including `section_views_resolve_offsets_and_aliases_in_place` and `section_views_survive_guards_and_remaps_with_one_import`) - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib memory --locked`: 22/22 passed (0 D3D12 debug errors) - `cargo test -p victory-hle --lib xmem --locked`: 15/15 passed (including `a_live_range_survives_a_guard_page_and_subrange_remaps`) AI-assisted; synthetic tests only, no game files used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:28 +00:00
github-bot force-pushed github-bot/gh-2494 from 593f02b38d to e34b586eb8 2026-11-26 06:31:46 +00:00 Compare
github-bot changed title from GPU/HLE: zero-reimport in-place memory remap prototype over SEC_COMMIT sections (#1905) to GPU/HLE: import committed physical-page sections in place for title memory (#1905) 2026-11-26 07:27:45 +00:00
github-bot force-pushed github-bot/gh-2494 from e34b586eb8 to 1a20686621 2026-11-26 07:27:45 +00:00 Compare
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:15 UTC · original

Automated triage for the maintainers.

Thanks for the detailed write-up of the Win32/D3D12 findings. As it stands the PR is not mergeable, for these reasons:

  • The new module isn't used by the runtime. crates/victory-gpu/src/inplace.rs (about 2,900 lines) adds InplaceArena/InplaceContext, capability probes and a benchmark. Nothing in the GPU path calls it, and the new xmem::mapped_runs and xmem::allocate_committed_physical_pages have no callers outside tests. Merging it would add a large unused module, plus public API in victory-hle that exists only for it.
  • The design notes need to move out of the code. The module header and much of the PR body give the design rationale. The repo keeps docs and comments short, so this material fits better in the issue (#1905).
  • One change affects the live game. xmem::map now goes through the new prepare_placeholder split/coalesce path, which every physical-page mapping the title makes will use. That is a real behaviour change, and a 3,800-line prototype hides it. The PR also notes it overlaps #76, #1224 and #2425.

What would change the verdict: split the work. First, a small PR with only the prepare_placeholder fix to xmem::map, its unit tests, and evidence that it fixes a failure the title hits (for example, the VirtualFree error 87 from #1947 reproduced on an actual mapping sequence). Second, the arena itself, once it is wired into the GPU memory path, with the probes and benchmark left out or kept much smaller.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2494#issuecomment-7184258139) <!-- victory-triage v1 head=e34b586eb85caf0c7bb896f1c32470a65c22a73e verdict=needs-work at=2026-11-26T06:16:00Z --> Automated triage for the maintainers. Thanks for the detailed write-up of the Win32/D3D12 findings. As it stands the PR is not mergeable, for these reasons: - **The new module isn't used by the runtime.** `crates/victory-gpu/src/inplace.rs` (about 2,900 lines) adds `InplaceArena`/`InplaceContext`, capability probes and a benchmark. Nothing in the GPU path calls it, and the new `xmem::mapped_runs` and `xmem::allocate_committed_physical_pages` have no callers outside tests. Merging it would add a large unused module, plus public API in `victory-hle` that exists only for it. - **The design notes need to move out of the code.** The module header and much of the PR body give the design rationale. The repo keeps docs and comments short, so this material fits better in the issue (#1905). - **One change affects the live game.** `xmem::map` now goes through the new `prepare_placeholder` split/coalesce path, which every physical-page mapping the title makes will use. That is a real behaviour change, and a 3,800-line prototype hides it. The PR also notes it overlaps #76, #1224 and #2425. What would change the verdict: split the work. First, a small PR with only the `prepare_placeholder` fix to `xmem::map`, its unit tests, and evidence that it fixes a failure the title hits (for example, the `VirtualFree` error 87 from #1947 reproduced on an actual mapping sequence). Second, the arena itself, once it is wired into the GPU memory path, with the probes and benchmark left out or kept much smaller. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-26 07:20 UTC · original

Addressed the triage items at head 1a20686 (rebased on origin/main 63bcca4):

  1. Wired into the runtime GPU memory path (crates/victory-gpu/src/memory.rs, crates/victory-gpu/src/watch.rs, crates/victory-hle/src/modules/xmem.rs) and removed unused code/APIs:
    • Removed the standalone crates/victory-gpu/src/inplace.rs module (including InplaceArena, InplaceContext, capability probes, and benchmark) and removed the test-only public items in xmem.rs (PhysicalSection, MappedRun, mapped_runs, allocate_committed_physical_pages).
    • xmem::map and Section::drop now notify victory_gpu::title_memory_mapped and victory_gpu::title_memory_section_freed, and watch::title_memory_remapped updates memory::unmapped.
    • memory::Shared::rewrite imports each committed physical-page section once via OpenExistingHeapFromFileMapping + CreatePlacedResource (ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER), allocates one persistent raw (SRV, UAV) pair per view heap, and populates write_table with [pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)] (IN_PLACE owner).
  2. Removed the overlapping prepare_placeholder change in xmem::map:
    • Reverted xmem::map's placeholder coalescing back to main's implementation so it does not overlap #76, #1224, or #2425.
  3. Moved design notes out of the code and shortened the PR description:
    • Kept comments in memory.rs and xmem.rs and the PR body concise (referencing #1905 for the empirical D3D12 findings and benchmarks).

Verified on Windows MSVC (1a20686):

  • cargo run -p xtask -- policy: 191 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features: 0 warnings
  • cargo test -p victory-gpu --lib memory --locked: 22/22 passed
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib memory --locked: 22/22 passed
  • cargo test -p victory-hle --lib xmem --locked: 15/15 passed
**@⁠nathanbzrr** on GitHub · 2026-11-26 07:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2494#issuecomment-7185343795) Addressed the triage items at head `1a20686` (rebased on `origin/main` `63bcca4`): 1. **Wired into the runtime GPU memory path (`crates/victory-gpu/src/memory.rs`, `crates/victory-gpu/src/watch.rs`, `crates/victory-hle/src/modules/xmem.rs`) and removed unused code/APIs**: - Removed the standalone `crates/victory-gpu/src/inplace.rs` module (including `InplaceArena`, `InplaceContext`, capability probes, and benchmark) and removed the test-only public items in `xmem.rs` (`PhysicalSection`, `MappedRun`, `mapped_runs`, `allocate_committed_physical_pages`). - `xmem::map` and `Section::drop` now notify `victory_gpu::title_memory_mapped` and `victory_gpu::title_memory_section_freed`, and `watch::title_memory_remapped` updates `memory::unmapped`. - `memory::Shared::rewrite` imports each committed physical-page section once via `OpenExistingHeapFromFileMapping` + `CreatePlacedResource` (`ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER`), allocates one persistent raw `(SRV, UAV)` pair per view heap, and populates `write_table` with `[pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)]` (`IN_PLACE` owner). 2. **Removed the overlapping `prepare_placeholder` change in `xmem::map`**: - Reverted `xmem::map`'s placeholder coalescing back to `main`'s implementation so it does not overlap #76, #1224, or #2425. 3. **Moved design notes out of the code and shortened the PR description**: - Kept comments in `memory.rs` and `xmem.rs` and the PR body concise (referencing #1905 for the empirical D3D12 findings and benchmarks). Verified on Windows MSVC (`1a20686`): - `cargo run -p xtask -- policy`: `191 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features`: 0 warnings - `cargo test -p victory-gpu --lib memory --locked`: 22/22 passed - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib memory --locked`: 22/22 passed - `cargo test -p victory-hle --lib xmem --locked`: 15/15 passed
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-26 14:48 UTC · original

First run on NVIDIA hardware, as far as I can see (the description and comments only mention WARP): RTX 4060 8 GB, driver 621.14, Windows 11 Pro 26300. Head 1a20686 merged onto main 63bcca4, cargo test -p victory-gpu --lib --locked -- --test-threads=1. Synthetic only, no game files.

  • section_views_resolve_offsets_and_aliases_in_place: passes.
  • section_views_survive_guards_and_remaps_with_one_import: fails, but only on the test's heap-layout assumption. It stops at assert!(initial_pair >= 1 << 18) (memory.rs:1614). Before that, the GPU reads through the imported section (OpenExistingHeapFromFileMapping + placed buffer) return the right markers for all six pages, so the import works on this driver. NVIDIA caps the view heap at 1,000,000, so HostHeap::new takes the capped layout and pair() comes from the dynamic slots. Here the section's pair was slot 2. With that assert replaced by a print, the whole test passes (guard page, PAGE_NOACCESS, the remap into three pieces, one import).
  • Otherwise the same as main on this card: the 2 known capped-heap failures (#1835).

Suggestion: assert that the pair is a valid slot of heap() (for example initial_pair < views.count + views.dynamic and not the null pair) rather than >= 1 << 18, so the test holds on capped hosts.

AI-assisted (Claude)

**@⁠potatoe0100** on GitHub · 2026-11-26 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2494#issuecomment-7195352382) First run on NVIDIA hardware, as far as I can see (the description and comments only mention WARP): **RTX 4060 8 GB**, driver 621.14, Windows 11 Pro 26300. Head `1a20686` merged onto `main` `63bcca4`, `cargo test -p victory-gpu --lib --locked -- --test-threads=1`. Synthetic only, no game files. - `section_views_resolve_offsets_and_aliases_in_place`: passes. - `section_views_survive_guards_and_remaps_with_one_import`: **fails, but only on the test's heap-layout assumption.** It stops at `assert!(initial_pair >= 1 << 18)` (memory.rs:1614). Before that, the GPU reads through the imported section (`OpenExistingHeapFromFileMapping` + placed buffer) return the right markers for all six pages, so the import works on this driver. NVIDIA caps the view heap at 1,000,000, so `HostHeap::new` takes the capped layout and `pair()` comes from the dynamic slots. Here the section's pair was slot **2**. With that assert replaced by a print, the whole test passes (guard page, `PAGE_NOACCESS`, the remap into three pieces, one import). - Otherwise the same as `main` on this card: the 2 known capped-heap failures (#1835). Suggestion: assert that the pair is a valid slot of `heap()` (for example `initial_pair < views.count + views.dynamic` and not the null pair) rather than `>= 1 << 18`, so the test holds on capped hosts. AI-assisted (Claude)
This pull request can be merged automatically.
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/2494/head:github-bot/gh-2494'
git switch 'github-bot/gh-2494'

Merge

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