Skip to content

Memory: keep single-window sparse_reserve allocations inside one window - #2886

Merged
raylitebull merged 1 commit into
xcl-dev:nvidia-devfrom
Decodere:fix-sparse-reserve-single-window
Nov 28, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:nvidia-devfrom
Decodere:fix-sparse-reserve-single-window

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Targets nvidia-dev (eae01502). Related to #2867.

After 3292b096 moved physical page homes out of window 0 into windows 1+ via Uma::sparse_alloc_above, Series S sparse-heap layouts place 664+ MiB of physical homes at the start of window 1 (0x11_0000_0000), leaving under 3.35 GiB in window 1 while window 2 (0x12_0000_0000) has a full 4 GiB free. Because Uma::sparse_reserve always passed single_window = false, a title reservation of at most one window (for example ~3.4 GiB) straddled the window 1 / window 2 boundary (0x12_0000_0000) instead of landing wholly inside window 2. Multiple sparse-window paths (title_buffer_window, uma_window_buffer, and view_bytes) reject or truncate ranges that cross a 4 GiB window boundary.

What is in it

  • crates/xcl/src/gpu/uma.rs (Uma::sparse_reserve):
    • Round size with checked arithmetic (size.max(1).checked_next_multiple_of(GRAIN)?), matching sparse_alloc and sparse_alloc_above.
    • When size <= WINDOW, first attempt take_sparse_in(&mut g, above_0, end, size, GRAIN, true) so single-window title reservations stay inside one window in windows 1+ whenever one has room (placing a ~3.4 GiB Series S arena wholly in window 2 after 664+ MiB of window 1 physical homes).
    • Fall back cleanly to take_sparse_in(&mut g, above_0, end, size, GRAIN, false) and then take_sparse_in(&mut g, lo, end, size, GRAIN, false) so window 0 stays uncluttered for 32-bit descriptor heaps and fragmented or multi-window (> WINDOW) reservations keep working unchanged.
  • crates/xcl/src/gpu/uma.rs (gpu::uma::tests::sparse_reserve_keeps_single_window_reservations_inside_one_window):
    • Reproduces the 3292b096 Series S startup layout (2892 MiB GPU heaps + 38 MiB view heap in window 0, 664 MiB physical homes in window 1) and asserts a 3500 MiB sparse_reserve lands wholly in window 2 (b + 2 * WINDOW) instead of straddling 0x12_0000_0000, smaller 256 MiB reservations reuse window 1's remaining tail, fragmented windows 1+ (2 GiB + 2 GiB across the boundary) still satisfy a 3 GiB reservation via cross-window fallback without touching window 0, and usize::MAX returns None.

