Skip to content

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

Open
nathanbzrr wants to merge 1 commit into
Marvisak:mainfrom
nathanbzrr:proto/issue-1905-inplace-remap
Open

nathanbzrr wants to merge 1 commit into
Marvisak:mainfrom
nathanbzrr:proto/issue-1905-inplace-remap

Conversation

@nathanbzrr

@nathanbzrr nathanbzrr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:
  • 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.

Copy link
Copy Markdown
Owner

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:

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

@nathanbzrr
nathanbzrr force-pushed the proto/issue-1905-inplace-remap branch from e34b586 to 1a20686 Compare November 26, 2026 07:19
@nathanbzrr nathanbzrr changed the title GPU/HLE: zero-reimport in-place memory remap prototype over SEC_COMMIT sections (#1905) GPU/HLE: import committed physical-page sections in place for title memory (#1905) Nov 26, 2026
@nathanbzrr

Copy link
Copy Markdown
Contributor Author

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:
  3. Moved design notes out of the code and shortened the PR description:

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

@potatoe0100

Copy link
Copy Markdown

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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants