Skip to content

XG: fix CopyFromSubresource 7-argument ABI and guard destination span - #684

Open
JGonzalezRodriguez wants to merge 1 commit into
xcl-dev:mainfrom
JGonzalezRodriguez:fix/xg-copy-from-subresource-abi
Open

JGonzalezRodriguez wants to merge 1 commit into
xcl-dev:mainfrom
JGonzalezRodriguez:fix/xg-copy-from-subresource-abi

Conversation

@JGonzalezRodriguez

Copy link
Copy Markdown

Fix XGTextureAddressComputer::CopyFromSubresource (vtable slot #9) taking 7 arguments instead of 6, and validate the destination span before writing rows.

CopyFromSubresource receives an extra u32 parameter before src (dst, plane, sub, arg4, src, row_pitch, slice_pitch). With the previous 6-argument signature, src was read as row_pitch, causing copy_nonoverlapping to stride rows by the low 32 bits of the source pointer and trigger access violations (#477, first crash in #662).

Supersedes #539 (the other parts of #539 have either landed on main in #435 / #451 / #486 / #574 / #602 / #634 / #636, are covered by focused open PRs, or need a separate single-purpose PR).

Fixes #477
Part of #662

What is in it

  • crates/xcl/src/hle/xg.rs:
    • Update copy_from (vtable slot Olympus: harden DXIL cache identity and validation #9) and the module doc comment to the 7-argument signature (dst, plane, sub, arg4, src, row_pitch, slice_pitch).
    • Validate row_pitch, 3D slice_pitch, and destination span readability (gpu::shader::readable) before copying, logging a bounded warning and returning E_INVALIDARG on invalid spans.
    • Add unit tests copy_into_and_copy_from_round_trip, copy_from_3d_round_trip, and copy_from_rejects_invalid_dst_span.
  • crates/xcl/tests/xg_oracle.rs:
    • Update the CopyFromSubresource call in subresource_copies_match_the_console_library to the 7-argument signature.

Tested

Regression run

  • Pending native Windows scripts/smoke.ps1 runs (opened as draft until native Windows scripts/test.ps1 and main + PR xcl-smoke blocks are attached).

Not tested

  • Native Windows scripts/test.ps1 (full workspace suite) and scripts/smoke.ps1 regression runs (author builds on Linux/Wine).
  • tests/xg_oracle.rs with XCL_SAMPLE_XG set against the console xg_xs.dll.
  • AMD and Intel GPUs.

AI use

CopyFromSubresource (vtable slot xcl-dev#9) takes an extra u32 argument before
src: (dst, plane, sub, arg4, src, row_pitch, slice_pitch). With the old
6-argument signature, src was decoded as row_pitch and rows were copied
far outside dst, causing access violations (xcl-dev#477, xcl-dev#662).

Update copy_from and xg_oracle to the 7-argument ABI, validate row_pitch,
3D slice_pitch, and destination span readability before writing (logging
a bounded warning and returning E_INVALIDARG on invalid spans), and add
2D, 3D, and invalid-span unit tests.

Fixes xcl-dev#477
Part of xcl-dev#662
@jvyden

jvyden commented Nov 24, 2026

Copy link
Copy Markdown

This branch seems to fix #477 on Linux!

@eizispark

Copy link
Copy Markdown

Hardware check of e56dbc3f4313e6950730ba4129c14b530b3e7e40 (verified clean merge with main 91f9a5e): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 695 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none)
  • cargo test -p xcl --lib hle::xg::tests: 6 passed, 0 failed; cargo test -p xcl --test xg_oracle: 6 passed, 0 failed, 12 ignored (XCL_SAMPLE_* unset)

Regression run
main (dd2ae9a):

xcl-smoke v1
commit: dd2ae9a70af5eb5aad60f02d86e386b72abe1e95
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1666 (PresentX 1666)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14851 MB

PR (e56dbc3):

xcl-smoke v1
commit: e56dbc3f4313e6950730ba4129c14b530b3e7e40
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1662 (PresentX 1662)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14848 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); xg_oracle with XCL_SAMPLE_XG set; gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@MonkeyPython

MonkeyPython commented Nov 24, 2026 •

Copy link
Copy Markdown

@odd/tasks/draft-pr684-comment.md

@imnicho

imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A retail run that reaches the call, on native Windows – the reports above cover the suite and the 60 s regression pair, which stay on the title's first screens.

Tested

  • Intel Core i7-7700K (4 cores / 8 threads), 16 GB RAM, NVIDIA GeForce RTX 5080 16 GB (driver 610.47, 32-lane waves), Windows 10 22H2 (19045), DXC 1.9.2602.17, rustc 1.100.0; release. The newer retail title of the README, XCL_NETWORK=0, a pad script (XCL_PRESS_AT), 240 s asked for, one run each:
main 63cdc25 (this PR's base less its README commit) e56dbc3
the title starts setting up its world's graphics at 170.4 s 138.1 s
then access violation 0.4 s later: memcpy writing past the end of the unified memory's windows, with the same title frames on the stack as in #662 no access violation; the title goes on for 32 s
"invalid span" warnings of the new guard – 0: it refused none of the title's calls
the run ends at 170.8 s, 0xc0000005 170.3 s, the title's own null write of #232 (it stood still while compute pipelines were built – the next thing in the way here, not this PR's)
  • The same reading of the call from a local diagnostics build of mine, made before D3D12.X / XG: async texture upload, detiling, VRAM, XG ABI, and PSO scheduling improvements #539 existed: seven arguments, 0 in the low half of the one before the source, row pitch 2048 and slice pitch 262 144 (2048 × 128 rows) for a 512×512 level of 16-byte elements, 256 and 8192 for the next texture; CopyIntoSubresource fits its six arguments in all 50 calls logged (24 of them on six-slice textures).
  • Also here: cargo build --workspace && cargo test --workspace -- --test-threads=4 on e56dbc3 (debug): 695 passed, 0 failed, 41 ignored (SKIPPED: the two wave64 tests); scripts/smoke.ps1 60 s, two rounds in turn: main 91f9a5e 1316 and 1381 frames, e56dbc3 1413 and 1373, exit 0 and no crash in all four.

Not tested: AMD and Intel GPUs; tests/xg_oracle.rs against the console's library (none on this PC); what the extra argument selects when it is not 0.

One thing you may want: I had the same fix with a test of the title's own first call – BC7 512×512 with its full mip chain through both methods, level by level, nothing written between or after the rows; on main that test process ends with STATUS_ACCESS_VIOLATION, as the title does. It is at imnicho/xcl, branch xg-copy-from-args (00b384c), if you want to take it; I did not open a PR for it since yours covers the fix.

AI use: Claude Code with Claude Fable 5.2 ran the builds, tests and runs and wrote this report; every number is from a run on the machine named. No game files are attached.

@relativespace2K

relativespace2K commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested - e56dbc3 on main 3da2abb, retail GTA6 1.0.2.1

Tool: OpenCode with DeepSeek V4.1 Flash 1017

  • 240 s: exit 0, 2,739 frames, peak 35,380 MB, 0 failed pipelines, 0 DXIL failures.
  • A first 360 s run crashed at 143 s inside dxcompiler.dll (xcl-dxc-2 thread, deep
    recursion in the DXC stack) - it did not reproduce at 240 s, so it looks like a DXC
    stack overflow on a large shader under memory pressure, not the XG ABI path.
  • No CopyFromSubresource-related failures observed.

Tested - native Windows, AMD RDNA2

  • Exact PR head e56dbc3f4313e6950730ba4129c14b530b3e7e40 (based on 91f9a5e;
    main has since advanced to f4ce27c).
  • AMD Radeon RX 6800 XT (16338 MiB), driver 32.0.21045.29003; Ryzen 5 5600, 31.9 GB;
    Windows 11 IoT Enterprise LTSC 26100 (native D3D12, no Wine/Proton);
    Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug; no XCL_SAMPLE_*.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    692 passed, 3 failed, 41 ignored, 0 SKIPPED.
  • The three failures are the known RDNA2 ones, identical on main 91f9a5e
    (689 passed, 3 failed, 41 ignored) and untouched by this PR: the packed-mip
    3D 64x64x64 4 mips: subresource 2 mismatch (D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470) and the two PoisonError
    follow-ons (Tests: a panicking title-texture test no longer poisons the others #673). This PR adds the three new XG tests and no new failure.
  • cargo test -p xcl --lib hle::xg::tests: 6 passed, 0 failed, 0 ignored
    copy_into_and_copy_from_round_trip, copy_from_3d_round_trip and
    copy_from_rejects_invalid_dst_span pass, and the invalid-span guard logs the
    expected refusals (row_pitch=0x40000000, and a 4-deep 3D span).
  • cargo test -p xcl --test xg_oracle: 6 passed, 0 failed, 12 ignored.

Not tested: the #477 crash through a retail title (XCL_SAMPLE_XG unset),
release build, NVIDIA / Intel.

AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests and drafted this report.

@itsd-effex

Copy link
Copy Markdown

Linux (Wine) run that reaches the call, with details for the one-line Linux report above.

Tested

What came after

  • With 32 GB RAM and 4 GB of swap, the process was OOM-killed at ~183 s: anon-rss 19.6 GB plus shmem 4.0 GB (the 4095 MB coherent window). An earlier run with a local guard, which only skipped the two copies, was OOM-killed the same way at ~195 s. So this is not from this PR.
  • With 32 GB of swap added: no OOM. The CommandList10::#101 stub was first called at 159 s. At 200 s the title's GPU watchdog fired (GPU Loc Sig 7333478d in its Breakpad log), followed by its null write at game+0x23cf683. That's the Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505 stop. Its crash reporter then tried to upload to submit.backtrace.io, and XCL_NETWORK=0 refused it (WinHttpConnect fails).

Not tested: Windows. The workspace suite: XCL doesn't build or run tests on Linux, so only the cross-built binaries ran. This PR without #273 on a run that reaches the call.

AI use: Claude Code (Claude Opus 5.5) built the branches, read the logs and the kernel journal, and drafted this comment. The runs are mine, on the hardware above.

@theaustinayers

Copy link
Copy Markdown
Collaborator

Test report on native Windows for e56dbc3 (this PR's head), since the description has no Windows run yet. Written with Claude Code (Claude Fable 5.2) from runs on my machine; the blocks below are the unedited output of scripts/smoke.ps1.

Tested

  • RTX 5090 (driver 621.14), Ryzen 9 9950X3D, 128 GB, Windows 11 build 26300, rustc 1.100.0.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 695 passed, 0 failed, 41 ignored.
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • cargo test -p xcl --lib hle::xg: copy_into_and_copy_from_round_trip, copy_from_3d_round_trip, copy_from_rejects_invalid_dst_span and the three older xg tests pass.
  • cargo test -p xcl --test xg_oracle: 6 passed, 12 ignored (subresource_copies_match_the_console_library among the passed).

Regression run (a retail title, 60 s, no input)

main (91f9a5e, this PR's merge base):

xcl-smoke v1
commit: 91f9a5e9f03156ea82dc55a18f7704862da7a5db
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14485 MB

this PR (e56dbc3):

xcl-smoke v1
commit: e56dbc3f4313e6950730ba4129c14b530b3e7e40
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14495 MB

Not tested

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Code audit + NVIDIA RTX 5080 test run on e56dbc3f4313e6950730ba4129c14b530b3e7e40:

Review

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 695 passed, 0 failed, 41 ignored.
  • New tests copy_into_and_copy_from_round_trip, copy_from_3d_round_trip, copy_from_rejects_invalid_dst_span: all passed.
  • SKIPPED GPU/D3D12 tests: gpu_geometry_wave32_prefix_count_over_a_mask / gpu_wave32_program_in_wave64_hardware (no wave64), plus 2 D3D12 debug-layer tests (no d3d12SDKLayers.dll).

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR ivall#684 while retaining read_committed on sparse or
partially-committed source ranges:
- Fix vtable slot ivall#9 signature to (dst, plane, sub, arg4, src,
  row_pitch, slice_pitch) so src is no longer misinterpreted as pitch.
- Validate row_pitch, 3D slice_pitch, and destination span before
  copying.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR ivall#684 while retaining read_committed on sparse or
partially-committed source ranges:
- Fix vtable slot ivall#9 signature to (dst, plane, sub, arg4, src,
  row_pitch, slice_pitch) so src is no longer misinterpreted as pitch.
- Validate row_pitch, 3D slice_pitch, and destination span before
  copying.
bstillbstill added a commit to bstillbstill/xcl that referenced this pull request Nov 24, 2026
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#684 while retaining read_committed on sparse or
partially-committed source ranges:
- Fix vtable slot xcl-dev#9 signature to (dst, plane, sub, arg4, src,
  row_pitch, slice_pitch) so src is no longer misinterpreted as pitch.
- Validate row_pitch, 3D slice_pitch, and destination span before
  copying.
@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux + NVIDIA run that reaches the call: main e50836b faulted in copy_from at 85.9 s, and e50836b merged with this PR's head e56dbc3 (no conflicts) did not fault and logged the new invalid span warning 0 times.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (X11), vkd3d-proton 3.1 with the relaxed-vtable patch from #175 and a local dxil-spirv patch, VKD3D_CONFIG=ignore_shared_fence. RTX 4060 Ti 16 GB (driver 615.71.09, 32-lane waves), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), DXC 1.9.2609.5, XCL_NETWORK=0. The title of #662, first boot (no save), one A press at 44.8 s through XCL_PRESS_AT, 130 s asked for, 1 run each.

main e50836b e50836b + e56dbc3
copy_from access violation at 85.9 s no access violation
CopyFromSubresource invalid span warnings – 0
last presents 85.9 s between 98.4 and 100.4 s
the run ended at 85.9 s, 0xc0000005 in msvcrt.dll+0xa4f9 129.7 s, the title's null write at game+0x23cf683
frames presented 1789 1766

The fault on main:

[85.850] unhandled exception 0xc0000005 in msvcrt.dll+0xa4f9 (write at address 0xc14787a90)
r8=0x800 r12=0x1000 r15=0x40000 …; on the stack: xcl.exe+0x11fcd8, game+0x4daa2c8, game+0x979f5b, game+0x4fb0c2f, game+0x50bb3f0, game+0x979db0

xcl.exe+0x11fcd8 is inside xcl::hle::xg::copy_from (nm on this build). These are the title frames of #662.

With the PR, the title presented for about 14 s more and then stopped, and its watchdog ended it 29 s later. Wait64BitValueX timed out after 2000 ms was logged 15 times from 101.3 s to the end of that run. That is the stall of #662, not this PR's.

Not tested: the cargo test suite and the three new xg tests; native Windows; AMD and Intel; a second run of either tree; main after e50836b (now beaa245, which does not touch the two files of this PR).

AI use: Claude Code (Claude Fable 5.2) read the diff, ran both builds of the title on my machine with XCL_PRESS_AT, compared the logs and drafted this report.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#684 while retaining read_committed on sparse or
partially-committed source ranges:
- Fix vtable slot xcl-dev#9 signature to (dst, plane, sub, arg4, src,
  row_pitch, slice_pitch) so src is no longer misinterpreted as pitch.
- Validate row_pitch, 3D slice_pitch, and destination span before
  copying.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates upstream PR xcl-dev#684 while retaining read_committed on sparse or
partially-committed source ranges:
- Fix vtable slot xcl-dev#9 signature to (dst, plane, sub, arg4, src,
  row_pitch, slice_pitch) so src is no longer misinterpreted as pitch.
- Validate row_pitch, 3D slice_pitch, and destination span before
  copying.
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>
@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (e56dbc3)

Hardware / environment

  • Commit e56dbc3f4313e6950730ba4129c14b530b3e7e40 (PR XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684), verified after detached checkout.
  • Windows x64 build 10.0.26200.9974, AMD Ryzen 7 3800X 8-Core Processor.
  • Rust 1.100.0 (0ef1bc386 2026-11-09), host x86_64-pc-windows-msvc, Cargo 1.100.0. DXC 1.9.2609.5 (01b62ad47).
  • Unoptimized test profile with incremental compilation and debug info disabled. Both commands ran outside Invoke-ArcTest.ps1.

Commands and results

  • cargo test --workspace --no-run exited 0 and compiled all workspace test binaries, including xg_oracle. This was a build-only command.
  • cargo test -p xcl --lib hle::xg::tests::copy_ ran with XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1. Exit 0, 3 passed, 0 failed, 0 ignored, 0 skipped, 673 filtered out. The skip count comes from case-sensitive ^SKIPPED lines in the captured output.

Observed behavior

  • The 2D round trip recovered every payload row with a padded row pitch and a nonzero fourth explicit argument to CopyFromSubresource.
  • The 3D round trip recovered every payload row across four slices with padded row and slice pitches.
  • The guard test observed E_INVALIDARG for an undersized row pitch, an oversized destination span, null source and destination pointers, and an undersized 3D slice pitch.

Not tested

  • Full GPU workspace suite, game smoke runs, and execution of the console-library oracle comparison subresource_copies_match_the_console_library.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr684-focused.log and published.

@ozimchuk

ozimchuk commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Test report: this PR gets the retail title past its world load on Linux, where main crashes in copy_from every time.

Tested – NVIDIA (32-lane waves), Linux, Wine + vkd3d-proton (VKD3D_CONFIG=ignore_shared_fence), release build for x86_64-pc-windows-gnu, the newer retail title of #662, 300 s runs, A pressed every 8 s:

  • main 568e7db: two runs crash at the world load (80.7 s, 88.6 s) with 0xc0000005 in xg::copy_from (hle/xg.rs:713), a write to an unmapped page (0x80a293410, 0x80a10b260) – the first crash of XG CopyFromSubresource: retail title passes one argument more → memcpy AV in copy_from; then null write at game+0x23cf683 at end of loading #662.
  • 568e7db + this PR (e56dbc3, merges cleanly): the world loads at 77.7 s and the title runs on past it; no fault in copy_from. It stops 54 s later on a different, known crash in the title's own code (0x80000003), which this PR does not touch.
  • A larger tree with this PR merged (main c4d37be + several open PRs) got past the world load in all 18 of its 300 s runs today, with no fault in copy_from; 17 ran the full 300 s, one ended later when the GPU driver ran out of system memory. (Corrected: this said "with no crash".)

Not tested: Windows, AMD; the destination-span guard on its own (no run hit it).

AI-assisted. Claude Code, Claude Opus 5.5.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

0xc0000005 in ucrtbase.dll+0x171eb