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

Open
github-bot wants to merge 1 commit from github-bot/gh-1847 into main AGit
Owner

@⁠gloger2003 on GitHub · 2026-11-24 21:44 UTC · original
gloger2003:fix/sparse-readback-keep-cpu-writes → main · +157 −43 · 2 files · 1 commits · draft

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.
**@⁠gloger2003** on GitHub · 2026-11-24 21:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1847) `gloger2003:fix/sparse-readback-keep-cpu-writes` → `main` · +157 −43 · 2 files · 1 commits · draft 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://git.gtahub.st/github/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.
Keep a dirty CPU chunk when the GPU still has its last synchronized contents. Partial GPU readbacks update the requested bytes without marking adjacent CPU writes as uploaded.

Assisted-by: OpenAI Codex (GPT-6.2 Sol)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:07 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:55 UTC · original

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.

**@⁠upipibi** on GitHub · 2026-11-24 22:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7146810395) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 01:15 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-25 01:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1847#issuecomment-7149365976) 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!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1847/head:github-bot/gh-1847'
git switch 'github-bot/gh-1847'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1847'
git switch 'github-bot/gh-1847'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1847'
git switch 'github-bot/gh-1847'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1847'
git switch 'main'
git merge --squash 'github-bot/gh-1847'
git switch 'main'
git merge --ff-only 'github-bot/gh-1847'
git switch 'main'
git merge 'github-bot/gh-1847'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.