D3D12.X: tolerate concurrent page decommits in title texture reads #484

Manually merged
github merged 2 commits from gh-pr/484/head into gh-pr/484/base 2026-11-26 04:23:04 +00:00
Owner

@⁠XaviFortes on GitHub · 2026-11-24 00:56 UTC · original
XaviFortes:title-textures-safe-read-committed → main · +118 −4 · 1 files · 2 commits · merged 2026-11-24 03:38 UTC

title_textures::read_committed previously called VirtualQuery and then copied each committed region with 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 / 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 raising 0xC0000005.

Relation to #454
This addresses the same crash as #454, with three improvements discovered while testing the concurrent-decommit race:

  • Avoids zeroing valid pages when ReadProcessMemory returns 0 with bytes_read == 0: On Windows, ReadProcessMemory over a multi-page span can return 0 with read == 0 when a later page in the span faults. Skipping ((cur + read) & !0xFFF) + 0x1000 (as in #454) then skips the first (still-committed) page and leaves it zeroed. Here copy_committed_region binary-splits failed multi-page spans at 4 KiB boundaries so every still-committed page is copied intact in O(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).
  • Overflow-safe bounds: uses at.checked_add(len) instead of saturating_add plus m.RegionSize == 0 / end <= p guards.
  • Full AMD wave64 test coverage: 0 failures and 0 SKIPPED GPU tests on RX 7900 XT, plus 60 s smoke runs.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: add copy_committed_region (ReadProcessMemory with 4 KiB binary-split fallback), use it in read_committed with overflow/zero-size guards, and add read_committed_copies_committed_pages_and_zeroes_gaps + read_committed_tolerates_concurrent_decommit unit tests.

Tested

  • Hardware / OS / toolchain: AMD Radeon RX 7900 XT (20420 MiB VRAM), AMD64 Family 25 Model 33 Stepping 2 (Zen 3), Windows 11 (10.0.26200.0), DXC 1.8.2502.11, rustc 1.98.1, debug (tests) and release (smoke).
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 678 passed, 0 failed, 41 ignored, 0 SKIPPED GPU tests.
  • New tests: hle::d3d12x::title_textures::tests::read_committed_copies_committed_pages_and_zeroes_gaps and hle::d3d12x::title_textures::tests::read_committed_tolerates_concurrent_decommit pass (400 unaligned 1 MiB reads racing against concurrent VirtualFree(MEM_DECOMMIT) / VirtualAlloc(MEM_COMMIT) on middle pages while asserting first/last committed sentinel pages stay intact).
  • Retail title check: sailed past the 462 s read_committed crash into world loading / compute PSO compilation; 60 s smoke run completes with 1,204 frames, 0 crashes, and 0 device removals.

Regression run

xcl-smoke v1
commit: 4017f8ff8faaae6007fd83910d230a027dd85a33
gpu: AMD Radeon RX 7900 XT
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1195 (PresentX 1196)
presents per 2 s (last 3): 56 54 57
device removals: 0
crashes: 0
peak commit: 14950 MB
xcl-smoke v1
commit: 27c35717840ddf68725af85f0ebe9b00d7f38442
gpu: AMD Radeon RX 7900 XT
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1204 (PresentX 1204)
presents per 2 s (last 3): 56 54 55
device removals: 0
crashes: 0
peak commit: 14830 MB
xcl-smoke v1
commit: 9783066756c9360cfe3e2d20a2f6d4b415fdeace
gpu: AMD Radeon RX 7900 XT
title: 9a60a330
seconds: 60
exit: 0x0
frames shown: 1204 (PresentX 1204)
presents per 2 s (last 3): 56 54 55
device removals: 0
crashes: 0
peak commit: 14830 MB

Not tested

  • NVIDIA / Intel GPUs and wave32-only adapters.
  • Other retail titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant).

AI use

  • Gemini 4 Neon: wrote the binary-split fix, unit tests; all builds, tests, and smoke runs were executed locally on the hardware listed above.
**@⁠XaviFortes** on GitHub · 2026-11-24 00:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/484) `XaviFortes:title-textures-safe-read-committed` → `main` · +118 −4 · 1 files · 2 commits · merged 2026-11-24 03:38 UTC `title_textures::read_committed` previously called `VirtualQuery` and then copied each committed region with `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 / 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 raising `0xC0000005`. **Relation to #454** This addresses the same crash as #454, with three improvements discovered while testing the concurrent-decommit race: - **Avoids zeroing valid pages when `ReadProcessMemory` returns `0` with `bytes_read == 0`:** On Windows, `ReadProcessMemory` over a multi-page span can return `0` with `read == 0` when a *later* page in the span faults. Skipping `((cur + read) & !0xFFF) + 0x1000` (as in #454) then skips the *first* (still-committed) page and leaves it zeroed. Here `copy_committed_region` binary-splits failed multi-page spans at 4 KiB boundaries so every still-committed page is copied intact in `O(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). - **Overflow-safe bounds:** uses `at.checked_add(len)` instead of `saturating_add` plus `m.RegionSize == 0` / `end <= p` guards. - **Full AMD wave64 test coverage:** 0 failures and 0 `SKIPPED` GPU tests on RX 7900 XT, plus 60 s smoke runs. **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`: add `copy_committed_region` (`ReadProcessMemory` with 4 KiB binary-split fallback), use it in `read_committed` with overflow/zero-size guards, and add `read_committed_copies_committed_pages_and_zeroes_gaps` + `read_committed_tolerates_concurrent_decommit` unit tests. **Tested** - Hardware / OS / toolchain: AMD Radeon RX 7900 XT (20420 MiB VRAM), AMD64 Family 25 Model 33 Stepping 2 (Zen 3), Windows 11 (10.0.26200.0), DXC 1.8.2502.11, `rustc 1.98.1`, debug (tests) and release (smoke). - `cargo build --workspace && cargo test --workspace -- --test-threads=4`: 678 passed, 0 failed, 41 ignored, 0 `SKIPPED` GPU tests. - New tests: `hle::d3d12x::title_textures::tests::read_committed_copies_committed_pages_and_zeroes_gaps` and `hle::d3d12x::title_textures::tests::read_committed_tolerates_concurrent_decommit` pass (400 unaligned 1 MiB reads racing against concurrent `VirtualFree(MEM_DECOMMIT)` / `VirtualAlloc(MEM_COMMIT)` on middle pages while asserting first/last committed sentinel pages stay intact). - Retail title check: sailed past the 462 s `read_committed` crash into world loading / compute PSO compilation; 60 s smoke run completes with 1,204 frames, 0 crashes, and 0 device removals. **Regression run** ``` xcl-smoke v1 commit: 4017f8ff8faaae6007fd83910d230a027dd85a33 gpu: AMD Radeon RX 7900 XT title: 9a60a330 seconds: 60 exit: 0x0 frames shown: 1195 (PresentX 1196) presents per 2 s (last 3): 56 54 57 device removals: 0 crashes: 0 peak commit: 14950 MB ``` ``` xcl-smoke v1 commit: 27c35717840ddf68725af85f0ebe9b00d7f38442 gpu: AMD Radeon RX 7900 XT title: 9a60a330 seconds: 60 exit: 0x0 frames shown: 1204 (PresentX 1204) presents per 2 s (last 3): 56 54 55 device removals: 0 crashes: 0 peak commit: 14830 MB ``` ``` xcl-smoke v1 commit: 9783066756c9360cfe3e2d20a2f6d4b415fdeace gpu: AMD Radeon RX 7900 XT title: 9a60a330 seconds: 60 exit: 0x0 frames shown: 1204 (PresentX 1204) presents per 2 s (last 3): 56 54 55 device removals: 0 crashes: 0 peak commit: 14830 MB ``` **Not tested** - NVIDIA / Intel GPUs and wave32-only adapters. - Other retail titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant). **AI use** - Gemini 4 Neon: wrote the binary-split fix, unit tests; all builds, tests, and smoke runs were executed locally on the hardware listed above.
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:03 +00:00
github manually merged commit 9783066756 into gh-pr/484/base 2026-11-26 04:23:04 +00:00
Author
Owner

@⁠xstraok on GitHub · 2026-11-24 01:55 UTC · original

Hit this crash on Linux (RX 9060 XT, RADV, Proton Experimental Wine; main a6f5f7a + #257 + #458 + #496):
unhandled exception 0xc0000005 in ucrtbase.dll+0x171c6 (read at address 0xb4ee13000), stack
title_textures::read_committed ← subresources ← refresh, 30 s into world loading. With this PR on top, 3 runs
(145 s, 148 s, 174 s) had no read_committed crash; ReadProcessMemory on the own process works under Wine.
The unit tests were not run separately on this branch.
AI-assisted report (Claude Code, Claude Opus 5.5); runs made by me on the hardware above.

**@⁠xstraok** on GitHub · 2026-11-24 01:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7119578592) Hit this crash on Linux (RX 9060 XT, RADV, Proton Experimental Wine; `main` `a6f5f7a` + #257 + #458 + #496): `unhandled exception 0xc0000005 in ucrtbase.dll+0x171c6 (read at address 0xb4ee13000)`, stack `title_textures::read_committed ← subresources ← refresh`, 30 s into world loading. With this PR on top, 3 runs (145 s, 148 s, 174 s) had no `read_committed` crash; `ReadProcessMemory` on the own process works under Wine. The unit tests were not run separately on this branch. AI-assisted report (Claude Code, Claude Opus 5.5); runs made by me on the hardware above.
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 01:56 UTC · original

NVIDIA run, since Not tested lists NVIDIA / wave32-only adapters.

Tested

  • Exact head 9783066756c9360cfe3e2d20a2f6d4b415fdeace, clean worktree
  • NVIDIA GeForce RTX 3060 (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 679 passed, 0 failed, 41 ignored (lib 639 / 0 / 21)
  • Both new tests passed in that run: read_committed_copies_committed_pages_and_zeroes_gaps, read_committed_tolerates_concurrent_decommit
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • XCL_SAMPLE_* not set

Not tested

  • A retail title, so no smoke.ps1 run here. The crash this fixes was not reproduced on this machine.
  • Release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above and wrote this report from the log.
**@⁠fromthemoonx** on GitHub · 2026-11-24 01:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7119606211) NVIDIA run, since **Not tested** lists NVIDIA / wave32-only adapters. **Tested** - Exact head `9783066756c9360cfe3e2d20a2f6d4b415fdeace`, clean worktree - NVIDIA GeForce RTX 3060 (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 `stable-x86_64-pc-windows-msvc`; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4`: **679 passed, 0 failed, 41 ignored** (lib 639 / 0 / 21) - Both new tests passed in that run: `read_committed_copies_committed_pages_and_zeroes_gaps`, `read_committed_tolerates_concurrent_decommit` - SKIPPED (no wave64 on this adapter): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` - `XCL_SAMPLE_*` not set **Not tested** - A retail title, so no `smoke.ps1` run here. The crash this fixes was not reproduced on this machine. - Release build. **AI use** - Claude Code (Claude Opus 5.5) ran the build and tests on the machine above and wrote this report from the log.
Author
Owner

@⁠H0UNDZER0 on GitHub · 2026-11-24 02:14 UTC · original · edited 2026-11-24 02:20 UTC

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.

  • Commit 9783066756c9360cfe3e2d20a2f6d4b415fdeace, this PR's head as is (on its base 7ebf1b8), release build.
  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No XCL_* variables set.
  • cargo build --release --workspace --locked: OK, the same single fetch_update warning as main.
  • cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with --show-output): 679 passed, 0 failed, 41 ignored both times. The base 7ebf1b8 gives 677 / 0 / 41 here: the difference is the 2 new read_committed_* tests.
  • SKIPPED: the usual 2, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • The 2 new tests alone, cargo test --release --locked -p xcl --lib hle::d3d12x::title_textures::tests::read_committed -- --test-threads=1, 3 runs: 2 passed each time.

Not tested

  • Whether the race test fails without the fix: it was not run against the old read_committed.
  • This PR merged onto a newer main. At the time of the run that was 508a0c7; git merge-tree showed no conflict.
  • Debug build, retail titles, scripts/smoke.ps1.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

**@⁠H0UNDZER0** on GitHub · 2026-11-24 02:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7119910836) · edited 2026-11-24 02:20 UTC **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. - Commit `9783066756c9360cfe3e2d20a2f6d4b415fdeace`, this PR's head as is (on its base `7ebf1b8`), release build. - NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No `XCL_*` variables set. - `cargo build --release --workspace --locked`: OK, the same single `fetch_update` warning as `main`. - `cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4`, run twice (the second with `--show-output`): **679 passed, 0 failed, 41 ignored** both times. The base `7ebf1b8` gives 677 / 0 / 41 here: the difference is the 2 new `read_committed_*` tests. - `SKIPPED`: the usual 2, `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no wave64). - The 2 new tests alone, `cargo test --release --locked -p xcl --lib hle::d3d12x::title_textures::tests::read_committed -- --test-threads=1`, 3 runs: 2 passed each time. **Not tested** - Whether the race test fails without the fix: it was not run against the old `read_committed`. - This PR merged onto a newer `main`. At the time of the run that was `508a0c7`; `git merge-tree` showed no conflict. - Debug build, retail titles, `scripts/smoke.ps1`. **AI use:** Claude Code (Claude Opus 5.5, Claude Fable 5.2)
Author
Owner

