D3D12.X: preserve pending CPU writes during sparse readback #1837

Closed
gloger2003 wants to merge 1 commit from upstream-pr/1847 into main
gloger2003 commented 2026-11-24 21:44:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gloger2003 on 2026-11-24T21:44:48Z.


A sparse readback can restore the previous GPU contents over CPU writes that have not been uploaded yet. A partial readback can also mark adjacent CPU bytes as synchronized even though the GPU has never seen those bytes.

What is in it

  • Compare the complete readback chunk with its last synchronized hash before replacing a dirty CPU chunk.
  • Copy partial readbacks into the requested range and keep pending CPU changes eligible for the next upload.
  • Verify the CPU and GPU contents after a full-chunk readback and a partial write in the same chunk.

Tested

  • Radeon RX 7800 XT (32.0.32029.2010), Ryzen 7 5700X, Windows 11 build 26300.9974, Rust 1.100.0 MSVC, DXC 1.9.2602.17.
  • The focused GPU test reproduced the lost write on main c160d86 and passed on this branch. It reads the GPU bytes again after the next submit.
  • cargo build --offline --locked --workspace and cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output. The repeated workspace run reported 859 passed, 0 failed and 42 ignored. The optional heap-window test reported a skip in the standard configuration and passed separately with XCL_HEAP_WINDOWS=1. The first run hit the cubemap idle-page reclamation assertion, followed by two poisoned-lock failures. Those tests passed in the rerun. A controlled 2.2-second delay before the second placement also reproduced the original cubemap assertion on unmodified main c160d86. Known cubemap test issue #718
  • Matched 30-second release runs of Minecraft Preview with a fresh 1x MSAA profile. Both presented visible frames and exited cleanly.

Regression run

main

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 30
exit: 0x0
frames shown: 1644 (PresentX 1644)
presents per 2 s (last 3): 120 120 98
device removals: 0
crashes: 0
peak commit: 3353 MB

PR

xcl-smoke v1
commit: 76ac614ae554e9013838cbcb614ec26be149c8c7
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 30
exit: 0x0
frames shown: 1689 (PresentX 1689)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3356 MB

Not tested

  • Other GPUs, other titles, gameplay beyond startup and overlapping CPU/GPU writes to the same bytes. The standalone GPU test exercises pending writes directly.

AI use

  • OpenAI Codex (GPT-6.2 Sol, high reasoning effort) reproduced the issue, wrote the change and test, ran the checks and drafted this description. Fast mode was selected in Codex.
<!-- greyfinch-sync:ivall/xcl:issue:5480849917 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847). Originally posted by [gloger2003](https://github.com/gloger2003) on 2026-11-24T21:44:48Z. --- A sparse readback can restore the previous GPU contents over CPU writes that have not been uploaded yet. A partial readback can also mark adjacent CPU bytes as synchronized even though the GPU has never seen those bytes. **What is in it** - Compare the complete readback chunk with its last synchronized hash before replacing a dirty CPU chunk. - Copy partial readbacks into the requested range and keep pending CPU changes eligible for the next upload. - Verify the CPU and GPU contents after a full-chunk readback and a partial write in the same chunk. **Tested** - Radeon RX 7800 XT (32.0.32029.2010), Ryzen 7 5700X, Windows 11 build 26300.9974, Rust 1.100.0 MSVC, DXC 1.9.2602.17. - The focused GPU test reproduced the lost write on main `c160d86` and passed on this branch. It reads the GPU bytes again after the next submit. - `cargo build --offline --locked --workspace` and `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output`. The repeated workspace run reported 859 passed, 0 failed and 42 ignored. The optional heap-window test reported a skip in the standard configuration and passed separately with `XCL_HEAP_WINDOWS=1`. The first run hit the cubemap idle-page reclamation assertion, followed by two poisoned-lock failures. Those tests passed in the rerun. A controlled 2.2-second delay before the second placement also reproduced the original cubemap assertion on unmodified main `c160d86`. [Known cubemap test issue #718](https://github.com/xcl-dev/xcl/issues/718) - Matched 30-second release runs of Minecraft Preview with a fresh 1x MSAA profile. Both presented visible frames and exited cleanly. **Regression run** main ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: AMD Radeon RX 7800 XT title: Xbox-Series-1.18.3064.0 seconds: 30 exit: 0x0 frames shown: 1644 (PresentX 1644) presents per 2 s (last 3): 120 120 98 device removals: 0 crashes: 0 peak commit: 3353 MB ``` PR ``` xcl-smoke v1 commit: 76ac614ae554e9013838cbcb614ec26be149c8c7 gpu: AMD Radeon RX 7800 XT title: Xbox-Series-1.18.3064.0 seconds: 30 exit: 0x0 frames shown: 1689 (PresentX 1689) presents per 2 s (last 3): 120 120 120 device removals: 0 crashes: 0 peak commit: 3356 MB ``` **Not tested** - Other GPUs, other titles, gameplay beyond startup and overlapping CPU/GPU writes to the same bytes. The standalone GPU test exercises pending writes directly. **AI use** - OpenAI Codex (GPT-6.2 Sol, high reasoning effort) reproduced the issue, wrote the change and test, ran the checks and drafted this description. Fast mode was selected in Codex.
upipibi commented 2026-11-24 23:08:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T22:55:47Z.


Reproduced and fixed on NVIDIA: RTX 3070 8 GB, driver 616.56, Windows 11, debug.

  • main 689f2db with only tests/sparse_readback_cpu_writes.rs copied in: sparse_readback_preserves_an_unsubmitted_cpu_chunk fails, 2 of 2 runs ("the readback must preserve the unsubmitted CPU chunk").
  • 76ac614 merged onto 689f2db (clean): passes, 2 of 2. The lib tests matching sparse (minus gpu_sparse_vram, for #1727): 16 passed, 0 failed.

AI-assisted (Claude Code). Synthetic tests only.

<!-- greyfinch-sync:ivall/xcl:comment:7146810395 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7146810395). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T22:55:47Z. --- Reproduced and fixed on NVIDIA: RTX 3070 8 GB, driver 616.56, Windows 11, debug. - `main` `689f2db` with only `tests/sparse_readback_cpu_writes.rs` copied in: `sparse_readback_preserves_an_unsubmitted_cpu_chunk` fails, 2 of 2 runs ("the readback must preserve the unsubmitted CPU chunk"). - `76ac614` merged onto `689f2db` (clean): passes, 2 of 2. The lib tests matching `sparse` (minus `gpu_sparse_vram`, for #1727): 16 passed, 0 failed. AI-assisted (Claude Code). Synthetic tests only.
DavidM1911 commented 2026-11-25 02:08:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:15:35Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7149365976 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7149365976). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T01:15:35Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
ettehn commented 2026-11-27 06:00:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ettehn on 2026-11-27T06:00:29Z.


I tested the copy_back implementation from 76ac614a as a local replacement for the chunk-level approach in the performance stack, on Windows x64 / RTX 5070 Ti Laptop (621.24), Rust 1.97.1 MSVC release. The exact stack parent 3d8182c9 passes the in-repo synthetic title. The next commit, 7724ec49 (same patch as 054270ca), fails its post-Wait32/64 write assertion with 0x0. This matches the existing stack report.

I replaced that commit’s sparse copy-back logic locally with this PR’s implementation, retaining the stack’s readback completion handling. The unmodified synthetic title then passed 2/2 runs with zero failures. I also ran this PR’s focused GPU test after adapting its placement and the stack’s before_execute call signature. It passed 1/1, with no skip. It preserved the pending CPU bytes through the next upload and verified the partial GPU write in the neighboring bytes of the same chunk. This tests a local adaptation on the stack. A clean upstream PR build, the full suite, and retail smoke were outside the run.

OpenAI Codex assisted with the adaptation and verification (exact serving model not exposed).

<!-- greyfinch-sync:ivall/xcl:comment:7211133339 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7211133339). Originally posted by [ettehn](https://github.com/ettehn) on 2026-11-27T06:00:29Z. --- I tested the `copy_back` implementation from `76ac614a` as a local replacement for the chunk-level approach in the performance stack, on Windows x64 / RTX 5070 Ti Laptop (621.24), Rust 1.97.1 MSVC release. The exact stack parent `3d8182c9` passes the in-repo synthetic title. The next commit, `7724ec49` (same patch as `054270ca`), fails its `post-Wait32/64 write` assertion with `0x0`. This matches the existing [stack report](https://github.com/xcl-dev/xcl/issues/2787#issuecomment-7194240223). I replaced that commit’s sparse copy-back logic locally with this PR’s implementation, retaining the stack’s readback completion handling. The unmodified synthetic title then passed **2/2** runs with zero failures. I also ran this PR’s focused GPU test after adapting its placement and the stack’s `before_execute` call signature. It passed **1/1**, with no skip. It preserved the pending CPU bytes through the next upload and verified the partial GPU write in the neighboring bytes of the same chunk. This tests a local adaptation on the stack. A clean upstream PR build, the full suite, and retail smoke were outside the run. OpenAI Codex assisted with the adaptation and verification (exact serving model not exposed).
Foniass commented 2026-12-01 06:58:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:58:32Z.


Triage (#1607) – head 76ac614

Main now does this in sparse.rs. Commit 04de323 added land_page, which copies GPU bytes only into chunks whose hash still matches sent and leaves CPU-dirty chunks and their hashes for the next upload. Commit 5f284cc added gpu_written, so a list's own GPU writes still land in a CPU-changed chunk and that chunk stays dirty. Together they cover both scenarios in sparse_readback_cpu_writes.rs: a full chunk the GPU did not change, and a partial GPU write next to a CPU write. The sync_sent_range / readback loop this PR rewrites has since been restructured (copy_back with gen), and the branch conflicts with it.
Recommendation: close (superseded by main commits 04de323 and 5f284cc).

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:7303498663 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7303498663). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:58:32Z. --- **Triage (#1607)** – head 76ac614 Main now does this in `sparse.rs`. Commit 04de323 added `land_page`, which copies GPU bytes only into chunks whose hash still matches `sent` and leaves CPU-dirty chunks and their hashes for the next upload. Commit 5f284cc added `gpu_written`, so a list's own GPU writes still land in a CPU-changed chunk and that chunk stays dirty. Together they cover both scenarios in `sparse_readback_cpu_writes.rs`: a full chunk the GPU did not change, and a partial GPU write next to a CPU write. The `sync_sent_range` / readback loop this PR rewrites has since been restructured (`copy_back` with `gen`), and the branch conflicts with it. Recommendation: close (superseded by main commits 04de323 and 5f284cc). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:49:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:49:04Z.


Closing as superseded: this change is already on main (5f284cc2). main land_page / gpu_written (04de323, 5f284cc) keeps CPU-dirty chunks and their hashes on copy-back and lets the GPU's own writes land in a changed chunk; replaces sync_sent_range overwrite the PR fixes

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311689446 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7311689446). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:49:04Z. --- Closing as superseded: this change is already on `main` (5f284cc2). main land_page / gpu_written (04de323, 5f284cc) keeps CPU-dirty chunks and their hashes on copy-back and lets the GPU's own writes land in a changed chunk; replaces sync_sent_range overwrite the PR fixes Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

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