Repository navigation
Conversation
|
Test report for the open point in the description: this port ( Tree: Merge: two conflicts in
Tests on the merged tree:
Retail title (edit): two runs of retail 1.0.2.1 on this combination, Series X profile, on the same tree plus later local merges (#1288, #1422, #1429, #1284 and local diagnostics), so they say little about this PR alone:
Not tested: the whole suite, AMD. AI use: Claude Code (Claude Opus 5.5) did the merge, ran the tests and wrote this report. |
The queue of the sparse windows (tile mappings, uploads of CPU writes, copies back) can stand still for as long as the GPU does. Two title threads waited for it on the CPU with the sparse state's mutex held: - a Map with a read range (sparse::readback_now -> readback_ranges -> wait_for), 5 s for each copy back, and after the 5 s it copied the readback buffer into the CPU's view without the copy in it; - a submit (sparse::before_execute -> upload_dirty), which waited for room in the 64 MiB upload ring in a loop that does not end while the queue stands still. Every other use of the lock stood behind them: commits and decommits (a thread moving physical pages), the next Map, the next submit, the activity line. Now the wait is made with the lock released (wait_released) and the state is looked at again after it. The uploads go a part at a time, each as large as the ring has room for (upload_room), scanned and uploaded in one hold of the lock, so the hole checks and the sent hashes stay as they were. A copy back is submitted, waited for with the lock released and then copied into the pages still committed; READBACK keeps the one readback buffer to one copy at a time. A copy back the queue has not made after 5 s leaves the CPU's view as it is. No upload is dropped: a submit still waits until the ring has room. Measured with tests/sparse_lock_released.rs (the sparse queue held by a fence): on main a commit and a submit on another thread are not through within 2 s behind a Map or behind a submit; with this both are, the Map returns the GPU's bytes and the submit's 96 MiB are in video memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22dd7d0 to
0012965
Compare
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Integration follow-up: the exact PR diff applies cleanly to main Readback follow-up on the same exact head The identical fixture on #1495 overwrites all1,024CPU words with old GPU data on both adapters, while its exact parent preserves them. Complete six-run comparison and fixture. This adds readback-timeout preservation evidence; it does not test the Map ABI, concurrent CPU writes during readback, or resolve the separate integration failure above. Codex (GPT-6) wrote and ran the synthetic fixture and prepared this report. No runtime change or competing PR. Independent native Windows validation of This supports the approach already implemented here for the dropped-upload risk you identified in #1277. I reproduced that risk on exact heads of #1277 and #1495; those reports use their own exact-parent controls. Tested
No skips or harness timeouts. Parent lock tests exit101 with both The additional diagnostic uses the same readback oracle as the #1277/#1495 checks: old0x11 bytes, one4KiB page changed to0x22, a queue held across its five-second warning, then six-second recovery. All1,024GPU words match on both parent and head. Head waits6018ms (3090) /6011ms (AMD); parent6012ms /6018ms. Ring write position advances67108864→67112960, and a same-page retry preserves the correct bytes. Queue drain and device-removal checks pass. Fixture adaptation: this PR reserves a page of upload-admission headroom, so the earlier fixture's first64MiB Commands, each with Windows10 Home19045; Ryzen7 7800X3D; RTX3090 driver591.74 / AMD Radeon integrated32.0.21030.2001; Rust1.98.1 MSVC, Agility1.620.2, debug, SSH Session0. This adds the previously untested AMD/debug coverage for these cases. All227source hashes match each tree; head restored and reverified afterward. Local patch reverse-apply and diff checks pass. Integration with main after #680 (separate trees, original author diff only) Main: Native interactive Session1, same hardware/toolchain,
Both test commands exit101; no timeout. Both have four explicit skips: native-wave64 reference tests Both share the known integer-CLAMP failure and a newly merged configuration-sensitive failure: Additional failure still unexplained: in the integrated first full run, Bounded follow-up on unchanged sources:
The single additional close failure has not been reproduced or attributed to this PR; those later passes do not explain it. Debug-layer diagnostics were unavailable in these runs. No complete full-workspace rerun with heap windows enabled, retail run, or claim that all integration gates are satisfied. All227baseline/228candidate file hashes match before and after testing; original worktrees retained. Not tested AI use Complete local diagnostic and explicit-adapter patch against0012965diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index d48b6d6..3d6f9f7 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -2393,3 +2393,7 @@ mod tests {
}
}
}
+
+#[cfg(test)]
+#[path = "sparse_timeout_probe.rs"]
+mod sparse_timeout_probe;
diff --git a/crates/xcl/tests/sparse_lock_released.rs b/crates/xcl/tests/sparse_lock_released.rs
index e071d61..fab1308 100644
--- a/crates/xcl/tests/sparse_lock_released.rs
+++ b/crates/xcl/tests/sparse_lock_released.rs
@@ -13,6 +13,7 @@ use windows::core::Interface;
use windows::Win32::Foundation::{CloseHandle, WAIT_OBJECT_0};
use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
use windows::Win32::Graphics::Direct3D12::*;
+use windows::Win32::Graphics::Dxgi::*;
use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_UNKNOWN, DXGI_SAMPLE_DESC};
use windows::Win32::System::Threading::{CreateEventW, WaitForSingleObject};
@@ -46,9 +47,13 @@ fn a_wait_for_the_sparse_queue_does_not_hold_the_state() {
unsafe {
std::env::set_var("XCL_UMA_MB", "64");
std::env::set_var("XCL_COHERENT_MB", "64");
- let Ok(dev) = xcl::gpu::agility::create_device(None, D3D_FEATURE_LEVEL_11_0) else {
+ let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
+ let selector = xcl::gpu::adapter::Selector::from_env_or("auto");
+ let Some((adapter, desc)) = xcl::gpu::adapter::candidates(&factory, &selector).into_iter().next() else {
return xcl::gpu::recomp::runner::skip_test("no GPU");
};
+ println!("adapter={}", xcl::gpu::adapter::name(&desc));
+ let dev = xcl::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_11_0).unwrap();
let windows = sparse::init(&dev);
let Some(&(k, raw, _)) = windows.first() else {
return xcl::gpu::recomp::runner::skip_test("no GPU");
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,119 @@
+//! Local PR1385 recovery 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();
+ before_execute(&title, &[], PAGE);
+ drain(&sparse, &dev);
+ drain(&title, &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);
+ // PR1385 reserves one page of admission headroom; prime the full real ring directly.
+ // Seed the tested page's sent hashes using the production scanner, then stage actual bytes.
+ {
+ let mut g = STATE.lock().unwrap();
+ let s = g.as_mut().unwrap();
+ let mut scanned = Vec::new();
+ let data = std::slice::from_raw_parts(p as *const u8, PAGE);
+ scan_page(data, p, &mut s.mapped.get_mut(&p).unwrap().sent[0], &mut scanned);
+ assert_eq!(scanned, vec![(p, PAGE)]);
+ s.upload_dirty(&[(p, bytes)]);
+ }
+ 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");
+ }
+} |
GonZiin
left a comment
There was a problem hiding this comment.
I verified that the sparse queue regression test fails on the parent, passes on this head, and passes in the full workspace after merging with current main. Given the separate results on #1277 and #1495 showing pending uploads lost after a timeout, I would use #1385 as the candidate for the shared upload-ring problem and keep the recovery cases in its review.
Tested
- Windows 11 Pro 26300, Ryzen 7 7800X3D, Radeon RX 9070 XT (driver 32.0.32029.2010), SDK DXC 1.8.2502.11, Rust 1.100.0 MSVC, debug. Set
XCL_ADAPTER=RX 9070 XTfor the workspace harness. The standalone integration fixture creates the default D3D12 device. cargo test -p xcl --test sparse_lock_released -- --test-threads=1 --nocaptureon head0012965eda27e2a528b02c8722a415bde3c02788gave 1 passed, 0 failed and 0 ignored. The unchanged test copied onto parent17216a14638659e550b76e3e8245728209b86b70gave 0 passed, 1 failed and 0 ignored. Both the Map and submit cases on the parent held up the other thread past the two-second limit..\scripts\test.ps1on the clean temporary merge withmainat9e3831e1f570d3646e53ab753b19ec07eb8f1485(tree66e1c11376a91a0e5f23fbbf1c362194e38d6c71) exited 0. It reported 777 passed, 0 failed and 41 ignored. One GPU skip within the passing count washeap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows). Both the sparse queue fixture and the bundled title end-to-end test passed.
Not tested
Retail titles, opt-in sample data and the other two PRs' timeout-recovery probes on this machine.
AI use
Codex (gpt-6.2-sol) compared the three proposals, ran the Windows tests and drafted this review.
|
Retail-title run on NVIDIA. GTA VI 1.0.2.1, RTX 3080 Ti (driver 610.88), Windows 11, release,
On main + #433 the symbolised thread dumps show the run is killed because a thread holds Not tested: AMD; together with #433. AI use: Claude Code (Claude Opus 5.5) ran the box, read the log and wrote this report. |
|
Linux / Proton check of the upload-slot path in Runtime comparison on RTX 5080 / 620.73.04, EndeavourOS, Ryzen 9 9950X3D, ~60 GiB usable RAM, Proton Experimental. Same instrumented Test orchestration and report assisted by Codex (GPT-6.2 Astra). Two instrumented repeats, same PR and cache starting point. One run logged a sparse timeout (target 37865, completed 37861) and lost the device at 222.357 s. The diagnostic did not recover the origin of that signal. With the diagnostic moved outside the state lock, the next run reached |
|
Tested commit Tested
Regression run ( Base ( PR ( Not tested
AI use
|
|
Empirical test report for PR #1385 on Intel Arc A770 (
Tested
Not tested
AI use
|
Two title threads waited on the CPU for XCL's sparse queue while holding the sparse state's mutex: a
Mapfor its copy back, and a submit for room in the upload ring. While the GPU stood still, so did every other thread that needed the lock: commits and decommits, the nextMap, the next submit, the activity line. This makes those waits with the lock released. Part of #505.In the newer retail title (#505) on an RTX 5080, with bounded pipeline waits (
XCL_PSO_WAIT_MS=50) andApressed at 20 s, thread dumps taken while its frames had stopped (on67a3735+ #433 + #968) showed the two waits above holding the lock for 15 s and more, with a thread moving physical pages and the nextMapstanding at it. With this change the "sparse: the queue has not reached fence value" lines are gone in the runs below and the title runs about 60–70 s longer before its watchdog ends it. It still ends there: the title's GPU queues waiting on each other (thequeue.Wait … released on CPUlines) are not changed by this.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:wait_released: the wait for the sparse queue's fence (5 s at most, as before) withSTATEreleased; the state is looked at again after it.upload_room/room_released: before each part of the uploads, the two command slots and the ring are checked and waited for with the lock released.before_executeandreadback_nowupload a part at a time, each as large as the ring has room for, scanned and uploaded in one hold of the lock. The waits insidebegin_slotandupload_dirtystay as they are and are not met any more.readback_released: a copy back (readback_now,readback_after_execute) is submitted (readback_submit), waited for with the lock released, then copied into the pages still committed (copy_back, taken out ofreadback_ranges).READBACKkeeps the one readback buffer to one copy at a time; it is taken beforeSTATE.crates/xcl/tests/sparse_lock_released.rs: the sparse queue is held by a fence. (1) A thread maps 8 bytes the GPU wrote; (2) a thread submits 96 MiB of CPU writes, more than the ring holds. In both, a commit and a submit on another thread must be through within 2 s; then theMapmust return the GPU's bytes and the first and last 8 bytes of the 96 MiB must be in video memory.Map), then the uploads (submit).Other open PRs on the same lock:
upload_dirty's ring loop after 5 s and drops the uploads that remain (their chunk hashes are already updated, so they are not sent later). This PR keeps them and gives the lock up instead. The two change the same loop; only one is needed.readback_after_execute(the copy back goes on the title's queue, landed by a worker). This PR keeps main'sreadback_after_executeand only moves its wait out of the lock.copy_backhas the signature D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433 gives it, so a rebase of either is mechanical. The first version of this change was written on67a3735+ D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433 + D3D12.X: the late-release drain gets the sparse queue without the sparse state's lock #968; there D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433's two tests passed with it (sparse_readback_lands,sparse_readback_waits: 1 passed each). This port tomainwas not run together with D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433.QUEUEstatic next to this PR'sREADBACK) and D3D12.X: release sparse buffer pins outside the driver callback #789 take other ways into the same lock away (sparse::queue(),forget_bufferfrom a release inside D3D12). Independent of this.Tested
NVIDIA GeForce RTX 5080 (driver 621.24 = 32.0.16.2124), AMD Ryzen 7 5800X3D, 32 GB, Windows 11 Pro 10.0.26200, Rust 1.100.0
stable-x86_64-pc-windows-msvc, release. On0012965(this PR rebased ontomain17216a1).cargo test --release -p xcl --test sparse_lock_released(before the rebase, on930e8b4):main(930e8b4) with only the test added: 0 passed, 1 failed after 5.6 s ("through within 2 s – behind a Map: false, behind a submit: false");cargo test --release -p xcl --lib sparse -- --test-threads=4: 16 passed, 0 failed, 1 ignored.cargo build --release --workspace && cargo test --release --workspace -- --test-threads=4on0012965: 761 passed, 0 failed, 41 ignored (752 / 0 / 41 on22dd7d0, before the rebase).SKIPPED:
gpu_wave32_program_in_wave64_hardware,gpu_geometry_wave32_prefix_count_over_a_mask(no wave64).The newer retail title (Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505), release,
XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=50 XCL_PRESS_AT=20:A XCL_RUN_SECONDS=300, warm DXIL and driver caches, counts fromxcl.log:main930e8b4+0x4684e7main930e8b4+0x23cf683)22dd7d0, before the rebase)22dd7d0, before the rebase)This PR's run 1 is left out: the scripted
Awas not taken (no GameInput line), so it stayed on the title screen. Earlier the same day, on67a3735+ D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433 + D3D12.X: the late-release drain gets the sparse queue without the sparse state's lock #968: without this change 3–9 such lines in each of 4 runs, ending at 168–176 s; with it 0–1 lines, ending at 164 s and 262 s. These are few runs and the title's runs vary a lot; the stall lines are the clear difference.Regression run
main:
this PR:
Not tested
title_textures::refreshholds its own lock (REFRESH) aroundbefore_execute.UpdateTileMappingsandCreateHeapare still called with the lock held.AI use
🤖 Generated with Claude Code