@⁠crosettiremi on GitHub · 2026-11-24 02:37 UTC · original

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 VCRUNTIME140.dll+0x1bc5b and the XCL PDB resolved the first XCL frame to title_textures::refresh+0x1db5. The runtime copy span was 512 KiB. The game logged 1,847 presents and zero device removals.

This was on an a6f5f7a-based local stack with #486, #508 and #458. It is a separate crash from the game-module watchdog in #505. The stack is consistent with the non-coherent read race that #484 addresses, with the specific inlined source line still unconfirmed.

AI disclosure: Codex ran the diagnostics and prepared this report.

**@⁠crosettiremi** on GitHub · 2026-11-24 02:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7120321647) 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 `VCRUNTIME140.dll+0x1bc5b` and the XCL PDB resolved the first XCL frame to `title_textures::refresh+0x1db5`. The runtime copy span was 512 KiB. The game logged 1,847 presents and zero device removals. This was on an `a6f5f7a`-based local stack with #486, #508 and #458. It is a separate crash from the game-module watchdog in #505. The stack is consistent with the non-coherent read race that #484 addresses, with the specific inlined source line still unconfirmed. AI disclosure: Codex ran the diagnostics and prepared this report.
Author
Owner

@⁠chadatouille on GitHub · 2026-11-24 03:00 UTC · original