Tested

  • Hardware & toolchain: Windows 11 Home (build 26200), Intel Core i5-11400F (6C/12T), 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (32-lane waves, driver 621.14), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug and release on origin/nvidia-dev (eae01502).
  • Baseline-fail proof on unmodified eae01502 sparse_reserve with only the new test added:
    • cargo test -p xcl --lib -- sparse_reserve_keeps_single_window_reservations_inside_one_window --nocapture --test-threads=1: 0 passed, 1 failed (left: 73710698496 = 0x11_2980_0000 straddling 0x12_0000_0000, right: 77309411328 = 0x12_0000_0000).
  • Fixed (237b7181):
    • cargo clippy --all-targets -- -A clippy::approx_constant: 0 new warnings and 0 errors in crates/xcl/src/gpu/uma.rs (1 pre-existing nvidia-dev clippy error remains in untouched crates/xcl/src/hle/d3d12x/sparse.rs:6393).
    • Debug: 3x cargo test -p xcl --lib -- gpu::uma::tests:: --test-threads=1: 19 passed, 0 failed, 0 ignored (0 skipped); cargo test -p xcl --lib -- physical_homes_leave_window_0_to_the_title --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored (0 skipped).
    • Release: 3x cargo test --release -p xcl --lib -- gpu::uma::tests:: --test-threads=1: 19 passed, 0 failed, 0 ignored (0 skipped); hle::kernelx::tests::: 59 passed, 0 failed, 1 ignored (0 skipped); hle::d3d12x::console_heap::tests::: 19 passed, 0 failed, 0 ignored (0 skipped).
    • cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4: 1819 passed, 5 failed, 48 ignored across 39 top-level test targets (30 expected SKIPPED notices: 21 wave64, 3 per-lane refusals, 3 D3D12 debug layer, 2 opt-in/heap-window skips, 1 Windows driver-cache toggle). All 5 failures are pre-existing on origin/nvidia-dev (eae01502) and unrelated to uma.rs: gpu_compute_thread_limits_leave_the_lanes_past_them_out (Tests: the split compute test's piece limit leaves room for the thread limit test #2854), split_compute_prefers_the_offline_whole_pipeline (Tests: the split compute test's piece limit leaves room for the thread limit test #2854), console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly (Tests: a console MS in the AS slot is refused by its MS translation #2788), async_compute_pso_registers_real_pso_and_not_standin (Tests: wait for late release before checking released pipelines are gone #2770), and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.

Regression run
Quiet 60 s release runs (scripts/smoke.ps1 -Seconds 60, XCL_NETWORK=0, default flags, RTX 4060 8 GB, driver 621.14). Includes same-day main ancestor (e120925e) for pr_check.py, freshly measured nvidia-dev target base (eae01502), and PR head (237b7181):

main ancestor (e120925e, same-day baseline for pr_check.py):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14025 MB

nvidia-dev target base (eae01502):

xcl-smoke v1
commit: eae015021c639866ab061cdff2e9daf8ba9daac5
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15268 MB

PR (237b7181):

xcl-smoke v1
commit: 237b7181b9b973a781dad8825101f03506237858
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16362 MB

Not tested

AI use

  • Google Antigravity (Gemini 4 Neon) audited Uma::sparse_reserve and 3292b096 on origin/nvidia-dev (eae01502), implemented the single-window-first placement and unit test, ran the baseline-fail check, clippy, unit/workspace tests, and paired 60 s retail smokes on the hardware above, and drafted this PR description.

After 3292b09 placed physical page homes in windows 1+ first via
`Uma::sparse_alloc_above`, the start of window 1 holds 664+ MiB of
homes on Series S sparse-heap layouts, leaving under 3.35 GiB in
window 1 while window 2 has a full 4 GiB free. Because
`Uma::sparse_reserve` always passed `single_window = false`, a title
reservation of at most one window (for example ~3.4 GiB) straddled the
window 1 / window 2 boundary (0x12_0000_0000) instead of landing
wholly in window 2.

Round `size` with checked arithmetic (`checked_next_multiple_of(GRAIN)?`),
try `take_sparse_in(..., above_0, end, size, GRAIN, true)` first when
`size <= WINDOW`, and fall back to cross-window placement in windows 1+
and then `lo..end` so window 0 stays uncluttered for 32-bit descriptor
heaps and fragmented or multi-window reservations keep working.

Related to xcl-dev#2867.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@joeypercia

Copy link
Copy Markdown
Contributor

@Decodere thanks for the fix. I ran it on the 12 GB card from #2867, where eae01502 crashed 3 of 3 times. With #2886 it still ended in the same window, 2 of 2 runs, so it does not cover what happens here.

Tree: #2867's (nvidia-dev eae01502 + #2794 + two local logging/input commits) with #2886 237b7181 merged, same settings as in #2867 (Series S profile, XCL_UMA_WINDOWS=16, XCL_COHERENT_HEAPS=sparse:1024, XCL_TWO_PASS_MB=3072), RTX 4070 Ti 12 GB, driver 621.40, warm caches.

run end
1 device removed 0x887a0006 at 203.8 s; DRED device state 7 (page fault, no breadcrumbs); the NVIDIA driver logged event 153 and 24 × event 13 at that moment
2 0xc0000005 at 167.5 s in game_scarlett_master.exe+0x4dd64da, read at 0xffffffffffffffff (rcx=0x3f8000003f800000, two floats of 1.0 where a pointer was expected); crash 2 in #2867 was the same read at +0x4dd64ec

So with #2886 the crash in the title still comes, and the other run faults on the GPU instead, at the same stage of the world load. The one run with 3292b096 reverted went to the 900 s cap. That fits your second point (the map_pages home check that only looks at the first and last page) more than the reservation crossing the window boundary, but I have not tested that.

AI use: Claude Code (Claude Opus 5.5) ran the runs on the hardware above, read the logs and wrote this.

@Decodere

Copy link
Copy Markdown
Contributor Author

Thank you @joeypercia for testing #2886 on the 12 GB #2867 setup — really helpful data.

Understood and agreed: #2886 alone does not stop the #2867 crashes, especially with @grahamster2's hardware measurement on #2867 showing Window 2 left only 3,911 MB contiguous vs the title's 3,977 MB MEM_64K_PAGES pool spilling into plain memory.

Keeping #2886 scoped strictly to Uma::sparse_reserve preventing <= 4 GiB reservations from straddling window boundaries when a clean single window exists (Related to #2867, not closing #2867), while leaving the Window 0 / top-down home placement fix to @grahamster2's #2867 PR.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…m, pure std)

Upstream single-commit 7575f67 on 8b957be: 1 file shaders.rs +38/-2.
Helper + 2 direct_sweep call-site swaps + regression test, hunk bodies
identical (only line offset from linux-only helpers). xcl-dev#2909/xcl-dev#2910 SKIP
(hle/d3d12x/real.rs, Windows-only); xcl-dev#2906 SKIP (dev-stack tip, same
shape as xcl-dev#2886); xcl-dev#2889 re-pinned f334cc9 (force-push, still SKIP).
@LocranKing

Copy link
Copy Markdown

Tested PR #2886 (237b7181) on Windows 11 (Series S / lockhart profile) with a 180 s open-world smoke comparison against base eae01502 and its unit test.

Environment

  • GPU: NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2140)
  • CPU / RAM: AMD Ryzen 5 5500 (6C/12T), 32 GB DDR4, Windows 11 Build 26300
  • Shader cache & runtime: Frozen nvidia-dev DXIL cache (XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PREPARE_GRAPHICS=0, XCL_DRED=1).

