Skip to content

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

Open
guinpereira wants to merge 1 commit into
xcl-dev:mainfrom
guinpereira:fix/title-textures-no-borrow
Open

guinpereira wants to merge 1 commit into
xcl-dev:mainfrom
guinpereira:fix/title-textures-no-borrow

Conversation

@guinpereira

@guinpereira guinpereira commented Nov 26, 2026 •

Copy link
Copy Markdown

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.

@pickles976

Copy link
Copy Markdown

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

@ClosetPie107

Copy link
Copy Markdown

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 D3D12.X: a texture worker faults in detile_level on title memory that title_bytes borrowed #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.

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.

3 participants