Skip to content

Memory: decommitted sparse tiles stay mapped until the next submit - #532

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
Vaximous:sparse-park-decommitted-tiles
Nov 24, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
Vaximous:sparse-park-decommitted-tiles

Conversation

@Vaximous

@Vaximous Vaximous commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A sparse window tile whose pages are all decommitted was unmapped at once (UpdateTileMappings with a NULL range, then a queue signal), and a commit at the same address mapped a pool tile again. Each of these calls took 0.12–0.15 ms in the NVIDIA driver here.

The retail title moves physical pages one at a time while it loads after its menus (MapTitlePhysicalPages, one page a call, on the thread that presents): thousands of tiles a second are decommitted and committed again. Timing probes in that phase: about 1,400 calls a second at ~0.68 ms each, 96% of that thread's time; symbolized thread dumps put it in nvwgf2umx → D3D12Core under sparse::State::map_tiles / unmap_tiles. When presents stop for more than about 30 s the title's own stall watchdog ends it (#232).

A tile that goes is now parked: it stays mapped in its window and keeps its pool tile, and nothing is sent to the GPU. Parked tiles are unmapped together, one UpdateTileMappings per window, and their pool tiles freed (flush_parked):

  • before the next title submit (before_execute, before anything is uploaded), so title work never sees a decommitted tile mapped;
  • when the free list runs out (take_tile flushes before it creates a new pool or fails, and then does not retire the pools it just freed);
  • when 4,096 are parked. That bounds the video memory parked tiles hold to 256 MB beyond what is committed.

A commit at a parked address before that takes its pool tile back with no mapping call and queues the whole tile to be cleared (to_zero), as a reused tile is.

Who else reads tile mappings:

  • mapped no longer holds a parked tile, so readback_ranges, before_execute's dirty scan, sync_sent_range and to_zero (pruned to mapped tiles by decommit_tiles) skip it, as they did when it was unmapped.
  • mapped_ranges / runs (title texture uploads) drop it: runs is reset and MAPPED_GEN bumped on park, and again when a parked tile is taken back, which maps nothing new.
  • release_if_unused (a placed buffer released) does not free a parked pool tile; flush_parked does not free a pinned one, as the unmap did not.
  • retire_free_pools does not count parked tiles as free, so their pool stays.
  • pool_bytes (XCL_ACTIVITY) counts them as in use.
  • free and the decommit paths in kernelx and placeholders all go through decommitted.
  • A state replaced by init drops its parked tiles with its pools.

One case behaves differently: a tile a placed buffer pins, decommitted and committed again before the next submit, is mapped back to the same pool tile (and cleared) instead of to a new one.

committed / decommitted keep their locking; their bodies moved into State::commit_range / decommit_range so that the test can drive a state of its own.

Overlaps: #236 (open) moves the VirtualAlloc / VirtualFree of sparse commits under the sparse lock and restructures the same functions; the two would need a rebase against each other but do not do the same thing. #262 is about CPU-write uploads beside the title queue; this does not change when or how those uploads run. #254 speeds up committed_page's VirtualQuery, not this path. A second PR, kernelx: a page moving between addresses is copied there, not via home, removes the home's two tile mappings per moved page. The two do not depend on each other, and together they bring the pause down the most.

What it does not achieve: the title still does not reach gameplay. With both PRs on a local tree it gets through the pause and keeps loading, but its memory keeps growing (peak commit 44 GB at 300 s, still rising; local video memory 19.4 GB on a 12 GB card). Memory growth, as in #248, is the next stop; that tree carries an earlier form of #288.

What is in it

  • Memory: decommitted sparse tiles stay mapped until the next submit (crates/xcl/src/hle/d3d12x/sparse.rs): State::parked, PARKED_MAX, flush_parked and its calls in before_execute, take_tile and the decommit path; taking a parked tile back in ensure_mapped; the release_if_unused check; and the test a_tile_decommitted_and_committed_again_keeps_its_video_memory. The test checks:

    • a decommitted tile is parked with no mapping call (the state's fence value unchanged) and is not freed by release_if_unused;
    • a commit there takes the same pool tile back with no mapping call, queues it to be cleared and bumps MAPPED_GEN;
    • a flush unmaps it and frees its pool tile;
    • with the free list empty, the next commit elsewhere flushes and takes it.

    It does not compile on main. With taking back disabled it fails.

Tested

  • NVIDIA GeForce RTX 4070 Ti 12 GB, driver 617.42 (32.0.16.1742), 32-lane waves; AMD Ryzen 9 7900X; 64 GB; Windows 11 Pro build 26300; rustc 1.100.0. Tests in debug, game runs in release. The PC was in use for other work during the runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 7f94c6f: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • Retail title, menus walked with XCL_PRESS_A_AT=14,17,21,40,60,66,72, 150 s runs. The loading pause is measured as the longest stretch with 0 presents (XCL_ACTIVITY lines, 2 s windows).
    • On this branch's base (main at 2997c9a), back to back, two runs each: neither main nor this branch reaches the phase within 150 s. In all four runs the title spends about 110 s at 7–9 presents per 2 s with no DirectStorage requests (an intro / logo screen), then loads at up to 60 presents per 2 s; longest gap with 0 presents 2 s and 2 s (main), 2 s and 4 s (this branch); 22,701–23,918 DirectStorage requests; frames 1,024 and 1,104 (main), 1,062 and 1,122 (this branch); no crash; peak commit 16.4–16.6 GB.
    • On a local tree of main plus other open PRs (Memory: a scatter or map home of n pages costs O(n), not O(n²) #254 among them), which gets into the phase about 36 s in: without this change the pause was 22 s, 22 s and 20 s (1,478, 1,522 and 1,596 frames in 150 s); with it 12 s and 8 s (1,843 and 1,986 frames), the runs back to back. No run crashed. Earlier runs of that tree without the change had pauses of 24 s and 30 s or more, three of those four ended by the watchdog; earlier runs with this change were 20 s and 18 s.
    • The same tree with both this change and the kernelx PR: pause 10 s and 10 s, no crash. In a 300 s run: no crash, 70,348 DirectStorage requests, 1,720 frames.

Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60, no input, release builds; main at 2997c9a (this branch's base).

main:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: NVIDIA GeForce RTX 4070 Ti
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1464 (PresentX 1464)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14470 MB

this PR:

xcl-smoke v1
commit: 7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5
gpu: NVIDIA GeForce RTX 4070 Ti
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1496 (PresentX 1496)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14457 MB

Not tested

  • AMD GPUs and GPUs with 64-lane waves; titles other than the retail title.
  • The loading phase on this branch built from main alone: main does not get there within 150 s (above), so the pause figures are from the local tree.
  • Gameplay: the title does not reach it with or without this change.

AI use

  • Claude Code. Claude Opus 5.5: the diagnosis (timing probes, symbolized thread dumps), the code, the tests and this description. Claude Fable 5.2: planning and review of the diff.

A sparse window tile whose pages were all decommitted was unmapped at
once (UpdateTileMappings with a NULL range, then a queue signal), and a
commit there again mapped a pool tile anew. Each of these calls took
about 0.12-0.15 ms in the NVIDIA driver on an RTX 4070 Ti.

A retail title moves physical pages one at a time while it loads, on the
thread that presents: thousands of tiles a second are decommitted and
committed again, and timing probes and symbolized thread dumps put that
thread in the driver under map_tiles / unmap_tiles most of the time. With
presents stopped for more than 30 s the title's own stall watchdog ended
it.

A tile that goes is now parked: it stays mapped in its window and keeps
its pool tile, and nothing is sent to the GPU. The parked tiles are
unmapped together (one UpdateTileMappings per window) and their pool
tiles freed (flush_parked) before the next title submit
(before_execute), when the free list runs out (take_tile), or when 4096
are parked (256 MB of video memory). A commit at a parked address before
that takes its pool tile back with no mapping call and queues it to be
cleared (to_zero), as a reused tile is. Readers of `mapped` see a parked
tile as unmapped, MAPPED_GEN changes when one is taken back, and
release_if_unused does not free a pool tile that is parked.

committed / decommitted keep their locking; their bodies are now State
methods (commit_range / decommit_range) so the test can drive a state of
its own.

Assisted-by: Claude Code (Claude Opus 5.5)
@vibryxcx

Copy link
Copy Markdown

Regression run on an AMD GPU, which Not tested lists, on the same retail title.

Tested

  • AMD Radeon RX 6800 (RDNA2, 64-lane waves, driver 32.0.21045.5002), Intel Core i5-10600KF, Windows 11 build 26200, Rust 1.100.0 MSVC, release build. cargo clean --release -p xcl before each build.
  • This PR's head 7f94c6f as it is, against its base, main 2997c9a. No uncommitted changes.
  • Standard run: scripts/smoke.ps1 -Game <folder> -Seconds 60, no input. Menu run with the presses from the description, XCL_PRESS_A_AT=14,17,21,40,60,66,72, -Seconds 180.
2997c9a 7f94c6f
frames shown, 60 s / 180 s 599 / 537 700 / 560
longest stretch with 0 presents after 10 s, 60 s / 180 s 4 s / 2 s 4 s / 4 s
DirectStorage requests, 60 s / 180 s 9,766 / 18,901 9,766 / 18,901
sparse pools at the end of the 180 s run 960 MB (951 MB mapped) 960 MB (951 MB mapped)
crashes / device removals 0 / 0 0 / 0
peak commit, 60 s / 180 s 15,171 / 15,555 MB 15,143 / 15,595 MB

Regression run

main 2997c9a:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 6800
title: GTA6
seconds: 60
exit: 0x0
frames shown: 599 (PresentX 599)
presents per 2 s (last 3): 35 36 34
device removals: 0
crashes: 0
peak commit: 15171 MB

This PR 7f94c6f:

xcl-smoke v1
commit: 7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5
gpu: AMD Radeon RX 6800
title: GTA6
seconds: 60
exit: 0x0
frames shown: 700 (PresentX 700)
presents per 2 s (last 3): 35 34 37
device removals: 0
crashes: 0
peak commit: 15143 MB

Not tested

  • The loading pause itself: as in the description's runs on 2997c9a, neither build reaches the loading phase within 180 s here (same DirectStorage request count, both end in the menus at 3 presents per 2 s). So this is a regression check on AMD, not a check of the fix.
  • The suite on this machine.
  • One run of each.

AI use

  • Claude Code (Claude Opus 5.5): ran the tests and wrote this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the sparse and uma tests pass.

Review: A tile that is committed again while parked gets its contents cleared: decommit_range passes &mut self.to_zero to decommit_tiles, so the tile is queued for zeroing when it is parked, before it can be taken back, which is what the comment at the unpark says. The flushes before before_execute and when the free list runs out keep title work from seeing a decommitted tile mapped. I found nothing to change; this adds an RDNA4 suite run to the RDNA2 regression run above.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@iggyvilla

Copy link
Copy Markdown
Contributor

Read of 7f94c6f (nothing built or run by me); the parked-tile state machine and the take-back path look consistent to me. One statement in the description is not what the code does: "That bounds the video memory parked tiles hold to 256 MB beyond what is committed."

PARKED_MAX is checked once per decommit_range, after every tile of the range has been parked (sparse.rs:1346-1348). A single decommit of a large range (the title releasing a whole reservation, or sparse::free of a multi-GiB block, which calls decommitted(start, len)) therefore parks all the tiles it removes before the flush, so the peak is what the range had mapped, not 256 MB; the bound holds between calls. Flushing inside the loop when parked.len() reaches the limit would make the sentence true, or the sentence could say "between calls".

Smaller: take_tile flushes when the free list is empty (:579-582) but does not call retire_free_pools afterwards, so a pool freed that way stays allocated until the next flush from decommit_range or before_execute, where main retired on every decommitted. If that is intended, a line in the comment would say so.

AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.

@zondy1i

zondy1i commented Nov 24, 2026

Copy link
Copy Markdown

Test report for exact PR head 7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5 on an 8 GB NVIDIA card (Ampere, wave32).

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.2101), Ryzen 5 7500F, 64 GB RAM, Windows 11 Build 26300, DXC 1.9.2609.5, Rust 1.100.0 (x86_64-pc-windows-msvc), debug (tests) + release (smoke).
  • cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (2 SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)).
  • Peak GPU VRAM sampled via nvidia-smi during the full test run: 3143 MiB (no E_OUTOFMEMORY).
  • 60 s offline smoke run (XCL_NETWORK=0, XCL_ACTIVITY=1, folder name redacted to retail-title):
xcl-smoke v1
commit: 7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1460 (PresentX 1460)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14481 MB

End-of-run memory line: video memory 6143 MB local, 4620 MB non-local; target pages 3579 MB (pools 3584 MB); arenas 465 MB in use, 465 MB made; sparse pools 896 MB (837 MB mapped).

Not tested

  • Rebased/merged onto current main (tested exact PR head 7f94c6f only).
  • World loading past menus.

AI use

  • Antigravity (Gemini 4 Neon) ran the commands above on this machine and formatted this report from the real run output.

@iggyvilla

Copy link
Copy Markdown
Contributor

Read of 7f94c6f (nothing built or run by me); the parked-tile state machine and the take-back path look consistent to me. One statement in the description is not what the code does: "That bounds the video memory parked tiles hold to 256 MB beyond what is committed."

PARKED_MAX is checked once per decommit_range, after every tile of the range has been parked (sparse.rs:1346-1348). A single decommit of a large range (the title releasing a whole reservation, or sparse::free of a multi-GiB block, which calls decommitted(start, len)) therefore parks all the tiles it removes before the flush, so the peak is what the range had mapped, not 256 MB; the bound holds between calls. Flushing inside the loop when parked.len() reaches the limit would make the sentence true, or the sentence could say "between calls".

Smaller: take_tile flushes when the free list is empty (:579-582) but does not call retire_free_pools afterwards, so a pool freed that way stays allocated until the next flush from decommit_range or before_execute, where main retired on every decommitted. If that is intended, a line in the comment would say so.

AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merged (9aec53d). Checked on an RX 9070 (RDNA4) on main 9aec53d together with #532 and #556: cargo test --workspace -- --test-threads=4 - 683 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps as before and starts loading the world. The merge needed parked in the test-only State from #923. iggyvilla's two points stand and are worth a follow-up: the 256 MB bound holds between calls, not within one large decommit_range, and a flush from take_tile does not retire the pools it frees.

@ivall
ivall merged commit 236e1a3 into xcl-dev:main Nov 24, 2026
2 checks passed
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
Upstream's xcl-dev#532 (decommitted sparse tiles stay mapped until the next submit) adds State::parked; its new tests' State literals get W2's queue_rb and unlanded.
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
A copy back on a queue held by a Wait64 gate lands when the GPU gets there, possibly
after the title decommitted pages it covers. With xcl-dev#532 such a tile is parked (still
mapped) and may be committed again with the same pool tile, cleared through to_zero;
the sparse queue may also unmap it (flush_parked) before the gated queue runs the copy,
which then reads nothing there. copy_back only checked that the page is mapped and
committed at landing, so old bytes could be written over a page committed again since.

Each TileEntry now has an epoch that changes whenever a page of it is committed or
decommitted; the copy remembers its tiles' epochs and lands only on tiles whose epoch
is unchanged. The synchronous readback is ordered on the sparse queue and unchanged.

Not run.

Assisted-by: omp (Claude Opus 5.5)
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