From e5e456cadc3855491621cf4cf9c82db08425a557 Mon Sep 17 00:00:00 2001 From: Sage <108908666+sage-sage@users.noreply.github.com> Date: Thu, 26 Nov 2026 03:47:49 -0800 Subject: [PATCH] Tests: wait for every quarantine mark before draining sparse tiles Two sparse tests failed now and then in parallel runs of the lib tests (a_tile_decommitted_and_committed_again_keeps_its_video_memory at `assert!(s.drain_quarantined())`, and flush_parked_does_not_free_or_reuse_tiles_while_unmap_is_in_flight at "completed unmap batch should drain after fence completion"). The tests wait for the sparse queue's fence and then expect the quarantined tiles to drain. But quarantine_tiles also signals a mark on every queue in present::known_queues, which keeps every queue that ever went through note_execute. In a parallel run those include other tests' queues, which can still have work in flight, so a batch can stay quarantined after the sparse queue is done. The runtime is right to wait; the tests now wait for every mark of the quarantined batches too (at most 30 s) before checking. Measured on an RTX 4080 SUPER, whole lib test binary at --test-threads=12: main 9 sparse failures in 450 runs, this change 0 in 300 (150 of them alternated with main runs). Assisted-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/sparse.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs index b7560f861e..06544b31ba 100644 --- a/crates/xcl/src/hle/d3d12x/sparse.rs +++ b/crates/xcl/src/hle/d3d12x/sparse.rs @@ -2205,6 +2205,7 @@ mod tests { assert!(s.value > v, "the unmapping is sent"); assert!(!s.flush_parked(), "nothing left to flush"); s.wait_for(s.value); + wait_for_quarantine(&s); assert!(s.drain_quarantined()); assert!(s.free.contains(&tile)); @@ -2215,6 +2216,7 @@ mod tests { s.free.clear(); assert!(s.flush_parked()); s.wait_for(s.value); + wait_for_quarantine(&s); s.commit_range(base + TILE, TILE); assert!(s.parked.is_empty()); assert_eq!(s.mapped[&(base + TILE)].pool, tile); @@ -2226,6 +2228,19 @@ mod tests { } } + /// Waits until the GPU is past every mark the quarantined tiles wait for. Besides the sparse + /// queue's, those are the marks of every title queue in `present::known_queues`, which in a + /// parallel run includes the queues of other tests that can still have work in flight. + unsafe fn wait_for_quarantine(s: &State) { + let start = std::time::Instant::now(); + for (f, v) in s.quarantined.iter().flat_map(|b| b.marks.iter().flatten()) { + while f.GetCompletedValue() < *v { + assert!(start.elapsed() < std::time::Duration::from_secs(30), "a queue did not pass its quarantine mark in 30 s"); + std::thread::sleep(std::time::Duration::from_millis(1)); + } + } + } + struct SignalOnDrop(ID3D12Fence, u64); impl Drop for SignalOnDrop { @@ -2327,6 +2342,7 @@ mod tests { gate.Signal(1).expect("release sparse queue"); s.wait_for(s.value); + wait_for_quarantine(&s); assert!(s.drain_quarantined(), "completed unmap batch should drain after fence completion"); assert!(s.free.contains(&tile), "unmapped tile must return to free list once unmap fence completes"); drop(_unblock);