D3D12.X: a texture worker faults in detile_level on title memory that title_bytes borrowed #2841

Open
opened 2026-11-26 17:36:06 +00:00 by github-bot · 3 comments
Owner

@⁠frozht on GitHub · 2026-11-26 17:34 UTC · original

A texture worker crashes in Chain::detile_level reading a title page that is no longer mapped. title_bytes decided the range was readable and borrowed it, so the copy runs on raw title memory.

What happened: the retail title from #505 (1.0.2.1) under Wine reached the intro cinematic, then crashed at 965.5 s:

[  965.490][ 1888][ERROR] unhandled exception 0xc0000005 in msvcrt.dll+0xa52b (read at address 0x7fed8a7f8000) ...
on the stack: xcl.exe+0x2eaae7, xcl.exe+0x8b3d10, xcl.exe+0x696cf4, xcl.exe+0x13b2fe, xcl.exe+0x8aa4d8, xcl.exe+0x273248

Symbolized with addr2line on the same binary:

frame function
+0x2eaae7 <[u8]>::copy_from_slice, inlined in gpu::tiling::Chain::detile_level (dst.copy_from_slice(s))
+0x696cf4 hle::d3d12x::title_textures::subresources (c.detile_level(&slice, i, s))
+0x13b2fe title_textures::subresources_on::{closure}, a worker thread of the parallel path

Why the bounds check does not help: in subresources, slice comes from title_bytes(va + s * slice_bytes, slice_bytes). When gpu::shader::readable says yes, title_bytes returns Cow::Borrowed(slice::from_raw_parts(at, len)), a view of the title's memory, not a copy. detile_level's src.get(o..o + e) only checks against the slice length, so it cannot catch a page inside the range that is unmapped when the copy happens. On the other branch (read_committed) the copy would come from an owned Vec and could not fault, so this crash took the borrowed branch.

So either readable answered yes for a range that was not all readable, or the title released or decommitted the pages between the check and the read on a worker thread. I did not determine which. The same structure is on main (title_textures.rs title_bytes, gpu/shader.rs readable).

Setup: RX 7900 XT 20 GB, Mesa 26.2.6 RADV, vkd3d-proton 30b0eb9b, wine-staging 11.22, Ryzen 9 5900X, 32 GB RAM, Linux 7.3, release (x86_64-pc-windows-gnu). Tree: main b49be183 + #877, #684, #1993, #2127, plus a local probe that routes 547 named compute records to the direct DXIL translator (without it the title does not get this far on RADV). #877 changes title_bytes under Wine: it skips the borrowed path for ranges in a committed UMA window. Not reproduced on main alone or on Windows. One run, so I don't know if it is deterministic.

Not tested: Windows, NVIDIA, a second run, which texture it was (its VA and format were not logged).

AI use: Claude Code (Claude Opus 5.5) ran the game, symbolized the stack, read the code and wrote this; checked against the run log before posting.

