D3D12.X: land a list's sparse GPU writes in chunks the CPU changed #3162

Closed
tiagonleal wants to merge 1 commit from upstream-pr/3162 into main
tiagonleal commented 2026-11-28 14:36:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-28T14:36:21Z.


Part of #3093 (group 1). On main e429936c the three e2e title tests fail on NVIDIA and AMD with post-Wait32/64 write failed (0x0). Since 04de3234 a sparse copy-back skips every 64-byte chunk whose hash no longer matches the last upload, so that a newer CPU store is not overwritten. After a list executes, though, the copy-back ranges are that list's recorded GPU writes, and those bytes are newer than any CPU store made before the list ran. When the CPU had written other bytes of the same chunk, the GPU's write was dropped. The test title does exactly this: its CPU thread stores the wait cells at +0x300 and +0x308, the list writes +0x310, and +0x310 read back 0.

The issue suggested rebuilding the uploaded bytes from the chunk's hash and merging byte by byte. That does not work here: logging showed the copy-back range was only the 4 written bytes and the chunk's sent hash matched neither the CPU's view nor the GPU's. The written range itself is what tells the two apart.

What is in it

  • sparse.rs: land_page and readback_ranges take gpu_wrote. The copy-back after a list executes (readback_after_execute) passes true: the written bytes land in a chunk the CPU changed as well, and the chunk keeps its old hash, so the next look uploads the CPU's bytes together with the GPU's. The Map-time copy-back (readback_now, whole spans) passes false and keeps the CPU-wins rule of 04de3234.
  • Test gpu_write_lands_next_to_cpu_writes_in_one_chunk: two CPU cells and one GPU cell in one chunk, all three present after the copy-back, and the chunk still uploads next.
  • No new memory. An unchanged chunk takes the same path as before; a changed one costs one extra copy of the written bytes.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug
  • cargo test -p xcl --test e2e -- --test-threads=1: 2 passed, 3 failed on main e429936c; 5 passed, 0 failed with this change.
  • New test with the new branch switched off: 0 passed, 1 failed ("GPU write lost"). With it: passes. cargo test -p xcl --lib d3d12x::sparse: 84 passed, 0 failed, 1 ignored, including 04de3234's dirty_chunks_survive_gpu_copy_back_and_upload_next and clean_chunks_take_gpu_copy_back_bytes.
  • cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4, one run on head b673f36d: 2126 passed, 10 failed, 48 ignored (25 SKIPPED lines). All 10 failures also fail on main e429936c on this machine (2122 passed, 13 failed, 48 ignored): the 4 gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_* (#1919 fixes them) and 6 of the 9 in #3093. Fixed against main: test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_and_game_folder_is_untouched, test_title_runs_under_the_debug_layer_with_dred.

Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e (Newer Retail Game), release builds of both commits in clean trees, main e429936c first, one run each, in one queue with this account's other PRs. Both runs had XCL_PREPARE=0 and the same warm DXIL cache. A warm-up run of main came before them and is not shown. A second run of main at the end of the queue showed 374 frames and a peak commit of 14157 MB, so differences of a few tens of frames between runs are noise here.

main (e429936c):

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 382 (PresentX 382)
presents per 2 s (last 3): 13 12 12
device removals: 0
crashes: 0
peak commit: 14225 MB

This PR (b673f36d):

xcl-smoke v1
commit: b673f36d1a6caba189ef6558b13976c5ae444578
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 367 (PresentX 368)
presents per 2 s (last 3): 11 14 13
device removals: 0
crashes: 0
peak commit: 14979 MB

Not tested

  • AMD, Intel, Wine. DarkPanda69 saw the same e2e failure on an RX 9070 XT in #3093; this change was not run there.
  • A CPU store to the very bytes the list wrote, made after the work ends and before the copy-back lands: the GPU's value now wins there. Before, the CPU's value won, but only when the chunk had changed. The existing comment on land_page already relies on the title's fence discipline for this window.
  • Whether the retail title has this pattern, and any effect on world loading. The smoke run is a regression check only.
  • The callers pass ranges recorded by the list's own memory methods (copy, fill, write, timestamp); a caller that passed a wider range than was written would overwrite CPU bytes inside it. I found none.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5541213067 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3162). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-28T14:36:21Z. --- Part of #3093 (group 1). On `main` `e429936c` the three `e2e` title tests fail on NVIDIA and AMD with `post-Wait32/64 write failed (0x0)`. Since 04de3234 a sparse copy-back skips every 64-byte chunk whose hash no longer matches the last upload, so that a newer CPU store is not overwritten. After a list executes, though, the copy-back ranges are that list's recorded GPU writes, and those bytes are newer than any CPU store made before the list ran. When the CPU had written other bytes of the same chunk, the GPU's write was dropped. The test title does exactly this: its CPU thread stores the wait cells at `+0x300` and `+0x308`, the list writes `+0x310`, and `+0x310` read back 0. The issue suggested rebuilding the uploaded bytes from the chunk's hash and merging byte by byte. That does not work here: logging showed the copy-back range was only the 4 written bytes and the chunk's sent hash matched neither the CPU's view nor the GPU's. The written range itself is what tells the two apart. **What is in it** - `sparse.rs`: `land_page` and `readback_ranges` take `gpu_wrote`. The copy-back after a list executes (`readback_after_execute`) passes true: the written bytes land in a chunk the CPU changed as well, and the chunk keeps its old hash, so the next look uploads the CPU's bytes together with the GPU's. The Map-time copy-back (`readback_now`, whole spans) passes false and keeps the CPU-wins rule of 04de3234. - Test `gpu_write_lands_next_to_cpu_writes_in_one_chunk`: two CPU cells and one GPU cell in one chunk, all three present after the copy-back, and the chunk still uploads next. - No new memory. An unchanged chunk takes the same path as before; a changed one costs one extra copy of the written bytes. **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug - `cargo test -p xcl --test e2e -- --test-threads=1`: 2 passed, 3 failed on `main` `e429936c`; 5 passed, 0 failed with this change. - New test with the new branch switched off: 0 passed, 1 failed ("GPU write lost"). With it: passes. `cargo test -p xcl --lib d3d12x::sparse`: 84 passed, 0 failed, 1 ignored, including 04de3234's `dirty_chunks_survive_gpu_copy_back_and_upload_next` and `clean_chunks_take_gpu_copy_back_bytes`. - `cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4`, one run on head `b673f36d`: 2126 passed, 10 failed, 48 ignored (25 `SKIPPED` lines). All 10 failures also fail on `main` `e429936c` on this machine (2122 passed, 13 failed, 48 ignored): the 4 `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_*` (#1919 fixes them) and 6 of the 9 in #3093. Fixed against `main`: `test_title_draws_with_a_root_signature_under_the_debug_layer`, `test_title_runs_and_game_folder_is_untouched`, `test_title_runs_under_the_debug_layer_with_dred`. **Regression run** `scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e` (Newer Retail Game), release builds of both commits in clean trees, `main` `e429936c` first, one run each, in one queue with this account's other PRs. Both runs had `XCL_PREPARE=0` and the same warm DXIL cache. A warm-up run of `main` came before them and is not shown. A second run of `main` at the end of the queue showed 374 frames and a peak commit of 14157 MB, so differences of a few tens of frames between runs are noise here. `main` (`e429936c`): ``` xcl-smoke v1 commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 382 (PresentX 382) presents per 2 s (last 3): 13 12 12 device removals: 0 crashes: 0 peak commit: 14225 MB ``` This PR (`b673f36d`): ``` xcl-smoke v1 commit: b673f36d1a6caba189ef6558b13976c5ae444578 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 367 (PresentX 368) presents per 2 s (last 3): 11 14 13 device removals: 0 crashes: 0 peak commit: 14979 MB ``` **Not tested** - AMD, Intel, Wine. DarkPanda69 saw the same e2e failure on an RX 9070 XT in #3093; this change was not run there. - A CPU store to the very bytes the list wrote, made after the work ends and before the copy-back lands: the GPU's value now wins there. Before, the CPU's value won, but only when the chunk had changed. The existing comment on `land_page` already relies on the title's fence discipline for this window. - Whether the retail title has this pattern, and any effect on world loading. The smoke run is a regression check only. - The callers pass ranges recorded by the list's own memory methods (copy, fill, write, timestamp); a caller that passed a wider range than was written would overwrite CPU bytes inside it. I found none. **AI use** - Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tiagonleal commented 2026-11-28 14:37:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-28T14:37:53Z.


Closing as a duplicate: #3149 (KOLESNiii) fixes the same copy-back case and was merged into main while this one was still running its suite and smoke pair.

AI use: Claude Code wrote this comment (Claude Fable 5.2).

<!-- greyfinch-sync:ivall/xcl:comment:7240813682 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3162#issuecomment-7240813682). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-28T14:37:53Z. --- Closing as a duplicate: #3149 (KOLESNiii) fixes the same copy-back case and was merged into `main` while this one was still running its suite and smoke pair. **AI use:** Claude Code wrote this comment (Claude Fable 5.2).

Pull request closed

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!3162
No description provided.