From ccb067d2af150f9d962a3dabea946bc3caab2ee5 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 09:31:46 -0800 Subject: [PATCH] Tests: a time breach is asked once more by a later device The stage cache's time breach (StageBreach::Time) refused its pipeline on every later device life until the driver's version changed. So one helper compile past the consumer's time limit, on a loaded host for example, refused a heavy kernel for good. Main's ruling: the record counts the device lives that met the breach. The first refuses in its own life alone, and a later device asks the helper once more. A second, in another life, refuses in every life, as before. A fill after the first clears the count. The record's format version is bumped, so old records are dropped, not trusted. tests/stage.rs, on a device, through the public API alone: - a_time_breach_is_asked_once_more_by_a_later_device: six device lives on one cache directory. - The first keeps a time breach and is refused. - The second asks for the same fill. A helper's fill there takes the breach's place, and the pipeline is made. - The third makes the pipeline from that fill. - The fourth keeps a time breach before its make (a first again) and is refused. - The fifth asks past it, keeps its own breach (the second life's), and is refused. - The sixth is refused, with no fill asked. - a_helper_killed_mid_make_leaves_every_make_its_refusal_at_once: after the time breach, the later device now asks for the same fill once. Its own breach then refuses there and on the device after it. The memory breach is unchanged. Verified (red): Radeon 780M (RADV PHOENIX, Mesa 26.2.6), m3-max-79073, at this commit. Both tests fail where the later device is refused: "Some(Unsupported(StageSize { weight: 204, cause: Breach(Time) }))" (stage.rs:577 "the second life"; stage.rs:782 "a later device, one time breach"). tests::stage: 11 tests run, 9 passed, 2 failed, 897 skipped. --- .../metal2vulkan-runtime/src/tests/stage.rs | 116 +++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/stage.rs b/crates/metal2vulkan-runtime/src/tests/stage.rs index 24e0a1201..76f9785da 100644 --- a/crates/metal2vulkan-runtime/src/tests/stage.rs +++ b/crates/metal2vulkan-runtime/src/tests/stage.rs @@ -529,6 +529,102 @@ mod on_device { } } + /// A time breach, kept as the consumer keeps one for a helper past its time limit, refuses the + /// pipeline's makes in its own device's life alone. A later device on the same directory asks + /// for the same fill, once; a fill there takes the breach's place, so the device after it + /// makes the pipeline from that entry. A time breach kept after the fill, by a device before + /// its make, is a first again, refused there: a later device asks past it, and the breach + /// that device keeps is the second life's, which refuses on every device after it, with no + /// fill asked. + #[test] + fn a_time_breach_is_asked_once_more_by_a_later_device() { + let Some(descriptor) = tiled() else { + return; + }; + crate::stage::TEST_BOUND.store(1, Relaxed); + let instance = crate::tests::validation::instance(&[]); + let devices = devices_of_the_cfgs_kind(&instance); + assert!(!devices.is_empty(), "no device of this cfg's kind"); + let make = |device: &Device| { + device.new_compute_pipeline_state(&descriptor, crate::tests::no_constexpr_samplers) + }; + let helpers: &crate::Instance = &instance; + for (name, physical) in &devices { + let scratch = Scratch::new("stage-time-lives"); + let device = on(name, physical, Some(&scratch.0), 0); + if !crate::tests::keeps_a_blob(name, &device) { + continue; + } + let request = match make(&device) { + Err(Error::StageUnfilled(request)) => request, + other => panic!("{name}: {:?}", other.err()), + }; + let refused = |what: &str, device: &Device| { + let refused = make(device).err(); + assert!( + matches!( + refused, + Some(Error::Unsupported(Gap::StageSize { + cause: StageGap::Breach(StageBreach::Time), + .. + })) + ), + "{name}: {what}: {refused:?}" + ); + }; + let asked = |what: &str, device: &Device| match make(device) { + Err(Error::StageUnfilled(again)) => assert_eq!(again, request, "{name}: {what}"), + other => panic!("{name}: {what}: {:?}", other.err()), + }; + // The first life keeps the breach, and is refused. + device.record_stage_breach(&request, StageBreach::Time); + refused("the first life", &device); + drop(device); + // The second asks once more, and a helper's fill takes the breach's place. + let device = on(name, physical, Some(&scratch.0), 0); + asked("the second life", &device); + let (helper_in, to_helper) = std::io::pipe().expect("a pipe"); + let (from_helper, helper_out) = std::io::pipe().expect("a pipe"); + let filled = std::thread::scope(|scope| { + let helper = scope.spawn(move || { + serve_stage(helpers, DeviceOptions::default(), helper_in, helper_out) + }); + let filled = device.fill_stage(&request, to_helper, from_helper); + helper + .join() + .expect("the helper's thread") + .expect("the helper's pipes"); + filled + }); + filled.unwrap_or_else(|fill| panic!("{name}: the fill: {fill}")); + make(&device).unwrap_or_else(|error| panic!("{name}: after the fill: {error}")); + drop(device); + // The third makes it from the fill. + let device = on(name, physical, Some(&scratch.0), 0); + make(&device).unwrap_or_else(|error| panic!("{name}: the third life: {error}")); + drop(device); + // A time breach the fourth keeps before its make is a first again, refused there. + let device = on(name, physical, Some(&scratch.0), 0); + device.record_stage_breach(&request, StageBreach::Time); + refused("the fourth life, its own breach", &device); + drop(device); + // The fifth asks past it; its own breach is the second life's. + let device = on(name, physical, Some(&scratch.0), 0); + asked("the fifth life", &device); + device.record_stage_breach(&request, StageBreach::Time); + refused("the fifth life, the second breach", &device); + drop(device); + // Every later device is refused, with no fill asked. + let device = on(name, physical, Some(&scratch.0), 0); + refused("the sixth life", &device); + assert_eq!(device.counters().metrics().stage_fills, 0, "{name}"); + println!( + "{name}: a time breach refused its own life, was asked past once by the next, \ + cleared by its fill; kept again, asked past once, then refused in every life" + ); + } + } + /// A helper that ends before its reply, as one whose driver faults in the compile does, gives /// the fill [`crate::StageFill::Ended`]; the consumer keeps that end as /// [`StageBreach::Ended`], and the next make, and a later device's on the same directory, is @@ -595,8 +691,10 @@ mod on_device { /// [`StageBreach::Memory`] or [`StageBreach::Time`], then answers every make of the pipeline /// with its typed refusal ([`Gap::StageSize`]) as the call returns: four makes on threads of /// their own at once, and a later device's on the same directory, with no helper asked again - /// and no fill counted. Every call is given the tests' patience on a thread of its own, so - /// one that waits for good fails the test rather than hanging it. + /// and no fill counted; but a time breach kept in one device life alone, which a later device + /// asks past once (the same request), and refuses there once kept in that life too. Every call + /// is given the tests' patience on a thread of its own, so one that waits for good fails the + /// test rather than hanging it. #[test] fn a_helper_killed_mid_make_leaves_every_make_its_refusal_at_once() { use crate::tests::command::on_device::PATIENCE; @@ -675,7 +773,19 @@ mod on_device { } }); drop(device); - let device = on(name, physical, Some(&scratch.0), 0); + let mut device = on(name, physical, Some(&scratch.0), 0); + // A time breach of one life: the later device asks the helper once more, and its + // own breach is the second life's, which refuses in every life. + if breach == StageBreach::Time { + match bounded(name, &device) { + Some(Error::StageUnfilled(again)) => assert_eq!(again, request, "{name}"), + other => panic!("{name}: a later device, one time breach: {other:?}"), + } + device.record_stage_breach(&request, breach); + refused(&format!("{name}: the second life's time breach"), &device); + drop(device); + device = on(name, physical, Some(&scratch.0), 0); + } refused(&format!("{name}: a later device, {breach:?}"), &device); assert_eq!(device.counters().metrics().stage_fills, 0, "{name}"); println!(