Skip to content

D3D12.X: title texture reads outside the coherent window use the safe copy - #751

Open
grahamster2 wants to merge 1 commit into
xcl-dev:mainfrom
grahamster2:title-bytes-decommit-race
Open

grahamster2 wants to merge 1 commit into
xcl-dev:mainfrom
grahamster2:title-bytes-decommit-race

Conversation

@grahamster2

@grahamster2 grahamster2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Since #602, the unchanged-content hash and the detile of title textures read the title's memory in place whenever gpu::shader::readable passes. That bypasses the ReadProcessMemory copy #484 gave read_committed: the title can decommit or unmap those pages from another thread at any moment, and the hash or detile then faults with 0xC0000005. @chadatouille spotted this on #484. @Dukiverse confirmed it independently in a retail title: on main dd2ae9a the fault is in tiling::Chain::detile_level ← title_textures::subresources on a subresources_on worker. 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 main cbc296a (head 59f8e7c). The only conflict was in the tests. #1986's 32 MiB / 256-item upload batch caps (batch_fits and its test) are kept as they are. #1990's 3D textures with packed mip tails go through subresources, so they are read through with_title_bytes too.

  • 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) replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window, and MEM_DECOMMIT there zeroes in place.
    • Everything else goes through 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_into writes 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_into copies the whole range with one ReadProcessMemory first. It walks region by region with VirtualQuery only when that copy is refused (a page not committed, no-access or guard). The walk was most of the copy's cost: 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. ReadProcessMemory on a guard page fails and leaves the guard in place.
    • The frame-trace sampler had the same in-place read and goes through it too.
    • Tests:
      • 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 as read_committed, holes zero, no stale bytes from a longer read, the 64 MiB cap, and the coherent window read in place. It replaces title_bytes_are_used_in_place_when_all_are_readable, whose behaviour this removes.

Tested

  • NVIDIA GeForce RTX 3080 10 GB (driver 32.0.16.1088), AMD Ryzen 5 7600X, 32 GB, Windows 11 26200; tests in debug unless noted, the retail title in release.
  • title_bytes_survive_concurrent_decommit:
    • with the old in-place title_bytes behind a local shim (not committed): 3 of 3 runs end in STATUS_ACCESS_VIOLATION;
    • on this change: 5 of 5 pass (cargo test --release -p xcl --lib title_bytes, at 4e101fc).
  • cargo build --workspace: no warnings.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 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_statistics and pso_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 and batch_fits_caps_items_bytes_and_device pass.
  • Before the rebase, on 1a480bc: 703 passed, 0 failed, 41 ignored.
  • The copy's cost: release microbenchmark, 7600X, not committed, measured before the rebase (the rebase does not change 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.
