Skip to content

D3D12.X: texture read-backs as PNG images - #2432

Open
madaraXor wants to merge 4 commits into
xcl-dev:mainfrom
madaraXor:replay-images
Open

madaraXor wants to merge 4 commits into
xcl-dev:mainfrom
madaraXor:replay-images

Conversation

@madaraXor

Copy link
Copy Markdown
Contributor

Texture read-backs as pictures, for xcl replay (next PRs), which shows what a captured draw wrote. Part of #675.

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

What is in it

  • gpu/texel_image.rs: the texels of the common DXGI formats as numbers (8 / 16 / 32-bit UNORM, UINT and float, 10:10:10:2, 11:11:10 float, the depth planes); 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; that image as a PNG (miniz_oxide, already a dependency).
  • Tests: the CRC against the PNG check value, a PNG's chunks and inflated rows, scaling and 3D tiling, BGRA order, an unknown format.

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
  • cargo test --release -p xcl --lib -- texel_image::: 3 passed, 0 failed
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on c84af06: 1263 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 and test_title_draws_with_a_root_signature_under_the_debug_layer, which fail on main on this machine too; hle::d3d12x::list_x::tests::a_reset_while_the_last_submit_runs_records_on_another_pc_list and hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory failed in this whole-suite run and passed alone (3 of 3 runs); they fail the same way in some whole-suite runs of the first branch of the stack, which runs no new code, and the second one on a main run on this machine. 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

  • No runtime code runs differently: the new module is not called yet.

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

main:

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

PR:

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

Not tested

  • Block-compressed formats (a format without a reader gets no PNG; the caller still writes the raw file).
  • The PNGs in viewers other than the ones on this machine.

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.

🤖 Generated with Claude Code

madaraXor and others added 4 commits November 25, 2026 16:32
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant