D3D12.X: add gpu::texture::download and title_textures read-back helpers #3675

Open
iggyvilla wants to merge 1 commit from upstream-pr/3675 into amd-dev
iggyvilla commented 2026-12-02 06:33:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-12-02T06:33:51Z.


Preparation for fault-driven texture copy-back (#2663, split out of #3601 per review so each PR stays under ~400 lines): adds gpu::texture::download and title_textures read-back/re-tile helpers with unit and GPU round-trip tests. Not yet called at runtime (zero behavior change).

TL;DR — Before vs After

Metric Before (origin/amd-dev 41aa60ce) After (effdc0a8)
Runtime behavior Baseline Unchanged (prep helpers only; tested directly by unit & GPU tests)
Diff size — +384 / -1 across 2 files (245 runtime + 139 test lines)
60 s smoke frames / peak commit 1,654 / 15,902 MB (0 crashes) 1,639 / 16,271 MB (0 crashes)

What is in it

  • crates/xcl/src/gpu/texture.rs: adds download() to copy every subresource of a single-plane, single-sample 1D/2D/3D texture to linear rows via a readback buffer (refuses multi-plane and MSAA textures cleanly; retains submitted objects if fence wait fails).
  • crates/xcl/src/hle/d3d12x/title_textures.rs: adds write_subresources, write_writable (writes only changed, committed, writable 4 KiB pages), read_back, download_and_write_after, read_back_after, copy_back_range, and exposes subresource_count, plus 3 unit/GPU tests (written_subresources_skip_a_page_the_title_unmapped, written_subresources_round_trip, read_back_writes_what_the_gpu_holds_into_the_title_memory).

Tested

  • Hardware: AMD Radeon RX 6650 XT 8 GB (RDNA2, driver 32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11 x64, rustc 1.100.0 (0ef1bc386 2026-11-09), debug tests + release smoke.
  • cargo test -p xcl --lib -- written_subresources read_back_writes_what_the_gpu_holds --test-threads=1: 3 passed, 0 failed, 0 ignored, 0 skipped.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 2,958 passed, 16 failed, 49 ignored. All 16 failures reproduce identically on clean origin/amd-dev 41aa60ce (2,954 passed, 17 failed, 49 ignored). SKIPPED (7): 4× f16_programs_on_the_gpu, 2× heap-window tests, 1× pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off).

Regression run
Base (main, required by pr_check.py):

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15479 MB

Base (origin/amd-dev merge base):

xcl-smoke v1
commit: 41aa60ce842060a597b7e8724896f7bf6a031af5
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15902 MB

PR head (effdc0a8):

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

Not tested

  • NVIDIA and Intel GPUs, and Wine.

AI use

  • Antigravity (Gemini 4 Neon High) split these preparation helpers out of #3601, ran the unit/GPU tests, workspace suite, and 60 s smoke, and wrote this description.
<!-- greyfinch-sync:ivall/xcl:issue:5601208194 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3675). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-12-02T06:33:51Z. --- Preparation for fault-driven texture copy-back (#2663, split out of #3601 per review so each PR stays under ~400 lines): adds `gpu::texture::download` and `title_textures` read-back/re-tile helpers with unit and GPU round-trip tests. Not yet called at runtime (zero behavior change). ### TL;DR — Before vs After | Metric | Before (`origin/amd-dev` `41aa60ce`) | After (`effdc0a8`) | |---|---|---| | **Runtime behavior** | Baseline | Unchanged (prep helpers only; tested directly by unit & GPU tests) | | **Diff size** | — | `+384 / -1` across 2 files (245 runtime + 139 test lines) | | **60 s smoke frames / peak commit** | `1,654` / `15,902 MB` (`0` crashes) | `1,639` / `16,271 MB` (`0` crashes) | **What is in it** - `crates/xcl/src/gpu/texture.rs`: adds `download()` to copy every subresource of a single-plane, single-sample 1D/2D/3D texture to linear rows via a readback buffer (refuses multi-plane and MSAA textures cleanly; retains submitted objects if fence wait fails). - `crates/xcl/src/hle/d3d12x/title_textures.rs`: adds `write_subresources`, `write_writable` (writes only changed, committed, writable 4 KiB pages), `read_back`, `download_and_write_after`, `read_back_after`, `copy_back_range`, and exposes `subresource_count`, plus 3 unit/GPU tests (`written_subresources_skip_a_page_the_title_unmapped`, `written_subresources_round_trip`, `read_back_writes_what_the_gpu_holds_into_the_title_memory`). **Tested** - Hardware: AMD Radeon RX 6650 XT 8 GB (RDNA2, driver `32.0.21045.29003`), AMD Ryzen 7 5700X, Windows 11 x64, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, debug tests + release smoke. - `cargo test -p xcl --lib -- written_subresources read_back_writes_what_the_gpu_holds --test-threads=1`: **3 passed, 0 failed, 0 ignored, 0 skipped**. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: **2,958 passed, 16 failed, 49 ignored**. All 16 failures reproduce identically on clean `origin/amd-dev` `41aa60ce` (`2,954 passed, 17 failed, 49 ignored`). `SKIPPED` (7): 4× `f16_programs_on_the_gpu`, 2× heap-window tests, 1× `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off). **Regression run** Base (`main`, required by `pr_check.py`): ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 15479 MB ``` Base (`origin/amd-dev` merge base): ``` xcl-smoke v1 commit: 41aa60ce842060a597b7e8724896f7bf6a031af5 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15902 MB ``` PR head (`effdc0a8`): ``` xcl-smoke v1 commit: effdc0a8764d8e15d47f00ff228f8d82304d2d34 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1639 (PresentX 1639) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16271 MB ``` **Not tested** - NVIDIA and Intel GPUs, and Wine. **AI use** - Antigravity (Gemini 4 Neon High) split these preparation helpers out of #3601, ran the unit/GPU tests, workspace suite, and 60 s smoke, and wrote this description.
Foniass commented 2026-12-02 06:38:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T06:38:36Z.


Review (head effdc0a8, diff read, not a merge-check):

  • Overlaps the copy-back helpers already on amd-dev. The base already reads textures back (TextureDownloadPlan / PendingDownload, title_textures.rs ~4590), reverse-tiles them (reverse_layout_subresource, ~4390) and writes changed pages (changed_page_runs / write_changed_pages, ~4940 / ~4966). The page-run loop in write_subresources (~4237) and write_writable (~4259) do the same jobs but behave differently on a page they cannot write, so there would be two reverse paths to keep in step. Reusing the existing helpers, or saying in the description why they cannot be, would help (this part of my split suggestion on #3601 did not account for them).
  • A partial write is reported as success. write_writable (~4276) skips changed pages that are read-only, guard or uncommitted, and write_subresources still returns Ok(bytes), so the caller cannot tell "nothing changed" from "every changed page was protected" and the title memory can hold part GPU texels and part stale bytes. The base's write_changed_pages refuses instead, so its publish is retried; the new GPU test asserts the skip-and-succeed behaviour.
  • More than part (1), and partly untested. download_and_write_after (~4309), read_back_after (~4334, with a 200 ms try_lock spin) and copy_back_range (~4354) are #3601's fault-handler entry points, with no caller and no test here. download_and_write_after also queues native_queue_wait for a title fence on the shared per-device upload queue (~4323), so every upload sent after it waits for the title's signal; that choice belongs with its caller.

Fine: nothing calls the new code yet; download gets footprints for all subresources in D3D12 order, copies the unpadded rows with depth slices NumRows × RowPitch apart, moves the texture to COPY_SOURCE and back from one state or one per subresource, keeps its objects alive when the fence wait fails, and refuses planar and MSAA textures; the description says it is split out of #3601.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7337243400 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3675#issuecomment-7337243400). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T06:38:36Z. --- Review (head effdc0a8, diff read, not a merge-check): - **Overlaps the copy-back helpers already on `amd-dev`.** The base already reads textures back (`TextureDownloadPlan` / `PendingDownload`, `title_textures.rs` ~4590), reverse-tiles them (`reverse_layout_subresource`, ~4390) and writes changed pages (`changed_page_runs` / `write_changed_pages`, ~4940 / ~4966). The page-run loop in `write_subresources` (~4237) and `write_writable` (~4259) do the same jobs but behave differently on a page they cannot write, so there would be two reverse paths to keep in step. Reusing the existing helpers, or saying in the description why they cannot be, would help (this part of my split suggestion on #3601 did not account for them). - **A partial write is reported as success.** `write_writable` (~4276) skips changed pages that are read-only, guard or uncommitted, and `write_subresources` still returns `Ok(bytes)`, so the caller cannot tell "nothing changed" from "every changed page was protected" and the title memory can hold part GPU texels and part stale bytes. The base's `write_changed_pages` refuses instead, so its publish is retried; the new GPU test asserts the skip-and-succeed behaviour. - **More than part (1), and partly untested.** `download_and_write_after` (~4309), `read_back_after` (~4334, with a 200 ms `try_lock` spin) and `copy_back_range` (~4354) are #3601's fault-handler entry points, with no caller and no test here. `download_and_write_after` also queues `native_queue_wait` for a title fence on the shared per-device upload queue (~4323), so every upload sent after it waits for the title's signal; that choice belongs with its caller. Fine: nothing calls the new code yet; `download` gets footprints for all subresources in D3D12 order, copies the unpadded rows with depth slices `NumRows × RowPitch` apart, moves the texture to `COPY_SOURCE` and back from one state or one per subresource, keeps its objects alive when the fence wait fails, and refuses planar and MSAA textures; the description says it is split out of #3601. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 12:47:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T12:47:21Z.


merge-check
base: 41aa60ce84
head: effdc0a876
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60ce alone on this card, so none is from this PR)
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3675#issuecomment-7337243400 and its findings stand. Most serious: it duplicates read-back helpers already on amd-dev, and write_writable (~4259) skips protected pages while write_subresources still returns Ok, so a partial write looks like success.
performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (effdc0a8): 1671 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16481 MB, 0 device removals, 0 crashes.
verdict: not yet: it duplicates read-back helpers already on amd-dev, and write_writable (~4259) skips protected pages while write_subresources still returns Ok, so a partial write looks like success (see the review)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7345881743 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3675#issuecomment-7345881743). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T12:47:21Z. --- merge-check base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: effdc0a8764d8e15d47f00ff228f8d82304d2d34 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60ce alone on this card, so none is from this PR) review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3675#issuecomment-7337243400 and its findings stand. Most serious: it duplicates read-back helpers already on `amd-dev`, and `write_writable` (~4259) skips protected pages while `write_subresources` still returns `Ok`, so a partial write looks like success. performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (effdc0a8): 1671 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16481 MB, 0 device removals, 0 crashes. verdict: not yet: it duplicates read-back helpers already on `amd-dev`, and `write_writable` (~4259) skips protected pages while `write_subresources` still returns `Ok`, so a partial write looks like success (see the review) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
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/3675:upstream-pr/3675'
git switch 'upstream-pr/3675'

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 'amd-dev'
git merge --no-ff 'upstream-pr/3675'
git switch 'upstream-pr/3675'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3675'
git switch 'upstream-pr/3675'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --no-ff 'upstream-pr/3675'
git switch 'amd-dev'
git merge --squash 'upstream-pr/3675'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3675'
git switch 'amd-dev'
git merge 'upstream-pr/3675'
git push origin 'amd-dev'
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!3675
No description provided.