D3D12.X: do not borrow title memory in texture workers #2849

Open
github-bot wants to merge 1 commit from github-bot/gh-2849 into main AGit
Owner

@⁠guinpereira on GitHub · 2026-11-26 18:31 UTC · original
guinpereira:fix/title-textures-no-borrow → main · +7 −3 · 1 files · 1 commits · open

Relates to #2841.

Copies title bytes page by page instead of borrowing the range, so a worker cannot fault if the title decommits pages between the readability check and the detile copy.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: page-by-page copy instead of borrowing the title range.

Tested

  • Windows 11, NVIDIA GeForce RTX 5060 Ti, Rust stable (x86_64-pc-windows-msvc), debug build.
  • cargo test -p xcl --lib -- --test-threads=4: 1315 passed, 4 failed (GPU OOM in dxil fuzz tests, environment), 27 ignored.
  • cargo build -p xcl: clean.

Regression run

xcl-smoke v1
commit: 05adb5a9cfc718119c0c9c097365983e67982d05
gpu: NVIDIA GeForce RTX 5060 Ti
title: gta6
seconds: 60
exit: 0x0
frames shown: 1043 (PresentX 1043)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15536 MB

Reference run on the author's local main (05adb5a). A run on ivall/xcl main and on this PR's head commit is still pending (cold shader cache crashes the title's startup precompile on this machine).

Not tested

  • Smoke on ivall/xcl main baseline and on this PR's head commit (pending, see above).
  • The decommit race itself not reproduced.

AI use
OpenCode, Beam Free - drafted the change; smoke run and review by the author.

**@⁠guinpereira** on GitHub · 2026-11-26 18:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/2849) `guinpereira:fix/title-textures-no-borrow` → `main` · +7 −3 · 1 files · 1 commits · open Relates to #2841. Copies title bytes page by page instead of borrowing the range, so a worker cannot fault if the title decommits pages between the readability check and the detile copy. **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`: page-by-page copy instead of borrowing the title range. **Tested** - Windows 11, NVIDIA GeForce RTX 5060 Ti, Rust stable (x86_64-pc-windows-msvc), debug build. - `cargo test -p xcl --lib -- --test-threads=4`: 1315 passed, 4 failed (GPU OOM in dxil fuzz tests, environment), 27 ignored. - `cargo build -p xcl`: clean. **Regression run** ``` xcl-smoke v1 commit: 05adb5a9cfc718119c0c9c097365983e67982d05 gpu: NVIDIA GeForce RTX 5060 Ti title: gta6 seconds: 60 exit: 0x0 frames shown: 1043 (PresentX 1043) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15536 MB ``` Reference run on the author's local main (05adb5a). A run on ivall/xcl main and on this PR's head commit is still pending (cold shader cache crashes the title's startup precompile on this machine). **Not tested** - Smoke on ivall/xcl main baseline and on this PR's head commit (pending, see above). - The decommit race itself not reproduced. **AI use** OpenCode, Beam Free - drafted the change; smoke run and review by the author.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:39:23 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 18:45 UTC · original

Independent Wine verification of production head 4e93173413fed5f2d079ae4f2da37f07996e9727: 2 focused tests passed, 0 failed/ignored, 1.45 s after fresh 25.42 s compilation from xcl-pr2849.

Environment: Linux, Wine 11.0, Rust 1.98.1, Windows MSVC target, 16 GiB host RAM; 9 GiB memory / 512 MiB swap cgroup limits, 180 s timeout, one test thread. RTX 4060 Laptop host, but these are CPU/Win32 memory tests, not GPU rendering. The installed vkd3d stack is diagnostic-relaxed; no native-Windows or stock-driver certification is implied.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib title_bytes -- --nocapture --test-threads=1

Production code unchanged. Two local test-only strengthenings:

  1. Existing title_bytes_are_used_in_place_when_all_are_readable: require VirtualFree(..., MEM_RELEASE) to succeed, then inspect the already returned whole/holed snapshots again. Original byte tags and the zero hole survive source release. The existing Cow::Owned assertion remains before release, so a borrowed-result control would fail safely before touching freed memory.
  2. lab_title_bytes_survive_concurrent_decommit: adapted #751's title_bytes_survive_concurrent_decommit to this PR's title_bytes/Cow API. One MiB source, 16 x 64 KiB regions, distinct byte tags per 4 KiB page; another thread repeatedly decommits/recommits the inner regions. For 256 snapshots, hash and verify each page consists only of its original-tag prefix followed by zeros. The counter recorded 420,948 decommits during the snapshot/hash interval, not an idle mutator. No exception. This is a stress interleaving, not proof of all schedules.

The API adaptation is simply:

let bytes = title_bytes(base, PAGES * PAGE);
std::hint::black_box(content_hash(&bytes));
assert!(bytes.chunks(4096).enumerate().all(|(k, c)| {
    let n = c.iter().position(|&x| x != tag(k)).unwrap_or(c.len());
    c[n..].iter().all(|&x| x == 0)
}));

The local fixture additionally uses a scoped thread and a stop-on-drop guard to stop the mutator on assertion failure. It requires a nonzero concurrent-decommit count and successful decommit/recommit calls. No production hooks or mocked memory calls.

Suggested changes before merge: rename the existing test/doc comment (it now requires copying outside UMA, not in-place use whenever readable), and retain a source-release/concurrent-decommit regression. The existing static byte-equality test alone does not exercise the lifetime defect from #2841.

Performance/RAM limitation: read_committed creates a fresh zeroed Vec per non-UMA read. This test does not measure title allocation pressure, texture-worker throughput, or peak RAM. #751 already proposes a reusable buffer and whole-range ReadProcessMemory fast path; coordinate with that owner rather than silently assuming the new copy is free. A bounded identical-input detile/streaming comparison is still needed before any performance claim. No recommendation to enable the experimental driver-window path from #2844 under Wine.

No matched-parent race run: deliberately reproducing the known worker access violation is not needed for this verification. No title launch, Game Init watchdog fix claim, or gameplay/OOM claim. Local evidence: .compat-xcl/logs/verify-pr2849-wine-title-bytes.log; local test-only edits retained for reproducibility. AI-assisted verification (OpenAI GPT-6 Astra).

**@⁠pickles976** on GitHub · 2026-11-26 18:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2849#issuecomment-7200816397) Independent Wine verification of production head `4e93173413fed5f2d079ae4f2da37f07996e9727`: **2 focused tests passed**, 0 failed/ignored, 1.45 s after fresh 25.42 s compilation from `xcl-pr2849`. Environment: Linux, Wine 11.0, Rust 1.98.1, Windows MSVC target, 16 GiB host RAM; 9 GiB memory / 512 MiB swap cgroup limits, 180 s timeout, one test thread. RTX 4060 Laptop host, but these are **CPU/Win32 memory tests**, not GPU rendering. The installed vkd3d stack is diagnostic-relaxed; no native-Windows or stock-driver certification is implied. ```text cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib title_bytes -- --nocapture --test-threads=1 ``` Production code unchanged. Two local test-only strengthenings: 1. Existing `title_bytes_are_used_in_place_when_all_are_readable`: require `VirtualFree(..., MEM_RELEASE)` to succeed, then inspect the **already returned** whole/holed snapshots again. Original byte tags and the zero hole survive source release. The existing `Cow::Owned` assertion remains before release, so a borrowed-result control would fail safely before touching freed memory. 2. `lab_title_bytes_survive_concurrent_decommit`: adapted [#751](https://git.gtahub.st/github/xcl-dev--xcl/pulls/751)'s `title_bytes_survive_concurrent_decommit` to this PR's `title_bytes`/Cow API. One MiB source, 16 x 64 KiB regions, distinct byte tags per 4 KiB page; another thread repeatedly decommits/recommits the inner regions. For **256 snapshots**, hash and verify each page consists only of its original-tag prefix followed by zeros. The counter recorded **420,948 decommits during the snapshot/hash interval**, not an idle mutator. No exception. This is a stress interleaving, not proof of all schedules. The API adaptation is simply: ```rust let bytes = title_bytes(base, PAGES * PAGE); std::hint::black_box(content_hash(&bytes)); assert!(bytes.chunks(4096).enumerate().all(|(k, c)| { let n = c.iter().position(|&x| x != tag(k)).unwrap_or(c.len()); c[n..].iter().all(|&x| x == 0) })); ``` The local fixture additionally uses a scoped thread and a stop-on-drop guard to stop the mutator on assertion failure. It requires a nonzero concurrent-decommit count and successful decommit/recommit calls. No production hooks or mocked memory calls. **Suggested changes before merge:** rename the existing test/doc comment (it now requires copying outside UMA, not in-place use whenever readable), and retain a source-release/concurrent-decommit regression. The existing static byte-equality test alone does not exercise the lifetime defect from #2841. **Performance/RAM limitation:** `read_committed` creates a fresh zeroed `Vec` per non-UMA read. This test does not measure title allocation pressure, texture-worker throughput, or peak RAM. #751 already proposes a reusable buffer and whole-range `ReadProcessMemory` fast path; coordinate with that owner rather than silently assuming the new copy is free. A bounded identical-input detile/streaming comparison is still needed before any performance claim. No recommendation to enable the experimental driver-window path from #2844 under Wine. No matched-parent race run: deliberately reproducing the known worker access violation is not needed for this verification. No title launch, Game Init watchdog fix claim, or gameplay/OOM claim. Local evidence: `.compat-xcl/logs/verify-pr2849-wine-title-bytes.log`; local test-only edits retained for reproducibility. AI-assisted verification (OpenAI GPT-6 Astra).
Author
Owner

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

Independent test report under Wine/Proton (not native Windows) for head 4e931734, merged cleanly onto main 8b957bec (test commit 3a077ec6). On this setup, main hits the #2841 crash (symbolized stack in #2841).

Tested

  • 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

  • cargo test -p xcl --lib hle::d3d12x::title_textures:: -- --test-threads=1: main 19 passed, 0 failed. This PR: 19 passed, 0 failed. None skipped (GPU tests ran).

  • Retail title (1.0.2.1). 300 s per run (XCL_RUN_SECONDS), A pressed every 10 s from 20 s, all runs from one copy of the same warm cache. Flags: XCL_PSO_WAIT_MS=50, XCL_DIRECT_DXIL=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_SPLIT_MIDLIST_WAIT=0, XCL_COHERENT_MB=1024, XCL_PSO_PRELOAD=1, XCL_NETWORK=0, VKD3D_CONFIG=ignore_shared_fence.

tree run end presents before 100 s / after draws (skipped) dispatches (skipped)
main 8b957bec 1 #2841 crash at 293 s 1,672 / 356 149,632 (512) 779,672 (1)
2 300 s, exit 0 1,625 / 407 198,874 (527) 927,998 (3)
3 300 s, exit 0 1,426 / 339 131,072 (377) 675,433 (2)
main + #2849 1 300 s, exit 0 1,688 / 518 225,510 (512) 1,092,032 (1)
2 300 s, exit 0 1,658 / 404 209,561 (542) 990,431 (0)
3 300 s, exit 0 1,678 / 482 227,101 (256) 1,117,190 (0)
4 300 s, exit 0 1,596 / 396 131,072 (407) 686,236 (0)
5 300 s, exit 0 1,682 / 464 236,757 (618) 1,048,576 (30)
6 300 s, exit 0 1,687 / 520 223,270 (374) 1,048,576 (3)

(Counts are from the last activity and console code so far lines.)

  • No crash in 6 runs with this PR. On the same setup the crash ended 1 of 3 runs of main, and 6 of 9 runs of main and two PRs that do not touch title_textures (see #2841).
  • I see no slowdown from copying instead of borrowing: presents, draws and dispatches are not lower than on main. The title presents only 1–4 times per 2 s after the world start on all trees, so a cost in the detile would be hard to see here.
  • No device removals.

The test change only switches the existing assertion from Borrowed to Owned. There is no test that fails without the fix, for example a page decommitted between the readability check and the detile.

Not tested

  • Native Windows, NVIDIA/Intel, XCL_TEXTURE_LEVEL_PAGES unset, cold caches
  • The cost of the copy on a scene that presents at full rate
  • The full workspace suite on this merge

AI use

  • Claude Code (Claude Opus 5.5) merged the PR, ran the tests and the title on this machine, and wrote this report.
**@⁠ClosetPie107** on GitHub · 2026-11-26 20:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/2849#issuecomment-7202695214) Independent test report under Wine/Proton (not native Windows) for head `4e931734`, merged cleanly onto `main` `8b957bec` (test commit `3a077ec6`). On this setup, `main` hits the #2841 crash (symbolized stack in #2841). **Tested** - 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 - `cargo test -p xcl --lib hle::d3d12x::title_textures:: -- --test-threads=1`: `main` 19 passed, 0 failed. This PR: **19 passed, 0 failed**. None skipped (GPU tests ran). - Retail title (1.0.2.1). 300 s per run (`XCL_RUN_SECONDS`), A pressed every 10 s from 20 s, all runs from one copy of the same warm cache. Flags: `XCL_PSO_WAIT_MS=50`, `XCL_DIRECT_DXIL=1`, `XCL_TEXTURE_LEVEL_PAGES=1`, `XCL_SPLIT_MIDLIST_WAIT=0`, `XCL_COHERENT_MB=1024`, `XCL_PSO_PRELOAD=1`, `XCL_NETWORK=0`, `VKD3D_CONFIG=ignore_shared_fence`. | tree | run | end | presents before 100 s / after | draws (skipped) | dispatches (skipped) | |---|---|---|---|---|---| | `main` `8b957bec` | 1 | **#2841 crash at 293 s** | 1,672 / 356 | 149,632 (512) | 779,672 (1) | | | 2 | 300 s, exit 0 | 1,625 / 407 | 198,874 (527) | 927,998 (3) | | | 3 | 300 s, exit 0 | 1,426 / 339 | 131,072 (377) | 675,433 (2) | | `main` + #2849 | 1 | **300 s, exit 0** | 1,688 / 518 | 225,510 (512) | 1,092,032 (1) | | | 2 | **300 s, exit 0** | 1,658 / 404 | 209,561 (542) | 990,431 (0) | | | 3 | **300 s, exit 0** | 1,678 / 482 | 227,101 (256) | 1,117,190 (0) | | | 4 | **300 s, exit 0** | 1,596 / 396 | 131,072 (407) | 686,236 (0) | | | 5 | **300 s, exit 0** | 1,682 / 464 | 236,757 (618) | 1,048,576 (30) | | | 6 | **300 s, exit 0** | 1,687 / 520 | 223,270 (374) | 1,048,576 (3) | (Counts are from the last `activity` and `console code so far` lines.) - No crash in 6 runs with this PR. On the same setup the crash ended 1 of 3 runs of `main`, and 6 of 9 runs of `main` and two PRs that do not touch `title_textures` (see #2841). - I see no slowdown from copying instead of borrowing: presents, draws and dispatches are not lower than on `main`. The title presents only 1–4 times per 2 s after the world start on all trees, so a cost in the detile would be hard to see here. - No device removals. The test change only switches the existing assertion from `Borrowed` to `Owned`. There is no test that fails without the fix, for example a page decommitted between the readability check and the detile. **Not tested** - Native Windows, NVIDIA/Intel, `XCL_TEXTURE_LEVEL_PAGES` unset, cold caches - The cost of the copy on a scene that presents at full rate - The full workspace suite on this merge **AI use** - Claude Code (Claude Opus 5.5) merged the PR, ran the tests and the title on this machine, and wrote this report.
Author
Owner

@⁠throny on GitHub · 2026-11-27 02:49 UTC · original

Two contributors checked independently and found that #2877 solves the same problem (for #2841) in a different way: #1607, group D142. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-27 02:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2849#issuecomment-7208468321) <!-- xcl-1607-hint:D142 --> Two contributors checked independently and found that #2877 solves the same problem (for #2841) in a different way: #1607, group D142. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠ettehn on GitHub · 2026-11-27 02:57 UTC · original

For D142, I compared the exact read helpers from 4e931734 (#2849) and c1c22863 (#2877) in an optimized standalone Windows fixture on a Ryzen 9 8945HX. Both worker paths returned an owned copy of an ordinary three-page span with a reserved middle page, preserving the two readable pages and zeroing the hole. For a fully committed coherent UMA window, #2849 returned the original slice and #2877 returned a separate copy, with identical bytes.

Across three processes with nine alternating samples each, the #2877 UMA helper’s per-process medians were 0.27–0.29 us (16 KiB), 4.75–6.60 us (256 KiB), and 476–485 us (4 MiB). In that same fixture #2849 did no copy for those ranges. This measures obtaining and dropping the slice or copy, before detile or upload. No GPU work, title run, or frame-rate claim. The choice also affects scope: #2849 changes the shared helper used by submit-time hashing for non-UMA memory; #2877 keeps that caller on the old path.

OpenAI Codex (6.2sol) assisted with verification.

**@⁠ettehn** on GitHub · 2026-11-27 02:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2849#issuecomment-7208580745) For D142, I compared the exact read helpers from `4e931734` (#2849) and `c1c22863` (#2877) in an optimized standalone Windows fixture on a Ryzen 9 8945HX. Both worker paths returned an owned copy of an ordinary three-page span with a reserved middle page, preserving the two readable pages and zeroing the hole. For a fully committed coherent UMA window, #2849 returned the original slice and #2877 returned a separate copy, with identical bytes. Across three processes with nine alternating samples each, the #2877 UMA helper’s per-process medians were 0.27–0.29 us (16 KiB), 4.75–6.60 us (256 KiB), and 476–485 us (4 MiB). In that same fixture #2849 did no copy for those ranges. This measures obtaining and dropping the slice or copy, before detile or upload. No GPU work, title run, or frame-rate claim. The choice also affects scope: #2849 changes the shared helper used by submit-time hashing for non-UMA memory; #2877 keeps that caller on the old path. OpenAI Codex (6.2sol) assisted with verification.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/title_textures.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2849/head:github-bot/gh-2849'
git switch 'github-bot/gh-2849'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2849'
git switch 'github-bot/gh-2849'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2849'
git switch 'github-bot/gh-2849'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2849'
git switch 'main'
git merge --squash 'github-bot/gh-2849'
git switch 'main'
git merge --ff-only 'github-bot/gh-2849'
git switch 'main'
git merge 'github-bot/gh-2849'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.