D3D12.X: stop sparse upload_dirty ring wait when fence times out #1277

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

@⁠ExoCalibra on GitHub · 2026-11-24 14:08 UTC · original
ExoCalibra:pr/sparse-upload-wait-timeout → main · +110 −5 · 1 files · 1 commits · open

sparse::State::wait_for returns after 5 s with a warning if the sparse upload queue stalls, but upload_dirty called wait_for(fv) inside a while loop waiting for staging ring space. When the oldest in-flight fence failed to advance, reclaim_ring freed nothing and upload_dirty looped forever while holding the global STATE mutex, hanging xcl-activity (sparse::pool_bytes) and every subsequent submit thread permanently.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: return whether wait_for reached its target fence value, break out of upload_dirty with a bounded warning on timeout so STATE is released cleanly, and add GPU regression test upload_dirty_exits_when_ring_fence_wait_times_out.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1088), AMD Ryzen 7 7800X3D, Windows 11 Pro Build 26200, rustc 1.100.0 (0ef1bc386 2026-11-09), debug (scripts/test.ps1) + release (cargo build --release -p xcl).
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored.
  • SKIPPED GPU tests on this adapter: 2 (no wave64 — gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).

Regression run

Main (67a3735):

xcl-smoke v1
commit: 67a3735177f42cf8e5c886e67a974da7f87541b3
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1084 (PresentX 1084)
presents per 2 s (last 3): 59 59 56
device removals: 0
crashes: 0
peak commit: 16561 MB

PR (0f66820):

xcl-smoke v1
commit: 0f66820065129bca1e0cd7f3ae0125e140d835f3
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1090 (PresentX 1091)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15699 MB

Not tested

  • The timeout bail-out branch is exercised by the GPU unit test (upload_dirty_exits_when_ring_fence_wait_times_out) and did not trigger during the healthy 60 s retail smoke run.
  • AMD RDNA / wave64 GPUs and Intel GPUs.
  • XCL_SAMPLE_* tests on local sample files (not set).

AI use

  • Antigravity (Gemini 4 Neon): assisted with root-cause analysis, fix, GPU regression test, audit, rebase verification, and PR description. All code, tests, and smoke logs reviewed by the author.
**@⁠ExoCalibra** on GitHub · 2026-11-24 14:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277) `ExoCalibra:pr/sparse-upload-wait-timeout` → `main` · +110 −5 · 1 files · 1 commits · open `sparse::State::wait_for` returns after 5 s with a warning if the sparse upload queue stalls, but `upload_dirty` called `wait_for(fv)` inside a `while` loop waiting for staging ring space. When the oldest in-flight fence failed to advance, `reclaim_ring` freed nothing and `upload_dirty` looped forever while holding the global `STATE` mutex, hanging `xcl-activity` (`sparse::pool_bytes`) and every subsequent submit thread permanently. **What is in it** - `crates/xcl/src/hle/d3d12x/sparse.rs`: return whether `wait_for` reached its target fence value, break out of `upload_dirty` with a bounded warning on timeout so `STATE` is released cleanly, and add GPU regression test `upload_dirty_exits_when_ring_fence_wait_times_out`. **Tested** - Hardware / OS / toolchain: NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1088), AMD Ryzen 7 7800X3D, Windows 11 Pro Build 26200, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, debug (`scripts/test.ps1`) + release (`cargo build --release -p xcl`). - `.\scripts\test.ps1` (`cargo test --workspace -- --test-threads=4`): 742 passed, 0 failed, 41 ignored. - `SKIPPED` GPU tests on this adapter: 2 (`no wave64` — `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`). **Regression run** Main (`67a3735`): ``` xcl-smoke v1 commit: 67a3735177f42cf8e5c886e67a974da7f87541b3 gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1084 (PresentX 1084) presents per 2 s (last 3): 59 59 56 device removals: 0 crashes: 0 peak commit: 16561 MB ``` PR (`0f66820`): ``` xcl-smoke v1 commit: 0f66820065129bca1e0cd7f3ae0125e140d835f3 gpu: NVIDIA GeForce RTX 3080 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1090 (PresentX 1091) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15699 MB ``` **Not tested** - The timeout bail-out branch is exercised by the GPU unit test (`upload_dirty_exits_when_ring_fence_wait_times_out`) and did not trigger during the healthy 60 s retail smoke run. - AMD RDNA / wave64 GPUs and Intel GPUs. - `XCL_SAMPLE_*` tests on local sample files (not set). **AI use** - Antigravity (Gemini 4 Neon): assisted with root-cause analysis, fix, GPU regression test, audit, rebase verification, and PR description. All code, tests, and smoke logs reviewed by the author.
sparse::State::wait_for intentionally returns after 5 s with a warning if the sparse queue stalls, but upload_dirty wrapped wait_for in a while loop waiting for staging ring space. When the oldest in-flight fence failed to advance, reclaim_ring freed nothing and upload_dirty looped forever while holding the global STATE mutex, blocking xcl-activity (pool_bytes) and every submitting thread.

Return whether wait_for reached its target fence value, bail out of upload_dirty with a bounded warning on timeout so STATE is released, and add a GPU regression test reproducing a full staging ring with a stalled fence.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:11 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 14:10 UTC · original

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

  • cargo test -p xcl --lib sparse: 17 passed, 0 failed, 1 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 14:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7133943389) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib sparse`: 17 passed, 0 failed, 1 ignored. Thanks!
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 14:38 UTC · original

Full-suite run to go with the subset check above. Tested exact head 0f66820 (on its base 47efa2e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: upload_dirty_exits_when_ring_fence_wait_times_out.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 14:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7134695670) Full-suite run to go with the subset check above. Tested exact head `0f66820` (on its base `47efa2e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **742 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `upload_dirty_exits_when_ring_fence_wait_times_out`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **742 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 17:08 UTC · original · edited 2026-11-24 17:13 UTC

Independent native recovery check: this branch reproduces the dropped-upload risk already described by #1385's author. Exact head 0f66820065129bca1e0cd7f3ae0125e140d835f3; exact parent 47efa2ecea0a12934719ae69b81930cf02a4b1c3.

Tested
The same fixture used for #1495, unchanged (SHA256 1fd8f7d154e9663b25d9fe98153fccd2bc8de5291db5aa24414e48f3ddfaa958): fill the real64MiB staging ring behind a controlled queue fence with0x11, change a4KiB page to0x22, wait through the actual5-second timeout, release the gate, explicitly retry that same dirty page, then read all1,024words from the GPU. A six-second recovery guard lets the parent finish without an infinite wait.

Source GPU passed / failed / ignored Wait Wrong words after retry
parent47efa2e RTX3090 1 /0 /0 6015ms 0 /1024
head0f66820 RTX3090 0 /1 /0 5015ms 1024 /1024
parent47efa2e AMD integrated 1 /0 /0 6018ms 0 /1024
head0f66820 AMD integrated 0 /1 /0 5002ms 1024 /1024

No skips or harness timeouts. Head exits101 on the byte assertion; parent exits0. All wrong head words are the old0x11111111. Head ring_write stays67108864 through timeout and retry; parent advances to67112960. Invalidating only the page's sent hashes and explicitly retrying the unchanged bytes yields0wrong on both GPUs. Queue drain/device-removal checks succeed; cleanup occurs before the failing assertion.

scan_page updates the hashes before upload, and the new early return loses the remaining bytes while before_execute clears its dirty runs. The next same-page retry sees matching hashes and stages nothing. Invalidation alone is not a complete fix: normal write-watch scans reset their records, so the next dirty-page list need not include the page. Retain pending uploads or propagate the failure. #1385 already proposes keeping pending work while releasing STATE during waits; native validation of that alternative now passes the byte-recovery and existing lock-progress tests on RTX3090 and AMD, with exact-parent controls. These focused results do not establish full merge readiness.