Unit test

cargo test --locked -p xcl --lib -- sparse_reserve_keeps_single_window --nocapture on 237b7181:

  • gpu::uma::tests::sparse_reserve_keeps_single_window_reservations_inside_one_window — ok (1 passed, 0 failed)

Paired 180 s Open-World Smoke Comparison (lockhart)

Run Exit Crashes / Removals Frames (PresentX) Heavy world start Peak Commit Peak Local VRAM Peak Non-Local Target Pages
Base eae01502 0x0 0 / 0 1764 109.31 s 25679 MB 8285 MB 4288 MB 3647 MB
#2886 (237b7181) 0x0 0 / 0 1845 116.05 s 26075 MB 8528 MB 4246 MB 3752 MB

Both runs entered the open world cleanly with 0 crashes and 0 device removals.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Merge status (I have been asked to prepare merges of PRs with several independent tests; the bar is: no open critical finding or performance regression, a fresh check of the merge result against today's main, and green required checks. Each merge is still confirmed by a person.)

This is against nvidia-dev, where Build and test is red on every open PR because of the branch's own test run, so nothing there can go in until that is fixed. I will run it in the world on an RTX 4080 16 GB with the current fast setup and post the result here, so the evidence is ready when the branch's check is green again.

AI use: Claude Code (Claude Fable 5.2).

@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: d1be8103644791b7a65f068954324e93d4b1b565 (nvidia-dev when tested)
head: 237b7181b9b973a781dad8825101f03506237858
merge: clean (git merge --no-commit --no-ff in a detached base worktree)
build: cargo build --workspace --locked -> ok
tests: cargo test --workspace --locked --no-fail-fast -- --test-threads=4 -> merge result 1,824 passed, 9 failed, 48 ignored, 26 skip notices; exact base with the same command and hardware 1,823 passed, 9 failed, 48 ignored, 26 skip notices. All nine failing instances matched; the PR's new sparse-reservation regression passed. Failures are listed below.
review: none after reading the complete one-file diff and tracing sparse_reserve through take_sparse_in, its free-list mutation, and the shared lock. The new behavior prefers one upper window when available; its cross-window fallback under fragmentation remains intentional. Checked arithmetic rejects oversized reservations.
performance: reasoned, not timed. At most one extra free-list scan occurs for a <= 4 GiB reservation when no single upper window fits. This is an allocation path; I did not measure title startup or frame time. No new per-frame loop was added.
verdict: not yet: the required Build and test check on nvidia-dev is red. This merge introduced no additional failures in my paired suite; the branch's inherited failures still need resolution before its CI gate can pass. I did not rerun the title smoke in this check.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti 12 GB / driver 621.35, rustc 1.99.1 MSVC. Codex (GPT-6.2 Sol) read the diff and ran the paired build and suites; Codex (GPT-6.2 Astra) independently checked the allocator invariant by static inspection.

Same nine failures on base and merge result
  • console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (1)
  • gpu_parts_of_a_texture_go_up_and_the_rest_stays and pieces_hold_the_texels_of_their_levels (2)
  • console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly (1)
  • async_compute_pso_registers_real_pso_and_not_standin (1)
  • split_compute_prefers_the_offline_whole_pipeline (2)
  • two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (2)

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 237b718

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d1be810 (nvidia-dev)
head: 237b718
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1825 passed, 8 failed, 48 ignored (27 SKIPPED lines). The 8 failures are the base's own on this GPU, the same six names with and without the PR (#2771 and #2788 fix three of them). Base alone: 1824 passed, 8 failed, 48 ignored.
review: none. A reservation of one window or less first tries to fit inside one window above window 0, then the old two attempts; the size rounding is overflow-checked; the new test fails on the base by reading the code. From the thread: it does not stop the #2867 crashes, and the description now says 'related'.
performance: default path, not per frame: up to three first-fit scans per title reservation; a reservation of 4 GiB or less now moves to the next window instead of straddling two (reasoned).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite unless said).

@raylitebull
raylitebull merged commit e33081b into xcl-dev:nvidia-dev Nov 28, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants