From ec101631cfee8fc2935fbfae9797096ab1a5a2cd Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 9 Nov 2026 04:08:08 -0800 Subject: [PATCH] Carry tests: the lost generation's blocks, not bytes allocated; the lane test lets go of its raw handles The rest probe (m3-max-11599, a print of the rest check's inputs, never landed) showed every lost generation coming to rest in both failing tests, and releasing its carried parts. Both failures were in the tests. - WorkCounts::device_memory_allocated counts bytes allocated so far, freed since or not, so it never falls. The carry test now checks the lost generation's live blocks (with a placement, or kept empty). The probe showed 2 before the loss and 1 at rest. The test also requires that the rest freed some (memory_frees.teardown). - The lane test's device was made through creation_checked, whose creation_kinds reads the driver's pipeline cache through Device::raw. Those handles keep the first generation's VkDevice until a later raw() call, as the neighbouring test there says. The test now makes that call before it waits for one live VkDevice. (cherry picked from commit 44a5fc55c935bf8c000884487f3561c5551e6734) --- .../src/tests/device_recovery_carry.rs | 28 ++++++++++--------- .../src/runtime_lane/device_recovery.rs | 5 ++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs index 39d338b3e..4acb6bc6f 100644 --- a/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs +++ b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs @@ -213,22 +213,24 @@ fn a_recovery_carries_events_private_and_fresh_page_buffers() { // It holds the lost `VkDevice`, which keeps no memory for work. assert_eq!(live_vk_devices(&device, 2), 2); let after = pooled.device().work_counts_now(); + let blocks = + |counts: &crate::WorkCounts| counts.memory_blocks_live + counts.empty_memory_blocks_live; + eprintln!( + "CARRY-LOST-MEMORY: {}: the lost generation held {} blocks before the loss, {} at rest, \ + {} freed as it came to rest", + device.name(), + blocks(&before), + blocks(&after), + after.memory_frees.teardown - before.memory_frees.teardown + ); assert_eq!(after.empty_memory_blocks_live, 0, "{after:?}"); assert!( - after.device_memory_allocated + REUSED <= before.device_memory_allocated, - "the lost generation holds {} bytes, {} before the loss", - after.device_memory_allocated, - before.device_memory_allocated - ); - eprintln!( - "CARRY-LOST-MEMORY: {}: the lost generation held {} bytes in {} blocks before the loss, \ - {} in {} at rest", - device.name(), - before.device_memory_allocated, - before.memory_blocks_live, - after.device_memory_allocated, - after.memory_blocks_live + blocks(&after) < blocks(&before), + "the lost generation holds {} blocks, {} before the loss", + blocks(&after), + blocks(&before) ); + assert!(after.memory_frees.teardown > before.memory_frees.teardown); drop(pooled); assert_eq!(live_vk_devices(&device, 1), 1); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs b/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs index 71853f096..78e6866bf 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs @@ -329,6 +329,11 @@ fn carried_objects_serve_on_the_new_vk_device() { let bytes = unsafe { std::slice::from_raw_parts(contents.as_ptr(), 4096) }; assert!(bytes.iter().all(|&byte| byte == round)); } + // The handles `Device::raw` answered as the lane checked the device's making + // (`creation_kinds` reads the driver's pipeline cache through them) keep the first + // generation's `VkDevice` until a later call answers the serving one's. + // SAFETY: the handles are read and not used. + let _ = unsafe { device.raw() }; let began = Instant::now(); while device.work_counts().vk_devices_live > 1 && began.elapsed() < Duration::from_secs(60) {