Skip to content

D3D12.X: a capture copies the textures its call reads - #2431

Open
madaraXor wants to merge 3 commits into
xcl-dev:mainfrom
madaraXor:capture-textures
Open

madaraXor wants to merge 3 commits into
xcl-dev:mainfrom
madaraXor:capture-textures

Conversation

@madaraXor

@madaraXor madaraXor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The textures of a captured call get their contents: each is copied on the GPU where the call stands and read back after the submit. Part of #675.

A copy recorded on the title's list sees the uploads of title memory that submit makes and what earlier commands of the list wrote; a read at record time or after the submit would not.

Stacked on #2430; only the top commit belongs here.

What is in it

  • hle/d3d12x/capture/textures.rs: copy_all records a CopyResource of each texture into a texture of XCL's own on the list at the call; read_back copies them to read-back buffers on a queue of XCL's own once the title's queue is past the list, and writes tex_<id>.bin (all subresources and planes in the layout of GetCopyableFootprints).
  • capture.rs, real.rs: the two calls.
  • XCL does not track resource states. The state a texture is copied from is its last transition on the list, else its use as a target, else its last transition on any list, else a shader-resource state; the manifest names which for each texture.
  • Test: the subresource and plane count of a copy (mips x slices, a 3D texture, a depth-stencil format).
  • Review fixes: a texture whose subresources are not in one known state (D3D12.X: XCL_CAPTURE_DRAW writes one draw or dispatch to disk #2430's partial:) is not copied and goes into left_out, so no ALL_SUBRESOURCES transition is made from a state some subresource is not in (copyable). Test: a_texture_in_no_one_state_is_not_copied.

Tested

  • AMD Radeon RX 6700 XT 12 GB (RDNA2), driver 32.0.21045; Ryzen 5 5600X, 16 GB; Windows 10 22H2 (19045); rustc 1.90.0; release
  • A retail title, top of the stack (on the head before the review fixes): a DrawIndexed captured in the menus with 4 textures (2 read through SRVs); replayed, its target went from the captured contents (zeros, before the draw) to the fill the draw makes.
  • Earlier, from a local branch with the same code: 156 textures of a volumetric light pass captured with nothing left out, among them the 3D R32_UINT mask the pass reads, sparse as expected (99.9 % zero words).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 5f8eb9c: 1430 passed, 6 failed, 46 ignored. The failures: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 540), hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory (Tests: align XMemVirtualQuery buffers and verify CPU flags #650) and the e2e tests test_title_runs_and_game_folder_is_untouched, test_title_draws_with_a_root_signature_under_the_debug_layer and test_title_runs_under_the_debug_layer_with_dred, which fail on main e1d84b7 on this machine too (its whole suite: 1416 passed, 7 failed, 46 ignored); hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory failed in this whole-suite run; it fails in the whole-suite run of main e1d84b7 on this machine too. SKIPPED: the six per-lane cases of f16_programs_on_the_gpu / f32_programs_on_the_gpu (refused), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run

scripts/smoke.ps1, 60 s, release builds, the same title on the same day.

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 788 (PresentX 788)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15646 MB

PR:

xcl-smoke v1
commit: 5f8eb9cd7a5702fc5bc9a5c0cdf0339b2a06980e
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 938 (PresentX 938)
presents per 2 s (last 3): 52 55 60
device removals: 0
crashes: 0
peak commit: 17459 MB

Not tested

  • Multisampled textures (left out, listed in the manifest).
  • A texture whose state is none of the four guesses: the copy's barrier is then wrong. Not seen; the debug layer was not on in a title run.
  • Captures over XCL_CAPTURE_MAX_MB.
  • NVIDIA, Intel, RDNA3 / RDNA4; Windows 11.

AI use

  • Claude Code. Claude Fable 5.2 wrote the code, the tests and this description, and ran the tests listed above. Claude Opus 5.5 coordinated the work and ran the game checks. Claude Opus 5.5 wrote the review fixes of the last push and their tests, and ran the suites and smoke runs of this description.

🤖 Generated with Claude Code

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 20059ab65622734ccf48be4edc99aa8633caca29 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1271 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All 8 hle::d3d12x::capture tests (including capture::textures::tests::a_copy_holds_every_subresource_and_plane) passed.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release; default capture off)

xcl-smoke v1
commit: 20059ab65622734ccf48be4edc99aa8633caca29
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1579)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14937 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • Live XCL_CAPTURE_DRAW capture on the retail title; D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@SlopTart

SlopTart commented Nov 25, 2026 •

Copy link
Copy Markdown

gpu_ suite (cold cache): 160 passed / 4 failed, no crashes. Three are the known baseline trio on this lane; the fourth is gpu_promoted_uav_clear_values_pass_create_committed_resource, newly red on main since #2280 (report), unrelated to this PR.
Targeted run of the capture tests: 8 passed.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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

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

Blocked by the P1 per-subresource state flaw introduced in #2430. state_of records one state per resource, then textures::snapshot transitions ALL_SUBRESOURCES through COPY_SOURCE and back using that one StateBefore. A valid partial mip/slice transition can thus make capture declare wrong states for every other subresource, causing debug-layer errors/undefined GPU state when enabled. Track per-subresource states or skip textures with unknown partial state; add a partial-state capture test. Other copy lifetime/queue ordering looked sound, but this stacked PR also lacks a clean suite/current broad validation.

A GPU hang in a retail title costs a whole game run per experiment. The
plan is to write one draw or dispatch of a named shader to disk during a
run and to run it again alone, in seconds (this stack: the format, the
hook, the textures, xcl replay).

