Skip to content

D3D12.X: XG CopyInto/FromSubresource take the newer library's added argument - #1435

Open
lukastaro wants to merge 1 commit into
xcl-dev:mainfrom
lukastaro:xg-copy-subresource-newer-form
Open

lukastaro wants to merge 1 commit into
xcl-dev:mainfrom
lukastaro:xg-copy-subresource-newer-form

Conversation

@lukastaro

Copy link
Copy Markdown

A retail game crashed during its world loading, every run: an access violation in a memcpy writing to title memory that was never reserved, mapped or committed. The writer was XCL's XGTextureAddressComputer::CopyFromSubresource (vtable #9), which the game calls as (linear dst, plane, subresource, 0, tiled src, row pitch, slice pitch): its XG library has a 32-bit argument before the source pointer, which the library the oracle test uses does not have. Read the 6-argument way, the source was the 0 dword with the stack slot's old upper half, and the row pitch the low half of the real source pointer, so the second row went gigabytes past the destination.

The game calls both forms, so they are told apart per call: a value of 16 bits or less in the fourth slot with address space in use at the fifth is the newer form (address space, not readable memory: a title's pages are committed on first use). A nonzero added argument is logged once and ignored; its meaning is not known (the game passes 0).

What is in it

  • copy_args and the two copy methods taking either form (hle/xg.rs).
  • A unit test: both forms tile the same bytes and read them back, with garbage in the upper half of the added argument's slot (hle/xg.rs).

Tested

  • NVIDIA GeForce RTX 5060 Ti (driver 617.42, Agility SDK 1.620.2), Intel Core i7-14700K, Windows 10 22H2 (19045), Rust 1.100.0; tests in debug, smoke and game runs in release.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware – no wave64 on this GPU).
  • The retail game: the crash was in every run before (8 runs, 60 – 112 s into the run); with the change the newer form is logged at that point and none of the runs since (more than 10) crashed there. They stop later for other reasons.

Regression run

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5060 Ti
title: Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1371 (PresentX 1371)
presents per 2 s (last 3): 1 3 12
device removals: 0
crashes: 0
peak commit: 25566 MB

PR:

xcl-smoke v1
commit: 14c8a2d11a7b975bc7a0e98468cfeb705244af8b
gpu: NVIDIA GeForce RTX 5060 Ti
title: Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1620 (PresentX 1620)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17179 MB

