Skip to content

D3D12.X: free buffer mirrors no draw used for 10 seconds - #825

Open
Cattn wants to merge 1 commit into
xcl-dev:mainfrom
Cattn:mirror-idle-free
Open

Cattn wants to merge 1 commit into
xcl-dev:mainfrom
Cattn:mirror-idle-free

Conversation

@Cattn

@Cattn Cattn commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

A buffer view outside unified memory gets a mirror that each draw copies what it reads into. Mirrors are never freed, so a title that binds ring buffers at new addresses while it streams its world keeps making them. On a retail title they reached 925 MB at 74 s, on the way to the 2 GiB cap. That memory is both system commit and, through the sparse pools, video memory, and on a 32 GB / 12 GB machine it is part of what runs the process out of memory during world loading.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: each mirror records when a lookup last used it. When a new mirror is made, at most once a second, mirrors unused for 10 s are taken out of the table and their sparse or coherent memory is freed. A range bound again later gets a new mirror, filled from the title's memory as before. A unit test covers the lookup marking a mirror used and the idle sweep.

Tested

  • NVIDIA GeForce RTX 4070 (driver 32.0.16.1742), AMD Ryzen 7 7800X3D, Windows 11 10.0.26200, rustc 1.93.1, debug tests and release smoke builds
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on b12bf42 (rebased on beaa245): 714 passed, 0 failed, 41 ignored
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)

Regression run

main:

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: NVIDIA GeForce RTX 4070
title: 7f4b2c91
seconds: 60
exit: 0x0
frames shown: 1516 (PresentX 1516)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16272 MB

this PR:

xcl-smoke v1
commit: b12bf42d76951c08f35c4b34d11f3aa13a53504e
gpu: NVIDIA GeForce RTX 4070
title: 7f4b2c91
seconds: 60
exit: 0x0
frames shown: 1550 (PresentX 1551)
presents per 2 s (last 3): 60 49 44
device removals: 0
crashes: 0
peak commit: 18262 MB

Not tested

  • A full world-loading run with this change alone: the 60 s smoke run ends before the title streams its world, where mirrors pile up, so it shows no regression but not the saving. The 925 MB figure is from a longer run without this change.
  • AMD and Intel GPUs, wave64 hardware.
  • Command lists recorded once and executed again more than 10 s later with a mirrored buffer bound would read a freed mirror (zeros for a freed sparse range). I did not find such a case in the title I ran.

AI use

  • Claude Code with Claude Opus 5.5: found the growth in the logs, wrote the change, the test and this description. It also ran the tests and smoke runs on the hardware above. A person has not yet reviewed the diff line by line.

🤖 Generated with Claude Code

@Cattn
Cattn marked this pull request as ready for review November 24, 2026 06:12
A buffer view outside unified memory gets a mirror (a sparse or coherent
allocation each draw copies what it reads into). Mirrors were never
freed, so a title that binds ring buffers at new addresses while it
streams its world kept making them: a retail title reached 925 MB of
mirrors at 74 s, on its way to the 2 GiB cap, in both system memory and
the sparse pools' video memory.

A lookup now marks its mirror used. Once a second, the next new mirror
first takes out the ones unused for 10 s and frees their memory; a range
bound again later gets a new mirror filled from the title's memory.
@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, applied on main@beaa245:

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
test result: 738 passed; 0 failed; 41 ignored   (20 blocks, exit 0)

That is one more passing test than main on the same box (737), so the idle-mirror sweep (free buffer mirrors no draw used for 10 s) runs green here and nothing else in the workspace changes verdict. No game data, hardware adapter, no Wine.

AI-assisted (opencode): applied the patch to a built tree, ran the suite, restored the two files.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head b12bf42 onto main 1ec4c98, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 706 passed, 10 failed, 41 ignored. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Unused buffer mirror reclaim tests green; no new failures.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@iggyvilla

Copy link
Copy Markdown
Collaborator

Review of b12bf42 (read only, nothing built or run by me): I think the 10 s idle rule can free a mirror that a recorded list still binds.

What the timer measures. A mirror is stamped only by find_mirror, which runs at record time: gpu_va -> mirror_of (list_x.rs:3066) when a buffer is bound, and sync_title_buffers -> mirrored (:3199-3200) at every draw. What the PC list holds is the mirror's GPU address (pc_va(p) at :3067), so the GPU reads the mirror when the list executes, not when it is recorded. "Not looked up for 10 s" therefore means "not recorded against for 10 s", not "no GPU work uses it".

Where it frees. mirror_of takes the idle entries out of the table and free_mirrors frees them straight away on the recording thread: u.free(p) for a coherent block, sparse::free(p) for a sparse one. There is no fence or allocator check. So if a list that bound a mirror is submitted (or is still executing, or is executed again, which D3D12 allows for a closed list) more than 10 s after its last draw was recorded, and any other thread creates a new mirror in between, the GPU reads a mirror that was freed. For a coherent block that can be memory the next alloc has already handed out and overwritten, so the draw reads another range's bytes rather than zeros; the PR text only describes the sparse case.

I have not shown that the title does this (the retail runs in the PR may never record that far ahead), so I'd call it a hypothesis about a window, but the code has no protection against it. Two ways to close it that the tree already has: hold the freed blocks until the allocator of the lists that could bind them resets (console_list::hold_until_reset / allocator_reset, the lifetime #838 relies on for its arena), or stamp each mirror with the submission it was last bound in and free only below completed work. A test that binds a mirror in a closed list, lets it go idle and checks it is not freed would pin it; the current test covers only find_mirror and take_idle_mirrors.

Smaller points:

  • The sweep only runs after a lookup miss in mirror_of (:3150 returns on a hit first), so once the title stops binding new ranges nothing sweeps and the table stays at its peak. A sweep from submit/present, or when MIRROR_BYTES crosses a threshold, would also reclaim after streaming stops.
  • free_mirrors returns at let Some(u) = uma::get() else { return } after take_idle_mirrors already removed the entries, so their bytes stay in MIRROR_BYTES. Only matters at shutdown.

AI use: read with Claude Code, Claude Sonnet 5.5, against the PR head; the findings are mine and I checked each line reference.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/list_x.rs
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

rtfmbrah pushed a commit to rtfmbrah/linux-xcl-nvidia that referenced this pull request Nov 26, 2026
rtfmbrah pushed a commit to rtfmbrah/linux-xcl-nvidia that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants