XMem: place a reservation above 128 GiB when nothing below has room (#2081) #2133

Closed
github-bot wants to merge 1 commit from github-bot/gh-2133 into main AGit
Owner

@⁠bstillbstill on GitHub · 2026-11-29 09:48 UTC · original
bstillbstill:fix/xmem-tileheap-fallback → main · +45 −0 · 1 files · 1 commits · closed without merging

Fixes #2081

What it changes

#1041 caps title memory below the by-address directory's 128 GiB (2^37). On native Windows the title's 6,236 MB TileHeap (flags 0x23) can find no hole below that, so XMemVirtualAlloc is refused (os error 8) and the title stops at its start at +0x1e6c284. That's the analysis in #2081; it happens on my RTX 3090 Ti / 32 GB PC too. Before #1041 the same request landed at 0x2000000000 and the game ran.

This does what #2081 suggests:

  • Capped range first: the capped range is still tried first, so everything that fits below 128 GiB stays there.
  • Fallback: only when that reservation fails is it retried up to the console field's own limit (console_top(flags): 40 bits with no field, 47 - field otherwise, as before #1041), with a warning in the log.
  • New test: the_fallback_reaches_where_the_tile_heap_went_before_the_cap.

crates/victory-hle/src/modules/xmem.rs only, +45 lines.

Not fixed here: what falls back lands above 128 GiB, which is read as 0 by shaders that reach it by address (#218). So on PCs that hit the refusal this restores the pre-#1041 behaviour; it doesn't make the 6.1 GiB hole below 2^37 that #2081 also suggests making. It is marked as a shortcut: in the code.

How it was tested

  • GPU and profile: RTX 3090 Ti 24 GB (driver 621.40), i9-13900K, 32 GB RAM, Windows 11 build 26300 (native). Series X, -Res 1440 with VICTORY_NATIVE_SIZE=2560x1440 (3440x1440 monitor, #2073), DLSS (performance / ultra performance from the F1 menu), FSR 3 frame generation, ray tracing off. Release build.
  • Before (829188e9): every start stopped about 2 s in: XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 ... (os error 8), then unhandled exception 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x1e6c284.
  • After:
    • This branch (89a957e0): started from scripts\play-foxhound.ps1, it reaches the game. The log shows XMemVirtualAlloc: no room below 128 GiB, placed above it as before #1041 size=6538919936 at=0x1fffff0000 flags=0x23. In game it ran at 16–18 fps, with FSR 3 frame generation on for every present (179–198 per 10 s).
    • Same change on my local build: 4 more starts reached the game.
  • Shader changes: none.
  • cargo test -p victory-hle --lib: 423 passed, 1 failed, 5 ignored. The one failure is a_read_by_range_waits_only_for_a_remapping_that_meets_it, which fails the same way on 829188e9 without this change (twice) and passes when run alone. heap_reuses_freed_addresses failed once in one full run and passed in the others and alone. The new test and title_memory_stays_within_the_by_address_directory pass.
  • cargo clippy -p victory-hle --all-targets -- -D warnings: fails on 829188e9 too, in victory-loader (unwind_copy never used) and victory-shader (unused imports, a loop condition), not in the files this touches.
  • Not tested:
    • Wine/Proton.
    • A host where the TileHeap does fit below 128 GiB: there the first, capped attempt succeeds, so nothing should change.
    • Whether the #218 symptoms (missing vehicle panels/faces) come back on hosts that use the fallback.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1811 (also changes address_range(), capping it at 128 GiB less 64 KiB, with no fallback, so it would hit the same refusal), #2112 (same refusal on an RTX 3090), #2073 (ultrawide start crash, separate).

Written with Claude Code (Claude Opus 5.5): it found the cause, wrote the change and the test, ran the tests and the in-game starts above on my PC, and wrote this description. I reviewed it before opening.

**@⁠bstillbstill** on GitHub · 2026-11-29 09:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133) `bstillbstill:fix/xmem-tileheap-fallback` → `main` · +45 −0 · 1 files · 1 commits · closed without merging Fixes #2081 ## What it changes #1041 caps title memory below the by-address directory's 128 GiB (2^37). On native Windows the title's 6,236 MB TileHeap (flags `0x23`) can find no hole below that, so `XMemVirtualAlloc` is refused (`os error 8`) and the title stops at its start at `+0x1e6c284`. That's the analysis in #2081; it happens on my RTX 3090 Ti / 32 GB PC too. Before #1041 the same request landed at `0x2000000000` and the game ran. This does what #2081 suggests: - **Capped range first:** the capped range is still tried first, so everything that fits below 128 GiB stays there. - **Fallback:** only when that reservation fails is it retried up to the console field's own limit (`console_top(flags)`: 40 bits with no field, `47 - field` otherwise, as before #1041), with a warning in the log. - **New test:** `the_fallback_reaches_where_the_tile_heap_went_before_the_cap`. `crates/victory-hle/src/modules/xmem.rs` only, +45 lines. **Not fixed here:** what falls back lands above 128 GiB, which is read as 0 by shaders that reach it by address (#218). So on PCs that hit the refusal this restores the pre-#1041 behaviour; it doesn't make the 6.1 GiB hole below 2^37 that #2081 also suggests making. It is marked as a `shortcut:` in the code. ## How it was tested - **GPU and profile:** RTX 3090 Ti 24 GB (driver 621.40), i9-13900K, 32 GB RAM, Windows 11 build 26300 (native). Series X, `-Res 1440` with `VICTORY_NATIVE_SIZE=2560x1440` (3440x1440 monitor, #2073), DLSS (performance / ultra performance from the F1 menu), FSR 3 frame generation, ray tracing off. Release build. - **Before** (829188e9): every start stopped about 2 s in: `XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 ... (os error 8)`, then `unhandled exception 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x1e6c284`. - **After:** - **This branch (89a957e0):** started from `scripts\play-foxhound.ps1`, it reaches the game. The log shows `XMemVirtualAlloc: no room below 128 GiB, placed above it as before #1041 size=6538919936 at=0x1fffff0000 flags=0x23`. In game it ran at 16–18 fps, with FSR 3 frame generation on for every present (179–198 per 10 s). - **Same change on my local build:** 4 more starts reached the game. - **Shader changes:** none. - **`cargo test -p victory-hle --lib`:** 423 passed, 1 failed, 5 ignored. The one failure is `a_read_by_range_waits_only_for_a_remapping_that_meets_it`, which fails the same way on 829188e9 without this change (twice) and passes when run alone. `heap_reuses_freed_addresses` failed once in one full run and passed in the others and alone. The new test and `title_memory_stays_within_the_by_address_directory` pass. - **`cargo clippy -p victory-hle --all-targets -- -D warnings`:** fails on 829188e9 too, in `victory-loader` (`unwind_copy` never used) and `victory-shader` (unused imports, a loop condition), not in the files this touches. - **Not tested:** - Wine/Proton. - A host where the TileHeap does fit below 128 GiB: there the first, capped attempt succeeds, so nothing should change. - Whether the #218 symptoms (missing vehicle panels/faces) come back on hosts that use the fallback. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1811 (also changes `address_range()`, capping it at 128 GiB less 64 KiB, with no fallback, so it would hit the same refusal), #2112 (same refusal on an RTX 3090), #2073 (ultrawide start crash, separate). --- Written with Claude Code (Claude Opus 5.5): it found the cause, wrote the change and the test, ran the tests and the in-game starts above on my PC, and wrote this description. I reviewed it before opening.
#1041 caps title memory below the by-address directory's 128 GiB. On
native Windows the title's 6,236 MB TileHeap (flags 0x23) can find no hole
below 2^37 there (RTX 4090 and RTX 3090 Ti hosts, 32 GB each), so the
reservation is refused (os error 8) and the title stops at its start at
+0x1e6c284. Before #1041 the same request landed at 0x2000000000 and the
game ran.

The capped range is still tried first; only when it fails is the request
retried up to the console field's own limit, as before #1041, and logged.
What lands above 128 GiB is read as 0 by shaders that reach it by address
(#218), as it was before #1041.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 09:50:27 +00:00
Author
Owner

@⁠botto854 on GitHub · 2026-11-29 10:06 UTC · original

Confirming this on a second 24 GB card (reporter of #2081).

Setup: RTX 4090 24 GB (driver 617.14), i9-14900K, 32 GB RAM, Windows 11 build 26300 (native), 2560x1440, Series X, DLSS quality.

I built the same fallback independently on top of v2026.11.29.01 (829188e9): capped range first, then the flags' full 40-bit range on failure. Result:

  • Log: XMemVirtualAlloc: no room below 2^37, placed in the flags' full range size=6538919936 at=0x1fffff0000, the same address as on your 3090 Ti.
  • 16 minutes in game, ~122 fps, no new entry in crashes.log. Without the fallback, 3/3 starts stopped at +0x1e6c284.
  • cargo test -p victory-hle --lib xmem: same picture as yours, only a_read_by_range_waits_only_for_a_remapping_that_meets_it fails, with and without the change.

One small nit, not blocking: requirements.HighestEndingAddress = ... writes the local directly after &raw mut requirements went into parameter. rustc flagged that on my build (value assigned to requirements is never read). It works in practice, but writing through the same pointer that VirtualAlloc2 reads is cleaner:

let requirements = &raw mut requirements;
parameter.Anonymous2.Pointer = requirements.cast();
// ...
// SAFETY: the requirements `parameter` points at, written through that pointer.
unsafe { (*requirements).HighestEndingAddress = console_top(flags) as *mut c_void };

(Comparison and test run with Claude Code.)

**@⁠botto854** on GitHub · 2026-11-29 10:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7254210636) Confirming this on a second 24 GB card (reporter of #2081). **Setup:** RTX 4090 24 GB (driver 617.14), i9-14900K, 32 GB RAM, Windows 11 build 26300 (native), 2560x1440, Series X, DLSS quality. I built the same fallback independently on top of v2026.11.29.01 (829188e9): capped range first, then the flags' full 40-bit range on failure. Result: - Log: `XMemVirtualAlloc: no room below 2^37, placed in the flags' full range size=6538919936 at=0x1fffff0000`, the same address as on your 3090 Ti. - 16 minutes in game, ~122 fps, no new entry in `crashes.log`. Without the fallback, 3/3 starts stopped at `+0x1e6c284`. - `cargo test -p victory-hle --lib xmem`: same picture as yours, only `a_read_by_range_waits_only_for_a_remapping_that_meets_it` fails, with and without the change. One small nit, not blocking: `requirements.HighestEndingAddress = ...` writes the local directly after `&raw mut requirements` went into `parameter`. rustc flagged that on my build (`value assigned to requirements is never read`). It works in practice, but writing through the same pointer that `VirtualAlloc2` reads is cleaner: ```rust let requirements = &raw mut requirements; parameter.Anonymous2.Pointer = requirements.cast(); // ... // SAFETY: the requirements `parameter` points at, written through that pointer. unsafe { (*requirements).HighestEndingAddress = console_top(flags) as *mut c_void }; ``` (Comparison and test run with Claude Code.)
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 10:27 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean merge in crates/victory-hle/src/modules/xmem.rs.
  • Tests: cargo test -p victory-hle --lib xmem -- --test-threads=1 passed (47 passed; 0 failed; 1 ignored, including the new the_fallback_reaches_where_the_tile_heap_went_before_the_cap test).
  • Minor nit: xmem.rs:273 emits an unused_assignments warning on requirements.HighestEndingAddress = console_top(flags) as *mut c_void;.

Important fallback fix for high-address reservations when the <128 GiB range has no contiguous room. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-29 10:27 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#pullrequestreview-6102470785) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean merge in `crates/victory-hle/src/modules/xmem.rs`. - **Tests**: `cargo test -p victory-hle --lib xmem -- --test-threads=1` passed (`47 passed; 0 failed; 1 ignored`, including the new `the_fallback_reaches_where_the_tile_heap_went_before_the_cap` test). - Minor nit: `xmem.rs:273` emits an `unused_assignments` warning on `requirements.HighestEndingAddress = console_top(flags) as *mut c_void;`. Important fallback fix for high-address reservations when the <128 GiB range has no contiguous room. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠botto854 on GitHub · 2026-11-29 10:46 UTC · original

Found where the 36 + 28 GiB below 2^37 come from: DLSS (NGX) init calls into nvcuda64, which reserves them at fixed addresses before the title asks for its TileHeap. Details, stacks and a DLSS-off cross-check: #2081

**@⁠botto854** on GitHub · 2026-11-29 10:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7254658843) Found where the 36 + 28 GiB below 2^37 come from: DLSS (NGX) init calls into `nvcuda64`, which reserves them at fixed addresses before the title asks for its TileHeap. Details, stacks and a DLSS-off cross-check: https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/2081
Author
Owner

@⁠Halfect on GitHub · 2026-11-29 11:08 UTC · original · approved these changes

LGTM. The change preserves the capped range as the first choice and only widens HighestEndingAddress after that attempt fails. It also leaves 32-bit requests bounded, while restoring the console-defined range for the TileHeap case.

Local verification at 89a957e0885af2d8ec76b826052e9725c26bf89c:

  • cargo test --locked -p victory-hle --lib xmem -- --test-threads=1: 47 passed, 0 failed, 1 ignored, including the_fallback_reaches_where_the_tile_heap_went_before_the_cap.
  • git diff --check origin/main..HEAD: clean.
  • Source inspection confirms that the fallback remains limited to address-selected (base.is_null()) allocations and logs when the wider range is used.

I also see the non-blocking unused_assignments warning at line 273; writing through the requirements pointer already stored in parameter, as suggested in the existing discussion, would avoid it.

This was source and unit-test verification only, not a fresh end-to-end game run.

**@⁠Halfect** on GitHub · 2026-11-29 11:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#pullrequestreview-6102601547) · **approved these changes** LGTM. The change preserves the capped range as the first choice and only widens `HighestEndingAddress` after that attempt fails. It also leaves 32-bit requests bounded, while restoring the console-defined range for the TileHeap case. Local verification at `89a957e0885af2d8ec76b826052e9725c26bf89c`: - `cargo test --locked -p victory-hle --lib xmem -- --test-threads=1`: **47 passed, 0 failed, 1 ignored**, including `the_fallback_reaches_where_the_tile_heap_went_before_the_cap`. - `git diff --check origin/main..HEAD`: clean. - Source inspection confirms that the fallback remains limited to address-selected (`base.is_null()`) allocations and logs when the wider range is used. I also see the non-blocking `unused_assignments` warning at line 273; writing through the requirements pointer already stored in `parameter`, as suggested in the existing discussion, would avoid it. This was source and unit-test verification only, not a fresh end-to-end game run.
Author
Owner

@⁠P1ayer-1 on GitHub · 2026-11-29 18:20 UTC · original

Confirmed on an 8 GB card, which is a different profile from the two 24 GB confirmations so far — RTX 3060 Ti 8 GB, Ryzen 5 3600X, 48 GB RAM, Windows 11 build 26300, Series X files, 2560x1440, DLSS Quality, frame generation off.

Built this branch at 89a957e0 (cargo build --release -p victory, MSVC 14.44, rustc 1.98.1). Two results:

The test passes: the_fallback_reaches_where_the_tile_heap_went_before_the_cap → ok.

In game, the TileHeap request (size=6538919936, flags=0x23) is placed by your fallback and the run reaches rendering:

WARN victory_hle::modules::xmem: XMemVirtualAlloc: no room below 128 GiB,
     placed above it as before #1041 size=6538919936 at=0x1fffff0000 flags=0x23
INFO victory_hle::modules::xmem: title memory asked for as protection 0x2004,
     kind 0x42000, flags 0x23: 1 times, 6236 MB, last 0x1fffff0000+0x185c00000
  • XMemVirtualAlloc refused: 0 occurrences (was 1 per run without this)
  • 60 dstorage: file opened lines, i.e. real loading, where refused runs stop at 3–5
  • still alive at 3 minutes, 6.9 GB working set, and the per-frame summaries are being printed (card time … per frame over 256 frames)

For contrast, same machine, same files:

build TileHeap placement outcome
v2026.11.28.03 0x2000000000 ran 17.5 h
v2026.11.29.01 asked 0x0 → refused halted at System Init, 5 of 6 runs
v2026.11.29.01 with only the address_range cap reverted 0x1fffff0000 ran, 256 frames
this branch 0x1fffff0000 ran, 256 frames

So it is not tied to 24 GB cards or to VRAM at all, and your version is the better shape of the fix: the bounded retry keeps everything that fits below 2^37 where it belongs, and only the request that cannot fit goes above. Nothing to change from my side.

**@⁠P1ayer-1** on GitHub · 2026-11-29 18:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7260410593) Confirmed on an **8 GB card**, which is a different profile from the two 24 GB confirmations so far — RTX 3060 Ti 8 GB, Ryzen 5 3600X, 48 GB RAM, Windows 11 build 26300, Series X files, 2560x1440, DLSS Quality, frame generation off. Built this branch at `89a957e0` (`cargo build --release -p victory`, MSVC 14.44, rustc 1.98.1). Two results: **The test passes**: `the_fallback_reaches_where_the_tile_heap_went_before_the_cap` → ok. **In game**, the TileHeap request (`size=6538919936`, `flags=0x23`) is placed by your fallback and the run reaches rendering: ``` WARN victory_hle::modules::xmem: XMemVirtualAlloc: no room below 128 GiB, placed above it as before #1041 size=6538919936 at=0x1fffff0000 flags=0x23 INFO victory_hle::modules::xmem: title memory asked for as protection 0x2004, kind 0x42000, flags 0x23: 1 times, 6236 MB, last 0x1fffff0000+0x185c00000 ``` - `XMemVirtualAlloc refused`: **0 occurrences** (was 1 per run without this) - 60 `dstorage: file opened` lines, i.e. real loading, where refused runs stop at 3–5 - still alive at 3 minutes, 6.9 GB working set, and the per-frame summaries are being printed (`card time … per frame over 256 frames`) For contrast, same machine, same files: | build | TileHeap placement | outcome | | --- | --- | --- | | `v2026.11.28.03` | `0x2000000000` | ran 17.5 h | | `v2026.11.29.01` | asked `0x0` → refused | halted at `System Init`, 5 of 6 runs | | `v2026.11.29.01` with only the `address_range` cap reverted | `0x1fffff0000` | ran, 256 frames | | this branch | `0x1fffff0000` | ran, 256 frames | So it is not tied to 24 GB cards or to VRAM at all, and your version is the better shape of the fix: the bounded retry keeps everything that fits below 2^37 where it belongs, and only the request that cannot fit goes above. Nothing to change from my side.
github-bot closed this pull request 2026-11-30 14:18:55 +00:00
Author
Owner

@⁠bstillbstill on GitHub · 2026-11-30 14:11 UTC · original

Closing this in favour of f72cec77 ("XMem: keep 8 GiB of the title's window spare at start, give it back if the 6.5 GB heap is refused"), which fixes #2081 better: the TileHeap stays below 128 GiB, so #218 isn't at risk.

Checked on the same PC (RTX 3090 Ti, 32 GB, Windows 11 26300) at 41adb551 without this patch: on Series X the 6,538,919,936-byte request now lands at 0x1800000000 and the game reaches play (~19 fps); Series S also starts and plays.

Thanks to everyone who tested this branch (@⁠botto854, @⁠P1ayer-1), and for tracking the 36 + 28 GiB reservations down to NGX/nvcuda.

(Checked with Claude Code, Claude Opus 5.5.)

**@⁠bstillbstill** on GitHub · 2026-11-30 14:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7280983276) Closing this in favour of f72cec77 ("XMem: keep 8 GiB of the title's window spare at start, give it back if the 6.5 GB heap is refused"), which fixes #2081 better: the TileHeap stays below 128 GiB, so #218 isn't at risk. Checked on the same PC (RTX 3090 Ti, 32 GB, Windows 11 26300) at 41adb551 without this patch: on Series X the 6,538,919,936-byte request now lands at `0x1800000000` and the game reaches play (~19 fps); Series S also starts and plays. Thanks to everyone who tested this branch (@⁠botto854, @⁠P1ayer-1), and for tracking the 36 + 28 GiB reservations down to NGX/nvcuda. *(Checked with Claude Code, Claude Opus 5.5.)*

Pull request closed

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!2133
No description provided.