Skip to content

xcl run: xcl replay variants (--sub, --profile, --split, --loops) - #2435

Open
madaraXor wants to merge 7 commits into
xcl-dev:mainfrom
madaraXor:replay-variants
Open

madaraXor wants to merge 7 commits into
xcl-dev:mainfrom
madaraXor:replay-variants

Conversation

@madaraXor

@madaraXor madaraXor commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What makes a replay an experiment rather than a reproduction: change the translated HLSL, the profile or the split flag without a build, and count loop passes. With the README. Part of #675.

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

What is in it

  • replay.rs: --sub FROM=>TO||... substitutes text in the HLSL of every stage it occurs in (as XCL_DEBUG_PS_SUB does in a run; one that matches nothing is reported); --profile compiles the stage of that kind with another profile; --split 0|1; --loops (count_loops): a counter in every [loop] of the pixel shader.
  • replay/gpu.rs: the counters' buffer and image, and their report: lanes, passes and the most in a lane, the same for each of the first 16 loops, the most per pixel as an image, and eight debug words (xcl_d0..xcl_d7) a substitution may set, as their most, their OR and the lanes they are not 0 in.
  • main.rs: the help. README.md: capturing and replaying one draw.
  • Tests: the counting text; on the GPU, three passes found in every pixel of the test's capture and a substitution changing what the shader writes (with --profile ps_6_7); options.
  • Review fixes: --split takes exactly 0 or 1; --sub with nothing before => is refused; a --profile that matches no stage prints a warning. Tests in options_parse. Each loop's sum has a high word with the carry, as the overall sum has (a 4096×4096 target at 256 passes a pixel is 2^32), the buffer is read by LoopCounts::read. Test: loop_counts_read_with_their_high_words.

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 capture of a volumetric light draw that hangs the GPU: with the loop budget lowered by --sub, --loops gave 782 passes a lane on average on a local branch with the same code (783.6 with this stack) and showed which of the shader's loops ran away (the march after the light list, not the list); debug words then showed that only helper lanes were left in its mask, their state reading as 0 from the second pass on. That is the finding behind Recompiler: pixel shader loops end on primitive edges (helper lanes) #2305. With Recompiler: pixel shader loops end on primitive edges (helper lanes) #2305's two changes in the translator (local branch), the same replay with the full budget: 7.2 passes a lane, 13.8 ms of GPU time.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on edcc0b7: 1439 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, and the README).

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

Not tested

  • --loops on compute shaders (pixel shaders only; the output says so).
  • --split on a wave64 pixel program.
  • 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

@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 and a_replay_counts_loop_passes_and_substitutes: 2 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.

P2: --split parses as value == "1", so invalid values such as --split 2, yes, or typos silently become false despite usage promising 0|1. Validate exactly 0/1 and add parser tests. Also reject an empty --sub FROM: --sub "=>x" calls replace("", to) and inserts at every boundary, potentially creating huge/invalid output. --profile with no matching captured stage should likely warn. Current Windows Build/test fails, so investigate/rerun before merge.

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:

  • --split accepts exactly 0 or 1; 2, yes, an empty value or 01 are usage errors.
  • --sub with nothing before => (e.g. =>x, also inside a=>b||=>x) is an error. Replacing with nothing (a=>) is still allowed.
  • --profile that matches no stage of the capture now prints a REPLAY WARNING naming the capture's stages.
  • Tests in options_parse.

@madaraXor

Copy link
Copy Markdown
Contributor Author

About the red Build and test on this push: no test failed. The --lib test process ended with 0xc0000005 partway through the run, in tests this PR does not touch, after replay::tests::a_capture_with_a_gs_is_refused had passed.

Here, with XCL_ADAPTER=warp (no GPU, like the CI), cargo test -p xcl --lib -- replay capture --test-threads=4 passes twice in a row: 17 passed, and the two GPU replay tests print SKIPPED … no GPU. The whole suite on a GPU is in the description.

Could someone with rights re-run the failed job? Pushing an unchanged commit again would not start a new run.

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

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

replay.rs:218–223 gives the overall loop-pass sum a high word on 32-bit wrap, but each per-loop sum is one uint (InterlockedAdd at 16 + 8*k). replay/gpu.rs:629–633 then prints that wrapped word as #k: ... passes. A 4096×4096 fullscreen replay with 256 passes per pixel in one loop has exactly 2^32 passes: the overall line reports 4,294,967,296 while #0 reports 0 passes, most 256. This is within the stated 65,536-per-lane loop budget and can make the per-loop diagnosis misleading on high-coverage captures.

Could per-loop totals use the same split-word carry as the overall sum, with the decoder and buffer offsets updated, and a synthetic decode test for low=0/high=1? This is exact-head source/arithmetic review at 9e602989cec27ede32dca6d5a0794568ecc9c947; I have not run a 4K GPU replay. AI-assisted review with Codex.

madaraXor and others added 6 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>
What makes a replay an experiment rather than a reproduction:
- --sub FROM=>TO||... substitutes text in the translated HLSL of every
  stage it occurs in, as XCL_DEBUG_PS_SUB does in a run; a substitution
  that matches nothing is reported;
- --profile compiles the stage of that kind with another profile
  (ps_6_7), --split forces the wave64 split flag;
- --loops counts the passes of every [loop] of the pixel shader per lane:
  lanes, passes and the most in a lane, the same for each of the first 16
  loops, and the most per pixel as an image. Eight debug words (xcl_d0..7)
  a substitution may set come back as their most, their OR and the lanes
  they are not 0 in – a register's value out of a shader without a build.

README: capturing and replaying one draw.

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

Copy link
Copy Markdown
Contributor Author

Thanks, fixed (force-pushed): each loop's sum now carries into a high word, as the overall sum does.

  • Layout: 3 words per loop (low, high, most) from word 4; the debug words move to word 52; the buffer is 128 words (LOOP_WORDS).
  • The read-back is a pure LoopCounts::read. Test: loop_counts_read_with_their_high_words, with low 0 / high 1 = 2^32 for both the overall and a loop's sum, and loops or debug words that never ran left out.
  • loops_are_counted_before_the_return checks the new offsets and that the last debug counter lies inside the buffer.
  • The GPU test a_replay_counts_loop_passes_and_substitutes passes on the RX 6700 XT.

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.

6 participants