XMem: hold room below 2^37 before DLSS starts, so the TileHeap fits (#2081) #2263

Closed
botto854 wants to merge 1 commit from upstream-pr/2263 into main
botto854 commented 2026-11-29 11:10:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by botto854 on 2026-11-29T11:10:50Z.


Fixes #2081

What it changes

Cause (details and stacks in #2081): DLSS's NGX start goes through NVAPI into nvcuda64, which reserves 36 + 28 GiB at fixed addresses (0xf00000000, 0x1800000000) inside [4 GiB, 2^37). That happens before the title asks for its 6.1 GiB TileHeap. Since #1041 caps title memory below 2^37, no hole that size is left, XMemVirtualAlloc is refused (os error 8) and the title stops at +0x1e6c284. With DLSS off the unpatched release starts.

Change: main reserves 7 GiB in that window right after the upload pool (reserve_upload_space), before Streamline loads (xmem::reserve_headroom). That room is in CUDA's way: CUDA places its 28 GiB above 2^37 instead (CUDA memory is never read by the title's shaders), and the TileHeap fits below 2^37. If a capped request still finds no room, the held room is given back and the request is retried once (release_headroom).

  • crates/victory-hle/src/modules/xmem.rs +76 (incl. one test), apps/victory/src/main.rs +2.
  • No change where the window has room: the held 7 GiB is address space only, nothing committed.

Relation to #2133: complementary. #2133 keeps the game starting by placing the TileHeap above 2^37 when nothing below has room, which brings back the #218 risk for that pool. With this change the TileHeap lands below 2^37 in all my runs, so #2133's fallback is never reached. It is still a sensible safety net; the two touch different lines of XMemVirtualAlloc and should merge cleanly together.

How it was tested

  • GPU and profile: RTX 4090 24 GB (driver 617.14), i9-14900K, 32 GB RAM, Windows 11 build 26300 (native). Series X, 2560x1440, DLAA, DLSS frame generation 2X. Release build on top of 829188e9 (this branch plus the #2133-style fallback in my local build, which never triggered).

  • Before (829188e9): 3/3 starts refused size=6538919936 kind=0x42000 flags=0x23 (os error 8), then 0x80000003 at +0x1e6c284.

  • After: 3 starts, all reached the game, TileHeap below 2^37 every time, no fallback, no crashes.log entry:

    Run Ray tracing TileHeap DLSS
    1 on 0x1800000000 loaded (menu only)
    2 on 0x1800000000 20 upscalings, frame generation on
    3 off 0x222800000 2023 upscalings, frame generation on

    Memory map of the running game (run 3, VirtualQueryEx): CUDA 36 GiB at 0x1200000000, CUDA 28 GiB at 0x2000000000 (above 2^37), held room 7 GiB at 0x1dbfff0000, TileHeap 6.09 GiB at 0x222800000.

  • Shader changes: none.

  • cargo test -p victory-hle --lib xmem -- --test-threads=1: 47 passed, 0 failed, 1 ignored, including the new headroom_is_held_below_the_directory_and_given_back_once. (Without --test-threads=1, a_read_by_range_waits_only_for_a_remapping_that_meets_it fails the same way on 829188e9 without this change.)

  • Not tested: Wine/Proton, AMD/Intel, cards with less VRAM (CUDA's reservation sizes probably differ), Series S.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2133 (fallback above 2^37, complementary), #1811 (also changes address_range()), #2112 and #2150 (same refusal).

Written with Claude Code (Claude Opus 5.5): it found the cause under cdb, wrote the change and the test, and ran the builds and tests. The in-game runs were on my PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5550131180 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263). Originally posted by [botto854](https://github.com/botto854) on 2026-11-29T11:10:50Z. --- Fixes #2081 ## What it changes **Cause** ([details and stacks in #2081](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/2081#issuecomment-7254658575)): DLSS's NGX start goes through NVAPI into `nvcuda64`, which reserves 36 + 28 GiB at fixed addresses (`0xf00000000`, `0x1800000000`) inside [4 GiB, 2^37). That happens before the title asks for its 6.1 GiB TileHeap. Since #1041 caps title memory below 2^37, no hole that size is left, `XMemVirtualAlloc` is refused (os error 8) and the title stops at `+0x1e6c284`. With DLSS off the unpatched release starts. **Change:** `main` reserves 7 GiB in that window right after the upload pool (`reserve_upload_space`), before Streamline loads (`xmem::reserve_headroom`). That room is in CUDA's way: CUDA places its 28 GiB above 2^37 instead (CUDA memory is never read by the title's shaders), and the TileHeap fits below 2^37. If a capped request still finds no room, the held room is given back and the request is retried once (`release_headroom`). - `crates/victory-hle/src/modules/xmem.rs` +76 (incl. one test), `apps/victory/src/main.rs` +2. - No change where the window has room: the held 7 GiB is address space only, nothing committed. **Relation to #2133:** complementary. #2133 keeps the game starting by placing the TileHeap above 2^37 when nothing below has room, which brings back the #218 risk for that pool. With this change the TileHeap lands below 2^37 in all my runs, so #2133's fallback is never reached. It is still a sensible safety net; the two touch different lines of `XMemVirtualAlloc` and should merge cleanly together. ## How it was tested - **GPU and profile:** RTX 4090 24 GB (driver 617.14), i9-14900K, 32 GB RAM, Windows 11 build 26300 (native). Series X, 2560x1440, DLAA, DLSS frame generation 2X. Release build on top of 829188e9 (this branch plus the #2133-style fallback in my local build, which never triggered). - **Before** (829188e9): 3/3 starts refused `size=6538919936 kind=0x42000 flags=0x23 (os error 8)`, then `0x80000003 at +0x1e6c284`. - **After:** 3 starts, all reached the game, TileHeap below 2^37 every time, no fallback, no `crashes.log` entry: | Run | Ray tracing | TileHeap | DLSS | |---|---|---|---| | 1 | on | `0x1800000000` | loaded (menu only) | | 2 | on | `0x1800000000` | 20 upscalings, frame generation on | | 3 | off | `0x222800000` | 2023 upscalings, frame generation on | Memory map of the running game (run 3, VirtualQueryEx): CUDA 36 GiB at `0x1200000000`, CUDA 28 GiB at `0x2000000000` (above 2^37), held room 7 GiB at `0x1dbfff0000`, TileHeap 6.09 GiB at `0x222800000`. - **Shader changes:** none. - **`cargo test -p victory-hle --lib xmem -- --test-threads=1`:** 47 passed, 0 failed, 1 ignored, including the new `headroom_is_held_below_the_directory_and_given_back_once`. (Without `--test-threads=1`, `a_read_by_range_waits_only_for_a_remapping_that_meets_it` fails the same way on 829188e9 without this change.) - **Not tested:** Wine/Proton, AMD/Intel, cards with less VRAM (CUDA's reservation sizes probably differ), Series S. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2133 (fallback above 2^37, complementary), #1811 (also changes `address_range()`), #2112 and #2150 (same refusal). --- Written with Claude Code (Claude Opus 5.5): it found the cause under cdb, wrote the change and the test, and ran the builds and tests. The in-game runs were on my PC. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ondra97 commented 2026-11-29 12:29:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ondra97 on 2026-11-29T12:29:18Z.


Independent Windows check of the exact unmodified 581bb5d2 head, without the #2133 fallback. RTX 4070 Ti SUPER, driver 621.40, Series X, 2560×1440, DLSS Performance, RT requested, and FG off. The emulator image, shader, and PSO caches started empty. The existing NVIDIA driver cache was left in place.

The first constrained request for the 6,236 MiB TileHeap had no room. The patch released its reservation at 0x1dbfff0000 and successfully retried at 0x1d00000000, with the whole allocation below 2^37. The BVH early reserve still got all 50 pieces (3,200 MiB), and Streamline reported 21 successful DLSS upscales. No device fault was reported. This directly exercised the release-and-retry branch on a second GPU model.

One separately reproduced cold crash on 70702bcd, which has the baseline XMem path, failed the same allocation and stopped at the known breakpoint. The matched 829188e9 control happened to find a hole on this attempt. The result supports the reservation/retry fix and shows that the unpatched failure is intermittent on this machine. During the 210-second candidate probe, unrelated cold PSO work stayed pending and the RT builder did not activate. This covers the TileHeap startup failure without claiming a completed cold gameplay run.

Locked offline release build and serial XMem tests passed (47 passed, one ignored).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255847817 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7255847817). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-11-29T12:29:18Z. --- Independent Windows check of the exact unmodified 581bb5d2 head, without the #2133 fallback. RTX 4070 Ti SUPER, driver 621.40, Series X, 2560×1440, DLSS Performance, RT requested, and FG off. The emulator image, shader, and PSO caches started empty. The existing NVIDIA driver cache was left in place. The first constrained request for the 6,236 MiB TileHeap had no room. The patch released its reservation at 0x1dbfff0000 and successfully retried at 0x1d00000000, with the whole allocation below 2^37. The BVH early reserve still got all 50 pieces (3,200 MiB), and Streamline reported 21 successful DLSS upscales. No device fault was reported. This directly exercised the release-and-retry branch on a second GPU model. One separately reproduced cold crash on 70702bcd, which has the baseline XMem path, failed the same allocation and stopped at the known breakpoint. The matched 829188e9 control happened to find a hole on this attempt. The result supports the reservation/retry fix and shows that the unpatched failure is intermittent on this machine. During the 210-second candidate probe, unrelated cold PSO work stayed pending and the RT builder did not activate. This covers the TileHeap startup failure without claiming a completed cold gameplay run. Locked offline release build and serial XMem tests passed (47 passed, one ignored).
tippythetaidum commented 2026-11-29 12:32:49 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tippythetaidum on 2026-11-29T12:32:49Z.


Works here too, on another card. RTX 5080 16 GB (driver 621.14), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 26200. Source build of 829188e9 plus #1926 and #1930 (neither touches XMem). Series X 2560x1440, DLSS Performance, DLSS frame generation 4x.

  • Without this PR: 2 starts out of 2 stopped at +0x1e6c284, one right after a full preload and one plain start, each after XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 ... (os error 8).
  • With this PR (581bb5d2, cherry-picked): the TileHeap request was granted on its first try, 6236 MB, last 0x1a00000000+0x185c00000, below 2^37. The "room held from the start given back" line never appeared, so on this PC the hold alone kept the room free and the retry wasn't needed. The game reached the start screen. XMem tests (serial): 47 passed, 1 ignored.

#2133 didn't apply cleanly on top of this (both change xmem.rs), so I tested this one alone.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7255889839 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7255889839). Originally posted by [tippythetaidum](https://github.com/tippythetaidum) on 2026-11-29T12:32:49Z. --- Works here too, on another card. RTX 5080 16 GB (driver 621.14), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 26200. Source build of `829188e9` plus #1926 and #1930 (neither touches XMem). Series X 2560x1440, DLSS Performance, DLSS frame generation 4x. - **Without this PR:** 2 starts out of 2 stopped at `+0x1e6c284`, one right after a full preload and one plain start, each after `XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 ... (os error 8)`. - **With this PR (`581bb5d2`, cherry-picked):** the TileHeap request was granted on its first try, `6236 MB, last 0x1a00000000+0x185c00000`, below 2^37. The "room held from the start given back" line never appeared, so on this PC the hold alone kept the room free and the retry wasn't needed. The game reached the start screen. XMem tests (serial): 47 passed, 1 ignored. #2133 didn't apply cleanly on top of this (both change `xmem.rs`), so I tested this one alone.
RomanFama592 commented 2026-11-29 12:53:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by RomanFama592 on 2026-11-29T12:53:23Z.


On an RTX 4060 Ti 8 GB this start crash turned out to be #2055 (a 21:9 primary monitor), not the TileHeap placement. With VICTORY_NATIVE_SIZE=2560x1440, main starts both with and without this PR. For reference, here the CUDA reservation was 12 GB at 0xf00000000, and about 47 GB stayed free below 2^37 (!address at the title's breakpoint), so the TileHeap would have fit either way.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256135637 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7256135637). Originally posted by [RomanFama592](https://github.com/RomanFama592) on 2026-11-29T12:53:23Z. --- On an RTX 4060 Ti 8 GB this start crash turned out to be #2055 (a 21:9 primary monitor), not the TileHeap placement. With `VICTORY_NATIVE_SIZE=2560x1440`, `main` starts both with and without this PR. For reference, here the CUDA reservation was 12 GB at `0xf00000000`, and about 47 GB stayed free below 2^37 (`!address` at the title's breakpoint), so the TileHeap would have fit either way.
botto854 commented 2026-11-29 14:34:49 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by botto854 on 2026-11-29T14:34:49Z.


Thanks, that fits: the CUDA reservation seems to scale with VRAM. On an RTX 4090 (24 GB) here it was 36 GiB at 0xf00000000 plus 28 GiB at 0x1800000000, which left no 6.2 GB hole below 2^37 (3/3 starts failed). Your 8 GB card reserved 12 GB, so the TileHeap fits either way. The repros so far (4070 Ti SUPER 16 GB, 5080 16 GB, 4090 24 GB) are all 16 GB+ cards.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7257413686 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7257413686). Originally posted by [botto854](https://github.com/botto854) on 2026-11-29T14:34:49Z. --- Thanks, that fits: the CUDA reservation seems to scale with VRAM. On an RTX 4090 (24 GB) here it was 36 GiB at `0xf00000000` plus 28 GiB at `0x1800000000`, which left no 6.2 GB hole below 2^37 (3/3 starts failed). Your 8 GB card reserved 12 GB, so the TileHeap fits either way. The repros so far (4070 Ti SUPER 16 GB, 5080 16 GB, 4090 24 GB) are all 16 GB+ cards.
Thomas316 commented 2026-11-29 20:29:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Thomas316 on 2026-11-29T20:29:24Z.


Validated on a second machine — RTX 4070 Ti 12 GB (driver 621.40), i7-ish 16-thread, 64 GB RAM, Windows 11 26200, native. Series X, 1440p (2560x1440 + VICTORY_NATIVE_SIZE=2560x1440), DLSS Quality + DLSS FG 2x, via victory.exe play (Play-MyRig path).

Before (stock f889bb07): every Series X start died ~2–3s in at Frame 0 — XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 (os error 8), then 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x1e6c284. Same signature as #2081. Series S started fine (smaller TileHeap).

After (this PR merged onto f889bb07): starts past System Init and runs. From the play log:

no XMemVirtualAlloc refused
title memory asked for as protection 0x2004, kind 0x42000, flags 0x23: 1 times, 6236 MB, last 0x1300000000+0x185c00000 — TileHeap at 76 GB, below 128 GB as designed
DLSS Frame Generation: 19–21 presents with it on, 0 off, 38–42 frames shown (status 0x0), no static/block artifacts, vehicle panels present
VICTORY_ALIAS_TARGETS=1 + VICTORY_LAZY_TWINS=1 were also set (pre-#1041 GPU behavior) — the startup still failed without this PR and passes with it, so the fix is what made the difference, not the GPU switches.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262120665 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7262120665). Originally posted by [Thomas316](https://github.com/Thomas316) on 2026-11-29T20:29:24Z. --- Validated on a second machine — RTX 4070 Ti 12 GB (driver 621.40), i7-ish 16-thread, 64 GB RAM, Windows 11 26200, native. Series X, 1440p (2560x1440 + VICTORY_NATIVE_SIZE=2560x1440), DLSS Quality + DLSS FG 2x, via victory.exe play (Play-MyRig path). Before (stock f889bb07): every Series X start died ~2–3s in at Frame 0 — XMemVirtualAlloc refused size=6538919936 kind=0x42000 flags=0x23 (os error 8), then 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x1e6c284. Same signature as #2081. Series S started fine (smaller TileHeap). After (this PR merged onto f889bb07): starts past System Init and runs. From the play log: no XMemVirtualAlloc refused title memory asked for as protection 0x2004, kind 0x42000, flags 0x23: 1 times, 6236 MB, last 0x1300000000+0x185c00000 — TileHeap at 76 GB, below 128 GB as designed DLSS Frame Generation: 19–21 presents with it on, 0 off, 38–42 frames shown (status 0x0), no static/block artifacts, vehicle panels present VICTORY_ALIAS_TARGETS=1 + VICTORY_LAZY_TWINS=1 were also set (pre-#1041 GPU behavior) — the startup still failed without this PR and passes with it, so the fix is what made the difference, not the GPU switches.
botto854 commented 2026-11-29 20:55:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by botto854 on 2026-11-29T20:55:26Z.


Superseded by f72cec7 (v2026.11.29.04), which is in main now. Confirmed on the RTX 4090 that hit this every start: 3/3 crashes on v2026.11.29.03, 3/3 clean starts on v2026.11.29.04 (details in #2081). Thanks!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262464008 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7262464008). Originally posted by [botto854](https://github.com/botto854) on 2026-11-29T20:55:26Z. --- Superseded by f72cec7 (v2026.11.29.04), which is in main now. Confirmed on the RTX 4090 that hit this every start: 3/3 crashes on v2026.11.29.03, 3/3 clean starts on v2026.11.29.04 (details in #2081). Thanks!

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