hle/xmem: reuse freed physical page numbers within 21-bit limit #35

Merged
Androtim merged 2 commits from upstream-pr/35 into main 2026-11-28 23:02:33 +00:00
Androtim commented 2026-11-28 10:33:21 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T10:33:21Z.


Summary

Port rustno1-coder/VIctory-NVIDIA 108a897 (after vatarmanz/VIctory-7900XTX#316):

  • In crates/victory-hle/src/modules/xmem.rs, add FIRST_PAGE, PAGE_LIMIT, Pages::take(), and ree_run() so XMemAllocatePhysicalPages hands out sequential physical page numbers until PAGE_LIMIT (1 << 25, matching the title's 21-bit
    umber >> 4), then reuses the lowest contiguous run of freed pages instead of overflowing past 21 bits (~124 GiB cumulative allocations). If no contiguous run fits, it logs a warning, writes to count, and returns .
  • Added unit test modules::xmem::tests::page_numbers_freed_are_given_again_past_the_title_s_21_bits.

Rig Specs Tested On

  • CPU: 13th Gen Intel(R) Core(TM) i7-13700F
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB
  • OS & GPU Driver: Windows 11 Home (Build 26300) / Driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA:
    elease @ $sha (static/clippy + ictory-hle unit suite + CI full workspace suite; no separate live game capture since sequential allocation below ~124 GiB cumulative physical allocations is unchanged)
  • Console Profile & Internal Resolution / Scale: N/A (XMem unit/static verification + full CI suite)
  • Ray Tracing: N/A
  • Upscaling: N/A
  • Frame Generation: N/A
  • Launcher Command / Preset & Extra VICTORY_ Overrides:* N/A
  • Scene / Area & Session Length: N/A

Measurements & Verification

  • Base FPS (without Frame Gen): N/A (long-session XMem page-number exhaustion fix)
  • Frame-Gen FPS (if enabled): N/A
  • VRAM / RAM Usage: N/A
  • Crashes / DRED Resets: N/A
  • Automated Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (sset policy: 294 files ok)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features victory-gpu/diagnostics -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle --lib -- --test-threads=1 (183 passed; 0 failed; 3 ignored, including page_numbers_freed_are_given_again_past_the_title_s_21_bits)
    • cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory + objdump -p check (0 non-system MinGW DLLs)
    • Full workspace test suite via GitHub Actions CI
<!-- greyfinch-sync:Androtim/MiniVI:issue:5539221842 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/35). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T10:33:21Z. --- ## Summary Port rustno1-coder/VIctory-NVIDIA 108a897 (after vatarmanz/VIctory-7900XTX#316): - In crates/victory-hle/src/modules/xmem.rs, add FIRST_PAGE, PAGE_LIMIT, Pages::take(), and ree_run() so XMemAllocatePhysicalPages hands out sequential physical page numbers until PAGE_LIMIT (1 << 25, matching the title's 21-bit umber >> 4), then reuses the lowest contiguous run of freed pages instead of overflowing past 21 bits (~124 GiB cumulative allocations). If no contiguous run fits, it logs a warning, writes to count, and returns . - Added unit test modules::xmem::tests::page_numbers_freed_are_given_again_past_the_title_s_21_bits. ## Rig Specs Tested On - **CPU:** 13th Gen Intel(R) Core(TM) i7-13700F - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB - **OS & GPU Driver:** Windows 11 Home (Build 26300) / Driver 32.0.16.2124 ## Run Settings & Profile - **Build & Commit SHA:** elease @ $sha (static/clippy + ictory-hle unit suite + CI full workspace suite; no separate live game capture since sequential allocation below ~124 GiB cumulative physical allocations is unchanged) - **Console Profile & Internal Resolution / Scale:** N/A (XMem unit/static verification + full CI suite) - **Ray Tracing:** N/A - **Upscaling:** N/A - **Frame Generation:** N/A - **Launcher Command / Preset & Extra VICTORY_* Overrides:** N/A - **Scene / Area & Session Length:** N/A ## Measurements & Verification - **Base FPS (without Frame Gen):** N/A (long-session XMem page-number exhaustion fix) - **Frame-Gen FPS (if enabled):** N/A - **VRAM / RAM Usage:** N/A - **Crashes / DRED Resets:** N/A - **Automated Checks:** - [x] cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (sset policy: 294 files ok) - [x] cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed) - [x] cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings) - [x] cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features victory-gpu/diagnostics -- -D warnings (0 warnings) - [x] cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle --lib -- --test-threads=1 (183 passed; 0 failed; 3 ignored, including page_numbers_freed_are_given_again_past_the_title_s_21_bits) - [x] cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory + objdump -p check (0 non-system MinGW DLLs) - [ ] Full workspace test suite via GitHub Actions CI
Androtim commented 2026-11-28 11:03:24 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T11:03:24Z.


Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Technical Review

  • Scope & Correctness (crates/victory-hle/src/modules/xmem.rs):
    • Introduces FIRST_PAGE (0x10_0000) and PAGE_LIMIT (1 << 25), matching the title's 21-bit number >> 4 packing for FRAMES (PAGE >> 12 = 16).
    • Pages::take / Pages::take_in preserves the existing sequential fast path while self.next_page + n * FRAMES <= PAGE_LIMIT, then falls back to free_run_in to find the lowest contiguous freed run within [floor, limit).
    • Updating self.next_page = self.next_page.max(first + len) preserves the invariant that all live keys in Pages::pages remain strictly below self.next_page, preventing duplicate page numbers when a reused run straddles next_page.
    • In XMemAllocatePhysicalPages, if table.take(n) returns None, table is dropped before returning 0 and writing 0 to count; Section::drop then cleanly calls victory_gpu::title_memory_section_gone and CloseHandle without holding the PAGES lock.
  • Tests & CI:
    • page_numbers_freed_are_given_again_past_the_title_s_21_bits covers boundary sequential allocation, free-run reuse, overflow/exhaustion, 21-bit packing, and the next_page-straddling regression case.
    • CI is passing. No shader, D3D12 host, VRAM budget, or launcher changes are involved, so local GPU testing is not required.

