Skip to content

D3D12.X: a placement on title pages sweeps the idle ones, not every page - #490

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
imnicho:vram-idle-sweep
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
imnicho:vram-idle-sweep

Conversation

@imnicho

@imnicho imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Every placement of a texture on the title's pages of video memory (vram::Pages::bind – since #288 also the textures kept in step with title memory) looks at every page of both maps for the ones idle for 2 s. While a retail title streams its world that is tens of thousands of placements over more than 100 000 pages, on the title's thread that creates its resources and with PAGES held, which the title's queues wait for before their work (before_execute). This keeps a queue of the pages that went idle and sweeps from its front.

It is one part of what stalls frames while the world loads – the runs in which the title's null write comes (#232) – not all of it: see the last point under Tested.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: Pages::idle, the pages of both maps whose last user went, oldest first, each with that moment (release_tiles queues them), and sweep_idle, which takes the ones idle for IDLE from the front. An entry whose page was used again since – in use now, or idle again from a later moment, which has an entry of its own – is dropped. sweep_map, the look at every page, goes. Which pages go back to the pools, and when, is unchanged.
  • Test idle_pages_are_swept_from_their_queue (no GPU): pages idle for less and for more than IDLE, one used again, one idle again later, an extra page; and 20 000 sweeps beside 200 000 pages in use within 2 s (looking at every page: 4 000 000 000 looks).

Tested

  • hardware: Intel Core i7-7700K (4 cores / 8 threads), 16 GB RAM, NVIDIA GeForce RTX 5080 16 GB (driver 610.47), Windows 10 22H2 (19045), rustc 1.100.0 stable-x86_64-pc-windows-msvc; debug for the tests, release for the title.

  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 7695539: 677 passed, 0 failed, 41 ignored (SKIPPED GPU tests: gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask – no wave64).

  • game checked: the newer retail title of the README into its world streaming (first-run pages done before, a pad script through XCL_PRESS_AT), 300 s runs. A counter around the sweep in bind was added to both builds for this (it is not in the PR); both on the same local base, main a6f5f7a with Textures: copy linear mip levels a row at a time #334 and Rect lists: the CPU expansion finds the rect's corner, not always v1 #266 merged:

    by the title's placement main: time in the sweeps, page entries looked at this change: time in the sweeps, queue entries looked at
    16 384th 4 082 ms, 995 441 482 1 ms, 16 942
    36 864th (113 460 + 17 088 pages then) 14 475 ms, 2 922 636 089 3 ms, 38 067
    57 344th (133 053 + 18 586 pages) not reached 5 ms, 58 975

    The main run ended at 225 s with the title's null write (+0x2215c35 on its stack, as in Retail title: null write at +0x2215c35 (#159) still hits on NVIDIA RTX 4070 Ti, with and without XCL_NETWORK=0 #232), 23 s after its last frame and with 13 frames in the 75 s before it; the run with the change reached its 300 s. That is one run each on a PC that pages heavily at that point, so I do not claim the difference in how they ended for this change.

  • What the rest of that stall is, from 12 thread dumps 7 s apart in the run with the change (150 s – 227 s, no frame presented for most of it): in 10 of them a title thread was building a texture layout's tables (gpu::tiling::Layout::from_bits – what Textures: a layout's high-coordinate tables hold one period, not 65536 entries #435 shrinks), in 4 one was in the upload of kept-in-step textures (title_textures::refresh).

Regression run

Both for 150 s with XCL_PRESS_AT=45:A,85:A,92:A,99:A,106:A,113:A in the environment (the script of the runs above).

main:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 150
exit: 0x0
frames shown: 773 (PresentX 773)
presents per 2 s (last 3): 4 3 4
device removals: 0
crashes: 0
peak commit: 14692 MB

PR:

xcl-smoke v1
commit: 76955398ea14836ff70aded18a18e9dbaac95b1b
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 150
exit: 0x0
frames shown: 762 (PresentX 762)
presents per 2 s (last 3): 3 4 3
device removals: 0
crashes: 0
peak commit: 14691 MB

On plain main the title's intro video plays at about 2 frames a second on this CPU (what #334 is about), so in 150 s neither of these runs gets to the world's streaming: they are the regression check, with the placements of the first screens and of the video. The streaming numbers are the ones under Tested, on main with #334 and #266.

Not tested

  • The frame-rate effect apart from run-to-run variation: one run of each build, on 16 GB of RAM.
  • AMD and Intel GPUs: the change is bookkeeping on the CPU, no D3D12 call is different. A device with tiled resources below tier 2 has no Pages.
  • Runs longer than 300 s.

AI use

  • Claude Code with Claude Fable 5.2: found the cause from a thread dump at the title's null write, wrote the change, the test and this description, and ran the test suite and the title runs above on the machine named.

