Repository navigation
D3D12.X: tolerate concurrent page decommits in title texture reads - #484
Conversation
read_committed previously called VirtualQuery followed by std::ptr::copy_nonoverlapping. When a title streaming thread concurrently decommits or unmaps a page in a GPU-viewed CPU memory pool between VirtualQuery and memcpy, the submit thread hits an unhandled 0xC0000005 read access violation (observed at ~462 s / 7500 frames on a retail title). Copy committed regions via ReadProcessMemory(GetCurrentProcess(), ...) instead. Because Windows can return 0 with bytes_read == 0 when a later page in the span faults, binary-split failed multi-page spans at 4 KiB boundaries so still-committed pages are copied intact in O(log N) calls and only unreadable pages stay zeroed. Also guard against at + len overflow and zero-sized VirtualQuery regions. Assisted-by: Antigravity (Gemini 4 Neon)
|
Hit this crash on Linux (RX 9060 XT, RADV, Proton Experimental Wine; |
|
NVIDIA run, since Not tested lists NVIDIA / wave32-only adapters. Tested
Not tested
AI use
|
|
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.
Not tested
AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2) |
|
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 This was on an AI disclosure: Codex ran the diagnostics and prepared this report. |
|
On current Probe (local, not pushed):
Not a regression of this PR: its copy does what it says. Either 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), AI use: Claude Code (Claude Opus 5.5) found it, wrote and ran the probe and wrote this comment. No game data. |
|
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, 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", then
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. |
|
Review and a repro of the remaining hole, from a crash I hit on a retail title. My crash, which this PR fixes. Build: Since #602, part of the race is outside this PR (as @chadatouille wrote above): Proposal (I can send it as a PR stacked on this one if @XaviFortes or @ivall agree):
Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) symbolised the crash, wrote and ran the probe, and wrote this comment. |
|
Confirming the race this fixes, now reachable on main: with #451's multi-threaded detile ( (Text by Claude Code / Claude Opus 5.5; runs done locally.) |
|
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 ( (symbolised with that build's PDB). A fix (local branch, one file, +21/−11, on - if crate::gpu::shader::readable(at, len) {
- std::borrow::Cow::Borrowed(std::slice::from_raw_parts(at as *const u8, len))
- } else {
- std::borrow::Cow::Owned(read_committed(at, len))
- }
+ if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(at, len)) {
+ return std::borrow::Cow::Borrowed(std::slice::from_raw_parts(at as *const u8, len));
+ }
+ let mut out = vec![0u8; len];
+ copy_committed_region(at, out.as_mut_ptr(), len);
+ std::borrow::Cow::Owned(out)I also extended Tested
Not tested
@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 |
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages.
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages.
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages.
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages. (cherry picked from commit 4e101fc)
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages. (cherry picked from commit 4e101fc)
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (ivall#602). That bypasses the ReadProcessMemory copy of read_committed (ivall#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages; it checks that every decommit and recommit succeeded, that some happened during the hashing and that each read holds the title's bytes or zeros. title_bytes_leave_guard_pages_alone reads a guard and a no-access page as zeros and checks that the guard stays. read_committed_into first copies the whole range with one ReadProcessMemory and walks it region by region with VirtualQuery only when that is refused (a page not committed, no-access or a guard page; the guard stays). VirtualQuery scans from the page asked about to the end of its run of like pages, and the title's memory is a few runs of hundreds of MiB: in a release microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a fully committed 64 MiB region took 128 / 125 / 280 us with the walk and 1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now 1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of read_committed (xcl-dev#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages; it checks that every decommit and recommit succeeded, that some happened during the hashing and that each read holds the title's bytes or zeros. title_bytes_leave_guard_pages_alone reads a guard and a no-access page as zeros and checks that the guard stays. read_committed_into first copies the whole range with one ReadProcessMemory and walks it region by region with VirtualQuery only when that is refused (a page not committed, no-access or a guard page; the guard stays). VirtualQuery scans from the page asked about to the end of its run of like pages, and the title's memory is a few runs of hundreds of MiB: in a release microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a fully committed 64 MiB region took 128 / 125 / 280 us with the walk and 1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now 1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
title_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 D3D12.X: read_committed survives concurrent decommit and unmap #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