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!(