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

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

@⁠botto854 on GitHub · 2026-11-29 11:10 UTC · original
botto854:fix-2081-title-headroom → main · +78 −0 · 2 files · 1 commits · closed without merging

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

**@⁠botto854** on GitHub · 2026-11-29 11:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263) `botto854:fix-2081-title-headroom` → `main` · +78 −0 · 2 files · 1 commits · closed without merging Fixes #2081 ## What it changes **Cause** ([details and stacks in #2081](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/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 - [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)
DLSS's NGX start has the CUDA driver reserve 36 + 28 GiB at fixed
addresses in [4 GiB, 2^37) (0xf00000000, 0x1800000000; RTX 4090,
RTX 3090 Ti). Since #1041 caps title memory there, the title's 6.1 GiB
TileHeap found no hole and the title stopped at its start (+0x1e6c284).

main now reserves 7 GiB in that window right after the upload pool,
before Streamline loads. CUDA then places its 28 GiB above 2^37 and the
TileHeap fits below. If a capped request still finds no room, the held
room is given back and the request retried.

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

@⁠Ondra97 on GitHub · 2026-11-29 12:29 UTC · original

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

**@⁠Ondra97** on GitHub · 2026-11-29 12:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7255847817) 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).
Author
Owner

@⁠tippythetaidum on GitHub · 2026-11-29 12:32 UTC · original

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.

**@⁠tippythetaidum** on GitHub · 2026-11-29 12:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7255889839) 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.
Author
Owner

@⁠RomanFama592 on GitHub · 2026-11-29 12:53 UTC · original

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.

**@⁠RomanFama592** on GitHub · 2026-11-29 12:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7256135637) 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.
Author
Owner

@⁠botto854 on GitHub · 2026-11-29 14:34 UTC · original

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.

**@⁠botto854** on GitHub · 2026-11-29 14:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7257413686) 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.
Author
Owner

@⁠Thomas316 on GitHub · 2026-11-29 20:29 UTC · original · edited 2026-11-29 20:31 UTC

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.

**@⁠Thomas316** on GitHub · 2026-11-29 20:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7262120665) · edited 2026-11-29 20:31 UTC 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.
github-bot closed this pull request 2026-11-29 20:57:39 +00:00
Author
Owner

@⁠botto854 on GitHub · 2026-11-29 20:55 UTC · original

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!

**@⁠botto854** on GitHub · 2026-11-29 20:55 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2263#issuecomment-7262464008) 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

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