Skip to content

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

Closed
tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/copy-back-keeps-gpu-bytes
Closed

tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:d3d12x/copy-back-keeps-gpu-bytes

Conversation

@tiagonleal

Copy link
Copy Markdown
Contributor

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 04de323 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 04de323.
  • 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 04de323'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_* (Recompiler: LDS ds_sub_u32 hides its negation from the driver (RTX 50 refuses it) #1919 fixes them) and 6 of the 9 in main e429936 on NVIDIA: 3 e2e title tests and 6 split-wave64 GPU tests fail since #2959 #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 main e429936 on NVIDIA: 3 e2e title tests and 6 split-wave64 GPU tests fail since #2959 #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

Since 04de323 a sparse copy-back skips every 64-byte chunk whose hash
no longer matches the last upload, so a newer CPU store is not
overwritten. After a list executes, though, the copy-back ranges are the
list's recorded GPU writes (`sparse_writes`), and those bytes are newer
than any CPU store made before the work ran. When the CPU had written
other bytes of the same chunk, the whole GPU write was dropped.

The e2e title hits this (xcl-dev#3093): its CPU thread stores the Wait32/64
cells at +0x300/+0x308, the list then writes +0x310, and +0x310 read
back 0. Scratch logging showed the copy-back range was only the 4
written bytes and that the chunk's sent hash matched neither the CPU
nor the GPU view, so recovering the uploaded bytes from the hash is not
possible; the written range itself is what tells the bytes apart.

`land_page` now takes `gpu_wrote`. For the post-execute copy-back
(true) the written bytes land in a changed chunk as well, and the chunk
keeps its old hash, so the next look uploads the CPU's bytes together
with the GPU's. Map-time copy-back (`readback_now`, whole spans) passes
false and keeps the CPU-wins rule. No new memory; the dirty-chunk branch
costs one extra copy of bytes already being copied for clean chunks.

Measured (RTX 5070 Ti, debug): e2e 2 passed / 3 failed before
("post-Wait32/64 write failed (0x0)"), 5 passed after; d3d12x::sparse
unit tests 84 passed, 1 ignored. New test
gpu_write_lands_next_to_cpu_writes_in_one_chunk fails without the
change ("GPU write lost").
@tiagonleal

Copy link
Copy Markdown
Contributor Author

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).

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