diff --git a/crates/metal2vulkan-runtime/src/device/create.rs b/crates/metal2vulkan-runtime/src/device/create.rs index 5e65d7df0..e677401c4 100644 --- a/crates/metal2vulkan-runtime/src/device/create.rs +++ b/crates/metal2vulkan-runtime/src/device/create.rs @@ -61,7 +61,7 @@ use std::sync::{Arc, Mutex, Weak}; /// How the runtime creates its instance and devices. No Metal counterpart: these choose the /// Vulkan side (`MTLCreateSystemDefaultDevice` takes nothing). #[non_exhaustive] -#[derive(Clone, Default)] +#[derive(Clone)] pub struct DeviceOptions { /// The policy each device's compile device is made with, and whose /// `recommended_enables` each device enables. @@ -475,6 +475,89 @@ impl std::fmt::Debug for DeviceOptions { } } +impl Default for DeviceOptions { + fn default() -> DeviceOptions { + // Every field is named, so a field added later is written here or this fails to compile. + DeviceOptions { + policy: Default::default(), + layers: Default::default(), + layer_settings: Default::default(), + instance_extensions: Default::default(), + device_extensions: Default::default(), + optional_device_extensions: Default::default(), + withheld_features: Default::default(), + withheld_extensions: Default::default(), + messages: Default::default(), + loader: Default::default(), + kinds: Default::default(), + shader_cache: Default::default(), + withhold_generated_commands: Default::default(), + withhold_view_reinterpretation: Default::default(), + load_no_dynamic_library_file: Default::default(), + instance_api_version: Default::default(), + gpu_times_from_host: Default::default(), + mac_class: Default::default(), + announce_each: Default::default(), + lowering_refuses: Default::default(), + record_executions: Default::default(), + fail_in_place_check: Default::default(), + assume_submissions_merge: Default::default(), + pending_audit: Default::default(), + encoder_trail: Default::default(), + withheld_attachment_formats: Default::default(), + color_attachment_limit: Default::default(), + pipeline_records: Default::default(), + extra_queues: Default::default(), + reserved_queues: Default::default(), + queue_limits: default_queue_limits(), + } + } +} + +/// The default of [`DeviceOptions::queue_limits`]: `None`, the queue plan, outside the runtime's +/// own tests; [`TEST_QUEUE_LIMITS`] in them. +fn default_queue_limits() -> Option { + cfg!(test).then_some(TEST_QUEUE_LIMITS) +} + +/// The queue limits of the devices the runtime's own tests make by default +/// (`DeviceOptions::default()` in its test build, nowhere else): a round robin of two `VkQueue`s +/// and none reserved for presenting, beside the staging and fill queues, so four on NVIDIA's +/// families where the plan takes 18. NVIDIA's driver makes and destroys a process's device while +/// every other process's waits: on an RTX 3090 (NVIDIA 620.70.06), devices of the plan took 540 to +/// 575 ms in `vkCreateDevice` and 163 ms in `vkDestroyDevice` each alone, and 55 device tests at +/// 12 threads took 66.9 s, 1.2 s each, no less than one at a time, their `vkCreateDevice` a median +/// of 8.1 s and their `vkDestroyDevice` 2.8 s. A device of fewer queues costs less of both +/// (`DeviceOptions::queue_limits`'s measurement). A test whose work needs more than these limits +/// give on a device with queues to spare (a command queue of the program's, unshared or not, made +/// while two are live, which would share a `VkQueue` with one of them; a presenting queue, which +/// would share the round robin's; reserved or extra queues, placed otherwise) panics where it +/// asks for it, on every device (`needs_the_queue_plan`), and makes its device with +/// `queue_limits: None`, the plan: as the runtime lane's tests make theirs past its +/// `LANE_QUEUE_LIMITS`. A read of the device's queue sharing reads what the plan's would: its check +/// measures two `VkQueue`s of the round robin, which these limits keep. A device made with limits +/// equal to these is taken for one of the default. +pub(crate) const TEST_QUEUE_LIMITS: QueueLimits = QueueLimits { + round_robin: 2, + presenting: 0, +}; + +/// In the runtime's own tests, a device made with [`TEST_QUEUE_LIMITS`] whose test's work asks for +/// more than they give on a device with queues to spare, `what` saying what: the test fails here, +/// on every device, so that it makes its device with the plan (`queue_limits: None`) rather than +/// run on a device whose queues share where the plan's would not. +#[cfg(test)] +#[track_caller] +pub(crate) fn needs_the_queue_plan(what: &str) -> ! { + panic!( + "this test's device takes the runtime tests' default queue limits (TEST_QUEUE_LIMITS: \ + a round robin of {} VkQueue(s), {} for presenting) and {what}, which needs more on a \ + device with queues to spare (NVIDIA's plan takes 18): make the device with \ + `queue_limits: None`, the queue plan", + TEST_QUEUE_LIMITS.round_robin, TEST_QUEUE_LIMITS.presenting + ) +} + /// One setting of an instance layer (`VkLayerSettingEXT`). #[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq)] @@ -2106,6 +2189,15 @@ pub(super) fn create_on( cache: &CacheSetup, recovering: Option<&Arc>, ) -> Result { + // In the runtime's own tests, a device of their default limits asks for no reserved or extra + // queue, which a device of its plan places otherwise (`TEST_QUEUE_LIMITS`): before anything + // is made. + #[cfg(test)] + if options.queue_limits == Some(TEST_QUEUE_LIMITS) + && (options.reserved_queues > 0 || !options.extra_queues.is_empty()) + { + needs_the_queue_plan("asks for reserved or extra queues"); + } // SAFETY: `physical` was enumerated from the instance, created at `api_version`. let mut description = unsafe { DeviceDescription::query(&instance.raw, physical, instance.api_version) } @@ -2497,6 +2589,12 @@ pub(super) fn create_on( ) }); } + // In the runtime's own tests, a device of their default limits fails its test where its work + // needs more (`TEST_QUEUE_LIMITS`). + #[cfg(test)] + if options.queue_limits == Some(TEST_QUEUE_LIMITS) { + (device.shared().test_queue_limits).store(true, std::sync::atomic::Ordering::Relaxed); + } let reserved_places = &plan_reserved; if let Some(planned) = &planned { if planned.reserved != *reserved_places { diff --git a/crates/metal2vulkan-runtime/src/device/mod.rs b/crates/metal2vulkan-runtime/src/device/mod.rs index 9e1e9c86a..9f6b0fdfa 100644 --- a/crates/metal2vulkan-runtime/src/device/mod.rs +++ b/crates/metal2vulkan-runtime/src/device/mod.rs @@ -672,6 +672,10 @@ pub(super) struct DeviceShared { /// `tests/read_twin_device.rs` on a driver that lays such rows in place. #[cfg(test)] pub(crate) linear_pitch_rule_forced: AtomicU64, + /// Made with the runtime tests' default queue limits (`create::TEST_QUEUE_LIMITS`), whose + /// test then fails where its work needs more (`create::needs_the_queue_plan`). + #[cfg(test)] + pub(crate) test_queue_limits: AtomicBool, /// The logs of its shadows over host pages a consumer logs the writes to /// (`dirty_pages.rs`). pub(super) dirty: super::dirty_pages::DirtyShadows, @@ -1873,6 +1877,8 @@ impl Device { /// a queue the program made, `None` the runtime's own and a presenting queue's, which /// `Device::next_presenting_queue` notes ([`note_past_limits`](Self::note_past_limits)). pub(super) fn next_queue(&self, noted: Option<&str>) -> (u64, usize) { + #[cfg(test)] + self.test_program_queue(noted); let (id, made) = self.round_robin_turn(); let vk_queue = self.take_round_robin(made, false); self.note_past_limits(noted, vk_queue); @@ -1885,6 +1891,8 @@ impl Device { /// (`Device::take_round_robin`). A queue the program made, as /// [`next_queue`](Self::next_queue)'s. pub(super) fn next_unshared_queue(&self) -> (u64, usize) { + #[cfg(test)] + self.test_program_queue(Some("an unshared command queue")); let (id, made) = self.round_robin_turn(); let vk_queue = (self.place_unshared()).unwrap_or_else(|| self.take_round_robin(made, true)); self.note_past_limits(Some("an unshared command queue"), vk_queue); @@ -1935,9 +1943,37 @@ impl Device { } } + /// Whether the device was made with the runtime tests' default queue limits + /// (`create::TEST_QUEUE_LIMITS`). + #[cfg(test)] + pub(crate) fn test_queue_limited(&self) -> bool { + self.shared().test_queue_limits.load(Ordering::Relaxed) + } + + /// On a device of the runtime tests' default queue limits, the program's command queue + /// `noted` names (`None` for the runtime's own, which no limit counts), before anything places + /// it: where as many of the program's queues as the limits' round robin has `VkQueue`s are + /// live, the test fails here (`create::needs_the_queue_plan`), as this one would share a + /// `VkQueue` with a live one where a plan of queues to spare gives it one of its own. + #[cfg(test)] + fn test_program_queue(&self, noted: Option<&str>) { + let (Some(queue), true) = (noted, self.test_queue_limited()) else { + return; + }; + let live = self.shared().program_queues_live.load(Ordering::Relaxed); + if live >= u64::from(create::TEST_QUEUE_LIMITS.round_robin) { + let what = format!("made {queue} while {live} of the program's are live"); + create::needs_the_queue_plan(&what); + } + } + /// A new presenting queue's identity, and the index of the `VkQueue` it submits to: the /// queues reserved for presenting, in turn. `None` where the device reserved none. pub(super) fn next_presenting_queue(&self) -> Option<(u64, usize)> { + #[cfg(test)] + if self.test_queue_limited() { + create::needs_the_queue_plan("made a command queue for presenting"); + } let reserved = self.shared().queues.len() - self.shared().round_robin; if let Some((_, planned)) = self.shared().planned { let asked = (self.shared().presenting_asked).fetch_add(1, Ordering::Relaxed); @@ -3187,6 +3223,8 @@ impl Device { explicit_plane_pitch_misread_forced: Default::default(), #[cfg(test)] linear_pitch_rule_forced: Default::default(), + #[cfg(test)] + test_queue_limits: Default::default(), dirty: Default::default(), standings: Default::default(), fresh: Default::default(), diff --git a/crates/metal2vulkan-runtime/src/tests/blit_holds.rs b/crates/metal2vulkan-runtime/src/tests/blit_holds.rs index c0a939815..852d30e35 100644 --- a/crates/metal2vulkan-runtime/src/tests/blit_holds.rs +++ b/crates/metal2vulkan-runtime/src/tests/blit_holds.rs @@ -171,6 +171,15 @@ pub(super) fn shadow_device(cache: &Path) -> Device { Device::system_default_with(&options).unwrap() } +/// As [`device`], with the queue plan (`queue_limits: None`) in place of the runtime tests' +/// default queue limits (`device/create.rs`): for a test that keeps more than two of its +/// command queues live at once. +pub(super) fn plan_device(cache: &Path) -> Device { + let mut options = options(cache); + options.queue_limits = None; + Device::system_default_with(&options).unwrap() +} + /// The options of [`device`]. pub(super) fn options(cache: &Path) -> DeviceOptions { DeviceOptions { diff --git a/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs b/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs index fa6b1cd72..4a6621205 100644 --- a/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs +++ b/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs @@ -22,6 +22,7 @@ //! //! Device tests: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). +use super::blit_holds::plan_device; use super::freed_memory::device; use crate::device::queue_quiet::QueueQuiet; use crate::memory::{Holds, BLOCK_BYTES}; @@ -549,7 +550,7 @@ fn a_creation_that_needs_a_block_whose_making_waits_for_quiet_waits_for_its_allo #[test] fn the_host_copies_block_made_ahead_joins_its_pool_at_its_placement_alone() { let scratch = Scratch::new("host-copies"); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); if !device.copies_color_on_the_host() { println!( "BLOCKS-AHEAD {}: copies no color texture on the host, so no block is made ahead for \ diff --git a/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs b/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs index f42c0b5df..629d46242 100644 --- a/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs +++ b/crates/metal2vulkan-runtime/src/tests/caller_queue_writes.rs @@ -65,6 +65,8 @@ fn device(cache: &Path) -> Device { ..ShaderCacheOptions::default() }, reserved_queues: 1, + // The plan, whose reserved queue this is. + queue_limits: None, ..DeviceOptions::default() }; Device::system_default_with(&options).unwrap() diff --git a/crates/metal2vulkan-runtime/src/tests/carried_draws.rs b/crates/metal2vulkan-runtime/src/tests/carried_draws.rs index 0e227e08a..b40a5458e 100644 --- a/crates/metal2vulkan-runtime/src/tests/carried_draws.rs +++ b/crates/metal2vulkan-runtime/src/tests/carried_draws.rs @@ -21,7 +21,7 @@ //! `validation/fixtures/public/engine/tob_renders.ll` and `engine/alv_levels.ll` (`llvm-as`). use super::blit_holds::{over_host, until, Host, Scratch, WAIT}; -use super::draw_again::{adding_state, device, warm, Heard}; +use super::draw_again::{adding_state, device, plan_device, warm, Heard}; use super::encoder_holds::{bytes_of, library, words_of}; use super::shadow_standing_device::reads_through_snapshots; use crate::{ @@ -319,7 +319,7 @@ fn channels(word: u32) -> [u8; 4] { fn passes_of_the_same_state_rebind_the_carried_draw() { let scratch = Scratch::new("carried-same"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let state = adding_state(&device); let color = colors(&device, &[[1.0 / 16.0; 4]]); @@ -400,7 +400,7 @@ fn an_encoder_that_carries_nothing_counts_why() { fn passes_of_several_states_rebind_each_state_s_carried_draw() { let scratch = Scratch::new("carried-states"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let states: [RenderPipelineState; 8] = std::array::from_fn(|_| adding_state(&device)); let color = colors(&device, &[[1.0 / 64.0; 4]]); @@ -466,7 +466,7 @@ fn passes_of_several_states_rebind_each_state_s_carried_draw() { fn a_carried_draw_rebinds_the_values_its_encoder_bound() { let scratch = Scratch::new("carried-values"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let state = adding_state(&device); let red = [0.25, 0.0, 0.0, 0.25]; @@ -508,7 +508,7 @@ fn a_carried_draw_rebinds_the_values_its_encoder_bound() { fn a_slot_the_next_encoder_leaves_unbound_stops_the_carry() { let scratch = Scratch::new("carried-stale"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let state = adding_state(&device); let color = colors(&device, &[[1.0 / 16.0; 4]]); @@ -556,7 +556,7 @@ fn a_slot_the_next_encoder_leaves_unbound_stops_the_carry() { fn a_texture_slot_no_function_reads_left_unbound_keeps_the_carry() { let scratch = Scratch::new("carried-unread"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let state = adding_state(&device); let color = colors(&device, &[[1.0 / 16.0; 4]]); @@ -717,7 +717,7 @@ fn backdrop_frame( fn a_carried_backdrop_reads_its_own_pass_s_copy() { let scratch = Scratch::new("carried-backdrop"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let solid = rect_state(&device, "tob_solid"); let read = rect_state(&device, "tob_read"); @@ -1020,7 +1020,7 @@ fn a_carry_its_queue_holds_keeps_nothing_released_alive() { let host = Host::new(); let scratch = Scratch::new("carried-released"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let Some(across) = released_frame(&queue, &host, Apart::CommandBuffers) else { return; @@ -1101,7 +1101,7 @@ fn a_pass_of_another_layout_drops_the_carry() { fn an_encoder_that_keeps_none_counts_what_its_carry_would_come_to() { let scratch = Scratch::new("carried-none-kept"); let heard = Heard::default(); - let device = device(&scratch.0, &[], &heard); + let device = plan_device(&scratch.0, &[], &heard); let queue = device.new_command_queue().unwrap(); let state = adding_state(&device); let color = colors(&device, &[[1.0 / 16.0; 4]]); diff --git a/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs b/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs index 07da0b47c..ae83503b8 100644 --- a/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs +++ b/crates/metal2vulkan-runtime/src/tests/commit_and_submit.rs @@ -37,6 +37,21 @@ const DRAINED: u64 = 50; /// The device the cfg selects: a CPU device under `m2v_cpu_icd`, else a GPU. fn device() -> Device { + device_of(DeviceOptions::default()) +} + +/// As [`device`], with the queue plan (`queue_limits: None`) in place of the runtime tests' +/// default queue limits (`device/create.rs`): for a test that keeps more than two of its +/// command queues live at once. +fn plan_device() -> Device { + device_of(DeviceOptions { + queue_limits: None, + ..DeviceOptions::default() + }) +} + +/// [`device`], its other options `base`'s. +fn device_of(base: DeviceOptions) -> Device { let options = DeviceOptions { kinds: match cfg!(m2v_cpu_icd) { true => vec![DeviceKind::Cpu], @@ -46,7 +61,7 @@ fn device() -> Device { DeviceKind::Virtual, ], }, - ..DeviceOptions::default() + ..base }; Device::system_default_with(&options).unwrap() } @@ -650,7 +665,7 @@ fn noting( /// own pass would. Submission handlers keep submission order: C's, A's, then B's. All complete. #[test] fn a_head_held_for_its_check_holds_back_only_the_commits_behind_it() { - let device = device(); + let device = plan_device(); let queues: Vec = (0..3) .map(|_| device.new_command_queue().unwrap()) .collect(); diff --git a/crates/metal2vulkan-runtime/src/tests/completion.rs b/crates/metal2vulkan-runtime/src/tests/completion.rs index fbeb4cafc..59dee01f4 100644 --- a/crates/metal2vulkan-runtime/src/tests/completion.rs +++ b/crates/metal2vulkan-runtime/src/tests/completion.rs @@ -157,6 +157,9 @@ fn device(cache: &Path) -> Device { directory: Some(cache.to_owned()), ..ShaderCacheOptions::default() }, + // Each test here keeps more than two command queues live at once: the queue plan, not + // the runtime tests' default queue limits (`device/create.rs`). + queue_limits: None, ..DeviceOptions::default() }; Device::system_default_with(&options).unwrap() diff --git a/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs b/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs index 059d92fa5..d9f4bc613 100644 --- a/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs +++ b/crates/metal2vulkan-runtime/src/tests/completion_wakes.rs @@ -34,6 +34,21 @@ const BOUND: Duration = Duration::from_secs(20); /// The device the cfg selects: a CPU device under `m2v_cpu_icd`, else a GPU. fn device() -> Device { + device_of(DeviceOptions::default()) +} + +/// As [`device`], with the queue plan (`queue_limits: None`) in place of the runtime tests' +/// default queue limits (`device/create.rs`): for a test that keeps more than two of its +/// command queues live at once. +fn plan_device() -> Device { + device_of(DeviceOptions { + queue_limits: None, + ..DeviceOptions::default() + }) +} + +/// [`device`], its other options `base`'s. +fn device_of(base: DeviceOptions) -> Device { let options = DeviceOptions { kinds: match cfg!(m2v_cpu_icd) { true => vec![DeviceKind::Cpu], @@ -43,7 +58,7 @@ fn device() -> Device { DeviceKind::Virtual, ], }, - ..DeviceOptions::default() + ..base }; Device::system_default_with(&options).unwrap() } @@ -118,7 +133,7 @@ fn an_idle_device_s_waiters_and_scheduler_stay_asleep() { #[test] fn with_parks_unbounded_every_change_still_wakes_its_waiter() { completion::park_unbounded(); - let device = device(); + let device = plan_device(); let queues: Vec = (0..3) .map(|_| device.new_command_queue().unwrap()) .collect(); diff --git a/crates/metal2vulkan-runtime/src/tests/draw_again.rs b/crates/metal2vulkan-runtime/src/tests/draw_again.rs index 618e2bb07..127896e43 100644 --- a/crates/metal2vulkan-runtime/src/tests/draw_again.rs +++ b/crates/metal2vulkan-runtime/src/tests/draw_again.rs @@ -53,6 +53,22 @@ pub(super) type Heard = Arc>>; /// A device of the kind the cfg selects that announces the kinds of `each` at every occurrence, /// its notices into `heard`. pub(super) fn device(cache: &Path, each: &[Degradation], heard: &Heard) -> Device { + device_of(cache, each, heard, DeviceOptions::default()) +} + +/// As [`device`], with the queue plan (`queue_limits: None`) in place of the runtime tests' +/// default queue limits (`device/create.rs`): for a test that keeps more than two of its +/// command queues live at once. +pub(super) fn plan_device(cache: &Path, each: &[Degradation], heard: &Heard) -> Device { + let base = DeviceOptions { + queue_limits: None, + ..DeviceOptions::default() + }; + device_of(cache, each, heard, base) +} + +/// [`device`], its other options `base`'s. +fn device_of(cache: &Path, each: &[Degradation], heard: &Heard, base: DeviceOptions) -> Device { let heard = Arc::clone(heard); let options = DeviceOptions { kinds: match cfg!(m2v_cpu_icd) { @@ -73,7 +89,7 @@ pub(super) fn device(cache: &Path, each: &[Degradation], heard: &Heard) -> Devic } })), announce_each: each.iter().copied().collect(), - ..DeviceOptions::default() + ..base }; Device::system_default_with(&options).unwrap() } diff --git a/crates/metal2vulkan-runtime/src/tests/fill_waits.rs b/crates/metal2vulkan-runtime/src/tests/fill_waits.rs index beaccdbf2..bd89625bd 100644 --- a/crates/metal2vulkan-runtime/src/tests/fill_waits.rs +++ b/crates/metal2vulkan-runtime/src/tests/fill_waits.rs @@ -24,7 +24,7 @@ //! Device tests: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind //! of device the cfg selects. -use super::blit_holds::{device, Scratch, WAIT}; +use super::blit_holds::{device, plan_device, Scratch, WAIT}; use crate::{ BlitOption, Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputePipelineState, Device, HeapDescriptor, HeapType, Origin, PipelineOptions, ResourceOptions, Size, Texture, @@ -105,10 +105,9 @@ fn completed(name: &str, command_buffer: &CommandBuffer) { ); } -/// The device the cfg selects, its own checks' submissions done, so the command buffers of a -/// test are what takes the fills. -fn settled(scratch: &Scratch) -> Device { - let device = device(&scratch.0); +/// `device`, its own checks' submissions done, so the command buffers of a test are what takes +/// the fills. +fn settled(device: Device) -> Device { let name = device.name().to_owned(); let settle = Duration::from_secs(120); assert!(device.settle_in_place_checks(settle), "{name}"); @@ -120,7 +119,7 @@ fn settled(scratch: &Scratch) -> Device { #[test] fn a_batch_that_reaches_no_new_memory_waits_for_none_of_its_fills() { let scratch = Scratch::new("fill-waits"); - let device = settled(&scratch); + let device = settled(device(&scratch.0)); let name = device.name().to_owned(); let has_fill_queue = device.fill_queue_family().is_some(); let scale_state = state(&device, "examples/runtime_examples.ll", "scale_and_offset"); @@ -252,7 +251,7 @@ fn over_garbage(device: &Device, queue: &CommandQueue) -> Buffer { #[test] fn new_memory_reads_zero_through_every_reach() { let scratch = Scratch::new("fill-reach"); - let device = settled(&scratch); + let device = settled(plan_device(&scratch.0)); let name = device.name().to_owned(); let scale_state = state(&device, "examples/runtime_examples.ll", "scale_and_offset"); let pointer_state = state( @@ -426,7 +425,7 @@ fn write_and_read( #[test] fn a_batch_that_reaches_no_new_texture_waits_for_none_of_its_first_work() { let scratch = Scratch::new("first-work-waits"); - let device = settled(&scratch); + let device = settled(device(&scratch.0)); let name = device.name().to_owned(); let scale_state = state(&device, "examples/runtime_examples.ll", "scale_and_offset"); let (app, compositor) = ( diff --git a/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs b/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs index 4be9a4634..aba6f54aa 100644 --- a/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs +++ b/crates/metal2vulkan-runtime/src/tests/hand_out_waits.rs @@ -68,6 +68,9 @@ fn device(cache: &Scratch) -> Device { directory: Some(cache.0.clone()), ..ShaderCacheOptions::default() }, + // Each test here keeps more than two command queues live at once: the queue plan, not + // the runtime tests' default queue limits (`device/create.rs`). + queue_limits: None, ..DeviceOptions::default() }; options.policy.queue_sharing = QueueSharingPolicy::PerQueue; diff --git a/crates/metal2vulkan-runtime/src/tests/inert_dispatch.rs b/crates/metal2vulkan-runtime/src/tests/inert_dispatch.rs index 05af38e7d..2ada3d6e2 100644 --- a/crates/metal2vulkan-runtime/src/tests/inert_dispatch.rs +++ b/crates/metal2vulkan-runtime/src/tests/inert_dispatch.rs @@ -23,7 +23,7 @@ //! `m2v_cpu_icd`), on the kind of device the cfg selects. The module is LLVM text written here //! (`llvm-as`). -use super::blit_holds::{device, Scratch, WAIT}; +use super::blit_holds::{device, plan_device, Scratch, WAIT}; use super::opencl_mode::{words, words_buffer}; use crate::{ Buffer, CommandBufferError, CommandBufferStatus, ComputePipelineState, CpuCacheMode, Device, @@ -244,7 +244,7 @@ fn fences_around_a_skipped_dispatch_order_a_later_read_of_an_earlier_write() { #[test] fn events_around_a_skipped_dispatch_order_a_later_read_of_an_earlier_write() { let scratch = Scratch::new("inert-events"); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); let (empty, fill, twice) = ( state(&device, "empty"), state(&device, "fill"), diff --git a/crates/metal2vulkan-runtime/src/tests/kept_shadowed_draws.rs b/crates/metal2vulkan-runtime/src/tests/kept_shadowed_draws.rs index 6fb9a05c3..b100399fb 100644 --- a/crates/metal2vulkan-runtime/src/tests/kept_shadowed_draws.rs +++ b/crates/metal2vulkan-runtime/src/tests/kept_shadowed_draws.rs @@ -65,7 +65,7 @@ //! `tob_read` and `tob_sample` of the owned fixture //! `validation/fixtures/public/engine/tob_renders.ll`. -use super::blit_holds::{device, Scratch, WAIT}; +use super::blit_holds::{plan_device, Scratch, WAIT}; use super::draw_again::{checks_ended, commands_of}; use super::encoder_holds::{bytes_of, library}; use crate::framebuffer_fetch::through_inputs; @@ -496,7 +496,7 @@ fn assert_reds(frames: &[(&str, &Frame)], want: &[Vec; 2]) { /// what each kept, and whether the device read in place. fn lane(scratch: &str, argued: bool) -> (Keeps, Keeps, bool) { let scratch = Scratch::new(scratch); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); let state = state(&device, "tob_read"); // Each frame into a queue of its own: the first frame's last draw, kept, is carried along its // queue into the next render encoder whose pass is its pass's like (`render/carried.rs`), @@ -624,7 +624,7 @@ fn draws_of_other_arguments_that_read_other_copies_rebind_with_them() { #[test] fn a_draw_rebound_that_reads_a_color_s_copy_after_a_barrier_takes_every_step() { let scratch = Scratch::new("kept-shadowed-barrier"); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); let queues = [(); 3].map(|_| device.new_command_queue().unwrap()); // The sampled texture, cleared to its red by a pass of its own. let source = target(&device); @@ -689,7 +689,7 @@ fn a_draw_rebound_that_reads_a_color_s_copy_after_a_barrier_takes_every_step() { #[test] fn draws_rebound_that_last_use_a_shadow_so_gather_it_themselves() { let scratch = Scratch::new("kept-shadowed-gathers"); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); if reads_in_place(&device) { eprintln!( "KEPT-SHADOWED-GATHERS {}: reads a color's texture in place; left out", diff --git a/crates/metal2vulkan-runtime/src/tests/least_queue_plan.rs b/crates/metal2vulkan-runtime/src/tests/least_queue_plan.rs index 778f82bd3..70b67bbd4 100644 --- a/crates/metal2vulkan-runtime/src/tests/least_queue_plan.rs +++ b/crates/metal2vulkan-runtime/src/tests/least_queue_plan.rs @@ -24,10 +24,12 @@ use std::sync::{Arc, Mutex}; type Heard = Arc>>; /// The device the cfg selects, its shader cache in `cache` and a message sink of its own, so a -/// device of its own, whose notices go to `heard`. +/// device of its own, whose notices go to `heard`; of its queue plan, the one its least plan +/// stands in for. fn device(cache: &Path, heard: &Heard) -> Result { let heard = Arc::clone(heard); let options = DeviceOptions { + queue_limits: None, kinds: match cfg!(m2v_cpu_icd) { true => vec![DeviceKind::Cpu], false => vec![DeviceKind::Discrete, DeviceKind::Integrated], diff --git a/crates/metal2vulkan-runtime/src/tests/many_devices.rs b/crates/metal2vulkan-runtime/src/tests/many_devices.rs index ec7165ab1..d0044b85e 100644 --- a/crates/metal2vulkan-runtime/src/tests/many_devices.rs +++ b/crates/metal2vulkan-runtime/src/tests/many_devices.rs @@ -47,6 +47,8 @@ fn bar1_used_mib() -> Option { /// prints its notices. fn own_device(cache: &Path, at: usize) -> Result { let options = DeviceOptions { + // The queue plan, as a guest's device takes it. + queue_limits: None, kinds: vec![DeviceKind::Discrete, DeviceKind::Integrated], shader_cache: ShaderCacheOptions { directory: Some(cache.to_owned()), diff --git a/crates/metal2vulkan-runtime/src/tests/queue_limits.rs b/crates/metal2vulkan-runtime/src/tests/queue_limits.rs index 997e9ebff..4c81c4e28 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_limits.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_limits.rs @@ -12,6 +12,7 @@ use crate::device::create::{ extra_queue_places, least_queue_plan, made_within_resources, planned_queues, queue_limits_reached, queue_plan, queue_plan_within, shares_past_limit, vk_queues, LeastPlanTaken, PlacedQueues, PlannedQueues, LEAST_QUEUE_LIMITS, QUEUE_LIMITS_REACHED, + TEST_QUEUE_LIMITS, }; use crate::{DeviceOptions, DeviceRefused, Error, QueueLimits, VkResultCode}; use ash::vk; @@ -374,3 +375,27 @@ fn a_device_refused_for_want_of_resources_is_asked_for_once_with_its_least_plan( assert_eq!(calls, 1); } } + +/// The runtime's own tests make their devices within their default limits +/// (`DeviceOptions::default()` in the test build, `TEST_QUEUE_LIMITS`): four `VkQueue`s of +/// NVIDIA's families (two for the round robin, the copy engine's staging and fill queues), where +/// the plan takes 18, each of which NVIDIA's driver makes and destroys with the device, one device +/// at a time across processes; and the plan itself on a device of no queue to spare (RADV's and +/// lavapipe's one graphics queue). +#[test] +fn the_tests_default_devices_take_four_of_nvidia_s_eighteen_queues() { + let default = DeviceOptions::default().queue_limits; + assert_eq!(default, Some(TEST_QUEUE_LIMITS)); + let placed = |families: &[vk::QueueFamilyProperties], limits| { + let mut plan = queue_plan_within(families, 0, limits, true).unwrap(); + let extra = extra_queue_places(families, &mut plan, &[]); + vk_queues(&(plan, extra)) + }; + assert_eq!( + (placed(&nvidia(), default), placed(&nvidia(), None)), + (4, 18) + ); + for families in [vec![family(ALL, 1)], radv()] { + assert_eq!(placed(&families, default), placed(&families, None)); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs b/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs index 7c355c866..d1adb80d4 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_limits_device.rs @@ -20,7 +20,7 @@ use super::blit_holds::{Scratch, WAIT}; use crate::device::create::{ extra_queue_places, planned_queues, queue_plan, queue_plan_within, shares_past_limit, - QUEUE_LIMITS_REACHED, + QUEUE_LIMITS_REACHED, TEST_QUEUE_LIMITS, }; use crate::memory::MemoryClass; use crate::{ @@ -258,3 +258,89 @@ fn without_limits_nothing_is_noted() { assert!(texts.is_empty(), "{texts:#?}"); assert_eq!(withheld, 0); } + +/// The panic of a call `call` makes, in words: `None` where it returns. +fn panic_of(call: impl FnOnce()) -> Option { + let caught = std::panic::catch_unwind(std::panic::AssertUnwindSafe(call)).err()?; + let text = (caught.downcast_ref::().cloned()) + .or_else(|| caught.downcast_ref::<&str>().map(|text| (*text).to_owned())); + Some(text.unwrap_or_default()) +} + +/// A device of the runtime tests' default queue limits (`DeviceOptions::default()` in the test +/// build, `TEST_QUEUE_LIMITS`) fails its test where the test's work needs more than they give on a +/// device with queues to spare, on every device, whatever its own plan: a command queue of the +/// program's, unshared or not, made while two are live, a presenting queue, reserved or extra +/// queues; and it makes two live command queues, a third once one of them went, and reads its +/// queue sharing. A device of the plan (`queue_limits: None`) makes each. +#[test] +fn a_default_test_device_fails_where_its_work_needs_the_plan() { + let scratch = Scratch::new("queue-limits-test-default"); + let options = |limits: Option| DeviceOptions { + kinds: match cfg!(m2v_cpu_icd) { + true => vec![DeviceKind::Cpu], + false => vec![ + DeviceKind::Discrete, + DeviceKind::Integrated, + DeviceKind::Virtual, + ], + }, + shader_cache: ShaderCacheOptions { + directory: Some(scratch.0.clone()), + ..ShaderCacheOptions::default() + }, + queue_limits: limits, + ..DeviceOptions::default() + }; + let default = DeviceOptions::default().queue_limits; + assert_eq!(default, Some(TEST_QUEUE_LIMITS)); + let needs = "make the device with `queue_limits: None`"; + let device = Device::system_default_with(&options(default)).unwrap(); + // Its command queues' `VkQueue`s: the limits' two at most (NVIDIA's plan gives 16). + let queues = device.shared().queues.len(); + eprintln!( + "TEST-QUEUE-LIMITS: {}: {queues} VkQueue(s) for command queues", + device.name() + ); + assert!(queues <= 2, "{queues}"); + let first = device.new_command_queue().unwrap(); + let _second = device.new_command_queue_unshared(64).unwrap(); + let third = panic_of(|| drop(device.new_command_queue())).unwrap_or_default(); + assert!(third.contains("while 2 of the program's are live") && third.contains(needs)); + let unshared = panic_of(|| drop(device.new_command_queue_unshared(64))).unwrap_or_default(); + assert!(unshared.contains("an unshared command queue"), "{unshared}"); + let presenting = panic_of(|| drop(device.new_command_queue_for_presenting())); + assert!(presenting.unwrap_or_default().contains("presenting")); + drop(first); + let made = panic_of(|| { + let _third = device.new_command_queue().unwrap(); + let _ = device.settle_queue_switch_check(std::time::Duration::ZERO); + }); + assert_eq!( + made, None, + "a third once the first went, and a read of the sharing" + ); + drop(device); + let reserved = panic_of(|| { + let asked = DeviceOptions { + reserved_queues: 1, + ..options(default) + }; + drop(Device::system_default_with(&asked)); + }); + assert!(reserved + .unwrap_or_default() + .contains("reserved or extra queues")); + // The plan's device makes each. + let device = Device::system_default_with(&options(None)).unwrap(); + let made = panic_of(|| { + let queues: Vec = (0..3) + .map(|_| device.new_command_queue().unwrap()) + .chain([device.new_command_queue_unshared(64).unwrap()]) + .chain([device.new_command_queue_for_presenting().unwrap()]) + .collect(); + let _ = device.settle_queue_switch_check(std::time::Duration::ZERO); + drop(queues); + }); + assert_eq!(made, None); +} diff --git a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs index 4f7abc24a..07097b657 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_share_device.rs @@ -111,6 +111,10 @@ fn options(cache: &Scratch, queue_sharing: QueueSharingPolicy) -> DeviceOptions directory: Some(cache.0.clone()), ..ShaderCacheOptions::default() }, + // Every test here asserts where command queues land on the queue plan's `VkQueue`s, and + // most keep more than two live at once: the plan, not the runtime tests' default queue + // limits (`device/create.rs`). + queue_limits: None, ..DeviceOptions::default() }; options.policy = DevicePolicy::UNTRUSTED; diff --git a/crates/metal2vulkan-runtime/src/tests/queue_sharing.rs b/crates/metal2vulkan-runtime/src/tests/queue_sharing.rs index 684b43833..7c1a542e0 100644 --- a/crates/metal2vulkan-runtime/src/tests/queue_sharing.rs +++ b/crates/metal2vulkan-runtime/src/tests/queue_sharing.rs @@ -23,7 +23,7 @@ //! A device test: 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::blit_holds::{device, Scratch}; +use super::blit_holds::{plan_device, Scratch}; use crate::CommandQueue; /// The most command queues the run makes: one past the round robin's ceiling @@ -35,7 +35,7 @@ const MOST: usize = 17; #[test] fn command_queues_past_the_devices_queues_are_counted_as_sharing_one() { let scratch = Scratch::new("queue-sharing"); - let device = device(&scratch.0); + let device = plan_device(&scratch.0); let sharing = || device.work_counts().queues_sharing_a_vk_queue; assert_eq!(sharing(), 0, "a device with no command queue shares none"); let mut kept: Vec = Vec::with_capacity(MOST); diff --git a/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs b/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs index 87f49cfc6..fe16e1e80 100644 --- a/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs +++ b/crates/metal2vulkan-runtime/src/tests/reserved_queues.rs @@ -50,6 +50,8 @@ fn device(cache: &Path, reserved: u32, messages: &Arc>>) -> De ..ShaderCacheOptions::default() }, reserved_queues: reserved, + // The plan, whose reserved queues these are. + queue_limits: None, messages: Some(MessageSink::new(move |message| { kept.lock().unwrap().push(message.text.clone()); })), diff --git a/crates/metal2vulkan-runtime/src/tests/store_out_device.rs b/crates/metal2vulkan-runtime/src/tests/store_out_device.rs index aabb67884..f4a8bb9aa 100644 --- a/crates/metal2vulkan-runtime/src/tests/store_out_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/store_out_device.rs @@ -148,6 +148,22 @@ fn options(private_bit: bool) -> ResourceOptions { /// The test's device, under `policy` where given; `None` where the store-out cannot fault here /// (said). fn device(policy: Option) -> Option { + device_of(policy, DeviceOptions::default()) +} + +/// As [`device`] under the default policy, with the queue plan (`queue_limits: None`) in place of +/// the runtime tests' default queue limits (`device/create.rs`): for a test that keeps more than +/// two of its command queues live at once. +fn plan_device() -> Option { + let base = DeviceOptions { + queue_limits: None, + ..DeviceOptions::default() + }; + device_of(None, base) +} + +/// [`device`], its other options `base`'s. +fn device_of(policy: Option, base: DeviceOptions) -> Option { if crate::read_only_view::VIEWS_DROP_WRITES { eprintln!("STORE-OUT: bit 24 maps a read-only view here; nothing to test"); return None; @@ -161,7 +177,7 @@ fn device(policy: Option) -> Option { DeviceKind::Virtual, ], }, - ..DeviceOptions::default() + ..base }; if let Some(policy) = policy { options.policy = policy; @@ -397,7 +413,7 @@ fn a_color_store_into_a_private_bit_buffer_without_a_twin_faults_its_command_buf #[test] fn a_resolve_into_a_private_bit_buffer_faults_its_command_buffer() { let pages = Pages::new(); - let Some(device) = device(None) else { + let Some(device) = plan_device() else { return; }; let kept = pages.bytes(); diff --git a/crates/metal2vulkan-runtime/src/tests/video_interop.rs b/crates/metal2vulkan-runtime/src/tests/video_interop.rs index 8f3425a29..edb35b440 100644 --- a/crates/metal2vulkan-runtime/src/tests/video_interop.rs +++ b/crates/metal2vulkan-runtime/src/tests/video_interop.rs @@ -63,6 +63,8 @@ pub(super) fn device(cache: &Path, messages: &Arc>>) -> Device ..ShaderCacheOptions::default() }, extra_queues: vec![vk::QueueFlags::COMPUTE, vk::QueueFlags::VIDEO_DECODE_KHR], + // The plan, whose extra queues these are. + queue_limits: None, optional_device_extensions: VIDEO_EXTENSIONS .iter() .map(|&name| CString::from(name)) diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 9e3859ccb..4c409a6e1 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -10416,7 +10416,7 @@ struct metal2vulkan-runtime::DepthStencilState #[derive(Clone)] pub struct Depth struct metal2vulkan-runtime::Device pub struct Device(Pin, holds::Share) struct metal2vulkan-runtime::DeviceCheckWork #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct DeviceCheckWork struct metal2vulkan-runtime::DeviceHandles #[derive(Clone, Copy)] #[non_exhaustive] pub struct DeviceHandles<'a> -struct metal2vulkan-runtime::DeviceOptions #[derive(Clone, Default)] #[non_exhaustive] pub struct DeviceOptions +struct metal2vulkan-runtime::DeviceOptions #[derive(Clone)] #[non_exhaustive] pub struct DeviceOptions struct metal2vulkan-runtime::DeviceProperties #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct DeviceProperties struct metal2vulkan-runtime::DeviceRefused #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct DeviceRefused struct metal2vulkan-runtime::DirtyStamp #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DirtyStamp(pub u64) @@ -10948,6 +10948,7 @@ trait-impl metal2vulkan-runtime::Device impl Drop impl Drop for Device trait-impl metal2vulkan-runtime::Device impl ImageMaker impl ImageMaker for Device trait-impl metal2vulkan-runtime::Device impl std::fmt::Debug impl std::fmt::Debug for Device trait-impl metal2vulkan-runtime::DeviceHandles impl std::fmt::Debug impl std::fmt::Debug for DeviceHandles<'_> +trait-impl metal2vulkan-runtime::DeviceOptions impl Default impl Default for DeviceOptions trait-impl metal2vulkan-runtime::DeviceOptions impl std::fmt::Debug impl std::fmt::Debug for DeviceOptions trait-impl metal2vulkan-runtime::DeviceRefused impl fmt::Display impl fmt::Display for DeviceRefused trait-impl metal2vulkan-runtime::DmaBufRequest impl fe impl Send unsafe impl Send for DmaBufRequest diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 8bf10ce98..feb1304c2 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -93,6 +93,13 @@ with 16 CPU threads to itself, and 0.1 to 0.3 s on an RX 7900 XTX and a Radeon 7 (`.config/nextest.toml` has the measurement). Past that, the driver refuses a device the plan's queues and the runtime makes it with its least plan's three, announcing `metal2vulkan-degrade-least-queue-plan`: a test may then pass on fewer queues than the plan's. +- **The runtime's own device tests take four `VkQueue`s, not the plan's 18.** Its test build's + `DeviceOptions::default()` holds queue limits of a round robin of two and none for presenting + (`TEST_QUEUE_LIMITS`, `device/create.rs`), as the runtime lane's devices hold theirs + (`LANE_QUEUE_LIMITS`): NVIDIA's driver makes and destroys one device at a time across processes, + each queue adding to both. A test whose work needs more (a command queue made while two are + live, a presenting, reserved or extra queue) panics where it asks for it, on every device, and + makes its device with `queue_limits: None`. - **Waits are bounded.** Every host wait on device work goes through `src/gpu/wait.rs` (10 seconds by default; `--gpu-wait-timeout SECONDS` raises it for one command). A test fails if an unbounded wait appears elsewhere.