D3D12.X: tolerate concurrent page decommits in title texture reads #484
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!484
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/484/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@XaviFortes on GitHub · 2026-11-24 00:56 UTC · original
XaviFortes:title-textures-safe-read-committed→main· +118 −4 · 1 files · 2 commits · merged 2026-11-24 03:38 UTCtitle_textures::read_committedpreviously calledVirtualQueryand then copied each committed region withstd::ptr::copy_nonoverlapping. When a title streaming thread concurrently decommits or unmaps a page in a GPU-viewed CPU memory pool betweenVirtualQueryandmemcpy, the submit thread hits an unhandled0xC0000005read access violation (observed at ~462 s / 7,500 frames on a retail title).This replaces the raw copy on non-coherent regions with
ReadProcessMemory(GetCurrentProcess(), ...)so the Windows kernel catches concurrent unmap faults without raising0xC0000005.Relation to #454
This addresses the same crash as #454, with three improvements discovered while testing the concurrent-decommit race:
ReadProcessMemoryreturns0withbytes_read == 0: On Windows,ReadProcessMemoryover a multi-page span can return0withread == 0when a later page in the span faults. Skipping((cur + read) & !0xFFF) + 0x1000(as in #454) then skips the first (still-committed) page and leaves it zeroed. Herecopy_committed_regionbinary-splits failed multi-page spans at 4 KiB boundaries so every still-committed page is copied intact inO(log N)calls and only unreadable pages stay zeroed (verified by our unaligned concurrent-decommit test with sentinel guard pages, which fails under the linear-skip approach).at.checked_add(len)instead ofsaturating_addplusm.RegionSize == 0/end <= pguards.SKIPPEDGPU tests on RX 7900 XT, plus 60 s smoke runs.What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs: addcopy_committed_region(ReadProcessMemorywith 4 KiB binary-split fallback), use it inread_committedwith overflow/zero-size guards, and addread_committed_copies_committed_pages_and_zeroes_gaps+read_committed_tolerates_concurrent_decommitunit tests.Tested
rustc 1.98.1, debug (tests) and release (smoke).cargo build --workspace && cargo test --workspace -- --test-threads=4: 678 passed, 0 failed, 41 ignored, 0SKIPPEDGPU tests.hle::d3d12x::title_textures::tests::read_committed_copies_committed_pages_and_zeroes_gapsandhle::d3d12x::title_textures::tests::read_committed_tolerates_concurrent_decommitpass (400 unaligned 1 MiB reads racing against concurrentVirtualFree(MEM_DECOMMIT)/VirtualAlloc(MEM_COMMIT)on middle pages while asserting first/last committed sentinel pages stay intact).read_committedcrash into world loading / compute PSO compilation; 60 s smoke run completes with 1,204 frames, 0 crashes, and 0 device removals.Regression run
Not tested
AI use
@xstraok on GitHub · 2026-11-24 01:55 UTC · original
Hit this crash on Linux (RX 9060 XT, RADV, Proton Experimental Wine;
maina6f5f7a+ #257 + #458 + #496):unhandled exception 0xc0000005 in ucrtbase.dll+0x171c6 (read at address 0xb4ee13000), stacktitle_textures::read_committed ← subresources ← refresh, 30 s into world loading. With this PR on top, 3 runs(145 s, 148 s, 174 s) had no
read_committedcrash;ReadProcessMemoryon the own process works under Wine.The unit tests were not run separately on this branch.
AI-assisted report (Claude Code, Claude Opus 5.5); runs made by me on the hardware above.
@fromthemoonx on GitHub · 2026-11-24 01:56 UTC · original
NVIDIA run, since Not tested lists NVIDIA / wave32-only adapters.
Tested
9783066756c9360cfe3e2d20a2f6d4b415fdeace, clean worktreestable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debugcargo build --workspace, thencargo test --workspace -- --test-threads=4: 679 passed, 0 failed, 41 ignored (lib 639 / 0 / 21)read_committed_copies_committed_pages_and_zeroes_gaps,read_committed_tolerates_concurrent_decommitgpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareXCL_SAMPLE_*not setNot tested
smoke.ps1run here. The crash this fixes was not reproduced on this machine.AI use
@H0UNDZER0 on GitHub · 2026-11-24 02:14 UTC · original · edited 2026-11-24 02:20 UTC
Tested on an RTX 5080: pass, 679 passed, 0 failed. Next to the RTX 3060 debug run above, this adds a release build on a second NVIDIA generation.
9783066756c9360cfe3e2d20a2f6d4b415fdeace, this PR's head as is (on its base7ebf1b8), release build.XCL_*variables set.cargo build --release --workspace --locked: OK, the same singlefetch_updatewarning asmain.cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with--show-output): 679 passed, 0 failed, 41 ignored both times. The base7ebf1b8gives 677 / 0 / 41 here: the difference is the 2 newread_committed_*tests.SKIPPED: the usual 2,gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).cargo test --release --locked -p xcl --lib hle::d3d12x::title_textures::tests::read_committed -- --test-threads=1, 3 runs: 2 passed each time.Not tested
read_committed.main. At the time of the run that was508a0c7;git merge-treeshowed no conflict.scripts/smoke.ps1.AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)
@crosettiremi on GitHub · 2026-11-24 02:37 UTC · original
On Windows 11 build 26100 with an RX 7900 XT, a saved-profile retail 1.0.2.1 run reached world loading and crashed at 172.887 seconds. The exception was a read access violation in
VCRUNTIME140.dll+0x1bc5band the XCL PDB resolved the first XCL frame totitle_textures::refresh+0x1db5. The runtime copy span was 512 KiB. The game logged 1,847 presents and zero device removals.This was on an
a6f5f7a-based local stack with #486, #508 and #458. It is a separate crash from the game-module watchdog in #505. The stack is consistent with the non-coherent read race that #484 addresses, with the specific inlined source line still unconfirmed.AI disclosure: Codex ran the diagnostics and prepared this report.
@chadatouille on GitHub · 2026-11-24 03:00 UTC · original
On current
main(dd2ae9a), part of the race this PR fixes is now reached by another path. #602 (3984bf1) addedtitle_bytes: whengpu::shader::readablesays the range is readable, the detile and the unchanged-content hash read the title's memory where it is, andread_committedis no longer called. A page decommitted after that check faults the same way, and the window is longer (the whole detile or hash).Probe (local, not pushed):
maindd2ae9a+ the diff of this PR (9783066, applies with no conflict) + one test shaped likeread_committed_tolerates_concurrent_decommit, but callingtitle_bytesand thencontent_hashon the result while another thread decommits and recommits 64 KiB pages.title_bytes_race_probe: 5 of 5 runs end in0xC0000005(each its own process).read_committed_tolerates_concurrent_decommiton the same tree: 5 of 5 pass.18c105a+ this PR: 5 of 5 end in0xC0000005.Not a regression of this PR: its copy does what it says. Either
title_bytesgoes back to the copy for memory a title can decommit, or the in-place read needs its own protection; that is for you and the maintainer.Setup: RTX 3080 Ti (driver 610.88, 32-lane waves), i9-12900F, 32 GB, Windows 11 build 26300, rustc 1.100.0, release.
Not tested: this path faulting in a title (I saw the original crash in a retail title, on a build from before #602),
mainwithout this PR, AMD, the cost of going back to the copy.AI use: Claude Code (Claude Opus 5.5) found it, wrote and ran the probe and wrote this comment. No game data.
@albertoglvn on GitHub · 2026-11-24 03:11 UTC · original
Tested on the newer retail title (TitleID 7952987A), RTX 4060 Laptop 8 GB, driver 621.24, Windows 11, XCL_NETWORK=0.
Before (main @
3db536e): access violation at 64.6 s,VCRUNTIME140.dll+0x1c32e(read at 0x25f7469f000, page-aligned). Matching the address against the PDB and disassembling puts it at thememcpyright afterVirtualQueryin theread_committedloop (title_textures::own_work<refresh>+0x1ba5), which is the race this PR fixes.With this PR (
9783066): ran 209 s at ~30 fps, and that crash did not come back. The run then ended on video memory running out (591× "no video memory for more pages of title textures", thenE_OUTOFMEMORYfrom CreatePlacedResourceX, then a write fault in the title). That looks like #333 / #560 and not related to this change.read_committed_copies_committed_pages_and_zeroes_gapsandread_committed_tolerates_concurrent_decommitpass here (release).Caveats: one run each, and the crash is a race. This PR head doesn't include #435, which main had.
AI use: the crash was analysed and this comment drafted with Claude Opus 5.5; I ran the game and checked the results.
@grahamster2 on GitHub · 2026-11-24 03:32 UTC · original
Review and a repro of the remaining hole, from a crash I hit on a retail title.
My crash, which this PR fixes. Build:
main3db536e+ #490, so before #602. At 59.8 s into world streaming:0xC0000005(read) inVCRUNTIME140.dll+0x1bc5b, first XCL frametitle_textures::refresh(symbolised with the build's PDB). That is theread_committedrace:VirtualQuery, then a raw copy while the title decommits a page. It is the same signature @crosettiremi reported above. The change here addresses it:ReadProcessMemoryinstead of the raw copy, with failed spans split in two at 4 KiB boundaries so committed pages before a hole are kept (the zeroing #454 had at first). I found nothing wrong in the diff.Since #602, part of the race is outside this PR (as @chadatouille wrote above):
title_byteshashes and detiles the title's memory in place wheneverreadable()passes, soread_committedis not involved.Probe (local test, not pushed): 1 MiB reserved and committed. One thread decommits and recommits 64 KiB pages 1–14 in a loop; the other runs
content_hash(&title_bytes(base, 1 MiB))2,000 times. Onmain91f9a5e+ this PR (9783066, clean merge), 3 of 3 runs end inSTATUS_ACCESS_VIOLATION(each run its own process).Proposal (I can send it as a PR stacked on this one if @XaviFortes or @ivall agree):
title_bytesuses the memory in place only inside the coherent committed window (read_committedalready treats that window as committed as a whole).mainand passes with the change.Tested
main91f9a5e+9783066:cargo test --release -p xcl --lib read_committed: 2 passed, 0 failed.0xC0000005on the same tree.Not tested
AI use: Claude Code (Claude Opus 5.5) symbolised the crash, wrote and ran the probe, and wrote this comment.
@claudetools-gh on GitHub · 2026-11-24 04:16 UTC · original
Confirming the race this fixes, now reachable on main: with #451's multi-threaded detile (
subresources_on), one of our runs crashed with an access violation in memcpy fromtitle_textures::subresources/note_gpu_write, reading title pages decommitted mid-copy during world streaming. With this PR applied the crash did not come back (several runs, RTX 5070 Ti). So #451 on main without this PR can hit it.(Text by Claude Code / Claude Opus 5.5; runs done locally.)
@Dukiverse on GitHub · 2026-11-24 04:31 UTC · original
The in-place hole that @chadatouille and @grahamster2 describe above does happen in a retail title. Here is a hit, and a local fix along the lines grahamster2 proposed.
The crash (
maindd2ae9a, RTX 3090, i7-9700K, 64 GB, Windows 11 26200, release,XCL_NETWORK=0): 120.5 s into a world load, on one of thesubresources_onworker threads:(symbolised with that build's PDB).
detile_levelis reading atitle_bytesslice in place, and the read faults.read_committed/ #484's copy is not on this path.A fix (local branch, one file, +21/−11, on
mainf4ce27c):title_bytesborrows the memory only whenin_committed_window(at, len). Everywhere else it fills a zeroed buffer withcopy_committed_region, so pages that go away mid-read come back as zeros instead of faulting. I have not added a thread-local buffer.I also extended
read_committed_tolerates_concurrent_decommitto runcontent_hash(&title_bytes(base, 1 MiB))5000 times against the decommitting thread (withblack_box, so the hash is not optimised away).Tested
0xC0000005with the oldtitle_bytes, and 3 of 3 pass with the change.cargo test --workspace -- --test-threads=4: 701 passed, 0 failed, 41 ignored. SKIPPED: 2 wave64 tests (32-lane GPU).scripts/smoke.ps1 -Seconds 60, no input:mainf4ce27c: 1465 frames, 0 crashes, 14632 MB peak.85674cb: 1470 frames, 0 crashes, 14650 MB peak.+0x23cf683), at 138 s and 141 s.Not tested
mainf4ce27chits this in the title. The 120 s crash came once in 2 driven runs, ondd2ae9a.@grahamster2, you offered to send this as a PR. Happy for you to take it, or I can open one if you would rather not.
Runs and report by Claude Code (Claude Opus 5.5) on my machine.
Generated by Claude Code