An offline shader precompile ran on the same machine during the main run (and less of it during the PR's), so the frame and commit numbers differ more than the change does; the 60 s stay in the game's menus, before the copy this changes.

Not tested

  • AMD and Intel GPUs (the change is CPU-side).
  • The console library itself: no copy of the newer XG library is at hand, so the newer form is inferred from the game's call sites (game code calling vtable Olympus: harden DXIL cache identity and validation #9 with the seven arguments above), not checked against it like xg_oracle.
  • What the added argument means when it is not 0.
  • Other titles with the newer library.

AI use

  • Claude Code (Claude Opus 5.5): found the crash (disassembly of the game's call site, XCL's logs), wrote the change, the test and this description; the runs above were made on the hardware named.

🤖 Generated with Claude Code

…rgument

A retail game crashed during its world loading, every run: an
access violation in a memcpy writing to title memory that was never
reserved, mapped or committed. The writer was XCL's
XGTextureAddressComputer::CopyFromSubresource (vtable xcl-dev#9), called by the
game as (linear dst, plane, subresource, 0, tiled src, row pitch, slice
pitch): its library has a 32-bit argument before the source pointer,
which the library the oracle test uses (XDefiant's) does not. Read the
6-argument way, the source was the 0 dword with the stack slot's old
upper half, and the row pitch the low half of the real source pointer,
so the second row went gigabytes past the destination.

The game calls both forms, so they are told apart per call: a value of
16 bits or less in the fourth slot with address space in use at the
fifth is the newer form (address space, not readable memory: title pages
are committed on first use). A nonzero added argument is logged once and
ignored; its meaning is not known.

New test: both forms tile the same bytes and read them back, with
garbage in the upper half of the added argument's slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukastaro
lukastaro marked this pull request as ready for review November 24, 2026 15:56
@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 14c8a2d (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: subresource_copies_take_both_argument_forms.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read at 14c8a2d (merge base 930e8b4; merges into main 9e3831e without conflicts) by reading the code; nothing of this PR was built or run here. A local logging patch on main 9e3831e was run on a retail title (below, one run). The crash and the reading of slot #9 match #662. The test goes through the real vtable slots, and its 7-argument calls cannot pass on main.

Overlap: #684 (open since 03:28 UTC, not named here) fixes the same crash by giving slot #9 seven arguments and leaving #8 alone; #976 and #992 build on it. The two conflict in xg.rs (git merge-tree), so only one can go in as it is. #684's PR checks is red (no regression run in its description; retail runs that reach the call are in its comments), this one's is green.

  1. CONFIRMED: every caller we could find splits the two forms by method (#8 six arguments, #9 seven), so copy_into should not guess (xg.rs:708-709).

    • Microsoft's public DirectXTex (MIT), built for xg_xs, passes the added 0u only to CopyFromSubresource. Its CopyIntoSubresource call has six arguments, with no Scarlett case.
    • The retail reports agree: #662 ("only slot 9 differs"), 50 logged CopyInto calls with six arguments, and a crash when #8 was read with seven. One run here of that logging patch (RTX 3060, 155 s, until the #505 null write): #8 was called at least 129 times; the 66 logged calls all fit six arguments, and each has a non-zero upper half in the pitch slot. #9 was called twice, and both calls fit seven (a zero before the source pointer). So in this run the forms split by method, as #662 says.
    • On #8 the guess can only do harm. A valid call with src = 0x8_0000_0000 (low dword 0) and a pitch slot of 0x7_00000100 (a dword under a stale upper half, as in #662's dump), with title memory at that address, is taken as the newer form: it tiles from 0x7_00000100 with the slice pitch as row pitch (wrong bytes, or a fault). This is traced in the code; none of the 66 logged calls had a source with a low dword of at most 0xFFFF, so the run did not hit it.
    • Fix, unless you saw a 6-argument call on #9 (question below): leave copy_into as on main and give copy_from a plain u32 before src. copy_args and its VirtualQuery go away, and so do two cases still misread on #9: an added value above 0xFFFF, and a null src (today a4, if its upper half is stale, becomes the source instead of E_INVALIDARG).
  2. CONFIRMED: the oracle does not show a 6-argument CopyFromSubresource (description; xg.rs:675-677). subresource_copies_match_the_console_library calls the console's slot #8 (xg_oracle.rs:400), but slot #9 only on XCL's own object (:403-405). It supports six arguments for CopyInto only. With the fix above, the from type in the oracle test, and from6 / into7 in the new one, change too.

Questions for the author

  • SEEN is shared by both methods, so the "6-argument" log line does not say which one was called. Did you see a 6-argument call on #9? (Here: none in two calls.)

Verdict: correct for the calls reported; copy_into should not guess, copy_from should be a fixed 7-argument method unless a 6-argument call on #9 was seen, and it needs a decision between this and #684.

Review by Claude Code (written by Claude Opus 5.5, checked with Claude Fable 5.2 and Claude Opus 5.5); each point checked by a person before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
…(port of xcl-dev#976, xcl-dev#992)

xcl-dev#976 and xcl-dev#992 are stacked on xcl-dev#684, which is not merged here: xcl-dev#1435 already
fixes the 7-argument ABI another way (copy_args tells the two forms apart).
Their checks are ported onto xcl-dev#1435's copy_from: the destination span (row and
3D slice pitch, from xcl-dev#684) must be writable memory (dstorage::writable, xcl-dev#976)
and the tiled source range readable (shader::readable_range, xcl-dev#992) before
anything is detiled or copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iggyvilla

Copy link
Copy Markdown
Collaborator

Test report on 14c8a2d (merged with #2120 on main cbc296a as b5c481f;
cargo build --release -p xcl), 2 world-load walks on RX 6650 XT 8 GB (RDNA2)
/ Adrenalin 32.0.21045.29003 / 32 GB RAM (PRELOAD=0, XCL_PSO_WAIT_MS=2000,
-FromSave, commit stop at 37.8 GB).

Tested: same tree and runs as the #2120 report on this machine
(b5c481f, walks auto-20261125-154354 and auto-20261125-155228).

What was measured: the PR's per-form logging fires once per copy form in
both walks — in the 6-argument form at 2.5 s / 2.7 s and in the newer 7-argument form at 125.5 s / 126.9 s (during world load). No 0x80000003
and no +0x4dcbc9d in either log: the packet-stream assert did not fire here.

Not tested: a run that reaches the account-prompt assert itself (these runs
come from a save); suite run on this tree; other GPUs.

AI use: Measured by an omp agent running DeepSeek v4.1 Flash; text drafted
by Muse Spark 1.3; checked and posted by Claude Code (Claude Opus 5.5) on my
behalf; I did not run the tests or write the text.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@xpatfussy69x

Copy link
Copy Markdown

Test report for head 14c8a2d as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's test subresource_copies_take_both_argument_forms ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run, so not with the title's real xg library)

Not tested

  • a smoke run on a title; AMD / native wave64; release build; the head merged onto current main

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV) test report for head 14c8a2d merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, --test-threads=1 --nocapture)

  • hle::xg::tests: 4 passed, 0 failed, 0 ignored, 0 skipped (0.00 s), including subresource_copies_take_both_argument_forms.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants