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

Open
madaraXor wants to merge 4 commits from upstream-pr/2432 into main
madaraXor commented 2026-11-25 18:38:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by madaraXor on 2026-11-25T18:38:07Z.


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.
  • Rebased on current main; the per-subresource state fix of the review lives in #2430 / #2431.

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 --workspace --no-fail-fast -- --test-threads=4 on 47447e4: 1434 passed, 5 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 (#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). 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: 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: 47447e49b5c5e344b90f19e9c632bd152e77e90a
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 921 (PresentX 921)
presents per 2 s (last 3): 49 60 60
device removals: 0
crashes: 0
peak commit: 17575 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. 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

<!-- greyfinch-sync:ivall/xcl:issue:5497043160 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432). Originally posted by [madaraXor](https://github.com/madaraXor) on 2026-11-25T18:38:07Z. --- 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. - Rebased on current `main`; the per-subresource state fix of the review lives in #2430 / #2431. **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 --workspace --no-fail-fast -- --test-threads=4` on `47447e4`: 1434 passed, 5 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` (#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). 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: 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: 47447e49b5c5e344b90f19e9c632bd152e77e90a gpu: AMD Radeon RX 6700 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 921 (PresentX 921) presents per 2 s (last 3): 49 60 60 device removals: 0 crashes: 0 peak commit: 17575 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. 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](https://claude.com/claude-code)
SlopTart commented 2026-11-25 20:08:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T19:46:20Z.


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 new read-back tests (manifest, CRC32-vs-PNG, float/int scaling and 3D slice tiling): 3 passed.

<!-- greyfinch-sync:ivall/xcl:comment:7172745135 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#issuecomment-7172745135). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-25T19:46:20Z. --- `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](https://github.com/xcl-dev/xcl/pull/2280#issuecomment-7172066690)), unrelated to this PR. Targeted run of the new read-back tests (manifest, CRC32-vs-PNG, float/int scaling and 3D slice tiling): 3 passed.
DavidM1911 commented 2026-11-25 20:08:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T20:04:34Z.


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

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7173155918 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#issuecomment-7173155918). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T20:04:34Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
bmjask commented 2026-11-25 20:28:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:28:31Z.

Review: COMMENTED


P1: capture state tracking is per resource, but normal barriers are per subresource. capture.rs:247-261 drops the subresource, and list_x.rs:4040-4048 passes b[6] while discarding b[4]. The snapshot helper later emits ALL_SUBRESOURCES with one recorded StateBefore (list_x.rs:111-124). After a valid transition of only one mip/slice, capture can therefore issue an invalid all-subresource transition for other slices, causing debug-layer errors or incorrect GPU state when capture is enabled. Track state per subresource, or decline capture after a partial transition unless complete states are known.

<!-- greyfinch-sync:ivall/xcl:review:6064502398 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#pullrequestreview-6064502398). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:28:31Z. **Review:** COMMENTED --- P1: capture state tracking is per resource, but normal barriers are per subresource. capture.rs:247-261 drops the subresource, and list_x.rs:4040-4048 passes b[6] while discarding b[4]. The snapshot helper later emits ALL_SUBRESOURCES with one recorded StateBefore (list_x.rs:111-124). After a valid transition of only one mip/slice, capture can therefore issue an invalid all-subresource transition for other slices, causing debug-layer errors or incorrect GPU state when capture is enabled. Track state per subresource, or decline capture after a partial transition unless complete states are known.
madaraXor commented 2026-11-26 00:05:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by madaraXor on 2026-11-25T23:43:49Z.


Thanks. The per-subresource state point is fixed where it lives:

  • #2430 now tracks state per subresource;
  • #2431 leaves out, and does not transition, a texture whose subresources are not in one known state.

This PR only reads back what #2431 copied, so it gets that behaviour unchanged. The stack is rebased on current main (with #2420), and the description has the new suite counts and smoke blocks.

<!-- greyfinch-sync:ivall/xcl:comment:7177968313 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#issuecomment-7177968313). Originally posted by [madaraXor](https://github.com/madaraXor) on 2026-11-25T23:43:49Z. --- Thanks. The per-subresource state point is fixed where it lives: - #2430 now tracks state per subresource; - #2431 leaves out, and does not transition, a texture whose subresources are not in one known state. This PR only reads back what #2431 copied, so it gets that behaviour unchanged. The stack is rebased on current `main` (with #2420), and the description has the new suite counts and smoke blocks.
DavidM1911 commented 2026-11-26 03:06:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T02:12:29Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7180568087 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#issuecomment-7180568087). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T02:12:29Z. --- 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
Foniass commented 2026-12-01 08:03:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:03:34Z.


Triage (#1607) – head 47447e4

This PR is stacked on #2431; only the top commit (gpu/texel_image.rs) belongs here. It overlaps with #2433-#2435 only because they are the same stack.
Main already has a small PNG writer with its own CRC32 (png_square in hle/xgameruntime/api.rs, plus a test-only one in recomp/tests.rs). This PR adds a third copy; sharing one encoder would avoid that. No correctness problems found.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7304820047 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2432#issuecomment-7304820047). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:03:34Z. --- **Triage (#1607)** – head 47447e4 This PR is stacked on #2431; only the top commit (`gpu/texel_image.rs`) belongs here. It overlaps with #2433-#2435 only because they are the same stack. Main already has a small PNG writer with its own CRC32 (`png_square` in `hle/xgameruntime/api.rs`, plus a test-only one in `recomp/tests.rs`). This PR adds a third copy; sharing one encoder would avoid that. No correctness problems found. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2432:upstream-pr/2432'
git switch 'upstream-pr/2432'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2432'
git switch 'upstream-pr/2432'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2432'
git switch 'upstream-pr/2432'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2432'
git switch 'main'
git merge --squash 'upstream-pr/2432'
git switch 'main'
git merge --ff-only 'upstream-pr/2432'
git switch 'main'
git merge 'upstream-pr/2432'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2422
No description provided.