On current main (dd2ae9a), part of the race this PR fixes is now reached by another path. #602 (3984bf1) added title_bytes: when gpu::shader::readable says the range is readable, the detile and the unchanged-content hash read the title's memory where it is, and read_committed is no longer called. A page decommitted after that check faults the same way, and the window is longer (the whole detile or hash).

Probe (local, not pushed): main dd2ae9a + the diff of this PR (9783066, applies with no conflict) + one test shaped like read_committed_tolerates_concurrent_decommit, but calling title_bytes and then content_hash on the result while another thread decommits and recommits 64 KiB pages.

  • title_bytes_race_probe: 5 of 5 runs end in 0xC0000005 (each its own process).
  • read_committed_tolerates_concurrent_decommit on the same tree: 5 of 5 pass.
  • The same probe on 18c105a + this PR: 5 of 5 end in 0xC0000005.

Not a regression of this PR: its copy does what it says. Either title_bytes goes back to the copy for memory a title can decommit, or the in-place read needs its own protection; that is for you and the maintainer.

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), main without this PR, AMD, the cost of going back to the copy.

AI use: Claude Code (Claude Opus 5.5) found it, wrote and ran the probe and wrote this comment. No game data.

**@⁠chadatouille** on GitHub · 2026-11-24 03:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7120682610) On current `main` (`dd2ae9a`), part of the race this PR fixes is now reached by another path. #602 (`3984bf1`) added `title_bytes`: when `gpu::shader::readable` says the range is readable, the detile and the unchanged-content hash read the title's memory where it is, and `read_committed` is no longer called. A page decommitted after that check faults the same way, and the window is longer (the whole detile or hash). **Probe** (local, not pushed): `main` `dd2ae9a` + the diff of this PR (`9783066`, applies with no conflict) + one test shaped like `read_committed_tolerates_concurrent_decommit`, but calling `title_bytes` and then `content_hash` on the result while another thread decommits and recommits 64 KiB pages. - `title_bytes_race_probe`: 5 of 5 runs end in `0xC0000005` (each its own process). - `read_committed_tolerates_concurrent_decommit` on the same tree: 5 of 5 pass. - The same probe on `18c105a` + this PR: 5 of 5 end in `0xC0000005`. Not a regression of this PR: its copy does what it says. Either `title_bytes` goes back to the copy for memory a title can decommit, or the in-place read needs its own protection; that is for you and the maintainer. **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), `main` without this PR, AMD, the cost of going back to the copy. **AI use:** Claude Code (Claude Opus 5.5) found it, wrote and ran the probe and wrote this comment. No game data.
Author
Owner

