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.

@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 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.
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.
@b3IKK

b3IKK commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

In-title validation on an RTX 5080 16 GB (retail 1.0.2.1, Windows 11 26300, release, XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1), this PR's head e56dbc3 on top of #2404 5b9d4ff + #2519's scratch + the free_aside patch + the 1 GiB shader heap + the full compute precompile:

  • The run presented to 579.0 s and ended only in the device removal at 578.8 s (0x887a0005, 1 GiB shader heap, 21.7 GB local). No VCRUNTIME 0xc0000005, no title null write.
  • Without this fix, the same stack ended in the VCRUNTIME copy AV at 384–551 s (8–16-byte reads at 0x81ccf8000 / 0xca8a78000 / 0xc4903a000), or in the title's null write at +0x2215c35 at 301 s, or its int3 at +0x63966f at 495 s.
  • The presentation minutes were steady from minute 2 to minute 9 (28–39 frames per 2 min, the world at ~0.3 fps), then the 1 GiB code heap ended it. I am rerunning with the 2 GiB heap now.

So on this title the 7-argument ABI is the right reading; the copy AV is gone. The remaining 0x887a0005 at 579 s is the shader-code heap (#2403), not this PR.

AI use: OpenCode, Claude Fable 5.2 applied the PR, ran the 600 s title, read the logs and wrote this.

voiceovarian1-max added a commit to voiceovarian1-max/xcl that referenced this pull request Nov 27, 2026
…nation guard

Carried from upstream PR xcl-dev#684 by gsucristo (XG: fix CopyFromSubresource
7-argument ABI and guard destination span), as our Linux tree has used it
since 11-25. Not our work.

Platform: carried

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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