Repository navigation
D3D12.X: title texture reads outside the coherent window use the safe copy - #751
grahamster2 wants to merge 1 commit into
Conversation
cbd78e6 to
dc9eec1
Compare
|
CPU cost on
Both scratch fixtures passed (1/1 each, zero skips) with |
cbd78e6 to
4e101fc
Compare
…copy non-coherent reads safely Integrates upstream PRs ivall#455 and ivall#751: - Submit title texture upload batches directly on the title's direct queue without per-batch CPU fence waits, reclaiming staging buffers asynchronously and ordering vram tile updates before each submit (ivall#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (ivall#751).
|
Test run of Tested
Review: The unchanged-content hash and the detile go back through the Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
…copy non-coherent reads safely Integrates upstream PRs ivall#455 and ivall#751: - Submit title texture upload batches directly on the title's direct queue without per-batch CPU fence waits, reclaiming staging buffers asynchronously and ordering vram tile updates before each submit (ivall#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (ivall#751).
|
Independent native Windows NVIDIA RTX 5080 build/test run and code review at head Code Review
Tested
Not tested
AI use: Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment. |
…copy non-coherent reads safely Integrates upstream PRs ivall#455 and ivall#751: - Submit title texture upload batches directly on the title's direct queue without per-batch CPU fence waits, reclaiming staging buffers asynchronously and ordering vram tile updates before each submit (ivall#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (ivall#751).
…copy non-coherent reads safely Integrates upstream PRs ivall#455 and ivall#751: - Submit title texture upload batches directly on the title's direct queue without per-batch CPU fence waits, reclaiming staging buffers asynchronously and ordering vram tile updates before each submit (ivall#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (ivall#751).
|
Test report on a retail title, 4e101fc (this PR's head, on 64b3f35). Setup: RTX 5080 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 26300, rustc 1.100.0, release, Without this PR (
In the other two runs the title reached the null write at With this PR: 2 of 2 Not tested: the race does not hit every run (1 of 3 on main), so two clean runs show no regression rather than prove the fix. I did not run the test suite on this head, and did not measure the upload time this PR adds back. Report written with Claude Code (Claude Opus 5.5) from my own runs. |
|
Test report: the fault this PR describes, reproduced in the retail title, and the same setup with this PR. Setup
Without this PR – during the story load, 114.1 s: Stack from
With this PR (same base, settings and scripted input): no fault in title textures. The title reaches the world (first Tests: Caveat: one run each. Across about ten runs on Not tested: the full suite on this stack, AMD, other titles, AI use: Claude Code (Claude Opus 5.5) ran the builds, tests and retail runs on the hardware above, symbolized the stack, and wrote this report. |
|
Test report and review for Tested
Head is 11 frames (0.7 %) above base and the warm-up (1544) is inside that spread, so no regression or gain is measurable in this window.
Review (diff read at
Not tested
AI use |
… 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).
4e101fc to
1a480bc
Compare
|
Linux / NVIDIA data point for this fault, and the same tree with this PR. Setup: RTX 2060 6 GB (NVIDIA 595.71.05, 32-lane waves), i7-13700K, 32 GB RAM, NixOS (kernel 6.18.60), GE-Proton11-14's Wine, vkd3d-proton v3.1 + #257's patch + dxil-spirv Without this PR: one of two runs on that tree crashed, at 62.6 s, at the start of the story load: Symbolized with that build's PDB, the stack is With Not tested: the PR's unit tests, its cost, Windows, AMD, a paired regression run. AI use: Claude Code (Claude Opus 5.5) ran the builds and runs on the owner's machine at their request, read the logs and wrote and posted this comment. The text was not reviewed line by line by a person before posting. |
|
Crash count on a retail title,
AI use: Claude Code (Claude Opus 5.5) |
|
RDNA3 data point, since the PR's reports are RDNA4, NVIDIA and Linux: the fault reproduces on an RX 7800 XT 16 GB (driver 32.0.32029.2010, 32 GB RAM, Windows 11 26300, release) and this PR's commit removes it.
Not tested: the full suite on this tree, the PR alone on AI use: Claude Code (Claude Fable 5.1) read the logs and wrote this; the runs were mine. |
|
Two more occurrences of this crash on The crash, on an RTX 3060 12 GB (581.80), Windows 11 26200: two retail-title runs, release builds of The alternative (local branch, commit
Trade-off against this PR:
If you or the maintainer prefer the lock, I can open it as a PR (or you can take the diff). Otherwise this PR's approach is fine by me, and I'll run it here: the crash is frequent enough on this machine to check it. Written with Claude Code (Claude Opus 5.5) from runs on this machine. |
|
@Anon64 thanks, and two more hits on a 3060 is useful data. A run of this PR on your machine, where it shows up ~2 in 25, would be the best confirmation it's gone. I'd appreciate that. On the lock vs the copy, my take:
So I'd keep this PR's approach, but it's the maintainer's call. The lock would be a reasonable follow-up if profiling ever shows the copy mattering. Written with Claude Code (Claude Opus 5.5). |
|
@grahamster2 I meant to run this against the detile crash here (about 2 in 25 runs on Written with Claude Code (Claude Opus 5.5). |
Since #602, the unchanged-content hash and the detile of title textures read the title's memory in place whenever
gpu::shader::readablepasses. That bypasses theReadProcessMemorycopy #484 gaveread_committed: the title can decommit or unmap those pages from another thread at any moment, and the hash or detile then faults with0xC0000005. @chadatouille spotted this on #484. @Dukiverse confirmed it independently in a retail title: onmaindd2ae9a the fault is intiling::Chain::detile_level←title_textures::subresourceson asubresources_onworker. Dukiverse also posted a local fix along the same lines; this version adds the regression test and reuses the read buffer.What is in it
D3D12.X: title texture reads outside the coherent window use the safe copy(crates/xcl/src/hle/d3d12x/title_textures.rs):with_title_bytes(at, len, f)replacestitle_bytes. A range inside the coherent committed window is still read in place: XCL'sVirtualFreenever decommits that window, andMEM_DECOMMITthere zeroes in place.read_committed's safe copy into a buffer reused per thread, so there is no new allocation and page faults per texture. A buffer that grew past 64 MiB is let go after the read. The scoped workers of a parallel batch detile still get a buffer per batch.read_committed_intowrites every byte (copied, or zero where a page can't be read), so the reused buffer needs no memset and nothing from an earlier read shows through a hole.read_committed_intocopies the whole range with oneReadProcessMemoryfirst. It walks region by region withVirtualQueryonly when that copy is refused (a page not committed, no-access or guard). The walk was most of the copy's cost:VirtualQueryscans 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.ReadProcessMemoryon a guard page fails and leaves the guard in place.title_bytes_survive_concurrent_decommit: hashes 1 MiB 2,000 times while another thread decommits and recommits its 64 KiB pages. It asserts that every decommit and recommit succeeds and that decommits happened during the hashing. Each 4 KiB holds its own value, and every read must hold those values or zeros.title_bytes_leave_guard_pages_alone: a guard page and a no-access page read as zeros, and the guard is still set afterwards.title_bytes_are_copied_outside_the_coherent_window: same bytes asread_committed, holes zero, no stale bytes from a longer read, the 64 MiB cap, and the coherent window read in place. It replacestitle_bytes_are_used_in_place_when_all_are_readable, whose behaviour this removes.Tested
title_bytes_survive_concurrent_decommit:title_bytesbehind a local shim (not committed): 3 of 3 runs end inSTATUS_ACCESS_VIOLATION;cargo test --release -p xcl --lib title_bytes, at 4e101fc).cargo build --workspace: no warnings.cargo test --workspace -- --test-threads=4on 1a480bc: 703 passed, 0 failed, 41 ignored. Other runs of earlier heads hit the flaky test under Notes.A range with holes pays one refused copy on top of the walk: 4 MiB with one 4 KiB hole went from 158 to 230 µs. With every other 64 KiB page missing it is ~150 µs either way.
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.Both builds then stop at the title's watchdog (#232). One main run ended earlier on a device hang (
0x887A0006, 63 s). The decommit crash is intermittent, so these runs don't show it either way.Regression run
main:
PR:
Not tested
main:placed_title_textures_share_vram_and_preserve_pixels("cubemap extra_pages must be reused at same va") fails intermittently on this card, and its panic poisonstransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memory.mainf4ce27c (cargo test -p xcl --lib -- --test-threads=4): 4 of 13 runs failed. Over 4 alternating pairs, main failed 1 of 4 with the same cubemap assertion and this branch 2 of 4. It also failed with this PR's two new tests skipped.read_committedandgpu::shader::readablealready did.XCL_TRACE_FRAME: samples on decommitted pages now count as zero bytes (they used to be skipped), so a texture whose samples all fall there shows as all zero. This is diagnostic only.AI use