**@⁠frozht** on GitHub · 2026-11-26 17:34 UTC · [original](https://github.com/xcl-dev/xcl/issues/2841) A texture worker crashes in `Chain::detile_level` reading a title page that is no longer mapped. `title_bytes` decided the range was readable and borrowed it, so the copy runs on raw title memory. **What happened:** the retail title from #505 (1.0.2.1) under Wine reached the intro cinematic, then crashed at 965.5 s: ``` [ 965.490][ 1888][ERROR] unhandled exception 0xc0000005 in msvcrt.dll+0xa52b (read at address 0x7fed8a7f8000) ... on the stack: xcl.exe+0x2eaae7, xcl.exe+0x8b3d10, xcl.exe+0x696cf4, xcl.exe+0x13b2fe, xcl.exe+0x8aa4d8, xcl.exe+0x273248 ``` Symbolized with `addr2line` on the same binary: | frame | function | |---|---| | `+0x2eaae7` | `<[u8]>::copy_from_slice`, inlined in `gpu::tiling::Chain::detile_level` (`dst.copy_from_slice(s)`) | | `+0x696cf4` | `hle::d3d12x::title_textures::subresources` (`c.detile_level(&slice, i, s)`) | | `+0x13b2fe` | `title_textures::subresources_on::{closure}`, a worker thread of the parallel path | **Why the bounds check does not help:** in `subresources`, `slice` comes from `title_bytes(va + s * slice_bytes, slice_bytes)`. When `gpu::shader::readable` says yes, `title_bytes` returns `Cow::Borrowed(slice::from_raw_parts(at, len))`, a view of the title's memory, not a copy. `detile_level`'s `src.get(o..o + e)` only checks against the slice length, so it cannot catch a page inside the range that is unmapped when the copy happens. On the other branch (`read_committed`) the copy would come from an owned `Vec` and could not fault, so this crash took the borrowed branch. So either `readable` answered yes for a range that was not all readable, or the title released or decommitted the pages between the check and the read on a worker thread. I did not determine which. The same structure is on `main` (`title_textures.rs` `title_bytes`, `gpu/shader.rs` `readable`). **Setup:** RX 7900 XT 20 GB, Mesa 26.2.6 RADV, vkd3d-proton `30b0eb9b`, wine-staging 11.22, Ryzen 9 5900X, 32 GB RAM, Linux 7.3, release (`x86_64-pc-windows-gnu`). Tree: `main` `b49be183` + #877, #684, #1993, #2127, plus a local probe that routes 547 named compute records to the direct DXIL translator (without it the title does not get this far on RADV). #877 changes `title_bytes` under Wine: it skips the borrowed path for ranges in a committed UMA window. Not reproduced on `main` alone or on Windows. One run, so I don't know if it is deterministic. **Not tested:** Windows, NVIDIA, a second run, which texture it was (its VA and format were not logged). AI use: Claude Code (Claude Opus 5.5) ran the game, symbolized the stack, read the code and wrote this; checked against the run log before posting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:36:06 +00:00
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-26 20:26 UTC · original

This reproduces on plain main (8b957bec) under Proton on an RX 9070 (RADV), with the same stack.

Stack. Release xcl.exe of 8b957bec. I symbolized it against a rebuild of the same commit with CARGO_PROFILE_RELEASE_DEBUG=line-tables-only. The bytes before each return address match the tested binary at the same offset.

unhandled exception 0xc0000005 in ucrtbase.dll+0x1724d (read at address 0x77730c000) rbx=0x1000 ...
xcl.exe+0x175590  copy_from_slice inlined in gpu::tiling::Chain::detile_level  (crates/xcl/src/gpu/tiling.rs:464)
xcl.exe+0x3bee36  hle::d3d12x::title_textures::subresources                    (crates/xcl/src/hle/d3d12x/title_textures.rs:1480)

(Under x86_64-pc-windows-gnu with Proton, the copy is in ucrtbase.dll rather than msvcrt.dll.)

How often. In 300 s runs of the retail title (1.0.2.1), with warm caches and XCL_TEXTURE_LEVEL_PAGES=1, XCL_PSO_WAIT_MS=50, XCL_DIRECT_DXIL=1, this crash ended:

  • 1 of 3 runs of main 8b957bec, at 293 s;
  • 6 of 9 runs of main and main + #2547 / #2581, which do not touch this code, between 165 and 293 s, always after the world start (about 100 s);
  • runs of main 2898511 and of other trees yesterday, with the same ucrtbase read signature. I did not symbolize those builds.

The faulting addresses of today's runs (e.g. 0x77730c000, 0xbdc2dbe90) are ordinary title memory, above XCL's UMA windows (which start at 0x400000000).

With #2849 on the same main, 6 of 6 runs went the full 300 s. Details are in the test report on #2849.

Setup

  • AMD Radeon RX 9070 (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux 7.3.5
  • Proton Experimental experimental-11.0-20261112, vkd3d-proton master ec207194 (dxil-spirv b540c8a2) with a local patch that drops the lpVtbl identity checks in d3d12_command_allocator_from_iface / d3d12_command_list_from_iface, DXC 1.9.2609.5, Rust 1.96.0, target x86_64-pc-windows-gnu, release builds for the title

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine, symbolized the stack and wrote this comment.

**@⁠ClosetPie107** on GitHub · 2026-11-26 20:26 UTC · [original](https://github.com/xcl-dev/xcl/issues/2841#issuecomment-7202694746) This reproduces on plain `main` (`8b957bec`) under Proton on an RX 9070 (RADV), with the same stack. **Stack.** Release `xcl.exe` of `8b957bec`. I symbolized it against a rebuild of the same commit with `CARGO_PROFILE_RELEASE_DEBUG=line-tables-only`. The bytes before each return address match the tested binary at the same offset. ``` unhandled exception 0xc0000005 in ucrtbase.dll+0x1724d (read at address 0x77730c000) rbx=0x1000 ... xcl.exe+0x175590 copy_from_slice inlined in gpu::tiling::Chain::detile_level (crates/xcl/src/gpu/tiling.rs:464) xcl.exe+0x3bee36 hle::d3d12x::title_textures::subresources (crates/xcl/src/hle/d3d12x/title_textures.rs:1480) ``` (Under `x86_64-pc-windows-gnu` with Proton, the copy is in `ucrtbase.dll` rather than `msvcrt.dll`.) **How often.** In 300 s runs of the retail title (1.0.2.1), with warm caches and `XCL_TEXTURE_LEVEL_PAGES=1`, `XCL_PSO_WAIT_MS=50`, `XCL_DIRECT_DXIL=1`, this crash ended: - 1 of 3 runs of `main` `8b957bec`, at 293 s; - 6 of 9 runs of `main` and `main` + #2547 / #2581, which do not touch this code, between 165 and 293 s, always after the world start (about 100 s); - runs of `main` `2898511` and of other trees yesterday, with the same `ucrtbase` read signature. I did not symbolize those builds. The faulting addresses of today's runs (e.g. `0x77730c000`, `0xbdc2dbe90`) are ordinary title memory, above XCL's UMA windows (which start at `0x400000000`). With #2849 on the same `main`, 6 of 6 runs went the full 300 s. Details are in the test report on #2849. **Setup** - AMD Radeon RX 9070 (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux 7.3.5 - Proton Experimental `experimental-11.0-20261112`, `vkd3d-proton` master `ec207194` (dxil-spirv `b540c8a2`) with a local patch that drops the `lpVtbl` identity checks in `d3d12_command_allocator_from_iface` / `d3d12_command_list_from_iface`, DXC `1.9.2609.5`, Rust 1.96.0, target `x86_64-pc-windows-gnu`, release builds for the title **AI use:** Claude Code (Claude Opus 5.5) ran the tests on this machine, symbolized the stack and wrote this comment.
Author
Owner

@⁠frozht on GitHub · 2026-11-26 20:49 UTC · original

Update: two open PRs already fix this. #751 (with_title_bytes, a per-thread reused buffer) and #2849 (page-by-page copy) both stop borrowing title memory outside the coherent window. I found them after writing the same fix locally, so I'm not opening a third PR. Here is what I measured with mine, in case it helps choose between them.

Recurrence and cause. The crash happened in 4 of 5 runs that got far enough, at 143, 243, 763 and 965 s, with the same stack each time. From the code: refresh_once re-uploads every registered texture that has written pages or is new, not only the ones in the current submit. It holds a reference to the D3D resource but nothing that keeps the title's memory alive. The title can then decommit that memory from another thread, through the VirtualFree hook for a sparse reservation or a placeholder, through plain VirtualFree, or through sparse::free, while title_bytes' borrowed view is still being read. A unit test that decommits the range after readable() returned true crashes the test exe with the old title_bytes ("wine: Unhandled page fault on read access") and passes with a fault-safe copy.

Copy cost under Wine (release test exe, wine-staging 11.22, Ryzen 9 5900X, average of 20):

64 MiB range ms
borrowed view + content_hash (old) 2.85
one ReadProcessMemory call, fresh buffer 20.0
one ReadProcessMemory call, reused buffer 16.1
ReadProcessMemory in 1 MiB steps, fresh buffer 8.7
ReadProcessMemory in 1 MiB steps, reused buffer 4.6
plain allocation + memcpy 8.2

So under Wine one ReadProcessMemory call over a large range costs 3 to 4 times as much as the same copy in 1 MiB steps. #751 makes one whole-range call first, so on Wine it may be worth splitting that read. I did not measure this on Windows.

Game runs with the fix: RX 7900 XT, Mesa 26.2.6 RADV, vkd3d-proton 30b0eb9b. Tree: main b49be183 + #877, #684, #1993, #2127, plus a local probe that routes 547 compute records to the direct DXIL translator, plus the fix. Two runs of 1500 s each: no crash. In one run presents stopped after 204 s, and the other had no presents from 160 s to 1056 s. Runs of this tree without the fix stalled the same way, but I don't know the cause. Two runs aren't enough to say the crash is gone.

Not tested: #751 and #2849 themselves; Windows.

AI use: Claude Code (Claude Opus 5.5) wrote the local fix and the test, ran the measurements and the game runs, and wrote this. I checked the numbers against the logs before posting.

**@⁠frozht** on GitHub · 2026-11-26 20:49 UTC · [original](https://github.com/xcl-dev/xcl/issues/2841#issuecomment-7203108361) Update: two open PRs already fix this. #751 (`with_title_bytes`, a per-thread reused buffer) and #2849 (page-by-page copy) both stop borrowing title memory outside the coherent window. I found them after writing the same fix locally, so I'm not opening a third PR. Here is what I measured with mine, in case it helps choose between them. **Recurrence and cause.** The crash happened in 4 of 5 runs that got far enough, at 143, 243, 763 and 965 s, with the same stack each time. From the code: `refresh_once` re-uploads every registered texture that has written pages or is new, not only the ones in the current submit. It holds a reference to the D3D resource but nothing that keeps the title's memory alive. The title can then decommit that memory from another thread, through the `VirtualFree` hook for a sparse reservation or a placeholder, through plain `VirtualFree`, or through `sparse::free`, while `title_bytes`' borrowed view is still being read. A unit test that decommits the range after `readable()` returned true crashes the test exe with the old `title_bytes` ("wine: Unhandled page fault on read access") and passes with a fault-safe copy. **Copy cost under Wine** (release test exe, wine-staging 11.22, Ryzen 9 5900X, average of 20): | 64 MiB range | ms | |---|---:| | borrowed view + `content_hash` (old) | 2.85 | | one `ReadProcessMemory` call, fresh buffer | 20.0 | | one `ReadProcessMemory` call, reused buffer | 16.1 | | `ReadProcessMemory` in 1 MiB steps, fresh buffer | 8.7 | | `ReadProcessMemory` in 1 MiB steps, reused buffer | 4.6 | | plain allocation + `memcpy` | 8.2 | So under Wine one `ReadProcessMemory` call over a large range costs 3 to 4 times as much as the same copy in 1 MiB steps. #751 makes one whole-range call first, so on Wine it may be worth splitting that read. I did not measure this on Windows. **Game runs with the fix:** RX 7900 XT, Mesa 26.2.6 RADV, vkd3d-proton `30b0eb9b`. Tree: `main` `b49be183` + #877, #684, #1993, #2127, plus a local probe that routes 547 compute records to the direct DXIL translator, plus the fix. Two runs of 1500 s each: no crash. In one run presents stopped after 204 s, and the other had no presents from 160 s to 1056 s. Runs of this tree without the fix stalled the same way, but I don't know the cause. Two runs aren't enough to say the crash is gone. **Not tested:** #751 and #2849 themselves; Windows. AI use: Claude Code (Claude Opus 5.5) wrote the local fix and the test, ran the measurements and the game runs, and wrote this. I checked the numbers against the logs before posting.
Author
Owner

@⁠andrewDoing on GitHub · 2026-11-27 03:10 UTC · original

The two proposals for #2841 have different CPU copy costs. I built each exact head on Windows with a test-only byte counter in read_committed and the same 256 × 256 R8 fixture. Each source held 65,536 bytes. I exercised content_hash, same_as_last_upload, and, only when the hash changed, subresources. One source was ordinary readable process memory. The other was allocated from XCL’s committed coherent UMA window.

Source and content #2849 4e931734 snapshot bytes #2877 c1c22863 snapshot bytes
Ordinary, unchanged 65,536 0
Ordinary, changed 131,072 65,536
Coherent UMA, unchanged 0 0
Coherent UMA, changed 0 65,536

On #2849, ordinary memory is copied for hashing and copied again for detiling when changed. Coherent memory is borrowed in both paths. On #2877, the hash borrows both readable sources and worker detiling copies either source. Both heads skipped unchanged content, and all four changed-source runs produced the expected 65,536 detiled bytes. Each focused test passed without a skip.

The counter measures requested CPU snapshot bytes, excluding the detiled destination and GPU uploads. This was a single-threaded helper comparison on stable memory, without a retail title, decommit, GPU dispatch or timing measurements. The result does not establish which source predominates during world loading.

AI use: OpenAI Codex with GPT-6.2 Astra adapted the fixture and ran the checks; Codex coordinated and prepared the comparison.

**@⁠andrewDoing** on GitHub · 2026-11-27 03:10 UTC · [original](https://github.com/xcl-dev/xcl/issues/2841#issuecomment-7208768403) The two proposals for #2841 have different CPU copy costs. I built each exact head on Windows with a test-only byte counter in `read_committed` and the same 256 × 256 R8 fixture. Each source held 65,536 bytes. I exercised `content_hash`, `same_as_last_upload`, and, only when the hash changed, `subresources`. One source was ordinary readable process memory. The other was allocated from XCL’s committed coherent UMA window. | Source and content | #2849 `4e931734` snapshot bytes | #2877 `c1c22863` snapshot bytes | | --- | ---: | ---: | | Ordinary, unchanged | 65,536 | 0 | | Ordinary, changed | 131,072 | 65,536 | | Coherent UMA, unchanged | 0 | 0 | | Coherent UMA, changed | 0 | 65,536 | On #2849, ordinary memory is copied for hashing and copied again for detiling when changed. Coherent memory is borrowed in both paths. On #2877, the hash borrows both readable sources and worker detiling copies either source. Both heads skipped unchanged content, and all four changed-source runs produced the expected 65,536 detiled bytes. Each focused test passed without a skip. The counter measures requested CPU snapshot bytes, excluding the detiled destination and GPU uploads. This was a single-threaded helper comparison on stable memory, without a retail title, decommit, GPU dispatch or timing measurements. The result does not establish which source predominates during world loading. AI use: OpenAI Codex with GPT-6.2 Astra adapted the fixture and ran the checks; Codex coordinated and prepared the comparison.
This discussion has been locked. Commenting is limited to contributors.
No description provided.