region the bytes lie in 4e101fc (walk first) 1a480bc (one copy first) memcpy, for scale
64 MiB 128 / 125 / 280 µs 1.3 / 6.9 / 156 µs 0.1 / 3.4 / 140 µs
512 MiB 1629 / 1179 / 1753 µs 1.4 / 7.5 / 128 µs 0.1 / 3.4 / 140 µs

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.

  • SKIPPED on 59f8e7c: every wave64 variant in gpu::recomp::lower::tests, lower_dxil::tests and recomp::tests ("no wave64"); three lower_dxil f16 / f32-conversion per-lane forms refused (V_MUL_F16, V_PK_MUL_F16 VOP3 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").
  • The retail title, before the rebase: 2 streaming runs per build (180 s, A pressed through the menus, caches warmed first; main f4ce27c vs the change on it), presents per second over fixed windows:
main, run 1 / 2 this PR, run 1 / 2
intro video (4–16 s) 22.8 / 22.2 22.2 / 22.2
menus and loading (16–44 s) 28.9 / 28.9 28.9 / 28.7
while streaming (44–84 s) 5.7 / 4.5 5.5 / 5.6
peak commit 30.2 / 29.0 GB 29.9 / 30.1 GB

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:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1463 (PresentX 1463)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15274 MB

PR:

xcl-smoke v1
commit: 59f8e7c992dda0044d18a660aad86fae1d94185f
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15457 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the crash with the retail title and symbolised it, wrote the probe, the fix and the tests (through a subagent), had separate subagents review the diff adversarially (also after the review follow-up) and applied their findings, profiled the copy, ran the tests, the retail-title and regression runs, and wrote this description.

@grahamster2
grahamster2 force-pushed the title-bytes-decommit-race branch from cbd78e6 to dc9eec1 Compare November 24, 2026 04:38
@thehollowedone

Copy link
Copy Markdown

CPU cost on dc9eec1, Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, release. Two local synthetic fixtures used only committed memory outside the coherent window.

  • On a rotating 128 MiB buffer, I compared the old readability check plus direct hash with the PR’s copy plus the same hash. Median time per read over seven alternating pairs (direct / copy): 1.58 / 107.72 µs for 16 KiB, 112.60 / 129.11 µs for 256 KiB, and 252.80 / 454.49 µs for 4 MiB. The hashes matched for every pair.

  • Holding reads at 16 KiB and varying the committed allocation from 1 / 16 / 128 MiB, median VirtualQuery alone took 0.89 / 11.08 / 100.75 µs, versus 2.49 / 13.32 / 101.77 µs for copy plus hash. The query accounts for most of the small-read cost inside the large allocation on this setup.

Both scratch fixtures passed (1/1 each, zero skips) with cargo test --offline --locked --release -p xcl --lib <filter> -- --nocapture --test-threads=1 using scratch_committed_texture_copy_cost and scratch_fixed_read_different_allocations. These are per-read CPU measurements. Frame timing, the concurrent decommit case, and retail use were outside the benchmarks. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the fixtures and drafted this report.

@grahamster2
grahamster2 force-pushed the title-bytes-decommit-race branch 3 times, most recently from cbd78e6 to 4e101fc Compare November 24, 2026 04:42
@grahamster2
grahamster2 marked this pull request as ready for review November 24, 2026 04:44
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…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).
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 4e101fc56b86f4f489a4485b7f2c0ef00381740e on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200 (native Windows, not Wine), Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; title_bytes_are_copied_outside_the_coherent_window, read_committed_copies_committed_pages_and_zeroes_gaps and read_committed_tolerates_concurrent_decommit pass.

Review: The unchanged-content hash and the detile go back through the ReadProcessMemory copy (with_title_bytes → read_committed_into), so a page the title decommits from another thread reads as zeros instead of faulting, and gaps are zeroed in the caller's buffer. The CPU cost measured above is the trade-off. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…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).
@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Independent native Windows NVIDIA RTX 5080 build/test run and code review at head 4e101fc56b86f4f489a4485b7f2c0ef00381740e.

Code Review

  • Clean fix for the #602 concurrent-decommit 0xC0000005 fault in content_hash / detile_level:
    • Only reads in place inside UMA's committed coherent window; everything else copies safely via read_committed_into into a thread-local reusable TITLE_BYTES buffer (releasing buffers larger than TITLE_BYTES_KEPT = 64 MiB).
    • Zeroing every hole/unreadable region in read_committed_into and failed single-page leaves in copy_committed_region prevents stale bytes from prior calls on the same thread from bleeding through.
    • Keeping VirtualQuery ahead of ReadProcessMemory avoids accidentally tripping PAGE_GUARD pages.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 (0ef1bc386 2026-11-09), DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 702 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific tests (2/2 ok):
    • hle::d3d12x::title_textures::tests::title_bytes_are_copied_outside_the_coherent_window
    • hle::d3d12x::title_textures::tests::title_bytes_survive_concurrent_decommit
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • D3D12 debug layer, AMD/wave64 hardware, CPU throughput benchmarks, and retail titles.

AI use: Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…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).
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…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).
@atk3001

atk3001 commented Nov 24, 2026

Copy link
Copy Markdown

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, XCL_NETWORK=0, retail 1.0.2.1. A pressed by script (XCL_PRESS_A_AT=20,22,25,30,35,40,50,60), so every run gets the same input.

Without this PR (main 077ce40): 1 of 3 runs faulted at 59.8 s. It was the fault this PR describes:

  • 0xc0000005 in VCRUNTIME140.dll+0x1c45a (read at 0x297bb048000)
  • tiling::Chain::detile_level (tiling.rs:438) ← title_textures::subresources (title_textures.rs:1175) ← a subresources_on worker

In the other two runs the title reached the null write at +0x23cf683 (#846) at 95.6 s, or no crash came within the 180 s.

With this PR: 2 of 2 scripts/smoke.ps1 -Seconds 180 runs show no fault in title_textures or tiling. Both end at the title's own null write at +0x23cf683 (#846), at 99.5 s and 94.5 s. That is the known later crash, not this one.

xcl-smoke v1
commit: 4e101fc56b86f4f489a4485b7f2c0ef00381740e
gpu: NVIDIA GeForce RTX 5080
title: GTA
seconds: 180
exit: 0xc0000005
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 2
peak commit: 29508 MB

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.

@maephisto666

Copy link
Copy Markdown

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:

unhandled exception 0xc0000005 in VCRUNTIME140.dll+0x1c45a (read at address 0xc72d00000)

Stack from xcl.pdb of that build:

xcl::gpu::tiling::Chain::detile_level +0x57a
xcl::hle::d3d12x::title_textures::subresources +0x302
alloc::vec::…::from_iter<…, title_textures::subresources_on::closure_env$0> +0xb3
xcl::hle::d3d12x::real::res_release +0x60
xcl::hle::d3d12x::title_textures::refresh +0x34d1

0xc72d00000 is outside the coherent window (0x400000000, 4095 MB) – the case this PR routes through the safe copy. res_release on the stack fits the title letting go of the memory while the detile reads it.

With this PR (same base, settings and scripted input): no fault in title textures. The title reaches the world (first ListX #101 at 130.7 s), shows the intro's "two years ago" title card at 141.8 s, and ends at 196.4 s in the #505 stall (cross-queue Write64 Signal … would close a GPU cycle – signalled on CPU from 144.9 s, then the watchdog at +0x23cf683).

Tests: cargo test --release -p xcl --lib title_textures on the stacked build: 14 passed, 0 failed, including title_bytes_are_copied_outside_the_coherent_window and title_bytes_survive_concurrent_decommit.

Caveat: one run each. Across about ten runs on main-based builds today this fault showed up once, so the run with the PR shows it got past that point, not a measured rate.

Not tested: the full suite on this stack, AMD, other titles, scripts/smoke.ps1 blocks.

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.

@iggyvilla

Copy link
Copy Markdown
Contributor

Test report and review for 4e101fc56b86f4f489a4485b7f2c0ef00381740e (current head of #751, crates/xcl/src/hle/d3d12x/title_textures.rs; base 64b3f35, the commit of the PR's own regression blocks) on an AMD RDNA2 card. The builds and runs were done by an agent (omp, DeepSeek V4.1 Flash); I checked the numbers against its saved suite, smoke and test logs and spot-checked the diff; the text is by Claude Code (Claude Sonnet 5.5).

Tested

  • AMD Radeon RX 6650 XT (RDNA2, 8 GB), driver 32.0.21045.29003; Ryzen 7 5700X, 31.9 GB; Windows 11 build 26300; rustc 1.100.0; no XCL_SAMPLE_*. Clean worktrees for head and base; debug for tests, release for smokes; no other title run during the measurements.
  • cargo test -j 4 --workspace --no-fail-fast -- --test-threads=4: head 699 passed, 3 failed, 41 ignored; base 698 passed, 3 failed, 41 ignored (sums of the saved logs). The head has one more test: the PR replaces title_bytes_are_used_in_place_when_all_are_readable and adds title_bytes_survive_concurrent_decommit.
  • The same three tests fail on both: placed_title_textures_share_vram_and_preserve_pixels (cubemap extra_pages must be reused at same va, different values each run) and its two PoisonError cascades (transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory). This is the known flake of this 8 GB card (D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470 family), not this PR; run alone, placed… failed on both commits and the other two passed on both. No SKIPPED lines.
  • The PR's tests, -p xcl --lib title_bytes -- --nocapture --test-threads=1: 2 passed, 0 failed (8.09 s). The log shows UMA: 3 sparse VRAM window(s) (12 GiB VA) + 512 MB coherent window, so title_bytes_are_copied_outside_the_coherent_window ran its in-place half rather than returning early.
  • Smoke (XCL_NETWORK=0, retail, 60 s): one unmeasured base warm-up (1544 frames, peak 15306 MB), then head, then base. All exit 0x0, 0 device removals, 0 crashes, 60 60 60.
xcl-smoke v1
commit: 4e101fc56b86f4f489a4485b7f2c0ef00381740e
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15302 MB
xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1549 (PresentX 1549)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15152 MB

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.

  • origin/main has moved (44+ commits); git merge-tree of the head onto it is clean. The results above are on the head as-is, not on that merge.

Review (diff read at 4e101fc)
Buffer reuse looks right: read_committed_into writes every byte (copied coherent window, copy_committed_region for readable regions, zeros elsewhere and for the tail when VirtualQuery stops early), so a short read after a long one cannot expose stale bytes. I found no other in-place read of title memory in hle/d3d12x outside tests; the hash in upload_all, the detile paths and the frame-trace sampler go through with_title_bytes. Points to weigh:

  1. The copy is now the default path. unchanged_skip() is on by default and title graphics memory sits in the sparse windows, so nearly every title texture takes the ReadProcessMemory copy. The PR's own measurement (on a 9800X3D; quoted from its description, not reproduced here) is 1.58 → 107.72 µs for 16 KiB, 112.60 → 129.11 µs for 256 KiB and 252.80 → 454.49 µs for 4 MiB. Slower CPUs are unmeasured; a regression, if any, would show on many-small-texture titles on older cores. On this 5700X nothing showed in 60 s.
  2. The coherent window is still read in place with no protection check. That predates the PR, but readable() used to catch a no-access or guard page there and nothing does now. The PR lists it under "Not tested"; I did not test it either.
  3. The frame-trace counter changed meaning: samples on decommitted pages used to be skipped and now count as zero bytes, so XCL_TRACE_FRAME can show a texture as "all zero". Diagnostic only.
  4. title_bytes_survive_concurrent_decommit can pass vacuously: its mutator ignores the return values of VirtualFree(…, MEM_DECOMMIT) and the recommit VirtualAlloc (confirmed in the source), and the test only asserts that no access violation occurs. Asserting the decommit succeeded would keep the negative control honest. The evidence that the old code faults is the author's run (3/3 access violations with the old behaviour behind a shim); I could not reproduce that without editing the tree.

Not tested

  • Gameplay past the first minute: the fault is intermittent, so one clean pair does not prove it gone (the PR says the same), and the one retail reproduction in the PR thread was ~114 s into a scripted load, beyond a 60 s smoke.
  • A slower CPU; a title protecting coherent-window memory as no-access/guard; the head merged onto current main; release-build workspace tests; any non-AMD GPU; XCL_SAMPLE_* runs.

AI use
Claude Code, Claude Sonnet 5.5: checked the numbers against the saved logs, spot-checked the diff and wrote this text; it ran nothing. The builds, suites, smokes and the first review pass were done by omp with DeepSeek V4.1 Flash, which changed no code.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

@grahamster2 I meant to run this against the detile crash here (about 2 in 25 runs on main), but 1a480bc no longer merges with main cbc296a: there is a conflict in crates/xcl/src/hle/d3d12x/title_textures.rs. GitHub shows the PR as conflicting too. Since its base, that file got fb9d059 (#1986: upload batches capped by count and 32 MiB) and 971c0e5 (3D textures with packed mip tails). Once it's rebased, I'll run a loop of world loads on it and post the crash count against main's.

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).
@grahamster2

Copy link
Copy Markdown
Collaborator Author

@Anon64 rebased onto main cbc296a, head is now 59f8e7c. It merges cleanly. The only conflict was in the tests, and #1986's batch caps are kept. The suite and a fresh smoke pair are in the description.

your crash loop against main would be really welcome, since it hits ~2 in 25 on your 3060 and I can't reproduce it on demand here.

Written with Claude Code (Claude Opus 5.5).

@Alm0stSurely

Copy link
Copy Markdown

Tested the rebased 59f8e7c on Linux/Proton Experimental with an RTX 5080 (620.73.04), Ryzen 9 9950X3D and Arch Linux 7.3.5. I applied the one-file diff to the 14d7a3c integration build. The only merge conflict was in test context.

Both title_bytes_are_copied_outside_the_coherent_window and title_bytes_leave_guard_pages_alone passed under Proton. In a matched pair of retail runs, the control stopped during the loading illustration at 50.874 s in Chain::detile_level. The patched run passed that point and reached 119.571 s before a different failure, DXGI_ERROR_DEVICE_REMOVED with VK_ERROR_DEVICE_LOST on queue submission. The capture shows the loading illustration followed by a uniform screen. This is one pair for an intermittent fault, with no frame-rate conclusion.

Both runs used the same driver build, separate copies of the same cache seed, XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=1, XCL_UMA_SHADOW=1, XCL_PSO_WAIT_MS=250 and VKD3D_CONFIG=ignore_shared_fence.

AI assistance: Codex (GPT-6.2 Astra) integrated the patch, ran the tests and checked the traces.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (59f8e7c)

PR #751, commit 59f8e7c992dda0044d18a660aad86fae1d94185f.

Hardware / environment

  • Windows x64 build 26200 on an AMD Family 23 Model 113 CPU. The focused tests use Windows virtual memory APIs and run outside the Arc test wrapper with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1.
  • rustc 1.100.0 (0ef1bc386 2026-11-09). DXC 1.9.2609.5 (01b62ad47). Cargo test profile, unoptimized, with debug info and incremental compilation disabled.

Commands and results

  • cargo test --workspace --no-run exited 0 and finished in 1m 14s.
  • cargo test -p xcl --lib 'hle::d3d12x::title_textures::tests::title_bytes_' exited 0. 3 passed, 0 failed, 0 ignored, 0 skipped, 1123 filtered out. The focused run finished in 13.49s. Counts come from case-sensitive matches against the saved output.

Observed behavior

  • title_bytes_are_copied_outside_the_coherent_window passed. The assertions verified a separate copy outside the coherent window, zeros in a decommitted hole even after buffer reuse, and an in-place read inside the 512 MiB coherent window. The oversized-buffer assertion is conditional on a successful allocation and the fixture does not log that branch.
  • title_bytes_survive_concurrent_decommit passed. The fixture completed 2,000 read-and-hash iterations while another thread decommitted and recommitted pages. The read-content assertions passed and the test confirmed that decommits overlapped hashing.
  • title_bytes_leave_guard_pages_alone passed. The guard and no-access pages read as zeros, and Windows still reported the guard flag afterward.

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 pr751-focused.log and published.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/title_textures.rs
@JRamos1993

Copy link
Copy Markdown

Another instance of the fault this fixes, on current main 568e7db (RTX 5090, MSVC release, retail title, XCL_NETWORK=0).

One of two 300 s runs ended at 42.7 s with unhandled exception 0xc0000005 in VCRUNTIME140.dll (a read of an unmapped address). XCL's frames, named with the build's xcl.pdb:

VCRUNTIME140.dll (memcpy) < xcl::hle::d3d12x::title_textures::title_bytes < xcl::hle::d3d12x::title_textures::subresources < … subresources_on::closure (worker thread)

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.

@imnicho

imnicho commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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, XCL_NETWORK=0, XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, scripted pad, nothing skipped; XCL_UMA_SHADOW=1 in every run but the first.

Not tested: this head on main by itself, and the suite on it. Two runs do not show that the fault is gone, only that it did not come in 27 minutes of world where it came after 10 and 11 before.

AI use: Claude Code with Claude Fable 5.2 ran the title, resolved the stacks and wrote this.

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA test report for 59f8e7c. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug. The PR is merged onto main 568e7db, with main run as a control on the same machine.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1155 passed, 1 failed, 46 ignored. main 568e7db: 1153 passed, 1 failed, 46 ignored.
    • The one failure is test_title_runs_and_game_folder_is_untouched in both, because my build step ran only cargo build --workspace --tests, so xcl_testtitle.exe and testgame_mw.dll, built from the repository's tests/testtitle, were missing (the panic says "build first: cargo build --workspace"). So the end-to-end test did not run here.
    • SKIPPED (25 in both): mostly no wave64, plus cannot disable the driver cache and no heap windows.

AI-assisted (Claude Code). Synthetic tests only; no title run.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.