perf(xmem): physical pages from sections of at most VICTORY_SECTION_MB MiB (off by default) #4988

Open
github-bot wants to merge 3 commits from github-bot/gh-4987 into main AGit
Owner

@⁠CLHelper on GitHub · 2026-12-01 16:34 UTC · original
CLHelper:pr/section-mb-3 → main · +509 −59 · 3 files · 3 commits · open

Replaces #44, rebased on the current main (5fabb46ea) as asked there.

What it changes

XMemAllocatePhysicalPages makes one section per request. The title asks for its 6.1 GiB of physical pages in one call and then maps them a 64 KiB view at a time, so one section ends up with views by the hundred thousand. Windows' large-page rebuild worker walks a section's views under that section's lock, and every map and unmap of the title's pages waits behind it. That shows up as stalls when the camera turns or the player moves.

VICTORY_SECTION_MB=<n> backs each request with sections of at most n MiB (2 is the measured value). The pages are still numbered as one request. Unset, 0 or not a number keeps one section per request: same calls, same numbers. Off by default. (Census lines group alike sections either way.)

  • xmem/section_mb.rs (new): the switch; sections(n, per, dir), which makes the request's sections with Section::new (pagefile-backed, or under Wine with page files one sparse file each); enter(), which reports each section to the GPU side (title_memory_section, procmem::section_made) and numbers the pages as one request from Pages::take. Each section keeps its own window and is closed (title_memory_section_gone) when its last page goes, as before.
  • xmem.rs: XMemAllocatePhysicalPages calls them. Its two failure paths (the host refuses a section; out of page numbers) and its log lines are as on main. A mapping or a write already ends a run at a section's end, and a DirectStorage destination that crosses a bound gets no window and goes through write_physical, run by run.
  • inplace.rs: sections (bytes, importable, generation) and our whole views of them are kept in maps by handle instead of vectors scanned on every lookup (with the switch on, a request is about 3,100 sections). The generation rule for a recycled handle is unchanged, and a new test pins it (below). Census lines group alike sections; a section that is one of a kind prints as before.

Not for use together with VICTORY_PORT_CONSTANTS=1 (off unless set on this main): port 1 needs the 32-bit heap's pages in one section. With VICTORY_SECTION_MB set, arrange() logs its "not of one section as big as it" warning and leaves the pages where they are, so that heap stays on the copy path.

