Skip to content

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

Open
imnicho wants to merge 1 commit into
ivall:mainfrom
imnicho:vram-idle-sweep
Open

imnicho wants to merge 1 commit into
ivall: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 GTA VI: 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.

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.

3 participants