Fresh process for each run, XCL_ADAPTER=3090 / AMD:
cargo test --locked -p xcl --lib timed_out_sparse_upload_retries_unsent_bytes -- --test-threads=1 --show-output --nocapture

Windows10 Home19045, Ryzen7 7800X3D, RTX3090 driver591.74 / AMD Radeon integrated32.0.21030.2001, Rust1.98.1 MSVC, Agility1.620.2, debug, SSH Session0. All222source-file hashes match each tree; parent/head differ only in sparse.rs, plus identical diagnostic wiring. Restored head verified. Patch reverse-apply and diff checks pass.

Not tested
Full workspace with this fixture, retail / xcl-smoke, actual device loss, partial multi-run suffixes, release, Linux/Wine. The existing timeout test demonstrates bounded return; this additional test checks recovery bytes. The parent control does not endorse repeated waits under STATE. Run alone because the fixture initializes sparse globals. No competing runtime implementation or PR.

AI use
Codex (GPT-6) inspected the overlap, adapted diagnostic wiring, ran tests and prepared this report. Synthetic bytes/public source only.

Complete diagnostic patch against0f66820
diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index 9b992d8..9a89710 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -2311,3 +2311,7 @@ mod tests {
         }
     }
 }
+
+#[cfg(test)]
+#[path = "sparse_timeout_probe.rs"]
+mod sparse_timeout_probe;
diff --git a/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs b/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs
new file mode 100644
--- /dev/null
+++ b/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs
@@ -0,0 +1,108 @@
+//! Local PR1495 diagnostic; run alone in a fresh process (initializes sparse globals).
+use super::*;
+use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*};
+
+unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) {
+    let done: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
+    queue.Signal(&done, 1).unwrap();
+    let start = std::time::Instant::now();
+    while done.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 {
+        std::thread::sleep(std::time::Duration::from_millis(1));
+    }
+    assert_eq!(done.GetCompletedValue(), 1, "queue drained");
+    dev.GetDeviceRemovedReason().unwrap();
+}
+
+unsafe fn read_page(dev: &ID3D12Device, queue: &ID3D12CommandQueue, source: &ID3D12Resource, offset: u64) -> Vec<u32> {
+    let mut rb: Option<ID3D12Resource> = None;
+    let mut desc = buffer_desc(PAGE as u64);
+    desc.Flags = D3D12_RESOURCE_FLAG_NONE;
+    dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_READBACK, ..Default::default() },
+        D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COPY_DEST, None, &mut rb).unwrap();
+    let rb = rb.unwrap();
+    let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
+    let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).unwrap();
+    list.CopyBufferRegion(&rb, 0, source, offset, PAGE as u64);
+    list.Close().unwrap();
+    queue.ExecuteCommandLists(&[Some(list.cast::<ID3D12CommandList>().unwrap())]);
+    drain(queue, dev);
+    let mut p = std::ptr::null_mut();
+    rb.Map(0, Some(&D3D12_RANGE { Begin: 0, End: PAGE }), Some(&mut p)).unwrap();
+    let words = std::slice::from_raw_parts(p as *const u32, PAGE / 4).to_vec();
+    rb.Unmap(0, Some(&D3D12_RANGE { Begin: 0, End: 0 }));
+    words
+}
+
+#[test]
+fn timed_out_sparse_upload_retries_unsent_bytes() {
+    unsafe {
+        let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
+        let sel = crate::gpu::adapter::Selector::from_env_or("auto");
+        let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &sel).into_iter().next() else {
+            return crate::gpu::recomp::runner::skip_test("no GPU");
+        };
+        println!("adapter={}", crate::gpu::adapter::name(&desc));
+        let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap();
+        let windows = init(&dev);
+        assert!(!windows.is_empty(), "sparse windows initialized");
+        for (_, raw, _) in windows { drop(ID3D12Resource::from_raw(raw as *mut c_void)); }
+        let (p, bytes) = alloc(STAGING, TILE).expect("64 MiB sparse allocation");
+        assert_eq!(bytes, STAGING);
+        let title: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
+        let sparse = queue().unwrap();
+        drain(&sparse, &dev);
+        let gate: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
+        // Ensure a panic never leaves our synthetic queue blocked.
+        struct Unblock(ID3D12Fence);
+        impl Drop for Unblock { fn drop(&mut self) { unsafe { let _ = self.0.Signal(1); } } }
+        let unblock = Unblock(gate.clone());
+        sparse.Wait(&gate, 1).unwrap();
+        std::ptr::write_bytes(p as *mut u8, 0x11, bytes);
+        let pages: Vec<usize> = (p..p + bytes).step_by(PAGE).collect();
+        before_execute(&title, &pages, PAGE);
+        let (source, offset, before_write) = {
+            let g = STATE.lock().unwrap();
+            let s = g.as_ref().unwrap();
+            assert_eq!(s.ring_write - s.ring_free, STAGING as u64, "real ring filled behind gate");
+            assert!(!s.inflight.is_empty());
+            assert!(s.fence.GetCompletedValue() < s.inflight.front().unwrap().0);
+            let wi = s.window_index(p).unwrap();
+            (s.windows[wi].1.clone(), (p - s.windows[wi].0) as u64, s.ring_write)
+        };
+        std::ptr::write_bytes(p as *mut u8, 0x22, PAGE);
+        // Bound the old implementation too: recover after six seconds if it keeps waiting.
+        let rescue = gate.clone();
+        let (tx, rx) = std::sync::mpsc::channel::<()>();
+        let recover = std::thread::spawn(move || {
+            let _ = rx.recv_timeout(std::time::Duration::from_secs(6));
+            rescue.Signal(1).unwrap();
+        });
+        let start = std::time::Instant::now();
+        before_execute(&title, &[p], PAGE);
+        let elapsed = start.elapsed();
+        let after_timeout = STATE.lock().unwrap().as_ref().unwrap().ring_write;
+        drop(unblock);
+        let _ = tx.send(());
+        recover.join().unwrap();
+        drain(&sparse, &dev);
+        assert!(elapsed >= std::time::Duration::from_secs(4) && elapsed < std::time::Duration::from_secs(10), "one bounded fence timeout: {elapsed:?}");
+        // Stronger than the next empty write-watch: explicitly offer the same dirty page again.
+        before_execute(&title, &[p], PAGE);
+        let after_retry = STATE.lock().unwrap().as_ref().unwrap().ring_write;
+        let got = read_page(&dev, &title, &source, offset);
+        let wrong = got.iter().filter(|&&v| v != 0x22222222).count();
+        let old = got.iter().filter(|&&v| v == 0x11111111).count();
+        // Diagnostic positive control: invalidate only this page's sent hashes, retry unchanged bytes.
+        STATE.lock().unwrap().as_mut().unwrap().clear_sent_range(p, PAGE);
+        before_execute(&title, &[p], PAGE);
+        let repaired = read_page(&dev, &title, &source, offset);
+        let control_wrong = repaired.iter().filter(|&&v| v != 0x22222222).count();
+        println!("timeout_ms={} ring_before={before_write} ring_after_timeout={after_timeout} ring_after_retry={after_retry}", elapsed.as_millis());
+        println!("words_checked={} wrong_after_retry={wrong} old_words={old} wrong_after_hash_invalidation={control_wrong}", PAGE / 4);
+        drain(&sparse, &dev);
+        assert!(free(p));
+        drain(&sparse, &dev);
+        assert_eq!(control_wrong, 0, "same-byte upload succeeds when hashes are invalidated");
+        assert_eq!(wrong, 0, "retry must upload bytes that timed out before staging");
+    }
+}
**@⁠WebIdentity1** on GitHub · 2026-11-24 17:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7138740183) · edited 2026-11-24 17:13 UTC Independent native recovery check: **this branch reproduces the dropped-upload risk already described by #1385's author.** Exact head `0f66820065129bca1e0cd7f3ae0125e140d835f3`; exact parent `47efa2ecea0a12934719ae69b81930cf02a4b1c3`. **Tested** The same fixture used for [#1495](https://github.com/ivall/xcl/pull/1495#issuecomment-7138616572), unchanged (SHA256 `1fd8f7d154e9663b25d9fe98153fccd2bc8de5291db5aa24414e48f3ddfaa958`): fill the real64MiB staging ring behind a controlled queue fence with0x11, change a4KiB page to0x22, wait through the actual5-second timeout, release the gate, explicitly retry that same dirty page, then read all1,024words from the GPU. A six-second recovery guard lets the parent finish without an infinite wait. | Source | GPU | passed / failed / ignored | Wait | Wrong words after retry | |---|---|---|---|---| | parent47efa2e | RTX3090 |1 /0 /0|6015ms|0 /1024| | head0f66820 | RTX3090 |0 /1 /0|5015ms|1024 /1024| | parent47efa2e | AMD integrated |1 /0 /0|6018ms|0 /1024| | head0f66820 | AMD integrated |0 /1 /0|5002ms|1024 /1024| No skips or harness timeouts. Head exits101 on the byte assertion; parent exits0. All wrong head words are the old0x11111111. Head ring_write stays67108864 through timeout and retry; parent advances to67112960. Invalidating only the page's `sent` hashes and explicitly retrying the unchanged bytes yields0wrong on both GPUs. Queue drain/device-removal checks succeed; cleanup occurs before the failing assertion. `scan_page` updates the hashes before upload, and the new early return loses the remaining bytes while `before_execute` clears its dirty runs. The next same-page retry sees matching hashes and stages nothing. Invalidation alone is not a complete fix: normal write-watch scans reset their records, so the next dirty-page list need not include the page. Retain pending uploads or propagate the failure. #1385 already proposes keeping pending work while releasing STATE during waits; [native validation of that alternative](https://github.com/ivall/xcl/pull/1385#issuecomment-7138790462) now passes the byte-recovery and existing lock-progress tests on RTX3090 and AMD, with exact-parent controls. These focused results do not establish full merge readiness. Fresh process for each run, `XCL_ADAPTER=3090` / `AMD`: `cargo test --locked -p xcl --lib timed_out_sparse_upload_retries_unsent_bytes -- --test-threads=1 --show-output --nocapture` Windows10 Home19045, Ryzen7 7800X3D, RTX3090 driver591.74 / AMD Radeon integrated32.0.21030.2001, Rust1.98.1 MSVC, Agility1.620.2, debug, SSH Session0. All222source-file hashes match each tree; parent/head differ only in sparse.rs, plus identical diagnostic wiring. Restored head verified. Patch reverse-apply and diff checks pass. **Not tested** Full workspace with this fixture, retail / `xcl-smoke`, actual device loss, partial multi-run suffixes, release, Linux/Wine. The existing timeout test demonstrates bounded return; this additional test checks recovery bytes. The parent control does not endorse repeated waits under STATE. Run alone because the fixture initializes sparse globals. No competing runtime implementation or PR. **AI use** Codex (GPT-6) inspected the overlap, adapted diagnostic wiring, ran tests and prepared this report. Synthetic bytes/public source only. <details> <summary>Complete diagnostic patch against0f66820</summary> ```diff diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs index 9b992d8..9a89710 100644 --- a/crates/xcl/src/hle/d3d12x/sparse.rs +++ b/crates/xcl/src/hle/d3d12x/sparse.rs @@ -2311,3 +2311,7 @@ mod tests { } } } + +#[cfg(test)] +#[path = "sparse_timeout_probe.rs"] +mod sparse_timeout_probe; diff --git a/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs b/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs new file mode 100644 --- /dev/null +++ b/crates/xcl/src/hle/d3d12x/sparse_timeout_probe.rs @@ -0,0 +1,108 @@ +//! Local PR1495 diagnostic; run alone in a fresh process (initializes sparse globals). +use super::*; +use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*}; + +unsafe fn drain(queue: &ID3D12CommandQueue, dev: &ID3D12Device) { + let done: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); + queue.Signal(&done, 1).unwrap(); + let start = std::time::Instant::now(); + while done.GetCompletedValue() == 0 && start.elapsed().as_secs() < 10 { + std::thread::sleep(std::time::Duration::from_millis(1)); + } + assert_eq!(done.GetCompletedValue(), 1, "queue drained"); + dev.GetDeviceRemovedReason().unwrap(); +} + +unsafe fn read_page(dev: &ID3D12Device, queue: &ID3D12CommandQueue, source: &ID3D12Resource, offset: u64) -> Vec<u32> { + let mut rb: Option<ID3D12Resource> = None; + let mut desc = buffer_desc(PAGE as u64); + desc.Flags = D3D12_RESOURCE_FLAG_NONE; + dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_READBACK, ..Default::default() }, + D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COPY_DEST, None, &mut rb).unwrap(); + let rb = rb.unwrap(); + let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); + let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).unwrap(); + list.CopyBufferRegion(&rb, 0, source, offset, PAGE as u64); + list.Close().unwrap(); + queue.ExecuteCommandLists(&[Some(list.cast::<ID3D12CommandList>().unwrap())]); + drain(queue, dev); + let mut p = std::ptr::null_mut(); + rb.Map(0, Some(&D3D12_RANGE { Begin: 0, End: PAGE }), Some(&mut p)).unwrap(); + let words = std::slice::from_raw_parts(p as *const u32, PAGE / 4).to_vec(); + rb.Unmap(0, Some(&D3D12_RANGE { Begin: 0, End: 0 })); + words +} + +#[test] +fn timed_out_sparse_upload_retries_unsent_bytes() { + unsafe { + let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap(); + let sel = crate::gpu::adapter::Selector::from_env_or("auto"); + let Some((adapter, desc)) = crate::gpu::adapter::candidates(&factory, &sel).into_iter().next() else { + return crate::gpu::recomp::runner::skip_test("no GPU"); + }; + println!("adapter={}", crate::gpu::adapter::name(&desc)); + let dev = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0).unwrap(); + let windows = init(&dev); + assert!(!windows.is_empty(), "sparse windows initialized"); + for (_, raw, _) in windows { drop(ID3D12Resource::from_raw(raw as *mut c_void)); } + let (p, bytes) = alloc(STAGING, TILE).expect("64 MiB sparse allocation"); + assert_eq!(bytes, STAGING); + let title: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); + let sparse = queue().unwrap(); + drain(&sparse, &dev); + let gate: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); + // Ensure a panic never leaves our synthetic queue blocked. + struct Unblock(ID3D12Fence); + impl Drop for Unblock { fn drop(&mut self) { unsafe { let _ = self.0.Signal(1); } } } + let unblock = Unblock(gate.clone()); + sparse.Wait(&gate, 1).unwrap(); + std::ptr::write_bytes(p as *mut u8, 0x11, bytes); + let pages: Vec<usize> = (p..p + bytes).step_by(PAGE).collect(); + before_execute(&title, &pages, PAGE); + let (source, offset, before_write) = { + let g = STATE.lock().unwrap(); + let s = g.as_ref().unwrap(); + assert_eq!(s.ring_write - s.ring_free, STAGING as u64, "real ring filled behind gate"); + assert!(!s.inflight.is_empty()); + assert!(s.fence.GetCompletedValue() < s.inflight.front().unwrap().0); + let wi = s.window_index(p).unwrap(); + (s.windows[wi].1.clone(), (p - s.windows[wi].0) as u64, s.ring_write) + }; + std::ptr::write_bytes(p as *mut u8, 0x22, PAGE); + // Bound the old implementation too: recover after six seconds if it keeps waiting. + let rescue = gate.clone(); + let (tx, rx) = std::sync::mpsc::channel::<()>(); + let recover = std::thread::spawn(move || { + let _ = rx.recv_timeout(std::time::Duration::from_secs(6)); + rescue.Signal(1).unwrap(); + }); + let start = std::time::Instant::now(); + before_execute(&title, &[p], PAGE); + let elapsed = start.elapsed(); + let after_timeout = STATE.lock().unwrap().as_ref().unwrap().ring_write; + drop(unblock); + let _ = tx.send(()); + recover.join().unwrap(); + drain(&sparse, &dev); + assert!(elapsed >= std::time::Duration::from_secs(4) && elapsed < std::time::Duration::from_secs(10), "one bounded fence timeout: {elapsed:?}"); + // Stronger than the next empty write-watch: explicitly offer the same dirty page again. + before_execute(&title, &[p], PAGE); + let after_retry = STATE.lock().unwrap().as_ref().unwrap().ring_write; + let got = read_page(&dev, &title, &source, offset); + let wrong = got.iter().filter(|&&v| v != 0x22222222).count(); + let old = got.iter().filter(|&&v| v == 0x11111111).count(); + // Diagnostic positive control: invalidate only this page's sent hashes, retry unchanged bytes. + STATE.lock().unwrap().as_mut().unwrap().clear_sent_range(p, PAGE); + before_execute(&title, &[p], PAGE); + let repaired = read_page(&dev, &title, &source, offset); + let control_wrong = repaired.iter().filter(|&&v| v != 0x22222222).count(); + println!("timeout_ms={} ring_before={before_write} ring_after_timeout={after_timeout} ring_after_retry={after_retry}", elapsed.as_millis()); + println!("words_checked={} wrong_after_retry={wrong} old_words={old} wrong_after_hash_invalidation={control_wrong}", PAGE / 4); + drain(&sparse, &dev); + assert!(free(p)); + drain(&sparse, &dev); + assert_eq!(control_wrong, 0, "same-byte upload succeeds when hashes are invalidated"); + assert_eq!(wrong, 0, "retry must upload bytes that timed out before staging"); + } +} ``` </details>
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-25 11:42 UTC · original

