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

Closed
bstillbstill wants to merge 1 commit from upstream-pr/2133 into main
bstillbstill commented 2026-11-29 09:48:03 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by bstillbstill on 2026-11-29T09:48:03Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549547917 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133). Originally posted by [bstillbstill](https://github.com/bstillbstill) on 2026-11-29T09:48:03Z. --- 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.
botto854 commented 2026-11-29 10:06:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by botto854 on 2026-11-29T10:06:21Z.


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.)

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254210636 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7254210636). Originally posted by [botto854](https://github.com/botto854) on 2026-11-29T10:06:21Z. --- 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.)
Dukestar69 commented 2026-11-29 10:27:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-29T10:27:32Z.

Review: APPROVED


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6102470785 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#pullrequestreview-6102470785). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-29T10:27:32Z. **Review:** APPROVED --- 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).
botto854 commented 2026-11-29 10:46:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by botto854 on 2026-11-29T10:46:25Z.


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://github.com/trustno1-coder/VIctory-NVIDIA/issues/2081#issuecomment-7254658575

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254658843 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7254658843). Originally posted by [botto854](https://github.com/botto854) on 2026-11-29T10:46:25Z. --- 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://github.com/trustno1-coder/VIctory-NVIDIA/issues/2081#issuecomment-7254658575
Halfect commented 2026-11-29 11:08:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Halfect on 2026-11-29T11:08:26Z.

Review: APPROVED


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6102601547 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#pullrequestreview-6102601547). Originally posted by [Halfect](https://github.com/Halfect) on 2026-11-29T11:08:26Z. **Review:** APPROVED --- 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.
P1ayer-1 commented 2026-11-29 18:20:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by P1ayer-1 on 2026-11-29T18:20:56Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7260410593 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7260410593). Originally posted by [P1ayer-1](https://github.com/P1ayer-1) on 2026-11-29T18:20:56Z. --- 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.
bstillbstill commented 2026-11-30 14:11:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by bstillbstill on 2026-11-30T14:11:39Z.


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.)

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280983276 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2133#issuecomment-7280983276). Originally posted by [bstillbstill](https://github.com/bstillbstill) on 2026-11-30T14:11:39Z. --- 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

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
trustno1-coder/VIctory-NVIDIA!2133
No description provided.