Files
metal2vulkan/crates/metal2vulkan-runtime/src/tests/queue_sharing.rs
T
Anees Iqbal 58de9ba9a1 The runtime's own device tests take four VkQueues by default, not the plan's 18
What: in the runtime crate's test build, DeviceOptions::default() carries queue limits of a round
robin of two VkQueues and none for presenting (TEST_QUEUE_LIMITS), beside the staging and fill
queues: four on NVIDIA's families, where the queue plan takes 18. Outside the crate's own tests the
default is unchanged (None, the plan), and on RADV's and lavapipe's one graphics queue the limits
leave the plan as it is. DeviceOptions' Default is now written out (every field named) so that its
queue_limits can be the test default there; the API signature table is re-blessed for the derive
moving to an impl, which changes nothing for a consumer.

A test whose work needs more than the default gives on a device with queues to spare (the
program's third command queue, unshared or not; a presenting queue; reserved or extra queues; a
read of the queue sharing) panics where it asks for it, on every device, and makes its device with
`queue_limits: None`: the runtime lane's LANE_QUEUE_LIMITS rule, whose failure is the device's
metal2vulkan-queue-limits-reached and so is said only on a device with queues to spare. Here the
check reads no plan, so a lavapipe run finds every such test. least_queue_plan and many_devices
measure the plan and take it.

Why: NVIDIA's driver makes and destroys one device at a time across processes, and each VkQueue
adds to both. Measured on the RTX 3090 (620.70.06, a probe build that timed each phase of a
device's opening and teardown, m3-max-30672): alone, vkCreateDevice took 540-575 ms and
vkDestroyDevice 163 ms of a device test's 1.17 s (priming 129-142 ms, loader and instance 93 ms,
the runtime's own phases under 25 ms); at 12 threads 55 device tests took 66.9 s, 1.2 s each, no
less than one at a time, their vkCreateDevice a median of 8.1 s and vkDestroyDevice 2.8 s. On the
RTX 5080 Laptop GPU a device of 2 queues took 145 ms against 445 ms with 17
(DeviceOptions::queue_limits' measurement).

Verified: tests::queue_limits::the_tests_default_devices_take_four_of_nvidia_s_eighteen_queues
(no device: NVIDIA's families give 4 VkQueues under the default, 18 at the plan; fails without the
change, whose default is the plan) and
tests::queue_limits_device::a_default_test_device_fails_where_its_work_needs_the_plan (on the
device the cfg selects: the third command queue, an unshared one past it, a presenting queue, a
read of the queue sharing and a reserved queue each panic under the default, and a plan device
makes each).

Also in this landing (the lane's later commits):
- 1edf6b494a The runtime tests' default queue limits fail a test by its live command queues, not its made ones
- 9a2bfa7bc5 Tests that ask for reserved or extra queues take the queue plan
- b9e7cd775b Tests that keep more than two command queues live take the queue plan

Proof (m3-max-30836 at b9e7cd775b): clippy plain and cpuicd 0; the no-device tests 33/33
(the_tests_default_devices_take_four_of_nvidia_s_eighteen_queues: 4 of 18 placed); lavapipe runtime
suite 2732/2732. Negative control m3-max-30752 (default_queue_limits returns None): fails at the 4-of-18
assert. No RUNTIME bump: the product default is unchanged.
2026-11-14 18:24:24 -08:00

82 lines
3.7 KiB
Rust

//! A device's `VkQueue`s are shared round robin among its command queues, and the sharing is
//! counted: the first command queues each take a `VkQueue` of their own, and the one past them
//! takes one an earlier command queue took (`WorkCounts::queues_sharing_a_vk_queue`).
//!
//! # Why this is a count
//!
//! Two command queues on one `VkQueue` submit to one Vulkan queue, which runs its submissions in
//! order, so one's command buffers wait for the other's whole command buffer. Metal's queues wait
//! for each other only inside one command: on this M3 Max a side queue's command buffer waited the
//! whole 2.50 s of another queue's single compute dispatch, but nothing at all behind the same
//! 2.50 s split into 256 dispatches of one command buffer (`queue.rs`). The runtime answers that
//! with queues, lending the round robin every queue the device's families have past the two
//! reserved for presenting, up to sixteen (`device/create.rs`); what it cannot answer is a
//! program with more command queues than the device has queues, and on this host MoltenVK's four
//! families of one queue each are four. The count is what makes that visible to a caller rather
//! than left to be inferred from a timing.
//!
//! The assertion is a count, never a time: it is a fact of the device's queue plan, so it holds on
//! any host under any load. The run asserts both sides of the step -- zero sharing up to the
//! device's queues, then one more share per command queue past them -- so a device that shared
//! from its first command queue fails it as surely as one that never counted a share.
//!
//! 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::{plan_device, Scratch};
use crate::CommandQueue;
/// The most command queues the run makes: one past the round robin's ceiling
/// (`device/create.rs`), so a device of any shape must have begun sharing by the last.
const MOST: usize = 17;
/// Command queues take a `VkQueue` of their own until the device has no more, and each one past
/// them is counted as sharing one.
#[test]
fn command_queues_past_the_devices_queues_are_counted_as_sharing_one() {
let scratch = Scratch::new("queue-sharing");
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<CommandQueue> = Vec::with_capacity(MOST);
// Up to the device's own queues, each command queue takes one of its own.
let mut own = 0;
while kept.len() < MOST {
kept.push(device.new_command_queue().unwrap());
if sharing() > 0 {
break;
}
own = kept.len();
}
assert!(
own > 0,
"the first command queue of a device must take a `VkQueue` of its own, not share one: \
the device counted {} sharing with one command queue made",
sharing()
);
assert_eq!(
sharing(),
1,
"the first command queue past the device's {own} queues must be counted as sharing one, \
once"
);
assert_eq!(
kept.len(),
own + 1,
"sharing must begin at the command queue past the device's queues, and a device of any \
shape must share by the {MOST}th: it began at {}",
kept.len()
);
// Each further command queue shares too: the round robin never runs out.
for step in 1..=3 {
kept.push(device.new_command_queue().unwrap());
assert_eq!(
sharing(),
1 + step,
"every command queue past the device's {own} queues shares one, so the {}th sharing \
queue is counted",
1 + step
);
}
}