GPU/HLE: import committed physical-page sections in place for title memory (#1905) #2492
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2494"
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 nathanbzrr on 2026-11-25T14:48:41Z.
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) andxmemphysical-page mappings (crates/victory-hle/src/modules/xmem.rs):crates/victory-hle/src/modules/xmem.rs:SEC_COMMITon Windows as on Wine (falling back toSEC_RESERVEfor multi-gigabyte reservations or ifSEC_COMMITfails).victory_gpu::title_memory_mapped) inxmem::mapand section closure (victory_gpu::title_memory_section_freed) inSection::drop, while leavingxmem::map's placeholder splitting unchanged (avoiding overlap with #76 / #1224 / #2425).crates/victory-gpu/src/memory.rs&crates/victory-gpu/src/watch.rs:ID3D12Device3::OpenExistingHeapFromFileMapping+CreatePlacedResource(ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER) and keeps one persistent raw(SRV, UAV)descriptor pair per view heap (Shared::rewrite).write_tableto[pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)](IN_PLACEowner), and trims/clears mappings onwatch::title_memory_remapped.VirtualProtectguard 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 okcargo clippy --workspace --all-targets --locked -- -D warnings: 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warningscargo test -p victory-gpu --lib memory --locked: 22/22 passed (includingsection_views_resolve_offsets_and_aliases_in_placeandsection_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 (includinga_live_range_survives_a_guard_page_and_subrange_remaps)AI-assisted; synthetic tests only, no game files used.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:15:58Z.
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:
crates/victory-gpu/src/inplace.rs(about 2,900 lines) addsInplaceArena/InplaceContext, capability probes and a benchmark. Nothing in the GPU path calls it, and the newxmem::mapped_runsandxmem::allocate_committed_physical_pageshave no callers outside tests. Merging it would add a large unused module, plus public API invictory-hlethat exists only for it.xmem::mapnow goes through the newprepare_placeholdersplit/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_placeholderfix toxmem::map, its unit tests, and evidence that it fixes a failure the title hits (for example, theVirtualFreeerror 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
[PR #2494] GPU/HLE: zero-reimport in-place memory remap prototype over SEC_COMMIT sections (#1905)to [PR #2494] GPU/HLE: import committed physical-page sections in place for title memory (#1905)Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-26T07:20:03Z.
Addressed the triage items at head
1a20686(rebased onorigin/main63bcca4):crates/victory-gpu/src/memory.rs,crates/victory-gpu/src/watch.rs,crates/victory-hle/src/modules/xmem.rs) and removed unused code/APIs:crates/victory-gpu/src/inplace.rsmodule (includingInplaceArena,InplaceContext, capability probes, and benchmark) and removed the test-only public items inxmem.rs(PhysicalSection,MappedRun,mapped_runs,allocate_committed_physical_pages).xmem::mapandSection::dropnow notifyvictory_gpu::title_memory_mappedandvictory_gpu::title_memory_section_freed, andwatch::title_memory_remappedupdatesmemory::unmapped.memory::Shared::rewriteimports each committed physical-page section once viaOpenExistingHeapFromFileMapping+CreatePlacedResource(ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER), allocates one persistent raw(SRV, UAV)pair per view heap, and populateswrite_tablewith[pair_slot, (page_va as u32).wrapping_sub(sec_offset as u32)](IN_PLACEowner).prepare_placeholderchange inxmem::map:xmem::map's placeholder coalescing back tomain's implementation so it does not overlap #76, #1224, or #2425.memory.rsandxmem.rsand 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 okcargo clippy --workspace --all-targets --locked -- -D warnings&--all-features: 0 warningscargo test -p victory-gpu --lib memory --locked: 22/22 passedVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib memory --locked: 22/22 passedcargo test -p victory-hle --lib xmem --locked: 15/15 passedImported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:48:15Z.
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
1a20686merged ontomain63bcca4,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 atassert!(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, soHostHeap::newtakes the capped layout andpair()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).mainon this card: the 2 known capped-heap failures (#1835).Suggestion: assert that the pair is a valid slot of
heap()(for exampleinitial_pair < views.count + views.dynamicand not the null pair) rather than>= 1 << 18, so the test holds on capped hosts.AI-assisted (Claude)
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T07:21:29Z.
@nathanbzrr — I put a comparison of the three open in-place PRs in #880 (comment 7212390146): yours is the only one that is self-contained (no
shadow.rs), and it is the one that makes a second CPU view of a title section possible, since it keeps theSEC_COMMITsection handle and its(at, len, size, offset).That matters for a follow-up nobody has: the title's own stores into guarded memory still open a guard (~5 µs, one process-wide at a time; codec-d/cool_fox measures 590 write faults a frame, 69 ms of thread time → ~6 ms) by writing through a second, unguarded view instead. If you want that to stack on your PR, I'll write it as an increment on your head and keep your authorship — but only with your nod; otherwise ignore this and I'll verify the winner instead. No game data, synthetic only.
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-27T07:33:58Z.
@borosf Sure, go ahead
Imported from Marvisak/VIctory. Originally posted by rpmaster2 on 2026-11-27T08:21:47Z.
RDNA4 (RX 9070 XT, 32 GB) test of
1a20686againstmain(63bcca4): copies drop 3-6x, total memory does not, black frames go up.Setup: Radeon RX 9070 XT 16 GB, Adrenalin 26.11.2 (32.0.32029.2010), Ryzen 5 5600, 32 GB DDR4-3600, Windows 11 10.0.26100.9974.
cargo build --locked --profile diag -p victory --features diagnostics, both builds from this repository, one dump, the same save. Series X,VICTORY_PRESENT_TARGET=1x1:1, scripted keys. Shader and pipeline caches warm; the driver's shader cache was emptied before the two runs and the machine rebooted, so both started from the same state.Method: 300 s each, private bytes and page-file usage sampled every 20 s, control first and the PR second, nothing else on the machine.
main63bcca41a20686What I take from it:
If it helps, I can repeat this pair with a smaller
--console series-sand withVICTORY_D3D12_DEBUG=1to see whether the black frames come with a D3D12 warning, and with a scene that is known to hold more title memory.AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; commits, counts, timings and driver version only, no game files or paths.
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.