Duplicate check before opening (2026-11-24 00:59 UTC, main 2997c9a): no PR or issue about the sweep; #447 changes tests in the same file and #470 its tile mapping (each merges together with this cleanly), #292 other parts of it.

🤖 Generated with Claude Code

Every placement of a texture on the title's pages of video memory
(Pages::bind) looked at every page of both maps for the ones idle for 2 s.
A retail game streaming its world places textures by the ten thousand over
more than 100 000 pages: on an i7-7700K, by its 36 864th placement (213 s
into the run, 113 460 + 17 088 pages) the sweeps had looked at
2 922 636 089 page entries and taken 14.5 s of the title's thread that
creates its resources - with PAGES held, which the title's queues wait for
before their work (before_execute).

The pages whose last user went are queued with that moment, oldest first,
and a sweep takes the ones idle for IDLE from the front (sweep_idle); an
entry whose page was used again since is dropped. The same run with it:
3 ms in the sweeps by the 36 864th placement, 38 067 queue entries looked
at. Which pages go back, and when, is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 76955398ea14836ff70aded18a18e9dbaac95b1b on AMD (RDNA4); the PR was tested on NVIDIA only. The branch is based on 2997c9a, so I merged it onto current main 7ebf1b8 locally (clean merge, only vram.rs) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), 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
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) on the merge: 678 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 638 passed, 0 failed, 21 ignored
  • 0 SKIPPED; idle_pages_are_swept_from_their_queue passes, and so do the GPU tests on the same pages, placed_title_textures_share_vram_and_preserve_pixels and streamed_targets_stay_bounded

Review of the change: the only two places that make a page idle (idle_since = Some(now), both in release_tiles) now also queue it, and the immediate_cool path still takes the page out at once, so no idle page is left out of the queue. Every now that reaches release_tiles (unmap_superseded, forget_pages, bind) is taken after PAGES is locked, so the queue stays in time order within a Pages and sweep_idle can stop at the first entry that is not old enough. An entry for a page used again is dropped when it reaches the front, so the queue holds at most the releases of the last IDLE. The Arenas sweep is a separate structure and is unchanged. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), so the stall in the description was not measured here; no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main, and main 7ebf1b8 itself was not run on this machine.

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

@thehollowedone

Copy link
Copy Markdown

Tested

I applied the diff from 7695539 to the pinned baseline 9ce2070, which includes #451. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, debug.

With XCL_ADAPTER=3080 Ti and XCL_REQUIRE_GPU=1, I ran cargo test --offline --locked -p xcl --lib <filter> -- --test-threads=1 --nocapture. The VRAM group passed 7/7, including the idle-page queue test. The title-texture group passed 9/9, including the GPU checks for mirroring CPU writes and preserving pixels in shared VRAM. Both had zero reported skips or ignored tests.

Main moved to cb868b2 while testing. Compared with the pinned baseline, its tree adds the timer changes in kernelx.rs and host.rs. These results apply to 9ce2070 plus the PR diff. Full workspace, retail loading, and frame-time impact were outside this run.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

@grahamster2

grahamster2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Benchmark of 7695539 merged onto main 63cdc25 (#451, #435, #602 in; clean merge). Edited: rerun on the newer main. The first version of this comment was against 3db536e and is summarised at the end.

Setup: RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release builds. Retail title, XCL_NETWORK=0, A at 14/17/21/25/31 s, 180 s runs. Both caches were warmed with one run per build first (not counted); then 2 measured runs per build.

presents/s main run 1 / 2 main + #490 run 1 / 2
intro video (4–16 s) 22.5 / 21.6 22.2 / 19.2
menus + loading (16–44 s) 29.9 / 30.0 28.5 / 28.2
streaming starts 44.0 s / 44.0 s 48.4 s / 46.4 s
while streaming (44–84 s) 6.0 / 6.0 8.1 / 11.9
44–100 s 4.3 / 4.3 5.8 / 8.5
peak commit 30.2 / 30.0 GB 30.6 / 30.4 GB
peak local video memory 14.2 / 14.2 GB 14.6 / 14.3 GB
end (#232 watchdog, +0x23cf683) 98.5 / 99.4 s 103.5 / 107.6 s

Regression run (no presses, 60 s; the title folder is a neutrally named junction)

main:

xcl-smoke v1
commit: 63cdc25bc0d2b59cc2af85e6e23f619dfaf72866
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1634 (PresentX 1634)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14684 MB

PR merged onto main:

xcl-smoke v1
commit: 6d70eb0d00812016504d890adc175d352f87f563
gpu: NVIDIA GeForce RTX 3080
title: xcl-title
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14754 MB

Test report written with Claude Code (Claude Opus 5.5) from my own runs.

@theaustinayers
theaustinayers merged commit 72a97d8 into xcl-dev:main Nov 24, 2026
2 checks passed
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…l#490, ivall#347)

The fork keeps its own pso_async (short waits, all compute pipelines built ahead); ivall#690 upstream is its used-pipelines part.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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