@⁠albertoglvn on GitHub · 2026-11-24 03:11 UTC · original

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, VCRUNTIME140.dll+0x1c32e (read at 0x25f7469f000, page-aligned). Matching the address against the PDB and disassembling puts it at the memcpy right after VirtualQuery in the read_committed loop (title_textures::own_work<refresh> +0x1ba5), which is the race this PR fixes.

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 E_OUTOFMEMORY from CreatePlacedResourceX, then a write fault in the title). That looks like #333 / #560 and not related to this change.

read_committed_copies_committed_pages_and_zeroes_gaps and read_committed_tolerates_concurrent_decommit pass here (release).

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.

**@⁠albertoglvn** on GitHub · 2026-11-24 03:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7120861079) 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, `VCRUNTIME140.dll+0x1c32e` (read at 0x25f7469f000, page-aligned). Matching the address against the PDB and disassembling puts it at the `memcpy` right after `VirtualQuery` in the `read_committed` loop (`title_textures::own_work<refresh>` +0x1ba5), which is the race this PR fixes. **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 `E_OUTOFMEMORY` from CreatePlacedResourceX, then a write fault in the title). That looks like #333 / #560 and not related to this change. `read_committed_copies_committed_pages_and_zeroes_gaps` and `read_committed_tolerates_concurrent_decommit` pass here (release). 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.
Author
Owner

@⁠grahamster2 on GitHub · 2026-11-24 03:32 UTC · original

Review and a repro of the remaining hole, from a crash I hit on a retail title.

My crash, which this PR fixes. Build: main 3db536e + #490, so before #602. At 59.8 s into world streaming: 0xC0000005 (read) in VCRUNTIME140.dll+0x1bc5b, first XCL frame title_textures::refresh (symbolised with the build's PDB). That is the read_committed race: VirtualQuery, then a raw copy while the title decommits a page. It is the same signature @⁠crosettiremi reported above. The change here addresses it: ReadProcessMemory instead of the raw copy, with failed spans split in two at 4 KiB boundaries so committed pages before a hole are kept (the zeroing #454 had at first). I found nothing wrong in the diff.

Since #602, part of the race is outside this PR (as @⁠chadatouille wrote above): title_bytes hashes and detiles the title's memory in place whenever readable() passes, so read_committed is not involved.
Probe (local test, not pushed): 1 MiB reserved and committed. One thread decommits and recommits 64 KiB pages 1–14 in a loop; the other runs content_hash(&title_bytes(base, 1 MiB)) 2,000 times. On main 91f9a5e + this PR (9783066, clean merge), 3 of 3 runs end in STATUS_ACCESS_VIOLATION (each run its own process).

Proposal (I can send it as a PR stacked on this one if @⁠XaviFortes or @⁠ivall agree):

  • title_bytes uses the memory in place only inside the coherent committed window (read_committed already treats that window as committed as a whole).
  • Everywhere else it takes this PR's safe copy into a reused thread-local buffer. That keeps most of what #602 saved (no new allocation or page faults per texture), but every byte is copied again.
  • The test is the probe above: it crashes on main and passes with the change.
  • On an RTX 3080 / Ryzen 5 7600X, #602 showed no intro gain (22.5 vs 22.0–22.5 presents/s, 2 runs each, numbers on #602), so the cost there would be about 0. Its author measured a gain on an RX 5700 XT / Ryzen 5 2600, where the extra copy would cost something.

Tested

  • RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release.
  • main 91f9a5e + 9783066: cargo test --release -p xcl --lib read_committed: 2 passed, 0 failed.
  • The probe above: 3 of 3 runs 0xC0000005 on the same tree.

