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 xcl-dev#455 and xcl-dev#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 (xcl-dev#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (xcl-dev#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 xcl-dev#455 and xcl-dev#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 (xcl-dev#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (xcl-dev#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 xcl-dev#455 and xcl-dev#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 (xcl-dev#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (xcl-dev#751).
…copy non-coherent reads safely Integrates upstream PRs xcl-dev#455 and xcl-dev#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 (xcl-dev#455). - Copy title texture bytes outside the coherent UMA window through a reusable thread-local ReadProcessMemory buffer so concurrent page decommits cannot fault (xcl-dev#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
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
Added 16:34Z: whole workspace on this head, after
AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
CPU-only lifetime checks passed on exact head Tested
Not tested |
| // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard | ||
| // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). | ||
| let mut read = 0usize; | ||
| if len == 0 || ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { |
There was a problem hiding this comment.
Wine 11 guard-page regression in the one-copy fast path, with a small correction tested locally.
I ported 59f8e7c992dda0044d18a660aad86fae1d94185f unchanged onto my existing XCL integration (base 06c9f5505f63f10c5ec49ef932d75b2c28177324, including #867/#1395/#1069/#1916/#615/#495/#1182/#2177). This is not a clean-head test. Host: Linux 6.17.0-40-generic, Wine 11.0, i7-13620H, RTX 4060 Laptop 8 GB, 16 GB RAM; Rust 1.98.1 MSVC cross-build. These focused tests are CPU memory tests, not GPU coverage.
Before this PR: a title-loading run crashed with 0xc0000005 in ucrtbase.dll. Its release PDB resolves the stack to Chain::detile_level (copy_from_slice) ← title_textures::subresources ← a subresources_on worker. Last successful GPU telemetry was 6,388 MiB. This matches the already reported intermittent fault; it is not an OOM diagnosis.
With this PR, before the suggestion below: cargo test -p xcl --lib --target x86_64-pc-windows-msvc title_bytes -- --test-threads=1 --nocapture under the Wine runner produced 2 passed, 1 failed. title_bytes_leave_guard_pages_alone failed at guard and no-access pages read as zeros; the copy/coherent-window and concurrent-decommit tests passed. XCL_UMA_MB=256 XCL_COHERENT_MB=64 were set, and the fixture reported a 256 MiB coherent window.
Wine 11's NtReadVirtualMemory implements the current-process pseudo-handle path as memmove inside exception handling. The unconditional read can therefore touch a guard before the fallback checks protections. Walking regions first on Wine avoids that; the existing util::under_wine() predicate is already present at this PR's head. Native Windows keeps the fast path.
| // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard | |
| // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`). | |
| let mut read = 0usize; | |
| if len == 0 || ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 { | |
| // Native Windows refuses a range containing an uncommitted, no-access or guard page. | |
| // Wine's current-process ReadProcessMemory uses memmove and consumes PAGE_GUARD on fault; | |
| // walk protections first there so existing guards are not touched. | |
| let mut read = 0usize; | |
| if len == 0 || (!crate::util::under_wine() && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0) { |
With this suggestion, tests unchanged: the title_bytes filter passed 3/3, including guard preservation; the read_committed filter passed 2/2. No ignored/skipped tests; the coherent-window branch was exercised. The release build passed. I did not repeat the failing unmodified run or run the full suite. Native Windows and read-copy performance were not measured.
One title follow-up with this correction: last resource sample at 111.54 s, GPU 7,561 MiB; the external 7,500 MiB guard then stopped the launch (exit 143). Minimum available system RAM was 2,725.6 MiB and free disk stayed above 13.29 GiB. The log contains no unhandled-exception/device-loss/OOM marker; unrelated DXGI display diagnostics remain. Last captured frames are loading artwork, not gameplay. This short, resource-stopped run cannot establish that the intermittent title fault is eliminated or that 30 fps gameplay works.
AI assistance: omp / openai-codex/gpt-6-astra investigated the recorded crash, ported the existing PR, wrote and tested this small Wine correction, and drafted/submitted this report at the repository owner's request.
|
AMD (RDNA2) test report for Tested (commit
Not tested
AI use
|
|
Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head Hardware & environment
Unit / GPU tests (
Retail title (300 s,
Not tested
AI use
|
bmjask
left a comment
There was a problem hiding this comment.
No blocking code issue found. The safe-copy path correctly zeroes unreadable holes and keeps the detile consumer within the snapshot lifetime; the targeted stale-byte and concurrent-decommit tests are useful. Residual risk remains the existing unchecked coherent-window pointer invariant: changing that window to no-access/guard can still fault. This predates the PR but should stay explicit in the validation record.
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