Skip to content

xcl run: xcl replay runs one captured call alone - #2434

Open
madaraXor wants to merge 6 commits into
xcl-dev:mainfrom
madaraXor:replay-run
Open

madaraXor wants to merge 6 commits into
xcl-dev:mainfrom
madaraXor:replay-run

Conversation

@madaraXor

@madaraXor madaraXor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

xcl replay now runs the captured draw or dispatch alone on a device of its own and reads back what it wrote: the GPU time, and each target, the depth buffer and each UAV texture as raw texels and a PNG. Part of #675.

The GPU part runs in a child process with a timeout: a call that hangs the GPU ends as timed out or device removed after N ms in the child, not in the caller.

Over 400 lines: replay/gpu.rs is one function's worth of device state (windows, textures, views, targets, the call, the read-back). A part of it cannot draw, and so cannot be tested.

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

What is in it

  • replay/gpu.rs: the device (the adapter the runtime would take, through the Agility SDK when there is one); the pipeline from the captured description; memory windows as buffers that hold the captured ranges at their offsets (a reserved buffer with only the touched tiles when a range lies far in); io to u0 as captured; textures in the state the call uses them in; views at the heap indices the T# name, null views where the capture has none; samplers; the call between two timestamp queries; read-backs with a hash and each channel's range.
  • replay.rs: the child process and the timeout, --timeout, --repeat, --debug (the D3D12 debug layer, its messages printed), --no-run.
  • main.rs: the help.
  • Test (skips without a GPU, or when the process cannot make XCL's root signature): a capture built in the test replays (a committed and a reserved window, textures with and without contents, a target the capture lacks, a 3D UAV texture, a slot without a view), and every checked pixel of the target is what the PS makes of its SGPR, of a word in memory and of its loop.
  • Review fixes: --timeout takes a finite number of seconds over 0 (no panic on -1, NaN, inf), --repeat 1 or more; unhex's errors are passed on. Tests in options_parse.

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's captures, top of the stack: a DrawIndexed of 30 with 4 textures replayed to done, its target going from zeros to a uniform fill, 3 image slots without a view (null views); a Draw of 3 that reads no texture replayed to done.
  • A capture of a draw that hangs the GPU in the title (a volumetric light pass, 72 x 6003), on a local branch with the same replay code: the replay ended as device removed after 4852 ms in the child (the caller went on), and with the loop budget lowered by a substitution it finished in about 100 ms. That replay led to Recompiler: pixel shader loops end on primitive edges (helper lanes) #2305. This stack's binary replays the same capture the same way (with the budget lowered: 783.6 loop passes a lane on average).
  • The debug layer on the replay of a capture made by hand, on a local branch with the same code: 0 messages.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on dca8ceb: 1436 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

  • The runtime is not changed (the command's own code).

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: dca8cebc27c13ccd5f0a2d695291c94b8341abae
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 935 (PresentX 936)
presents per 2 s (last 3): 60 59 60
device removals: 0
crashes: 0
peak commit: 17000 MB

Not tested

  • Compute captures on the GPU (the code is there; no dispatch was captured).
  • Only mip 0 / slice 0 of an output is read back; multisampled outputs are not.
  • The direct DXIL translator in the replay; memory windows through the descriptor heap (XCL_HEAP_WINDOWS): the replay always uses root UAVs.
  • NVIDIA, Intel, RDNA3 / RDNA4, WARP; 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

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@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 a_capture_made_here_replays: passed.

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

P2 CLI bug: --timeout passes parsed f64 directly to Duration::from_secs_f64, so -1, NaN, or inf panic rather than yielding usage error. Require finite positive values and add parser tests. --repeat 0 is silently converted to one run by max(1), so reject or document it. This also depends on #2430/#2432 capture state tracking, which cannot faithfully reconstruct partial mip/array transitions until that P1 is fixed. Current Windows CI fails and compute replay remains untested.

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 in the force-pushed commit:

@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 5 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>
gpu::texel_image: the texels of the common DXGI formats (8 / 16 / 32-bit
UNORM, UINT and float, 10:10:10:2, 11:11:10 float, the depth planes) as
numbers, an RGB image of a read-back – UNORM as it is, float and integer
formats scaled by their largest finite value and square-rooted, the slices
of a 3D texture side by side – with each channel's least and largest value,
and that image as a PNG (miniz_oxide, which the crate has; no new
dependency). For xcl replay, which shows what a captured draw wrote.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
xcl replay <capture folder> reads a capture written by XCL_CAPTURE_DRAW,
translates its console shaders with this build's translator – the memory
windows and the split flag the run used are in the manifest – compiles them
and writes the HLSL to <capture>/replay_<name>. The call itself is run by
the next change; this part needs no GPU, and shows what a translator change
does to a captured shader.

The test builds its capture here: a VS and a PS of our own in console
containers (xbox::tests), no title's data.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
After translating a capture's shaders, xcl replay now makes a device of
its own (the adapter the runtime would take, through the Agility SDK when
there is one), the capture's memory windows, textures, views, samplers and
targets, runs the draw or dispatch once and reads back what it wrote: the
GPU time from timestamp queries, and each target, the depth buffer and
each UAV texture as raw texels and a PNG in <capture>/replay_<name>, with
a hash and each channel's range.

Addresses are the capture run's, so nothing in the shaders or the data is
relocated: a memory window is a buffer that holds the captured ranges at
their offsets (a reserved buffer with only the tiles they touch when a
range lies far in), the io words go to u0 as they were, and views sit at
the heap indices the T# name.

The GPU part runs in a child process, and the call gets --timeout seconds
(15): a call that hangs the GPU ends as 'timed out' or 'device removed
after N ms' in the child, not in the caller. --no-run stops after the
shaders, --debug adds the D3D12 debug layer and prints its messages.

The test replays a capture built here (our own VS and PS, a committed and
a reserved window, textures with and without contents, a target the
capture lacks, a 3D UAV texture, a slot without a view) and checks every
pixel of the target against what the PS makes of its SGPR, of a word in
memory and of its loop. It skips without a GPU.

replay/gpu.rs is one function's worth of device state and is not split: a
part of it cannot draw, and so cannot be tested.

Co-Authored-By: Claude Fable 5.2 <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.

5 participants