From d9d61177814f328158bcb5f27c9190f7bf253933 Mon Sep 17 00:00:00 2001 From: Prime1997 Date: Mon, 23 Nov 2026 17:55:14 -0800 Subject: [PATCH] Tests: cover Wait64 recording and satisfied batch submission The existing PendingWait checks construct the comparison directly, and the submission check manually pushes a 32-bit wait. Exercise wait64_x itself so interpreting the trailing flags slot as a mask cannot return unnoticed. Check high counter bits, garbage flag upper halves, unfinished and equal counters, and the unchanged Wait32 mask; an already satisfied Wait64 must keep the submitted batch together. The production correction from Sr-0w PR #218 is already in upstream d4f17ca. This commit ports only the two original synthetic controls from42297943db3cfd4cf14ee37a7a0a53b8888d0d2c, byte-identical. Earlier separate negative controls captured both incorrect stored mask and a 2000ms false timeout/batch split with the old behavior. Fresh release focused run on official508a0c7 plus these tests:2passed,0failed,0ignored. Broader validation follows on this clean head. Assisted-by: OpenAI Codex (exact model variant not exposed) --- crates/xcl/src/hle/d3d12x/list_x.rs | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index 2080100306..40b07ff380 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -2741,6 +2741,59 @@ mod tests { } } + #[test] + fn wait64_flags_do_not_mask_the_recorded_counter() { + let mut token = 0usize; + let list = (&mut token as *mut usize).cast::(); + let cell = AtomicU64::new(0); + let va = &cell as *const AtomicU64 as u64; + for (current, wanted, flags) in [ + (2, 1, 0x231_0000_0001), + (4, 2, 0x270_0000_0001), + (5, 3, 1), + (0x1_0000_0004, 0x1_0000_0002, 0xFFFF_FFFF_0000_0001), + ] { + cell.store(current, Ordering::Release); + unsafe { wait64_x(list, va, D3D12_COMPARISON_FUNC_GREATER_EQUAL.0 as u32, wanted, flags, 0) }; + let waits = LISTS.lock().unwrap().as_ref().unwrap()[&(list as usize)].pending_waits.clone(); + on_release(list as usize); + assert_eq!(waits.len(), 1); + let w = waits[0]; + assert_eq!((w.width, w.value, w.mask), (8, wanted, u64::MAX)); + unsafe { + assert!(w.is_satisfied(), "{current:#x} >= {wanted:#x}; flags {flags:#x}"); + cell.store(wanted - 1, Ordering::Release); + assert!(!w.is_satisfied(), "a genuinely earlier counter must still wait"); + cell.store(wanted, Ordering::Release); + assert!(w.is_satisfied(), "equality satisfies GREATER_EQUAL"); + } + } + } + + #[test] + fn wait64_satisfied_counter_keeps_submission_together_and_wait32_keeps_its_mask() { + let mut tokens = [0usize; 2]; + let lists = [tokens.as_mut_ptr().cast::(), unsafe { tokens.as_mut_ptr().add(1).cast::() }]; + let cell64 = AtomicU64::new(4); + let cell32 = AtomicU32::new(0xDEAD_005A); + unsafe { + wait64_x(lists[1], &cell64 as *const AtomicU64 as u64, D3D12_COMPARISON_FUNC_GREATER_EQUAL.0 as u32, 2, 0x270_0000_0001, 0); + } + let mut batches = Vec::new(); + unsafe { execute_with_waits(&lists, |chunk| batches.push(chunk.to_vec())) }; + on_release(lists[1] as usize); + assert_eq!(batches, vec![lists.to_vec()], "an already satisfied counter must not split the batch"); + + unsafe { + wait32_x(lists[0], &cell32 as *const AtomicU32 as u64, D3D12_COMPARISON_FUNC_EQUAL.0 as u32, 0x5A, 0xFF, 0); + } + let waits = LISTS.lock().unwrap().as_ref().unwrap()[&(lists[0] as usize)].pending_waits.clone(); + on_release(lists[0] as usize); + assert_eq!(waits.len(), 1); + assert_eq!((waits[0].width, waits[0].mask), (4, 0xFF)); + assert!(unsafe { waits[0].is_satisfied() }); + } + #[test] fn written_ranges_detect_same_list_overlap() { let mut s = ListState::default();