Skip to content

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

Merged
theaustinayers merged 2 commits into
xcl-dev:mainfrom
XaviFortes:title-textures-safe-read-committed
Nov 24, 2026
Merged

theaustinayers merged 2 commits into
xcl-dev:mainfrom
XaviFortes:title-textures-safe-read-committed

Conversation

@XaviFortes

@XaviFortes XaviFortes commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 D3D12.X: read_committed survives concurrent decommit and unmap #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)
@xstraok

xstraok commented Nov 24, 2026

Copy link
Copy Markdown

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.

@fromthemoonx

Copy link
Copy Markdown

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.

@H0UNDZER0

H0UNDZER0 commented Nov 24, 2026 •

Copy link
Copy Markdown

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)

@crosettiremi

Copy link
Copy Markdown

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.

@chadatouille

Copy link
Copy Markdown

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.

@albertoglvn

Copy link
Copy Markdown

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.

@grahamster2

Copy link
Copy Markdown
Collaborator

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):

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.

@claudetools-gh

Copy link
Copy Markdown

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

@Dukiverse

Copy link
Copy Markdown

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

Not tested

@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

grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 24, 2026
…l#490, ivall#347)

The fork keeps its own pso_async (short waits, all compute pipelines built ahead); ivall#690 upstream is its used-pipelines part.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
wondercrash pushed a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.

(cherry picked from commit 4e101fc)
themaoci pushed a commit to themaoci/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages.

(cherry picked from commit 4e101fc)
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 24, 2026
… copy

The unchanged-content hash, the detile of title textures and the
frame-trace sampler read the title's memory in place once it looked
readable (ivall#602). That bypasses the ReadProcessMemory copy of
read_committed (ivall#484): the title can decommit or unmap those pages from
another thread at any moment, and the read then faults with 0xC0000005.

with_title_bytes replaces title_bytes. A range inside the coherent
committed window is still read in place: XCL's VirtualFree never
decommits that window (MEM_DECOMMIT there zeroes the block in place).
Everything else is read as read_committed reads it, into a buffer kept
per thread and dropped after a read that grew it past 64 MiB.
read_committed_into now writes every byte (copied, or zero for a page
that is not readable), so the reused buffer needs no memset and nothing
of an earlier read shows through a hole. Only long-lived threads reuse
the buffer: the scoped workers of a parallel batch detile allocate one
per batch.

title_bytes_survive_concurrent_decommit hashes 1 MiB while another
thread decommits and recommits its 64 KiB pages; it checks that every
decommit and recommit succeeded, that some happened during the hashing and
that each read holds the title's bytes or zeros.
title_bytes_leave_guard_pages_alone reads a guard and a no-access page
as zeros and checks that the guard stays.

read_committed_into first copies the whole range with one
ReadProcessMemory and walks it region by region with VirtualQuery only
when that is refused (a page not committed, no-access or a guard page;
the guard stays). VirtualQuery scans from the page asked about to the
end of its run of like pages, and the title's memory is a few runs of
hundreds of MiB: in a release
microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a
fully committed 64 MiB region took 128 / 125 / 280 us with the walk and
1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now
1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top
of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
grahamster2 added a commit to grahamster2/xcl that referenced this pull request Nov 25, 2026
… 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.