This is the format only: capture::manifest, the manifest.json of a capture
folder (the call, shader files, the PC pipeline description, root
arguments, fixed-function state, targets, memory ranges, textures, views,
samplers, descriptor slots, what was left out) with Manifest::write and
Manifest::read. Structures D3D12 gives as plain data are kept as hex of
their bytes. Nothing writes a capture yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@madaraXor

Copy link
Copy Markdown
Contributor Author

Thanks, fixed, with #2430's per-subresource tracking.

  • copy_all no longer copies a texture whose subresources are not in one known state (copyable). It goes into left_out with the reason, so snapshot never issues an ALL_SUBRESOURCES transition from a state some subresource is not in.
  • Textures in one known state, or with no transition seen (assumed shader-resource, as before), are still copied.
  • Test: a_texture_in_no_one_state_is_not_copied.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for c01c55b (this branch contains #2430's head f6354cd): RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.

cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 (the hle::xaudio2 tests hang on this machine, on main too):

  • this PR c01c55b: 1301 passed, 0 failed, 26 ignored.
  • main at 08db802: 1295 passed, 0 failed, 27 ignored.
  • The same 25 SKIPPED lines on both sides (no wave64 etc.).

Lib tests only; no title run.

AI-assisted (Claude Code, Claude Opus 5.5).

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

madaraXor and others added 2 commits November 26, 2026 10:43
XCL_CAPTURE_DRAW=<container fnv64, hex>[:N] writes the Nth draw or dispatch
whose VS, PS or CS is that console shader to <data>/captures: the shader
containers, the PC pipeline description, the root arguments and the io
words bind_abi made, the list's fixed-function state, targets, PC vertex
and index buffer views, the non-zero slots of each descriptor table, the
samplers made so far, and the unified memory the tables, root buffers and
V# name. Textures are listed with their descriptions and the PC views made
of them; their contents follow in the next change.

The call is taken in bind_abi, where the io words and the argument table
exist. Memory is read at the submit of the call's list, not when the call
is recorded: titles fill buffers in between. The matching calls are not
run unless XCL_CAPTURE_RUN=1: the switch is for calls that hang the GPU.

To find the hash to give: with the variable set (XCL_CAPTURE_DRAW=list for
that alone) every pipeline made from translated console shaders is logged
with its shaders' hashes, the first 200, where dred::label names it – the
one place all five pipeline kinds pass. Draws of VS + PS pipelines and
dispatches of single compute pipelines are captured; geometry, mesh and
split compute pipelines are listed only.

To name what a slot's T# means on the PC, the SRV / UAV made at each heap
index, the RTV / DSV at each handle, samplers and the last transition of a
resource are noted while a shader is chosen. A view counts only if its
resource was not released since. Without the variable every hook returns
at capture::on().

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The textures of a captured call (table slots by their SRV / UAV, render
targets, depth) get their contents: capture::textures records a
CopyResource of each into a texture of XCL's own on the title's list where
the call stands, and reads the copies back on a queue of its own once the
title's queue is past the list. On the list, the copy sees the uploads of
title memory that submit makes and what earlier commands of the list wrote,
which a read at record time or after the submit would not.

XCL does not track resource states. The state a texture is copied from is
its last transition on the list, else its use as a target, else its last
transition on any list, else a shader-resource state; the manifest names
which for each texture. Multisampled textures and what is over
XCL_CAPTURE_MAX_MB are left out and listed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA re-run for 5f8eb9c (on main e1d84b7; this branch contains #2430): RTX 3070 8 GB (Ampere, driver 616.56), Windows 11, debug. Earlier I ran c01c55b (1301 passed).
cargo test -p xcl --lib capture -- --test-threads=4, 3 runs: 13 passed, 0 failed, 0 skipped each, including the new a_call_that_never_reaches_the_capture_does_not_stand_for_the_next.
Whole lib (--skip hle::xaudio2 --test-threads=4): 1302 passed, 0 failed, 26 ignored. SKIPPED: 21 no wave64, 3 per-lane forms the translator refuses, 1 needs Developer Mode.
Lib tests only; no title run.
AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@a-DuckGod

Copy link
Copy Markdown

Independent Windows 11 / NVIDIA test report on exact PR head 5f8eb9cd7a5702fc5bc9a5c0cdf0339b2a06980e (clean detached checkout; merge-base e1d84b7d; stacked on #2430).

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 Ti (12 GB, wave32, mesh shaders), driver 32.0.16.2114; Intel Core i7-8700K, 32 GB RAM; Windows 11 Pro (Version Dev 29708.1003); rustc 1.100.0 (0ef1bc386 2026-11-09) (x86_64-pc-windows-msvc), Windows SDK DXC 1.8.2502.11, D3D12 debug layer installed, debug build.
  • cargo build --workspace: succeeded.
  • cargo test -p xcl --lib hle::d3d12x::capture -- --nocapture: 13 passed, 0 failed, 0 ignored, 0 skipped — including a_texture_in_no_one_state_is_not_copied and GPU test a_copy_holds_every_subresource_and_plane.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1436 passed, 0 failed, 46 ignored (including all e2e tests under the D3D12 debug layer and DRED).
  • SKIPPED GPU tests (26): 21 no wave64 (RTX 3080 Ti is 32-lane waves only), 3 per-lane gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 refused forms (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache; Windows Developer Mode required), 1 heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Not tested

  • Release build, retail title / scripts/smoke.ps1 run, XCL_SAMPLE_* tests, live XCL_CAPTURE_DRAW capture/replay on a game, AMD / Intel / native wave64 GPUs.

AI use

  • Antigravity (Gemini 4 Neon) checked out the PR, read commit 5f8eb9cd, ran the build and tests, and drafted this report. I checked it before posting.

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