Skip to content

D3D12.X: an allocator put aside keeps its recordings' memory (#1358) - #1422

Open
venglov wants to merge 1 commit into
xcl-dev:mainfrom
venglov:d3d12x-pending-per-pc-allocator
Open

venglov wants to merge 1 commit into
xcl-dev:mainfrom
venglov:d3d12x-pending-per-pc-allocator

Conversation

@venglov

@venglov venglov commented Nov 24, 2026

Copy link
Copy Markdown

Fixes #1358.

When the title resets a command allocator while the GPU still runs what was recorded on it, alloc_pool (#897) puts that PC allocator aside and returns S_OK. real::alloc_reset took the S_OK as "the GPU is done" and freed every unified-memory block that ended recordings had filed under the title's allocator: root argument tables, io and AllocateUploadMemory blocks. Coherent blocks go back on the pool's LIFO stack, so the next translated draw can take one and write over arguments a submitted draw has not read yet; sparse ones are decommitted. #897 counted 240 such swaps in 60 s of a retail title's world. Filing the blocks under the title's allocator could not work either: since #897 it stands for PC allocators that change, so no one Reset could tell whether the GPU was done with all of them.

Now a recording's blocks are filed under the PC allocator it is on, and alloc_pool gives a PC allocator's blocks back at the title's Reset once the GPU has passed every submit on it (whether it is in use, was reset or was put aside).

What is in it
One commit:

  • alloc_pool.rs: title_reset gives back the blocks of the title allocator's PC allocators whose submits the GPU has passed (done_with, Backing::idle); a PC allocator made here gives its blocks back when it is released. Tests ended_recordings_keep_their_memory_until_the_gpu_passes_their_allocator (CPU) and a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads (D3D12 device, through the Reset hook, with the queue held on a fence).
  • real.rs: alloc_reset frees the blocks itself only when it reset the title's allocator itself.
  • list_x.rs: reset_x, the Wait64 mid-list split and KickoffX's split give bind the PC allocator the new recording is on. Test a_recordings_memory_is_held_for_the_pc_allocator_it_is_on (CPU).
  • bind.rs, console_list.rs: doc comments only.

Tested
No Windows machine here: Apple M1 Pro, macOS 27.2, Wine 11.21 (Gcenx build) with Wine's D3D12 on MoltenVK 1.4.0, under Rosetta 2. Rust 1.100.0, x86_64-pc-windows-gnu (mingw-w64 14.0.0), debug. Every test binary of cargo test --workspace --no-run run under Wine with --test-threads=1 (with 4 threads the lib test binary exits with status 5 a few seconds in, on main too).

  • this PR, 7901856: 745 passed, 9 failed, 41 ignored; SKIPPED: 89 no GPU, 5 no DXC
  • main, 930e8b4: 742 passed, 9 failed, 41 ignored; the same skips
  • the same 9 fail on both (Wine / MoltenVK): disk_free_space_ex_reports_pls_quota, test_title_runs_and_game_folder_is_untouched, readable_answers_from_the_working_set_without_touching_pages, timestamps_outside_unified_memory_land_after_the_queue, write_buffer_immediate_on_open_existing_heap_visible_to_cpu, a_tile_decommitted_and_committed_again_keeps_its_video_memory, ensure_mapped_with_query_holes_skips_uncommitted_pages_on_readback, d32s8_targets_take_their_own_size_of_video_memory, reset_dxgi_device_manager_with_d3d12_device_and_token_validation
  • the three new tests with real.rs and list_x.rs put back as on main (and title_reset freeing the title allocator's blocks on success, as alloc_reset did): all three fail. The device test finds the blocks freed at the swap (left: []); the list_x test finds the recording filed under the title's allocator.

Regression run
None yet: no Windows PC and no retail title here. This stays a draft until scripts/smoke.ps1 runs on main and on this head are in.

Not tested

  • Windows, any NVIDIA / AMD / Intel GPU, the Windows D3D12 runtime; the GPU tests that need SM 6.6 or DXC (skipped above).
  • A retail title. Whether the overwritten arguments explain any of the reported GPU hangs or device removals is not measured.
  • XCL_CONSOLE_LISTS=1: its lists are not tracked by alloc_pool, so its allocators are never put aside; unchanged.
  • Not changed here: a KickoffX without a mid-list split keeps the list's blocks with the PC allocator of its last Reset, so if the title resets its allocator while that list is open, blocks recorded after the KickoffX stay filed under the earlier one. And the split's newly created segments leave no submit marks in alloc_pool, as before (D3D12.X: track split and created lists on alloc_pool's active backing #1071 registers them).

AI use

  • Claude Code (Claude Opus 5.5): traced the issue, wrote the fix, the tests and this description, and ran the tests above.

🤖 Generated with Claude Code

…#1358)

A title's allocator Reset while the GPU still runs what was recorded on
it puts that PC allocator aside (alloc_pool, xcl-dev#897) and returns S_OK.
real::alloc_reset took the S_OK as "the GPU is done" and freed every
unified-memory block that ended recordings on the title's allocator had
used: root argument tables, io and AllocateUploadMemory blocks. Coherent
blocks go back on the pool's LIFO stack, so the next translated draw can
take one and write its arguments over those a submitted draw has not
read yet; sparse ones are decommitted. xcl-dev#897 counted 240 such swaps in
60 s of a retail title's world.

The blocks were also held under the title's allocator, which since xcl-dev#897
stands for PC allocators that change, so no one Reset could tell whether
the GPU was done with all of them.

A recording's blocks are now held for the PC allocator it is on (the one
alloc_pool's reset_list hands to the PC Reset), and alloc_pool gives a
PC allocator's blocks back at the title's Reset once the GPU has passed
every submit on it, whether it is in use, was reset or was put aside. A
PC allocator made here that is released gives its blocks back with it.

The device test through the Reset hook finds the blocks freed at the
swap on the old code (run on Wine's D3D12 over MoltenVK; no Windows
machine here).

Fixes xcl-dev#1358.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ySKELLETONX

Copy link
Copy Markdown

Test report on head 7901856, on Windows with a GPU (the description has Wine / MoltenVK only). AI-written (Claude Code, Claude Opus 5.5) from real runs; checked by me.

Tested

  • AMD Radeon RX 7600 XT (RDNA3, driver 32.0.32015.2008), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0 (stable-x86_64-pc-windows-msvc), debug build, DXC from Windows SDK 10.0.26100
  • scripts/test.ps1 (cargo test --workspace -- --test-threads=4): 754 passed, 0 failed, 41 ignored; no SKIPPED lines (so the 9 Wine failures and the no GPU / no DXC skips in the description do not occur here)
  • The three new tests pass, and a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads ran on the D3D12 device (not skipped).
  • With real.rs and list_x.rs put back as on the base 930e8b4 (alloc_pool.rs kept as in this PR): a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads fails at alloc_pool.rs:530, the memory of a recording the GPU had not run is held over the Reset (left: []). ended_recordings_keep_their_memory_until_the_gpu_passes_their_allocator passes in that state, since it calls title_reset_with directly, not through alloc_reset; I did not also make title_reset free on success as the description did.

Not tested

  • NVIDIA, Intel, WARP; XCL_CONSOLE_LISTS=1; any retail title (no smoke runs).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 79018563 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 790185635d73eb160a44e1822682099e1fbcefc3
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14813 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA test report for 7901856 (part of #2057's stack). RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug. The PR is merged onto main 568e7db, with main run as a control on the same machine the same hour.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1156 passed, 1 failed, 46 ignored. main 568e7db: 1153 passed, 1 failed, 46 ignored.
    • The one failure is test_title_runs_and_game_folder_is_untouched in both, because my build step ran only cargo build --workspace --tests, so xcl_testtitle.exe and testgame_mw.dll, built from the repository's tests/testtitle, were missing (the panic says "build first: cargo build --workspace"). So the end-to-end test did not run here.
    • SKIPPED (25 in both): mostly no wave64 (20), plus cannot disable the driver cache and no heap windows.

AI-assisted (Claude Code). Synthetic tests only; no title run.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 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.

D3D12.X: alloc_reset frees UMA/sparse shader argument tables while alloc_pool keeps a busy allocator aside

6 participants