How it was tested

  • GPU and profile: RTX 4060 Laptop GPU (8 GB), 32 GB RAM, Windows 11, Series S. Measured in the game with the same change on an earlier main (6a31e431e). On 5fabb46ea it is built and unit-tested only, not run in the game.
  • Before / after (host left as it was, two pairs, one run per arm; mapping cost from the title's mapping calls):
pair a, off pair a, 2 MiB pair b, off pair b, 2 MiB
time in mapping calls, whole run 55.5 s 7.3 s 17.8 s 5.9 s
waits on the section lock, whole run 26.6 s 0.6 s 6.5 s 0.4 s
worst second of mapping calls (after 60 s) 1,950 ms 264 ms 1,657 ms 442 ms
standing frame time in the world 82.1 ms 74.7 ms 75.9 ms 72.9 ms
world entry 66.2 s 45.0 s 56.1 s 50.3 s

No device removals or exceptions in any of the four runs. One run per arm; pair b ran hands-off, in pair a the player moved in the 2 MiB run only, so pair a's frame times are not a clean A/B (the mapping and lock numbers are the point there).

  • Costs: each DirectStorage destination that crosses a 2 MiB bound costs one extra copy (not counted separately); more kernel section objects and handles (about 3,100 for 6.1 GiB) and more views. Total commit does not change.
  • For shader changes, the wave sizes tested: no shader change.
  • cargo test passed for the crates it touches: yes for this change; victory-gpu's lib has two failures that main has too (below). Run on cdc96ead8 (5fabb46ea + these commits), Rust 1.98.1, offline, --test-threads=1, Windows 11:
    • cargo test -p victory-hle --lib section_mb: 5 passed, 1 ignored (the bench), with the switch unset and with VICTORY_SECTION_MB=2. The tests: the switch's values; 33 pages whole vs 32+1 (numbering, window and write over the bound, one call mapping two views); 70 pages in 32/32/6, every section closed after free; five pages in sections of two mapped, written, partly unmapped and page-mapping-copied over the bounds; the title call stays one section by default.
    • cargo test -p victory-gpu --features diagnostics --lib inplace: 16 passed, among them the new an_eligible_handle_given_again_does_not_take_the_earlier_views. The existing native_import_requires_the_current_eligible_section_generation still passes with the generation comparison removed from the lookup, because its earlier generation is not eligible; in the new one both generations are, so only the generation can refuse the earlier views.
    • Each test fails when the change is broken: no per-section cap (3 of the section_mb tests fail), the switch on when unset (3 fail), page numbers that ignore the sections (4 fail), the generation not compared in inplace (the new test fails).
    • cargo test -p victory-hle --lib: 474 passed, 14 ignored.
    • cargo test -p victory-gpu --features diagnostics --lib: 1167 passed, 2 failed, 69 ignored. The two are compose::tests::bgrx_plane_selects_a_typed_view (format 88 where 93 is expected) and host::bury_tests::bury_drops_retired_objects_asynchronously; main 5fabb46ea without these commits fails the same two the same way (1166 passed, 2 failed, 69 ignored). This change adds one test there, and five plus the ignored bench to victory-hle (main: 469 passed, 13 ignored).
    • cargo check -p victory-hle -p victory-gpu (no features): no warnings.
    • physical_remap_bench (#[ignore = "benchmark"], title-free): remaps single pages of a 4 GiB request while another thread makes and frees 2 GiB, one section vs 2 MiB sections. Test code only.
    • Clippy was not run (not in this toolchain).

Checked for overlap

  • Searched the open and closed pull requests and issues for SECTION_MB, and main 5fabb46ea: no other change splits a request's section. Related, same files, other topics: #4874 (the 32-bit graphics heap as private memory), #4611 (what the title is told about memory), #2776, #3503 (opt-in SEC_COMMIT views), #4205 (procmem section line), #2455.
  • With VICTORY_INPLACE (off by default), a window of title memory in place must be one run of one section; with this switch set, a window over a 2 MiB bound is turned down ("not one section run") and stays a copy. #2776's views of our own (VICTORY_INPLACE_VIEWS) map one view per run of one section, so the same window needs one more view per bound it crosses. Both are opt-in; they were not run together.

Credit

This is a port. The finding and the cure are RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274). The code follows voidopcode/vilocity 0f44a1706. The tests follow KainanP (Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax (Xeltax/VIcky a8c223149).

AI-assisted.

**@⁠CLHelper** on GitHub · 2026-12-01 16:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4987) `CLHelper:pr/section-mb-3` → `main` · +509 −59 · 3 files · 3 commits · open Replaces #44, rebased on the current main (5fabb46ea) as asked there. ## What it changes `XMemAllocatePhysicalPages` makes one section per request. The title asks for its 6.1 GiB of physical pages in one call and then maps them a 64 KiB view at a time, so one section ends up with views by the hundred thousand. Windows' large-page rebuild worker walks a section's views under that section's lock, and every map and unmap of the title's pages waits behind it. That shows up as stalls when the camera turns or the player moves. `VICTORY_SECTION_MB=<n>` backs each request with sections of at most n MiB (2 is the measured value). The pages are still numbered as one request. Unset, `0` or not a number keeps one section per request: same calls, same numbers. **Off by default.** (Census lines group alike sections either way.) - `xmem/section_mb.rs` (new): the switch; `sections(n, per, dir)`, which makes the request's sections with `Section::new` (pagefile-backed, or under Wine with page files one sparse file each); `enter()`, which reports each section to the GPU side (`title_memory_section`, `procmem::section_made`) and numbers the pages as one request from `Pages::take`. Each section keeps its own window and is closed (`title_memory_section_gone`) when its last page goes, as before. - `xmem.rs`: `XMemAllocatePhysicalPages` calls them. Its two failure paths (the host refuses a section; out of page numbers) and its log lines are as on main. A mapping or a write already ends a run at a section's end, and a DirectStorage destination that crosses a bound gets no window and goes through `write_physical`, run by run. - `inplace.rs`: sections (bytes, importable, generation) and our whole views of them are kept in maps by handle instead of vectors scanned on every lookup (with the switch on, a request is about 3,100 sections). The generation rule for a recycled handle is unchanged, and a new test pins it (below). Census lines group alike sections; a section that is one of a kind prints as before. Not for use together with `VICTORY_PORT_CONSTANTS=1` (off unless set on this main): port 1 needs the 32-bit heap's pages in one section. With `VICTORY_SECTION_MB` set, `arrange()` logs its "not of one section as big as it" warning and leaves the pages where they are, so that heap stays on the copy path. ## How it was tested - GPU and profile: RTX 4060 Laptop GPU (8 GB), 32 GB RAM, Windows 11, Series S. **Measured in the game with the same change on an earlier main (6a31e431e). On 5fabb46ea it is built and unit-tested only, not run in the game.** - Before / after (host left as it was, two pairs, one run per arm; mapping cost from the title's mapping calls): | | pair a, off | pair a, 2 MiB | pair b, off | pair b, 2 MiB | |---|---|---|---|---| | time in mapping calls, whole run | 55.5 s | 7.3 s | 17.8 s | 5.9 s | | waits on the section lock, whole run | 26.6 s | 0.6 s | 6.5 s | 0.4 s | | worst second of mapping calls (after 60 s) | 1,950 ms | 264 ms | 1,657 ms | 442 ms | | standing frame time in the world | 82.1 ms | 74.7 ms | 75.9 ms | 72.9 ms | | world entry | 66.2 s | 45.0 s | 56.1 s | 50.3 s | No device removals or exceptions in any of the four runs. One run per arm; pair b ran hands-off, in pair a the player moved in the 2 MiB run only, so pair a's frame times are not a clean A/B (the mapping and lock numbers are the point there). - Costs: each DirectStorage destination that crosses a 2 MiB bound costs one extra copy (not counted separately); more kernel section objects and handles (about 3,100 for 6.1 GiB) and more views. Total commit does not change. - For shader changes, the wave sizes tested: no shader change. - `cargo test` passed for the crates it touches: yes for this change; victory-gpu's lib has two failures that main has too (below). Run on cdc96ead8 (5fabb46ea + these commits), Rust 1.98.1, offline, `--test-threads=1`, Windows 11: - `cargo test -p victory-hle --lib section_mb`: 5 passed, 1 ignored (the bench), with the switch unset and with `VICTORY_SECTION_MB=2`. The tests: the switch's values; 33 pages whole vs 32+1 (numbering, window and write over the bound, one call mapping two views); 70 pages in 32/32/6, every section closed after free; five pages in sections of two mapped, written, partly unmapped and page-mapping-copied over the bounds; the title call stays one section by default. - `cargo test -p victory-gpu --features diagnostics --lib inplace`: 16 passed, among them the new `an_eligible_handle_given_again_does_not_take_the_earlier_views`. The existing `native_import_requires_the_current_eligible_section_generation` still passes with the generation comparison removed from the lookup, because its earlier generation is not eligible; in the new one both generations are, so only the generation can refuse the earlier views. - Each test fails when the change is broken: no per-section cap (3 of the section_mb tests fail), the switch on when unset (3 fail), page numbers that ignore the sections (4 fail), the generation not compared in `inplace` (the new test fails). - `cargo test -p victory-hle --lib`: 474 passed, 14 ignored. - `cargo test -p victory-gpu --features diagnostics --lib`: 1167 passed, 2 failed, 69 ignored. The two are `compose::tests::bgrx_plane_selects_a_typed_view` (format 88 where 93 is expected) and `host::bury_tests::bury_drops_retired_objects_asynchronously`; main 5fabb46ea without these commits fails the same two the same way (1166 passed, 2 failed, 69 ignored). This change adds one test there, and five plus the ignored bench to victory-hle (main: 469 passed, 13 ignored). - `cargo check -p victory-hle -p victory-gpu` (no features): no warnings. - `physical_remap_bench` (`#[ignore = "benchmark"]`, title-free): remaps single pages of a 4 GiB request while another thread makes and frees 2 GiB, one section vs 2 MiB sections. Test code only. - Clippy was not run (not in this toolchain). ## Checked for overlap - [x] Searched the open and closed pull requests and issues for `SECTION_MB`, and main 5fabb46ea: no other change splits a request's section. Related, same files, other topics: #4874 (the 32-bit graphics heap as private memory), #4611 (what the title is told about memory), #2776, #3503 (opt-in `SEC_COMMIT` views), #4205 (`procmem` section line), #2455. - With `VICTORY_INPLACE` (off by default), a window of title memory in place must be one run of one section; with this switch set, a window over a 2 MiB bound is turned down ("not one section run") and stays a copy. #2776's views of our own (`VICTORY_INPLACE_VIEWS`) map one view per run of one section, so the same window needs one more view per bound it crosses. Both are opt-in; they were not run together. ## Credit This is a port. The finding and the cure are RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274). The code follows voidopcode/vilocity 0f44a1706. The tests follow KainanP (Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax (Xeltax/VIcky a8c223149). AI-assisted.
XMemAllocatePhysicalPages makes one section per request (6.1 GiB at once
for the title), which it then maps a 64 KiB view at a time. Windows'
large-page rebuild worker walks a section's views under the section's
lock, so every map and unmap of the title's pages waits behind it while
the camera turns. VICTORY_SECTION_MB=<n> backs a request with sections of
at most n MiB (2 measured); unset, 0 or not a number keeps one section per
request: same calls, same numbers.

- xmem/section_mb.rs (new): the switch; sections(n, per, dir), which makes
  the request's sections with Section::new (pagefile, or a sparse file
  each under Wine with page files); enter(), which reports each to the GPU
  side (title_memory_section, procmem::section_made) and numbers the pages
  as one request from Pages::take. Each section keeps its own window and
  is closed (title_memory_section_gone) when its last page goes, as before.
- xmem.rs: XMemAllocatePhysicalPages calls them; its failure paths (host
  refusal, out of page numbers) and logs stay as they were. A mapping or
  a write already ends a run at a section's end; DirectStorage
  destinations over a bound get no window and go through write_physical.
- inplace.rs: sections (bytes, importable, generation) and our whole
  views of them by handle in maps, not vectors scanned per lookup; census
  lines group alike sections (one of a kind reads as before, lines now in
  size order).

Not combined with VICTORY_PORT_CONSTANTS=1: renderer port 1 needs the
32-bit heap in one section; with the switch set, arrange() logs that the
pages are not of one section and leaves them, so the heap stays on the
copy path.

Tests: the switch's values; 33 pages whole vs 32+1 (numbering, window and
write over the bound, one call mapping two views); 70 pages in 32/32/6
with every section closed after free; five pages in sections of two
mapped, written, partly unmapped and page-mapping-copied over the bounds;
the title call stays one section by default.

Replaces #44, rebased on 5fabb46ea.

Port of voidopcode/vilocity 0f44a1706; the finding and the cure are
RyanCase94's and CuteBooty's (fxceless's fork, issue #1089, PR #1274).
Tests after KainanP (Skyfrye/anyXboxx-diffbase ee8b92e14) and Xeltax
(Xeltax/VIcky a8c223149). AI-assisted.
physical_remap_bench maps a 4 GiB request a page at a time, then remaps
random single pages for 10 s while another thread makes, touches and
frees 2 GiB, for one section against 2 MiB sections (3 rounds). Test
code only: victory.exe is unchanged.

Adapted from KainanP's bench (Skyfrye/anyXboxx-diffbase ee8b92e14).
AI-assisted.
native_import_requires_the_current_eligible_section_generation passes
with the generation comparison removed, because the earlier generation
there is ineligible. This one is eligible both times, so only the
generation can refuse the earlier views. Covers the lookup that the
previous commit moved from a vector scan to a map by handle.

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 16:34:54 +00:00
Author
Owner

@⁠GarethLlewelyn on GitHub · 2026-12-01 16:43 UTC · original · approved these changes

**@⁠GarethLlewelyn** on GitHub · 2026-12-01 16:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4987#pullrequestreview-6135721897) · **approved these changes**
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/inplace.rs
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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