Verdict

merge-candidate — clean HLE physical page-number reuse fix with solid edge-case handling and unit test coverage (pending maintainer review/merge).


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7238297657 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/35#issuecomment-7238297657). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T11:03:24Z. --- <!-- minivi-triage v1 head=fe3c5e87d458f34dfb1aff50c5376c6ab4d17df0 verdict=merge-candidate ci=passing at=2026-11-28T22:03:38Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Technical Review - **Scope & Correctness (`crates/victory-hle/src/modules/xmem.rs`)**: - Introduces `FIRST_PAGE` (`0x10_0000`) and `PAGE_LIMIT` (`1 << 25`), matching the title's 21-bit `number >> 4` packing for `FRAMES` (`PAGE >> 12` = 16). - `Pages::take` / `Pages::take_in` preserves the existing sequential fast path while `self.next_page + n * FRAMES <= PAGE_LIMIT`, then falls back to `free_run_in` to find the lowest contiguous freed run within `[floor, limit)`. - Updating `self.next_page = self.next_page.max(first + len)` preserves the invariant that all live keys in `Pages::pages` remain strictly below `self.next_page`, preventing duplicate page numbers when a reused run straddles `next_page`. - In `XMemAllocatePhysicalPages`, if `table.take(n)` returns `None`, `table` is dropped before returning `0` and writing `0` to `count`; `Section::drop` then cleanly calls `victory_gpu::title_memory_section_gone` and `CloseHandle` without holding the `PAGES` lock. - **Tests & CI**: - `page_numbers_freed_are_given_again_past_the_title_s_21_bits` covers boundary sequential allocation, free-run reuse, overflow/exhaustion, 21-bit packing, and the `next_page`-straddling regression case. - CI is passing. No shader, D3D12 host, VRAM budget, or launcher changes are involved, so local GPU testing is not required. ### Verdict `merge-candidate` — clean HLE physical page-number reuse fix with solid edge-case handling and unit test coverage (pending maintainer review/merge). --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-11-28 21:41:05 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-28T21:41:05Z.


Fixed the Pages::take / next_page invariant bug flagged in review (fe3c5e8):

  • In crates/victory-hle/src/modules/xmem.rs, when Pages::take_in falls through to free_run_in because self.next_page + len > limit, it now advances self.next_page = self.next_page.max(first + len) so [self.next_page, limit) stays disjoint from self.pages and subsequent smaller take(1) allocations cannot hand out an already-live page number.
  • Extended page_numbers_freed_are_given_again_past_the_title_s_21_bits with a regression test covering a free_run span that straddles self.next_page followed by take_in(..., 1).

Verified locally:

  • xtask policy: 294 files ok
  • xtask tests: 6 passed; 0 failed
  • clippy --workspace --all-targets -- -D warnings: 0 warnings
  • clippy --workspace --all-targets --features diagnostics -- -D warnings: 0 warnings
  • victory-hle xmem: 22 passed; 0 failed; 1 ignored
  • victory-hle --lib: 183 passed; 0 failed; 3 ignored
<!-- greyfinch-sync:Androtim/MiniVI:comment:7246196267 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/35#issuecomment-7246196267). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-28T21:41:05Z. --- Fixed the `Pages::take` / `next_page` invariant bug flagged in review (`fe3c5e8`): - In `crates/victory-hle/src/modules/xmem.rs`, when `Pages::take_in` falls through to `free_run_in` because `self.next_page + len > limit`, it now advances `self.next_page = self.next_page.max(first + len)` so `[self.next_page, limit)` stays disjoint from `self.pages` and subsequent smaller `take(1)` allocations cannot hand out an already-live page number. - Extended `page_numbers_freed_are_given_again_past_the_title_s_21_bits` with a regression test covering a `free_run` span that straddles `self.next_page` followed by `take_in(..., 1)`. Verified locally: - `xtask policy`: `294 files ok` - `xtask` tests: `6 passed; 0 failed` - `clippy --workspace --all-targets -- -D warnings`: 0 warnings - `clippy --workspace --all-targets --features diagnostics -- -D warnings`: 0 warnings - `victory-hle xmem`: `22 passed; 0 failed; 1 ignored` - `victory-hle --lib`: `183 passed; 0 failed; 3 ignored`
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Androtim/MiniVI!35
No description provided.