diff --git a/crates/metal2vulkan-runtime/src/tests/blit_holds.rs b/crates/metal2vulkan-runtime/src/tests/blit_holds.rs index 852d30e35..8ddcff5cf 100644 --- a/crates/metal2vulkan-runtime/src/tests/blit_holds.rs +++ b/crates/metal2vulkan-runtime/src/tests/blit_holds.rs @@ -17,6 +17,7 @@ //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. +use super::plan_room::device_with_room; use crate::error::RuntimeGap; use crate::{ BlitCommandEncoder, BlitOption, Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, @@ -177,7 +178,7 @@ pub(super) fn shadow_device(cache: &Path) -> Device { pub(super) fn plan_device(cache: &Path) -> Device { let mut options = options(cache); options.queue_limits = None; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// The options of [`device`]. diff --git a/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs b/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs index 629d46242..d5b57056b 100644 --- a/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs +++ b/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs @@ -21,6 +21,7 @@ //! shape and what each round read. use super::blit_holds::Scratch; +use super::plan_room::device_with_room; use crate::{ BlitOption, Buffer, BufferContents, BufferDescriptor, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, IoSurfacePlane, Origin, ReservedQueue, ResourceOptions, @@ -69,7 +70,7 @@ fn device(cache: &Path) -> Device { queue_limits: None, ..DeviceOptions::default() }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// The queue the caller submits to. diff --git a/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs b/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs index ae83503b8..57eafc724 100644 --- a/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs +++ b/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs @@ -12,6 +12,7 @@ //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. +use super::plan_room::device_with_room; use crate::{ Buffer, CommandBuffer, CommandBufferError, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, EncoderKind, EventRef, ResourceOptions, Submission, @@ -63,7 +64,7 @@ fn device_of(base: DeviceOptions) -> Device { }, ..base }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// A command buffer of `queue` that fills `target` whole with `value`. diff --git a/crates/metal2vulkan-runtime/src/tests/completion.rs b/crates/metal2vulkan-runtime/src/tests/completion.rs index 59dee01f4..6cea4e26d 100644 --- a/crates/metal2vulkan-runtime/src/tests/completion.rs +++ b/crates/metal2vulkan-runtime/src/tests/completion.rs @@ -86,6 +86,7 @@ //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. +use super::plan_room::device_with_room; use crate::{ host_time, CommandBuffer, CommandBufferStatus, Device, DeviceKind, DeviceOptions, ResourceOptions, ShaderCacheOptions, @@ -162,7 +163,7 @@ fn device(cache: &Path) -> Device { queue_limits: None, ..DeviceOptions::default() }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// Whether `device`'s GPU end times are when the GPU ended the work: its timestamps, placed on diff --git a/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs b/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs index d9f4bc613..2eb53cd50 100644 --- a/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs @@ -16,6 +16,7 @@ //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. +use super::plan_room::device_with_room; use crate::command_buffer::completion; use crate::{ Buffer, CommandBuffer, CommandQueue, Device, DeviceKind, DeviceOptions, EventRef, @@ -60,7 +61,7 @@ fn device_of(base: DeviceOptions) -> Device { }, ..base }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// A command buffer of `queue` that fills `target` whole with `value`. diff --git a/crates/metal2vulkan-runtime/src/tests/draw_again.rs b/crates/metal2vulkan-runtime/src/tests/draw_again.rs index 127896e43..fb0bac110 100644 --- a/crates/metal2vulkan-runtime/src/tests/draw_again.rs +++ b/crates/metal2vulkan-runtime/src/tests/draw_again.rs @@ -22,6 +22,7 @@ use super::blit_holds::{until, Scratch, WAIT}; use super::encoder_holds::{bytes_of, library, pass, words_of}; +use super::plan_room::device_with_room; use super::rebind_behind_a_wait::{Page, BYTES}; #[cfg(debug_assertions)] use crate::render::dynamic_compares; @@ -91,7 +92,7 @@ fn device_of(cache: &Path, each: &[Degradation], heard: &Heard, base: DeviceOpti announce_each: each.iter().copied().collect(), ..base }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// The draws again of a pass of [`DRAWS`] of the same draw: all but its first, which begins the diff --git a/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs b/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs index 4cfe7de7f..e38ae4305 100644 --- a/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs +++ b/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs @@ -30,6 +30,7 @@ //! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). use super::blit_holds::{Scratch, WAIT}; +use super::plan_room::device_with_room; #[cfg(unix)] use crate::error::{Error, RuntimeGap}; use crate::{ @@ -75,7 +76,7 @@ fn device(cache: &Scratch) -> Device { ..DeviceOptions::default() }; options.policy.queue_sharing = QueueSharingPolicy::PerQueue; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// A command queue on another `VkQueue` than the device's first, with the queues made before it diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index f3c9b53d1..c5f829fe1 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -578,6 +578,8 @@ mod pipeline_wait_order; #[cfg(unix)] mod pixel_format_info; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod plan_room; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod point_size_notices; #[cfg(all(any(m2v_gpu, m2v_cpu_icd), target_os = "linux"))] mod pointer_residency; diff --git a/crates/metal2vulkan-runtime/src/tests/plan_room.rs b/crates/metal2vulkan-runtime/src/tests/plan_room.rs new file mode 100644 index 000000000..b5cdc8137 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/plan_room.rs @@ -0,0 +1,113 @@ +//! A device of the queue plan in the runtime's own device tests, made again while the driver +//! lacks room for it (test tooling). +//! +//! A test whose work needs the plan's queues makes its device with `queue_limits: None`. The +//! driver shares what a device needs among every process's devices: NVIDIA's gives each +//! `VkQueue` a channel, and an RTX 2080 (NVIDIA 620.70.06) holds about 210 across processes, 11 +//! devices of the plan's 18 (`create.rs`'s `made_within_resources`). Beside the suite's other +//! test processes the driver refuses the plan there, and the runtime makes the device with its +//! least plan (10 of the 12 `queue_share_device` tests ran on it in one run of 31 queue tests at +//! 16 threads), whose command queues share one `VkQueue`, or refuses that too +//! (`Error::DeviceRefused`). A test of the plan's queues would then run without them and could +//! pass on what it does not test. +//! +//! So [`device_with_room`] makes such a device again, the one made dropped first, after a pause +//! that doubles from [`FIRST_PAUSE`] up to [`LONGEST_PAUSE`], until [`ROOM_WAIT`] in all has +//! passed, each pause a `PLAN-DEVICE-ROOM` line on standard error naming the answer and the time +//! waited: the evidence that the wait ran. Past the bound a refusal is handed back, and a device +//! still of its least plan fails the test. A device dropped so has delivered its notices to the +//! options' sink, as a device the test kept would have. A test of the least plan itself makes its +//! device without this, the driver's refusal stood in for (`refuse_next_devices`). + +use super::blit_holds::Scratch; +use crate::device::create::{queue_plan, refuse_next_devices}; +use crate::{Device, DeviceKind, DeviceOptions, Error, ShaderCacheOptions}; +use std::time::Duration; + +/// The first pause before a device is asked for again. +const FIRST_PAUSE: Duration = Duration::from_millis(250); + +/// The longest pause between two asks. +const LONGEST_PAUSE: Duration = Duration::from_secs(2); + +/// The most a device waits for room, in all: the suite's other processes' devices of a refused +/// one's time have gone well within it. +const ROOM_WAIT: Duration = Duration::from_secs(120); + +/// The device `options` make, of the `VkQueue`s they ask for (the queue plan's where +/// `queue_limits` is `None`): made again while the driver refuses it for want of what other +/// devices hold (`Error::DeviceRefused`) or it took its least plan, until [`ROOM_WAIT`]. Any other +/// error is returned at once, and a refusal past the bound; a device of its least plan past the +/// bound fails the test here. +pub(super) fn device_with_room(options: &DeviceOptions) -> Result { + let mut waited = Duration::ZERO; + let mut next = FIRST_PAUSE; + loop { + let made = Device::system_default_with(options); + let answer = match &made { + Ok(device) if device.shared().least_plan => { + format!("the device on {} took its least queue plan", device.name()) + } + Err(Error::DeviceRefused(refused)) => refused.to_string(), + _ => return made, + }; + if waited >= ROOM_WAIT { + eprintln!("PLAN-DEVICE-ROOM: {answer}; no room after {waited:?}"); + return match made { + Err(error) => Err(error), + Ok(_) => panic!( + "{answer} after {waited:?} of pauses: a test of the plan's queues runs on \ + them or not at all" + ), + }; + } + drop(made); + eprintln!("PLAN-DEVICE-ROOM: {answer}; asked again in {next:?} ({waited:?} waited)"); + std::thread::sleep(next); + waited += next; + next = (next * 2).min(LONGEST_PAUSE); + } +} + +/// A device of the plan the driver refused once (the stand-in, `refuse_next_devices`) is made +/// again of the plan's queues: on a GPU of queues to spare its first making took the least plan, +/// and on one whose least plan takes no fewer it was refused. Made plainly, it would be the +/// first answer. +#[test] +fn a_plan_device_refused_once_is_made_again_of_the_plan_s_queues() { + let scratch = Scratch::new("plan-room"); + let options = DeviceOptions { + queue_limits: None, + kinds: match cfg!(m2v_cpu_icd) { + true => vec![DeviceKind::Cpu], + false => vec![DeviceKind::Discrete, DeviceKind::Integrated], + }, + shader_cache: ShaderCacheOptions { + directory: Some(scratch.0.clone()), + ..ShaderCacheOptions::default() + }, + ..DeviceOptions::default() + }; + refuse_next_devices(1); + let device = device_with_room(&options).unwrap(); + // SAFETY: the handles are read while the device lives. + let raw = unsafe { device.raw() }; + // SAFETY: the physical device is the instance's. + let families = unsafe { + raw.instance + .get_physical_device_queue_family_properties(raw.physical_device) + }; + let plan = queue_plan(&families, 0, true).unwrap(); + let shared = device.shared(); + let took = (shared.round_robin(), shared.presenting()); + println!( + "PLAN-ROOM: {} took {} + {} of the plan's {} + {}", + device.name(), + took.0, + took.1, + plan.queues.len(), + plan.present.len() + ); + assert!(!shared.least_plan); + assert_eq!(took, (plan.queues.len(), plan.present.len())); +} diff --git a/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs b/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs index d0de60420..f0ce632db 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs @@ -18,6 +18,7 @@ //! of device the cfg selects. use super::blit_holds::{Scratch, WAIT}; +use super::plan_room::device_with_room; use crate::device::create::{ extra_queue_places, planned_queues, queue_plan, queue_plan_within, shares_past_limit, QUEUE_LIMITS_REACHED, TEST_QUEUE_LIMITS, @@ -71,7 +72,7 @@ fn device(cache: &Path, limits: Option, noted: &Arc = (0..3) .map(|_| device.new_command_queue().unwrap()) diff --git a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs index 9449b8a0f..a2d9cd057 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs @@ -72,6 +72,7 @@ use super::blit_holds::Scratch; use super::dispatch_pending::{self, Buffers, Grid}; +use super::plan_room::device_with_room; use super::waiter_submits::Held as HeldThread; use crate::command_buffer::completion::trace; use crate::tests::SETTLE; @@ -135,7 +136,7 @@ fn isolated( ) -> Device { let mut options = options(cache, queue_sharing); options.policy.unshared_isolation = isolation; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); assert!(device.settle_queue_switch_check(WAIT), "the check settles"); println!( "{queue_sharing:?}: {}; late rounds {}", @@ -519,7 +520,7 @@ fn each_placement(leg: &str, test: impl Fn(&Device)) { let scratch = Scratch::new(&format!("queue-place-{leg}-{policy:?}-{untimed}")); let mut options = options(&scratch, policy); options.gpu_times_from_host = untimed; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); assert!(device.settle_queue_switch_check(WAIT), "the check settles"); println!( "PLACEMENT {leg} {policy:?}, untimed {untimed}, round robin {}: {}", @@ -850,7 +851,7 @@ fn a_device_that_answers_gpu_times_from_the_host_does_not_share_and_counts_it() let scratch = Scratch::new("queue-share-untimed"); let mut options = options(&scratch, QueueSharingPolicy::Adaptive); options.gpu_times_from_host = true; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); assert!(device.settle_queue_switch_check(WAIT), "the check settles"); let counts = device.work_counts(); let could = crate::queue_switch_check::pair(&device).is_some(); @@ -1554,7 +1555,7 @@ fn an_unshared_commit_posted_during_a_pass_goes_before_work_let_go_after_it() { let mut options = options(&scratch, QueueSharingPolicy::PerQueue); options.policy.unshared_isolation = UnsharedIsolationPolicy::Bounded; options.policy.completion = CompletionPolicy::Exact; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); assert!(device.settle_queue_switch_check(WAIT), "the check settles"); assert!( device.settle_submit_checks(SETTLE), @@ -1645,7 +1646,7 @@ fn beside_unshared( options.policy.unshared_isolation = UnsharedIsolationPolicy::Bounded; options.policy.completion = completion; options.policy.pipeline_waits = PipelineWaitPolicy::Exact; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); assert!(device.settle_queue_switch_check(WAIT), "the check settles"); assert!( device.settle_submit_checks(SETTLE), diff --git a/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs b/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs index 87bf832d5..4b340278c 100644 --- a/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs +++ b/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs @@ -17,6 +17,7 @@ //! of device the cfg selects. use super::blit_holds::{Scratch, WAIT}; +use super::plan_room::device_with_room; use crate::device::create::{queue_plan, refuse_next_devices, LEAST_QUEUES, ROUND_ROBIN_CEILING}; use crate::{ CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, Error, MessageSink, @@ -67,7 +68,7 @@ fn options(cache: &Path, reserved: u32, messages: &Arc>>) -> D /// That device. fn device(cache: &Path, reserved: u32, messages: &Arc>>) -> Device { - Device::system_default_with(&options(cache, reserved, messages)).unwrap() + device_with_room(&options(cache, reserved, messages)).unwrap() } /// How many queues a device of the families of the device the cfg selects spares for the caller diff --git a/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs b/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs index e9e22db7e..293594a54 100644 --- a/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/scheduler_held_wakes.rs @@ -25,6 +25,7 @@ //! `m2v_cpu_icd`), on the kind of device the cfg selects; the kept groups' batches group by //! `DeviceOptions::assume_submissions_merge`. +use super::plan_room::device_with_room; use crate::command_buffer::completion::trace::{self, Point}; use crate::{ Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, @@ -63,7 +64,7 @@ fn device(merge: bool) -> Device { ..DeviceOptions::default() }; options.policy.queue_sharing = QueueSharingPolicy::PerQueue; - let device = Device::system_default_with(&options).unwrap(); + let device = device_with_room(&options).unwrap(); // False where the device runs no in-place check (its policy keeps no texture in place). let _ = device.settle_in_place_checks(SETTLE); assert!( diff --git a/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs b/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs index c0e94fb6e..d27ac9e2c 100644 --- a/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/scheduler_wakes.rs @@ -24,6 +24,7 @@ //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`), on the kind of device the cfg selects. +use super::plan_room::device_with_room; use crate::command_buffer::completion::trace::{self, Point}; use crate::tests::SETTLE; use crate::{ @@ -84,7 +85,7 @@ fn device_of(base: DeviceOptions) -> Device { }, ..base }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// A command buffer of `queue` that fills `target` with `value`, counting its completion into diff --git a/crates/metal2vulkan-runtime/src/tests/store_out_device.rs b/crates/metal2vulkan-runtime/src/tests/store_out_device.rs index 1e2cd57e6..a1bba4e21 100644 --- a/crates/metal2vulkan-runtime/src/tests/store_out_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/store_out_device.rs @@ -42,6 +42,7 @@ //! that imports no host memory, and a system that maps read-only views (macOS, where Metal's own //! GPU faults the store), say so and pass. +use super::plan_room::device_with_room; use crate::{ BlitOption, Buffer, CommandBufferError, CommandBufferStatus, CommandQueue, Device, DeviceKind, DeviceOptions, EventRef, Heap, HeapDescriptor, HeapType, HostMemory, LoadAction, Origin, @@ -195,7 +196,7 @@ fn device_of(policy: Option, base: DeviceOptions) -> Option>>) -> Device })), ..DeviceOptions::default() }; - Device::system_default_with(&options).unwrap() + device_with_room(&options).unwrap() } /// The families of the device's queue family properties. diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 3a8d6379d..3b01188d1 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -94,8 +94,10 @@ with 16 CPU threads to itself, and 0.1 to 0.3 s on an RX 7900 XTX and a Radeon 7 announcing `metal2vulkan-degrade-least-queue-plan`, or refuses those too (`Error::DeviceRefused`). A runtime lane device so made or so refused is made again, the one made dropped first, after a pause that doubles from 0.25 s to 2 s, for at most 120 s in all - (`runtime_lane/device_room.rs`), each pause a `LANE-DEVICE-ROOM` line on stderr; a test of the - runtime crate's own may pass on the least plan's queues. `cargo nextest run --profile + (`runtime_lane/device_room.rs`), each pause a `LANE-DEVICE-ROOM` line on stderr. The runtime + crate's own device tests make theirs the same way (`src/tests/plan_room.rs`, `PLAN-DEVICE-ROOM` + lines), and one still of its least plan past the bound fails its test; the tests of the least + plan itself stand the driver's refusal in (`refuse_next_devices`). `cargo nextest run --profile few-channels` runs three device tests at a time (`.config/nextest.toml` has the measurement), leaving room for other programs' devices on the same GPU. - **The runtime's own device tests take four `VkQueue`s, not the plan's 18.** Its test build's