Test report for head 0f66820 as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's tests: upload_dirty_exits_when_ring_fence_wait_times_out ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • a smoke run on a title; AMD / native wave64; release build; the head merged onto current main

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
**@⁠xpatfussy69x** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7161390657) Test report for head `0f66820` as pushed (not merged onto current `main`) – NVIDIA, wave32. **Tested** - NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5 - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 742 passed, 0 failed, 41 ignored - SKIPPED GPU tests on this adapter: 2 (no wave64) - this PR's tests: `upload_dirty_exits_when_ring_fence_wait_times_out` ran and passed - no `XCL_SAMPLE_*` data set (game-data tests not run) **Not tested** - a smoke run on a title; AMD / native wave64; release build; the head merged onto current `main` **AI use** - Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
Author
Owner

@⁠4usphs on GitHub · 2026-11-25 11:52 UTC · original

AMD run on the exact head 0f66820 (0f66820065), as pushed on its base 47efa2e (not merged onto current main), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.

Tested

  • Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, XCL_TRANSLATED_CACHE=0; adapter picked with XCL_ADAPTER.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: 742 passed, 0 failed, 41 ignored
    • AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, gfx1036), driver 32.0.21045.29003: 742 passed, 0 failed, 41 ignored
  • No SKIPPED tests on either adapter.
  • This PR's test upload_dirty_exits_when_ring_fence_wait_times_out runs and passes on both adapters.

Not tested

  • smoke or a retail title (I have none), a release build, Linux.

AI use

  • Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
**@⁠4usphs** on GitHub · 2026-11-25 11:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7161622572) AMD run on the exact head `0f66820` (0f66820065129bca1e0cd7f3ae0125e140d835f3), as pushed on its base `47efa2e` (not merged onto current `main`), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2. **Tested** - Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, `XCL_TRANSLATED_CACHE=0`; adapter picked with `XCL_ADAPTER`. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: - AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: **742 passed, 0 failed, 41 ignored** - AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, `gfx1036`), driver 32.0.21045.29003: **742 passed, 0 failed, 41 ignored** - No `SKIPPED` tests on either adapter. - This PR's test `upload_dirty_exits_when_ring_fence_wait_times_out` runs and passes on both adapters. **Not tested** - smoke or a retail title (I have none), a release build, Linux. **AI use** - Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-25 12:19 UTC · original

Linux / AMD RDNA4 (RADV) test report for head 0f66820 merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, XCL_ADAPTER=9070 XCL_REQUIRE_GPU=wave64, --test-threads=1 --nocapture)

  • hle::d3d12x::sparse: 16 passed, 0 failed, 1 ignored (early_commit_timing), 0 skipped (2.31 s), including upload_dirty_exits_when_ring_fence_wait_times_out on RX 9070 / RADV.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

**@⁠ClosetPie107** on GitHub · 2026-11-25 12:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7162222598) Linux / AMD RDNA4 (RADV) test report for head `0f66820` merged locally onto `main` `1a0bbe3` (clean merge). **Environment** - AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS - Proton Experimental (`experimental-11.0-20261112`), vkd3d-proton v3.1 (`#257` + `dxil-spirv` `53aac418`), DXVK `v3.1.1-209`, DXC `1.9.2609.5`, `x86_64-pc-windows-gnu` cross-compile **Tested** (debug test binary under Wine, `XCL_ADAPTER=9070 XCL_REQUIRE_GPU=wave64`, `--test-threads=1 --nocapture`) - `hle::d3d12x::sparse`: **16 passed, 0 failed, 1 ignored (`early_commit_timing`), 0 skipped** (2.31 s), including `upload_dirty_exits_when_ring_fence_wait_times_out` on RX 9070 / RADV. **Not tested:** full workspace suite, retail title run, native Windows. **AI use:** T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 13:19 UTC · original

AMD RDNA3 (native wave64) test report for exact head 0f66820065129bca1e0cd7f3ae0125e140d835f3, as pushed on its base 47efa2e (not merged onto current main).

Tested

  • AMD Radeon RX 7800 XT (RDNA3, native wave64), driver 32.0.31035.1003; Windows 11 Pro 10.0.26200; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.0.5512 (dxcompiler.dll)
  • cargo build --workspace: ok
  • Targeted: upload_dirty_exits_when_ring_fence_wait_times_out: 1 passed; sparse filter: 17 passed, 0 failed, 1 ignored
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored (summed over all test binaries)
  • SKIPPED lines: none in the output

Not tested

  • No game title, no scripts/smoke.ps1 regression run (synthetic GPU/unit tests only)
  • Not merged onto current main; other GPUs (NVIDIA / Intel / RDNA2 / RDNA4)
  • Whether the new test fails without the fix; the dropped-upload risk raised in earlier comments (this run only checks the tests pass)

AI use: Claude Code (Claude Sonnet 5.5) ran the build and tests and wrote this report; the numbers are from the runs above.

**@⁠oni-swr** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7163605441) AMD RDNA3 (native wave64) test report for exact head `0f66820065129bca1e0cd7f3ae0125e140d835f3`, as pushed on its base `47efa2e` (not merged onto current `main`). **Tested** - AMD Radeon RX 7800 XT (RDNA3, native wave64), driver 32.0.31035.1003; Windows 11 Pro 10.0.26200; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.0.5512 (dxcompiler.dll) - `cargo build --workspace`: ok - Targeted: `upload_dirty_exits_when_ring_fence_wait_times_out`: 1 passed; `sparse` filter: 17 passed, 0 failed, 1 ignored - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 742 passed, 0 failed, 41 ignored (summed over all test binaries) - SKIPPED lines: none in the output **Not tested** - No game title, no `scripts/smoke.ps1` regression run (synthetic GPU/unit tests only) - Not merged onto current `main`; other GPUs (NVIDIA / Intel / RDNA2 / RDNA4) - Whether the new test fails without the fix; the dropped-upload risk raised in earlier comments (this run only checks the tests pass) **AI use**: Claude Code (Claude Sonnet 5.5) ran the build and tests and wrote this report; the numbers are from the runs above.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 04:40 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 04:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1277#issuecomment-7182809036) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
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/1277/head:github-bot/gh-1277'
git switch 'github-bot/gh-1277'

Merge

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