Not tested

  • The whole suite on the merged tree; the retail title with this PR (the crash above came once in 2 runs on a build without it, so one run would not show much); AMD.

AI use: Claude Code (Claude Opus 5.5) symbolised the crash, wrote and ran the probe, and wrote this comment.

**@⁠grahamster2** on GitHub · 2026-11-24 03:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7121191612) Review and a repro of the remaining hole, from a crash I hit on a retail title. **My crash, which this PR fixes.** Build: `main` 3db536e + #490, so before #602. At 59.8 s into world streaming: `0xC0000005` (read) in `VCRUNTIME140.dll+0x1bc5b`, first XCL frame `title_textures::refresh` (symbolised with the build's PDB). That is the `read_committed` race: `VirtualQuery`, then a raw copy while the title decommits a page. It is the same signature @⁠crosettiremi reported above. The change here addresses it: `ReadProcessMemory` instead of the raw copy, with failed spans split in two at 4 KiB boundaries so committed pages before a hole are kept (the zeroing #454 had at first). I found nothing wrong in the diff. **Since #602, part of the race is outside this PR** (as @⁠chadatouille wrote above): `title_bytes` hashes and detiles the title's memory in place whenever `readable()` passes, so `read_committed` is not involved. Probe (local test, not pushed): 1 MiB reserved and committed. One thread decommits and recommits 64 KiB pages 1–14 in a loop; the other runs `content_hash(&title_bytes(base, 1 MiB))` 2,000 times. On `main` 91f9a5e + this PR (`9783066`, clean merge), 3 of 3 runs end in `STATUS_ACCESS_VIOLATION` (each run its own process). **Proposal** (I can send it as a PR stacked on this one if @⁠XaviFortes or @⁠ivall agree): - `title_bytes` uses the memory in place only inside the coherent committed window (`read_committed` already treats that window as committed as a whole). - Everywhere else it takes this PR's safe copy into a reused thread-local buffer. That keeps most of what #602 saved (no new allocation or page faults per texture), but every byte is copied again. - The test is the probe above: it crashes on `main` and passes with the change. - On an RTX 3080 / Ryzen 5 7600X, #602 showed no intro gain (22.5 vs 22.0–22.5 presents/s, 2 runs each, numbers on #602), so the cost there would be about 0. Its author measured a gain on an RX 5700 XT / Ryzen 5 2600, where the extra copy would cost something. **Tested** - RTX 3080 10 GB (driver 32.0.16.1088), Ryzen 5 7600X, 32 GB, Windows 11 26200, release. - `main` 91f9a5e + `9783066`: `cargo test --release -p xcl --lib read_committed`: 2 passed, 0 failed. - The probe above: 3 of 3 runs `0xC0000005` on the same tree. **Not tested** - The whole suite on the merged tree; the retail title with this PR (the crash above came once in 2 runs on a build without it, so one run would not show much); AMD. _AI use: Claude Code (Claude Opus 5.5) symbolised the crash, wrote and ran the probe, and wrote this comment._
Author
Owner

@⁠claudetools-gh on GitHub · 2026-11-24 04:16 UTC · original

Confirming the race this fixes, now reachable on main: with #451's multi-threaded detile (subresources_on), one of our runs crashed with an access violation in memcpy from title_textures::subresources / note_gpu_write, reading title pages decommitted mid-copy during world streaming. With this PR applied the crash did not come back (several runs, RTX 5070 Ti). So #451 on main without this PR can hit it.

(Text by Claude Code / Claude Opus 5.5; runs done locally.)

**@⁠claudetools-gh** on GitHub · 2026-11-24 04:16 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7121869404) Confirming the race this fixes, now reachable on main: with #451's multi-threaded detile (`subresources_on`), one of our runs crashed with an access violation in memcpy from `title_textures::subresources` / `note_gpu_write`, reading title pages decommitted mid-copy during world streaming. With this PR applied the crash did not come back (several runs, RTX 5070 Ti). So #451 on main without this PR can hit it. (Text by Claude Code / Claude Opus 5.5; runs done locally.)
Author
Owner

@⁠Dukiverse on GitHub · 2026-11-24 04:31 UTC · original

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 (main dd2ae9a, RTX 3090, i7-9700K, 64 GB, Windows 11 26200, release, XCL_NETWORK=0): 120.5 s into a world load, on one of the subresources_on worker threads:

unhandled exception 0xc0000005 in VCRUNTIME140.dll+0x1cc4d (read at address 0x1fb4be2dcc0)
xcl.exe+0xf599d   tiling::Chain::detile_level+0x56d
xcl.exe+0x238492  title_textures::subresources+0x302
xcl.exe+0x1181aa  (subresources_on worker closure)

(symbolised with that build's PDB). detile_level is reading a title_bytes slice in place, and the read faults. read_committed / #484's copy is not on this path.

A fix (local branch, one file, +21/−11, on main f4ce27c): title_bytes borrows the memory only when in_committed_window(at, len). Everywhere else it fills a zeroed buffer with copy_committed_region, so pages that go away mid-read come back as zeros instead of faulting. I have not added a thread-local buffer.

-    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 read_committed_tolerates_concurrent_decommit to run content_hash(&title_bytes(base, 1 MiB)) 5000 times against the decommitting thread (with black_box, so the hash is not optimised away).

Tested

  • The extended test: 3 of 3 runs end in 0xC0000005 with the old title_bytes, and 3 of 3 pass with the change.
  • cargo test --workspace -- --test-threads=4: 701 passed, 0 failed, 41 ignored. SKIPPED: 2 wave64 tests (32-lane GPU).
  • scripts/smoke.ps1 -Seconds 60, no input:
    • main f4ce27c: 1465 frames, 0 crashes, 14632 MB peak.
    • branch 85674cb: 1470 frames, 0 crashes, 14650 MB peak.
  • Two driven runs into the world load with the branch: no crash in XCL's code. Both ended at the known #616 null write (+0x23cf683), at 138 s and 141 s.

Not tested

  • How often main f4ce27c hits this in the title. The 120 s crash came once in 2 driven runs, on dd2ae9a.
  • The cost of the copy on a slower CPU, where #602 measured its gain.
  • AMD GPUs.

@⁠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

**@⁠Dukiverse** on GitHub · 2026-11-24 04:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/484#issuecomment-7122097718) 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** (`main` `dd2ae9a`, RTX 3090, i7-9700K, 64 GB, Windows 11 26200, release, `XCL_NETWORK=0`): 120.5 s into a world load, on one of the `subresources_on` worker threads: ``` unhandled exception 0xc0000005 in VCRUNTIME140.dll+0x1cc4d (read at address 0x1fb4be2dcc0) xcl.exe+0xf599d tiling::Chain::detile_level+0x56d xcl.exe+0x238492 title_textures::subresources+0x302 xcl.exe+0x1181aa (subresources_on worker closure) ``` (symbolised with that build's PDB). `detile_level` is reading a `title_bytes` slice in place, and the read faults. `read_committed` / #484's copy is not on this path. **A fix** (local branch, one file, +21/−11, on `main` `f4ce27c`): `title_bytes` borrows the memory only when `in_committed_window(at, len)`. Everywhere else it fills a zeroed buffer with `copy_committed_region`, so pages that go away mid-read come back as zeros instead of faulting. I have not added a thread-local buffer. ```diff - 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 `read_committed_tolerates_concurrent_decommit` to run `content_hash(&title_bytes(base, 1 MiB))` 5000 times against the decommitting thread (with `black_box`, so the hash is not optimised away). **Tested** - The extended test: 3 of 3 runs end in `0xC0000005` with the old `title_bytes`, and 3 of 3 pass with the change. - `cargo test --workspace -- --test-threads=4`: 701 passed, 0 failed, 41 ignored. SKIPPED: 2 wave64 tests (32-lane GPU). - `scripts/smoke.ps1 -Seconds 60`, no input: - `main` `f4ce27c`: 1465 frames, 0 crashes, 14632 MB peak. - branch `85674cb`: 1470 frames, 0 crashes, 14650 MB peak. - Two driven runs into the world load with the branch: no crash in XCL's code. Both ended at the known #616 null write (`+0x23cf683`), at 138 s and 141 s. **Not tested** - How often `main` `f4ce27c` hits this in the title. The 120 s crash came once in 2 driven runs, on `dd2ae9a`. - The cost of the copy on a slower CPU, where #602 measured its gain. - AMD GPUs. @⁠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](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No description provided.