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 |
4e101fc to
1a480bc
Compare
|
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). |
… 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).
1a480bc to
59f8e7c
Compare
|
@Anon64 rebased onto your crash loop against Written with Claude Code (Claude Opus 5.5). |
|
Tested the rebased Both Both runs used the same driver build, separate copies of the same cache seed, AI assistance: Codex (GPT-6.2 Astra) integrated the patch, ran the tests and checked the traces. |
Empirical test report (59f8e7c)PR #751, commit Hardware / environment
Commands and results
Observed behavior
Not tested The full GPU workspace suite and game smoke runs were omitted. AI use Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against |
# Conflicts: # crates/xcl/src/hle/d3d12x/title_textures.rs
|
Another instance of the fault this fixes, on current One of two 300 s runs ended at 42.7 s with This is the path this PR moves to the safe copy. The other run, same build, did not hit it, so this is a race and one run doesn't give a rate. I have not run this PR's head to compare. AI use: Claude Code with Claude Opus 5.5 ran the title, looked up the frames and wrote this. No title data beyond XCL's own frames. |
|
RTX 5080: the same fault twice without this, none in two long runs with it
Setup: RTX 5080 16 GB (driver 610.47), i7-7700K, 16 GB RAM, Windows 10 22H2, release, Not tested: this head on AI use: Claude Code with Claude Fable 5.2 ran the title, resolved the stacks and wrote this. |
|
NVIDIA test report for
AI-assisted (Claude Code). Synthetic tests only; no title run. |
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
Rebased onto
maincbc296a (head 59f8e7c). The only conflict was in the tests. #1986's 32 MiB / 256-item upload batch caps (batch_fitsand its test) are kept as they are. #1990's 3D textures with packed mip tails go throughsubresources, so they are read throughwith_title_bytestoo.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. Since D3D12.X: cap title texture upload batches by count and 32 MiB #1986 a batch is capped at 32 MiB and 256 textures, which bounds those buffers too.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 --no-fail-fast -- --test-threads=4on 59f8e7c: 1154 passed, 2 failed, 46 ignored. The two failures are timing tests this change does not touch,frame::tests::origin_events_issue_tokens_and_flips_have_statisticsandpso_async::used_tests::a_bind_waits_for_a_slow_pipeline_no_longer_than_its_budget("waited 460.8 ms"). Both pass when run alone on 59f8e7c (cargo test -p xcl --lib <name> -- --exact). The three new tests andbatch_fits_caps_items_bytes_and_devicepass.read_committed_into); a 16 KiB / 256 KiB / 4 MiB read of fully committed memory. The microsecond figures quoted in review came from a 9800X3D; these were measured on the 7600X.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::recomp::lower::tests,lower_dxil::testsandrecomp::tests("no wave64"); threelower_dxilf16 / f32-conversion per-lane forms refused (V_MUL_F16,V_PK_MUL_F16VOP3 modifiers,V_CVT_F16_F32, gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426);heap_window_out_of_memory_falls_back_to_the_switch_form("no heap windows").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