From be47523f80deb3629ef4f360c3f23dc15b0c3f74 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 3 Nov 2026 02:15:48 -0800 Subject: [PATCH] State queue sharing's residual stall and the unshared form for queues that must never wait What: docs/FAST-PATHS.md's queue sharing row, docs/API.md's policy bullet and the runtime README's new_command_queue_unshared entry now state the residual stall exactly: once per logical queue that goes long, for a queue that joined its VkQueue during its short phase, about one long command buffer's length. They also say a queue that must never wait (a compositor's) is made with Device::new_command_queue_unshared. The row's cost column carries the measured rates. The queue_share example's rates mode takes --threads, --in-flight and --one-vk-queue for one shape. It prints each command buffer's GPU end and commit to its completed handler, the submission, scheduler and wake counts per command buffer, and the busiest threads' CPU from /proc (Linux). Why: on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, release, 3 runs a side), the trap and slow-alternating shapes cost a shared compositor 64 completions over 10 ms, at most 29.4 to 30.6 ms, in every run, with one join each. That is the first long command buffer of the application it joined during the application's short phase. PerQueue had none in 5 of those 6 runs and 4 in the sixth (at most 3.7 to 10.7 ms). An unshared compositor had none over 10 ms in any run. No join rule built on what a queue has shown can avoid the first one: the long command buffer gives no sign before it runs. A re-pick at submission would not either: the compositor holds about 4 uncompleted command buffers at each commit (p50 commit to handler 0.78 to 0.87 ms at a 208 us period), and the stall is all or nothing in a queue's own order. So the docs name the unshared form as the answer for such a queue. The probe settled the 2 threads x 3 in flight drop (15.4k against 26.0k a second in one run): it was the lock hold's warm-up. In the hold's first runs both policies ran slow (11.1k and 10.4k), and later runs gave Adaptive 46.5k and 39.7k against PerQueue's 25.2k and 26.5k. Two queues on one forced VkQueue ran 38.1k to 46.6k under PerQueue and 41.4k to 49.9k pinned under Adaptive, so one VkQueue is not slow in the runtime's path. No runtime thread was busy in the slow runs (scheduler 10%, handler threads 5%, waiters 3%), and every shape made one vkQueueSubmit per command buffer. Verified: tests::fast_paths, degradation_catalogue and degradation_sites (25 passed); clippy of the example with all features. (cherry picked from commit b1dbea95dad3a5a156191df01084db0f86cb67a0) (cherry picked from commit 24af60dbf8175da8e60ea24f38f9103c20c23e8b) --- crates/metal2vulkan-runtime/README.md | 9 +- .../examples/queue_share.rs | 156 +++++++++++++++++- docs/API.md | 13 +- docs/FAST-PATHS.md | 2 +- 4 files changed, 167 insertions(+), 13 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 03a560d26..444091f98 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -319,8 +319,13 @@ Calls Metal does not have, for a consumer that emulates a Metal device: finds its GPU idle between consecutive work of two `VkQueue`s (NVIDIA's driver), the other command queues move among the `VkQueue`s of their family at their idle points and share them ([docs/API.md](../../docs/API.md#the-policy)); this one keeps the `VkQueue` it takes for its - life, no queue moves onto it, and a queue already there leaves at its next idle point. Under - `QueueSharingPolicy::PerQueue`, and on a device that does not share, it is + life, no queue moves onto it, and a queue already there leaves at its next idle point. A + shared queue waits behind another's long command buffer once per queue that goes long: the + first long command buffer of a queue it shares a `VkQueue` with holds its command buffers for + that command buffer's whole length (beside 30 ms command buffers on an RTX 5080, a compositor's + 64 completions over 10 ms and one of 30 ms). Make a queue that must never wait so (a + compositor's) with this call: on that GPU, none of its completions took over 10 ms in any run. + Under `QueueSharingPolicy::PerQueue`, and on a device that does not share, it is `new_command_queue_with_max_command_buffer_count`. A count of 0 and a lost device are refused as there. diff --git a/crates/metal2vulkan-runtime/examples/queue_share.rs b/crates/metal2vulkan-runtime/examples/queue_share.rs index 6f04f94e9..21ef48e9e 100644 --- a/crates/metal2vulkan-runtime/examples/queue_share.rs +++ b/crates/metal2vulkan-runtime/examples/queue_share.rs @@ -3,7 +3,8 @@ //! //! ```sh //! cargo run --release -p metal2vulkan-runtime --example queue_share -- \ -//! [--policy adaptive|per-queue] [--seconds S] [--dispatches N] [--unshared] +//! [--policy adaptive|per-queue] [--seconds S] [--dispatches N] [--unshared] \ +//! [--threads T --in-flight F [--one-vk-queue]] //! ``` //! //! Every command buffer is one of two kinds. A *draw*: a render pass over a 512x512 `RGBA8Unorm` @@ -30,6 +31,10 @@ //! share of the run (from their GPU start and end times, in commit order on the GPU). //! - **rates**: 2 and 8 threads, each its own queue, committing draws as fast as they can with 3, //! then 1, in flight a thread: command buffers a second, and the GPU's idle share at switches. +//! With `--threads` and `--in-flight`, that one shape, with each command buffer's GPU end and +//! commit to its completed handler, the device's submission, scheduler and wake counts per +//! command buffer, and the busiest threads' CPU (Linux); `--one-vk-queue` puts every thread's +//! queue on one `VkQueue`, each lent once (`with_vk_queue`) so it never moves. //! - **idle-queues**: one thread committing draws in turn over 16, then 2,048 queues, 3 in flight: //! command buffers a second, and the thread's time in `command_buffer` per command buffer. @@ -68,6 +73,11 @@ struct Options { seconds: f64, dispatches: u64, unshared: bool, + /// `rates` of this many threads alone (0: the default set). + threads: usize, + in_flight: usize, + /// `rates` with every thread's queue on one `VkQueue`, each lent once so it never moves. + one_vk_queue: bool, } fn options() -> Options { @@ -78,6 +88,9 @@ fn options() -> Options { seconds: 2.0, dispatches: 300, unshared: false, + threads: 0, + in_flight: 3, + one_vk_queue: false, }; while let Some(arg) = args.next() { let mut value = || args.next().unwrap_or_else(|| panic!("{arg} needs a value")); @@ -92,6 +105,9 @@ fn options() -> Options { "--seconds" => options.seconds = value().parse().unwrap(), "--dispatches" => options.dispatches = value().parse().unwrap(), "--unshared" => options.unshared = true, + "--threads" => options.threads = value().parse().unwrap(), + "--in-flight" => options.in_flight = value().parse().unwrap(), + "--one-vk-queue" => options.one_vk_queue = true, other => panic!("unknown argument {other}"), } } @@ -513,32 +529,126 @@ fn interleave(kit: &Arc, options: &Options) { /// `threads` threads, each its own queue, committing draws with `in_flight` in flight: command /// buffers a second over the run, and the GPU's idle share at switches. +/// The queues of `threads` threads: each its own where `one` is false; else all on the first's +/// `VkQueue`, made until the round robin comes back to it, each lent once so it never moves. +fn rate_queues(kit: &Kit, threads: usize, one: bool) -> Vec { + if !one { + return (0..threads).map(|_| kit.queue(false)).collect(); + } + // SAFETY: the closures keep the handle only to compare it; nothing is submitted. + let raw = |queue: &CommandQueue| unsafe { queue.with_vk_queue(|raw, _| raw) }; + let first = kit.queue(false); + let home = raw(&first); + let mut queues = vec![first]; + let mut others = Vec::new(); + while queues.len() < threads { + let queue = kit.queue(false); + match raw(&queue) == home { + true => queues.push(queue), + false => others.push(queue), + } + } + queues +} + +/// Per-thread CPU time of this process by thread name, in clock ticks (Linux; empty elsewhere). +fn thread_ticks() -> Vec<(u64, String, u64)> { + let Ok(tasks) = std::fs::read_dir("/proc/self/task") else { + return Vec::new(); + }; + let mut ticks = Vec::new(); + for task in tasks.flatten() { + let Ok(stat) = std::fs::read_to_string(task.path().join("stat")) else { + continue; + }; + let (Some(open), Some(close)) = (stat.find('('), stat.rfind(')')) else { + continue; + }; + let name = stat[open + 1..close].to_owned(); + let fields: Vec<&str> = stat[close + 2..].split(' ').collect(); + let (Some(user), Some(system)) = (fields.get(11), fields.get(12)) else { + continue; + }; + let tid = task.file_name().to_string_lossy().parse().unwrap_or(0); + ticks.push(( + tid, + name, + user.parse::().unwrap_or(0) + system.parse::().unwrap_or(0), + )); + } + ticks +} + +/// The busiest threads between `before` and `after`, as a share of `seconds` each. +fn busiest(before: &[(u64, String, u64)], after: &[(u64, String, u64)], seconds: f64) -> String { + let mut used: Vec<(f64, String)> = after + .iter() + .map(|(tid, name, ticks)| { + let was = before + .iter() + .find(|(t, _, _)| t == tid) + .map_or(0, |(_, _, t)| *t); + ((ticks - was) as f64 / 100.0 / seconds, name.clone()) + }) + .filter(|(share, _)| *share > 0.02) + .collect(); + used.sort_by(|a, b| b.0.total_cmp(&a.0)); + used.iter() + .take(8) + .map(|(share, name)| format!("{name} {:.0}%", share * 100.0)) + .collect::>() + .join(", ") +} + +/// The p50 and p99 of `samples`, in microseconds. +fn quantiles(samples: &mut [f64]) -> String { + if samples.is_empty() { + return "none".to_owned(); + } + samples.sort_by(f64::total_cmp); + let at = |p: f64| samples[((samples.len() as f64 * p) as usize).min(samples.len() - 1)] * 1e6; + format!("p50 {:.1} p99 {:.1} us", at(0.5), at(0.99)) +} + fn rate(kit: &Arc, options: &Options, threads: usize, in_flight: usize) { let stop = Arc::new(AtomicBool::new(false)); let times = Arc::new(Mutex::new(Vec::new())); + // Each command buffer's GPU end to its completed handler, and its commit to that handler. + let latencies = Arc::new(Mutex::new((Vec::new(), Vec::new()))); + let queues = rate_queues(kit, threads, options.one_vk_queue); + let counts = kit.device.work_counts(); + let cpu = thread_ticks(); let began = Instant::now(); - let handles: Vec<_> = (0..threads) - .map(|thread| { + let handles: Vec<_> = (queues.into_iter().enumerate()) + .map(|(thread, queue)| { let kit = Arc::clone(kit); let stop = Arc::clone(&stop); let times = Arc::clone(×); + let latencies = Arc::clone(&latencies); std::thread::spawn(move || { - let queue = kit.device.new_command_queue().unwrap(); let target = kit.target(); let mut flying = std::collections::VecDeque::new(); let mut made = 0u64; while !stop.load(Ordering::Relaxed) { let command_buffer = kit.draw(&queue, &target); let times = Arc::clone(×); + let latencies = Arc::clone(&latencies); + let committed = Arc::new(Mutex::new(0.0)); + let at = Arc::clone(&committed); command_buffer .add_completed_handler(Box::new(move |done: &CommandBuffer| { + let now = metal2vulkan_runtime::host_time(); if let (Ok(start), Ok(end)) = (done.gpu_start_time(), done.gpu_end_time()) { times.lock().unwrap().push((thread, start, end)); + let mut latencies = latencies.lock().unwrap(); + latencies.0.push(now - end); + latencies.1.push(now - *at.lock().unwrap()); } })) .unwrap(); + *committed.lock().unwrap() = metal2vulkan_runtime::host_time(); command_buffer.commit().unwrap(); flying.push_back(command_buffer); made += 1; @@ -558,15 +668,48 @@ fn rate(kit: &Arc, options: &Options, threads: usize, in_flight: usize) { stop.store(true, Ordering::Relaxed); let made: u64 = handles.into_iter().map(|h| h.join().unwrap()).sum(); let elapsed = began.elapsed().as_secs_f64(); + let cpu_after = thread_ticks(); std::thread::sleep(Duration::from_millis(100)); + let after = kit.device.work_counts(); let (idle, switches) = switch_idle(&mut times.lock().unwrap()); + let mut latencies = latencies.lock().unwrap(); + let per = |a: u64, b: u64| (a - b) as f64 / made.max(1) as f64; println!( - "rates (policy {:?}): {threads} threads, {in_flight} in flight: {:.1}k command buffers/s; GPU idle at {switches} switches {:.1}%; {}", + "rates (policy {:?}{}): {threads} threads, {in_flight} in flight: {:.1}k command buffers/s; GPU idle at {switches} switches {:.1}%; {}", options.policy, + if options.one_vk_queue { ", one VkQueue" } else { "" }, made as f64 / elapsed / 1e3, idle * 100.0, kit.counts() ); + println!( + " GPU end to handler {}; commit to handler {}", + quantiles(&mut latencies.0), + quantiles(&mut latencies.1) + ); + println!( + " per command buffer: submissions {:.2}, submit infos {:.2}, VkCommandBuffers {:.2}, scheduler passes {:.2} (by waiters {:.2}, their batches {:.2}), scheduler sleeps {:.2} (woken by commits {:.2}, completions {:.2}), timeline waits {:.2}, fence waits {:.2}, waiter parks {:.2} (timed out {:.2}), waiter wakes {:.2}, handler-thread wakes {:.2}, command-buffer wakes {:.2}, completed where seen {:.2}, turns taken {:.2}, submit {:.1} us", + per(after.queue_submissions, counts.queue_submissions), + per(after.submit_infos, counts.submit_infos), + per(after.command_buffers_submitted, counts.command_buffers_submitted), + per(after.scheduler_passes, counts.scheduler_passes), + per(after.scheduler_passes_by_waiters, counts.scheduler_passes_by_waiters), + per(after.batches_submitted_by_waiters, counts.batches_submitted_by_waiters), + per(after.scheduler_sleeps, counts.scheduler_sleeps), + per(after.scheduler_wakes_commit, counts.scheduler_wakes_commit), + per(after.scheduler_wakes_completion, counts.scheduler_wakes_completion), + per(after.timeline_waits, counts.timeline_waits), + per(after.fence_waits, counts.fence_waits), + per(after.completion_waiter_parks, counts.completion_waiter_parks), + per(after.completion_waiter_parks_timed_out, counts.completion_waiter_parks_timed_out), + per(after.wakes_completion_waiters, counts.wakes_completion_waiters), + per(after.wakes_handler_threads, counts.wakes_handler_threads), + per(after.wakes_command_buffer_waiters, counts.wakes_command_buffer_waiters), + per(after.completed_where_seen, counts.completed_where_seen), + per(after.completion_turns_where_taken, counts.completion_turns_where_taken), + per(after.batch_submit_nanos, counts.batch_submit_nanos) / 1e3, + ); + println!(" threads' CPU: {}", busiest(&cpu, &cpu_after, elapsed)); } fn idle_queues(kit: &Arc, options: &Options, count: usize) { @@ -623,6 +766,9 @@ fn main() { "alternating" => beside(&kit, &options, Duration::from_millis(2), 1, 1), "slow-alternating" => beside(&kit, &options, Duration::from_millis(1500), 1, 1), "interleave" => interleave(&kit, &options), + "rates" if options.threads > 0 => { + rate(&kit, &options, options.threads, options.in_flight); + } "rates" => { for in_flight in [3, 1] { for threads in [2, 8] { diff --git a/docs/API.md b/docs/API.md index cf26706f6..84fafcffd 100644 --- a/docs/API.md +++ b/docs/API.md @@ -227,11 +227,14 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: family whose oldest batch has run under 0.5 ms, so short command buffers of several queues run with no switch between them. A queue whose batch ran over 2 ms as its `VkQueue`'s oldest is long: no queue joins its `VkQueue`, and it moves once more, at its next such make, to an idle - `VkQueue` of its own. The first long command buffer of a queue that shared holds the command - buffers committed behind it there for its whole length, announced `queue-sharing` at the - device's first join (section 9). A queue made with `Device::new_command_queue_unshared` never - moves, and no queue joins its `VkQueue`: a compositor's, whose command buffers must not wait - behind an application's. Presenting queues, and a queue that lent its `VkQueue` + `VkQueue` of its own. So a queue waits behind another's long command buffer once per queue + that goes long, about that command buffer's length: the first long command buffer of a queue + that shared holds the command buffers committed behind it there for its whole length, + announced `queue-sharing` at the device's first join (section 9). A queue made with + `Device::new_command_queue_unshared` never moves, and no queue joins its `VkQueue`: the form + for a queue whose command buffers must never wait behind another's (a compositor's beside an + application's; on the RTX 5080 Laptop GPU none of its completions took over 10 ms in any run, + where a shared one's had one stall of 30 ms beside 30 ms command buffers). Presenting queues, and a queue that lent its `VkQueue` (`CommandQueue::with_vk_queue`), never move. Before the check answers, and on a device whose check finds no idling or that has no two `VkQueue`s of one family (MoltenVK, RADV, lavapipe), each queue keeps the `VkQueue` it took at its creation, round robin. diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 6c3279709..c20c00b73 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -36,7 +36,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X | A heap's colour texture that Metal keeps losslessly compressed (`allowGPUOptimizedContents`, no `ShaderWrite`, `PixelFormatView` or `ShaderAtomic` usage, 16 texels or more a side), on a driver whose compressed images may keep their texels apart from the memory they are bound to (`DriverFact::CompressedImagesHideAliasedWrites`: ANV), is the driver's compressed optimal image, its compression and fast clears kept. A texture Metal keeps uncompressed takes the uncompressed image under either value. The runtime's choice: no pipeline differs. | `heap_compression = HeapCompressionPolicy::Compressed` | `heap_compression = HeapCompressionPolicy::Uncompressed`: an image the driver keeps uncompressed in the heap's bytes, as for a texture Metal keeps uncompressed: host-transfer usage where the device enabled `hostImageCopy` (`heap-texture-host-transfer`), else a linear image (`heap-texture-linear`), else the optimal one (`heap-texture-hides-aliased-writes`) | A write through a buffer or another texture over the texture's bytes may leave its texels as they were or change them otherwise than as written, where Metal's texture reads opaque magenta (`0xffff00ff`) in every texel of drawn content the write covers and the written bytes where it held only a clear; the texture's own writes may show in those bytes compressed. Within Metal's contract: Metal documents such a texture's layout as its own (`allowGPUOptimizedContents` lets it "adjust the private layout"), so no write through another view over its bytes has a defined result there either. `HeapTextureCompressed` (`heap-texture-compressed`), announced once per device where such a texture is made; `runtime_lane::heap_textures` | ANV (Iris Xe of RPL-P; `heap_textures::heap_compression_costs`), a 2048x2048 `RGBA8Unorm` render target in a `Private` placement heap: a pass that clears it 26.9 us against 676.2-676.5 us; a copy into another such texture 647.7-649.1 us against 673.9-693.2 us | | Batches of command buffers committed on one queue that the scheduler finds ready together (a backlog) go to the driver in one `vkQueueSubmit`, at most four, only the last signalling the queue's timeline, on a driver measured to merge a submission that signals nothing into the next (`DriverFact::SubmissionsWithoutSignalsMerge`: Mesa 26.2.4's ANV on the Iris Xe of RPL-P and the UHD 770 of RPL-S, RADV on the Radeon 780M and the RX 7900 XTX, and llvmpipe; every other driver, measured or not, takes the ungrouped form under either value of the switch): one kernel submission, where ANV on i915 lists every `VkDeviceMemory` in each (the consumer's guest drag on the Iris Xe: about 300 entries per execbuffer, 260 of them its host imports, at 112 to 128 execbuffers a frame). A batch's event signals ride to the group's end, which signals each event's semaphore to the highest index the batches held signal it to (an event's indices rise in commit order). A batch that signals a binary semaphore, takes a fence, binds a sparse update, does first work, names the caller's wrapped image, or waits for anything not seen complete (an event, another queue's work) goes alone, after the batches held: a batch with a wait leads a group, never joins one. So that checked command buffers (the consumer checks each) are found ready together, the submission checks of up to three batches right behind a line's head that goes run with the head's, in commit order, none committed after another queue's batch: such a check runs before the previous batch's `vkQueueSubmit` rather than after it, in the scheduler pass that submits its own batch. A pass that finds no batch ready sends the batches held, unless two or more earlier submissions of their `VkQueue` are not seen complete: the GPU runs those first in any case, so the batches stay held, and those committed meanwhile join them, until one submission is left in flight (a completion turn wakes the scheduler at its value), the group fills, a later batch sends it, a head waits for the GPU, or a thread waits for one of their command buffers' completion, which sends them at once; a batch that ends a command buffer with a switch of storage forms riding on it, which settles by its submission's outcome, is never kept so. A held batch that ends its command buffer is `Scheduled` as it is held, its submission handlers run first, then its scheduled handlers, and its kernel end time set, as an M3 Max schedules a command buffer committed behind running work 0.04 to 0.18 ms after its commit. The runtime's: no pipeline differs. | `completion = CompletionPolicy::Grouped` | `completion = CompletionPolicy::Exact`: one submission per batch, each signalling its own values; each line's head checked alone | Each command buffer of a submission but the last is seen complete (status, completed handlers, waits), and the event values it signals are reached (by the GPU waits on other queues, the host's waits, value reads and listeners), once the last completed: late by the GPU time of at most three later batches (about 0.1 to 0.2 ms each in the consumer's compositor frames on the Iris Xe; about 20 ms behind a 20 ms batch), never early, in commit order. Metal's contract states no bound on when completion is seen (an M3 Max reports a command buffer complete, its handlers, status, waits and event listeners alike, 0.04 to 0.10 ms after its GPU end), and no member but the first waits, so no wait holds a member back: a valid program sees only later completion, as of slower GPU work. A batch kept while earlier work runs is seen complete within the same bound, and, where the one submission left in flight ends before its group reaches the GPU, late besides by that gap: at most a completion turn's reaction and the group's `vkQueueSubmit`. Commands, barriers and GPU times are unchanged. `GroupedCompletion` (`grouped-completion`), announced once per device at its first such submission; `runtime_lane::grouped_submissions` | ANV (Iris Xe of RPL-P; `frame_costs::frame_costs_over_imports`, the checked device, 67 command buffers a frame, GPU at 467-783 MHz), with 520 host imports live, where the Exact form's submissions fall behind the commits as the guest's do: 32.0-33.2 kernel submissions a frame against 67.0, 3.4-3.5 ms of execbuffer ioctl a frame against 6.9-7.9 ms, the scheduler thread's CPU 61-63 us a command buffer against 121-136 us, a frame through completion 4.7-5.9 ms against 8.6-9.7 ms; in the guest's shape with 520 (a second queue taking every 20th command buffer, each signalling a shared event, every 10th waiting for one): 26.2-26.7 kernel submissions a frame against 67.0, 2.8 ms of ioctl a frame against 6.9-7.0 ms, the scheduler 52-53 us a command buffer against 122-123 us, a frame through completion 6.0 ms against 8.7 ms; with 260, where it keeps up, 64.9-66.3 kernel submissions a frame against 67.0, the CPU and wall times alike. The cost (`grouped_submissions::grouped_completion_delays`, 8 command buffers of 0.3-0.5 ms of GPU work ready together): the host saw each but a group's last complete later by the later ones' GPU time, the last 0.1-0.3 ms later than alone (the completion turn's per-command-buffer work for the group, done at its end). Keeping a group while earlier work runs (UHD 770 of RPL-S, ANV, the guest's shape with 520 host imports, a submission handler on every command buffer and a 16 MiB fill ahead of each, about 1.3 ms of GPU each; the kept form against the batches sent as found): committed every 1 ms, 18.1-18.2 groups kept a frame, 24.9-25.0 kernel submissions a frame against 57.9, 2.18-2.90 ms of execbuffer ioctl a frame against 4.64-5.43 ms, the scheduler thread's CPU 67-82 us a command buffer against 113-118 us, the GPU idle within a frame's span 0.61 ms against 0.68-0.69 ms, a frame through completion 89.5-89.6 ms alike, completion seen later (GPU end to completed handler: mean 1.82-1.86 ms against 0.43-0.46 ms, p50 1.57-1.60 against 0.11-0.13, p99 4.35-4.37 against 4.09-4.11, max 4.52-4.55 against 4.18-4.23); committed at once, 18.0 kernel submissions a frame against 23.4; with no fill, 18.0 against 20.6, the GPU idle 0.59 ms against 0.58-0.66 ms. In the consumer's guest drag on the Iris Xe (i9-13900H; three passes each way): 24.4-27.5 kernel submissions a frame against 42.4-43.8, the scheduler thread 0.4-1.7 ms of CPU a frame less, 15.7-17.3 frames a second against 16.4-17.6: the frame rate alike within noise, as the scheduler thread does not bound that frame | | Batches of command buffers on one `VkQueue`, on a driver measured to start no kernel submission of a queue before the one before it completed (ANV, RADV and NVIDIA's; `batch_order.rs`), are ordered by their ends: each ends with a barrier ordering its work before every later command of its `VkQueue` (the exact form's end orders it before the host's reads and writes alone), so a batch that depends on an earlier one there begins with no barrier of its own, often no command buffer of barriers, and its first encoder's GPU start is written at the bottom of the pipe, once everything before it completed. Metal starts an independent command buffer committed behind running work while that work runs (an M3 Max under macOS 27.0.1, probe `gpustart`); those drivers ran two batches of independent work one after the other under every shape measured (no end barrier, the host's or the widened one; in one `vkQueueSubmit` or two, merged into one kernel submission or not), where two dispatches of one command buffer ran side by side. The runtime's: no pipeline differs. | `batch_order = BatchOrderPolicy::Ends` | `batch_order = BatchOrderPolicy::Exact`: a barrier for each dependency of a batch's work on an earlier batch's of its `VkQueue`, the end's barrier to the host's reads and writes alone, the GPU start written at the top of the pipe; every other driver takes it under either value | None: on those drivers each batch starts once the one before it completed under either value, so the work's order, its results and its GPU times are the same, and a batch's GPU start is the end of the work before it, when such a driver starts it. Not announced; `runtime_lane::commit_work` and `runtime_lane::gpu_times` test both values | UHD 770 (ANV, RPL-S), the consumer's frame shape over 520 host imports, 67 command buffers a frame, Grouped completion, the widened end barrier against the exact form (a probe build of each): with no fill ahead of each command buffer, 67.0 command buffers submitted a frame against 129.3-129.7, the GPU's span a frame 1.84-1.90 ms against 1.99-2.06 ms, a frame through completion 2.13-2.22 ms against 2.27-2.38 ms; with a 1 MiB fill ahead of each, 134.0 against 262.9, 8.03-8.22 ms against 8.32-8.42 ms, 9.00-9.15 ms against 9.25-9.36 ms. Radeon 780M (RADV, Mesa 26.0.8), this switch: with no fill, 67.0 against 128.9-129.0, a frame through completion 48.3-48.6 ms against 42.6-47.0 ms; with a 16 MiB fill committed at once, 134.0 against 251.0-251.1, 50.6-50.8 ms against 50.8-57.3 ms; committed every 1 ms, 134.0 against 249.7-250.2, 71.3-83.6 ms against 106.3-113.6 ms (each kernel submission there leaves about 2.5 ms of the GPU idle over 520 host imports, which sets these frames) | -| Command queues on a device whose GPU idles when consecutive work comes from another `VkQueue` share `VkQueue`s by choice (`queue_share.rs`): the runtime's own self-check, not a `DriverFact` row, measures that idling once per driver, release and runtime on a thread of its own and keeps its verdict (`Idles`, `DoesNotIdle`, `Unchecked`) in the shader cache's directory, as the in-place check keeps its own (`queue_switch_check.rs`: 49.0 to 51.3 us a switch on the RTX 5080 Laptop GPU, NVIDIA 615.71.09, `Idles` above 20 us). A command queue that makes a command buffer while it holds no other uncompleted one moves onto the busy `VkQueue` of its family whose oldest batch has run under 0.5 ms, the most batches in flight first, so short command buffers of several queues run with no switch between them. A queue whose batch ran over 2 ms as its `VkQueue`'s oldest is long: no queue joins its `VkQueue`, and it moves once more, at its next idle point, to an idle `VkQueue` no long or unshared queue holds. A queue made with `Device::new_command_queue_unshared` never moves and no queue joins its `VkQueue` (a compositor's beside an application's); presenting queues and a queue that lent its `VkQueue` (`with_vk_queue`) never move. Before the verdict, and where it is not `Idles` or there are no two `VkQueue`s of one family (MoltenVK, RADV, lavapipe), every queue keeps the `VkQueue` it took at its creation. The runtime's: no pipeline differs. | `queue_sharing = QueueSharingPolicy::Adaptive` | `queue_sharing = QueueSharingPolicy::PerQueue`: each command queue keeps the `VkQueue` it took at its creation, round robin, and the check does not run | A command buffer waits behind the command buffers of the queues sharing its `VkQueue`, where Metal's queues wait for each other only inside one command: the first long command buffer of a queue that shared holds those committed behind it there for its whole length (one stall of about 29 ms beside an application's 30 ms command buffers), and its later ones while its queue holds work, until its next idle point; an application that keeps two long command buffers in flight reaches no idle point. A command buffer's GPU start time includes the other queues' work before it. `QueueSharing` (`queue-sharing`), at the device's first join | Eight threads' one-draw command buffers, each thread its own queue: 25,800 to 29,500 a second one `VkQueue` per queue, the GPU idle at the switches 60% of its time, against 54,700 to 58,700 on one `VkQueue` (the audit that set the default) | +| Command queues on a device whose GPU idles when consecutive work comes from another `VkQueue` share `VkQueue`s by choice (`queue_share.rs`): the runtime's own self-check, not a `DriverFact` row, measures that idling once per driver, release and runtime on a thread of its own and keeps its verdict (`Idles`, `DoesNotIdle`, `Unchecked`) in the shader cache's directory, as the in-place check keeps its own (`queue_switch_check.rs`: 48.7 to 51.3 us a switch on the RTX 5080 Laptop GPU, NVIDIA 615.71.09, `Idles` above 20 us). A command queue that makes a command buffer while it holds no other uncompleted one moves onto the busy `VkQueue` of its family whose oldest batch has run under 0.5 ms, the most batches in flight first, so short command buffers of several queues run with no switch between them. A queue whose batch ran over 2 ms as its `VkQueue`'s oldest is long: no queue joins its `VkQueue` while it lives, and it moves once more, at its next idle point, to an idle `VkQueue` no long or unshared queue holds. A queue whose command buffers must never wait behind another queue's (a compositor's beside an application's) is made with `Device::new_command_queue_unshared`: it never moves and no queue joins its `VkQueue`. Presenting queues and a queue that lent its `VkQueue` (`with_vk_queue`) never move. Before the verdict, and where it is not `Idles` or there are no two `VkQueue`s of one family (MoltenVK, RADV, lavapipe), every queue keeps the `VkQueue` it took at its creation. The runtime's: no pipeline differs. | `queue_sharing = QueueSharingPolicy::Adaptive` | `queue_sharing = QueueSharingPolicy::PerQueue`: each command queue keeps the `VkQueue` it took at its creation, round robin, and the check does not run | A command buffer waits behind the command buffers of the queues sharing its `VkQueue`, where Metal's queues wait for each other only inside one command. The residual stall: once per logical queue that goes long, for a queue that joined its `VkQueue` during its short phase, about one long command buffer's length: the command buffers committed behind that queue's first long one there wait for its whole length (and those behind its later ones while it holds work, until its next idle point). Measured on the RTX 5080 Laptop GPU beside an application that alternates draws with 30 ms command buffers: a shared compositor's commits at 4,800 a second had 64 completions over 10 ms, at most 29.4 to 30.6 ms, in each of 3 runs of each of two such shapes (one join each), against none over 10 ms under `PerQueue` in 5 of those 6 runs and 4 in the sixth (at most 3.7 to 10.7 ms). On an unshared queue, 0 over 10 ms in every run. A command buffer's GPU start time includes the other queues' work before it. `QueueSharing` (`queue-sharing`), at the device's first join | Command buffers a second on the RTX 5080 Laptop GPU, one-draw command buffers, each thread its own queue, 3 runs each after the lock's first runs, the default against `PerQueue`: 8 threads with 3 in flight 50.7k to 54.7k against 27.9k to 28.0k; 8 threads with 1 in flight 47.0k to 48.1k against 14.3k; 2 threads with 3 in flight 39.7k to 46.5k against 25.2k to 26.5k; 2 threads with 1 in flight 16.9k to 17.2k against 10.1k to 10.8k. Beside an application whose queue never shares with the compositor (isolation, 300 and 30 dispatches), both 0 over 10 ms | | A chain of `half` additions, subtractions and products on a device without `shaderFloat16` (vk12-floor, SwiftShader, Pascal; capability emulation: the module computes each in `float` and rounds it by the device's `OpQuantizeToF16`): an operation whose flags hold `contract` and `reassoc` and whose result only such operations read is held at `float` precision unrounded, so the chain rounds where a value leaves it (a store, an output, a conversion, a comparison, a call, a phi, a vector move, an operation without both flags), one quantize per exit instead of one per operation (`lower::arith::half_chain`). A device with `shaderFloat16` computes `half` alike under either value. | `half_chains = HalfChainPolicy::AtExits` | `half_chains = HalfChainPolicy::EachOperation`: every operation's result rounded to `half`, as the AIR computes it | The result may differ from the rounded operations' by the roundings the chain skips, each within half a unit in the last place of a `half` at its step, compounded along the chain; a value inside the chain past `half`'s range (65504) stays finite where the rounded operations reach infinity. Within the AIR's flags, which let a compiler regroup and fuse such operations. `FastMathRewrites` (`fast-math-rewrites`) | Not timed. Size on vk12-floor (the fixtures' SPIR-V words, the default against the accurate form): `hfb_filter_bank` 121,270 against 131,766 (1,024 quantizes against 2,464), `grd_half_many_samples` 82,019 against 84,627, `nan_half_fast` 9,808 against 9,832 | | A texture that only samples or reads (no `RenderTarget`, `ShaderWrite` or `ShaderAtomic` usage) over host pages (a no-copy buffer's, or a no-copy heap's buffer's, imported by their pointer or as dma-bufs; or a buffer in fresh pages) is a linear image aliasing the pages in place, where the device's own check shows that the image's first move, which Vulkan lets read and write every byte bound to it (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), leaves every byte alone while the CPU writes beside it: a deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's ruling (`in_place.rs`). The check runs once per driver, release and runtime, per class of pages, on a thread of its own, its verdict kept in the shader cache's directory; a texture made before its class's verdict is a shadow. A texture whose usage renders or writes, a check that failed or made no image, and a pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`). | `host_page_textures = HostPageTexturePolicy::InPlace` | `host_page_textures = HostPageTexturePolicy::Shadow`: every texture over host pages a shadow, its texels copied in before each command buffer that uses it and merged back after each write (the host-pages bullet under **Costs of matching Metal**) | Exact where the driver keeps what its check showed: the check covers texels, the bytes between rows and those after the image, of 1, 2, 4, 8 and 16-byte texels and a 3840x2160 surface, three rounds each; a driver whose first move changed a byte outside every round's window would undo a CPU write made meanwhile. Not announced where the check passed. A CPU write reaches the image's reads as it reaches the buffer's (Host Write Ordering Guarantees) | See **Costs of matching Metal** (host pages): the shadow copies a sampled 3840x2160 surface in whole each command buffer | | A render or compute state's creation hands the driver's making of its predicted pipeline (`pipeline/predicted.rs`, `pipeline/dispatch_making.rs`) to the runtime's pool, kept by the state as a draw's or dispatch's making is, and waits for it `pipeline_creation_wait` at most; a committed command buffer's recordings wait until its commit plus `pipeline_commit_wait` at most, one deadline its commands share, for its draws' and dispatches' (a compute encoder's, a render pass's tile dispatches) pipelines still being made (the scheduler wakes at the bound, `StepWaits::until`), an execution's replayed draws (`render/pending.rs`) among them, whose pipelines the commit's settle hands to the pool (a device replay's, one recording for every command, waits until made under either value), then record each such command as nothing: a draw's barriers and visibility query, a dispatch's barrier (a tile dispatch's copies into its scratch and back), no draw or dispatch, the command buffer running on without error. The making goes on, and the command buffers after it draw and dispatch with the pipeline once made. Metal compiles inside `newRenderPipelineState`, so no draw of a made state waits or is dropped; a host that creates a state inside a command buffer's encoding (the consumer creates a guest's state at an execution's first lookup of it) held that execution through the driver's whole compile: 11.59 s inside one execution on an M2 Pro (MoltenVK 1.4.2, a cold Metal compiler service; a sample of such a stall finds the compile's thread waiting in `MVKMetalCompiler::compile` for Metal's compiler), past the guest's 10 s FIFO check, which ended the guest's task. Each bound is 4.5 s: a creation and a commit may fall in one step of the guest's FIFO (a task's jobs run one after another, and a draw's own variant waits under its command buffer's bound), and no runtime call waits for both, so one step waits 9 s at most for makings, under that 10 s check. A creation waits on no command buffer's deadline and a `commit` on no creation's; a `commit` waits until its own deadline at most (it records there what it can, an execution of render commands the CPU writes among them), every other recording on the scheduler's thread. Made until made under either value, in the call that makes them: a draw that records nothing, one in a pass of custom sample positions and one recorded again into another instance of its pass (each in the draw's call or an execution's replay), a device replay's draws (in its `commit`), and a failed making made again (`PipelineWaitPolicy`'s docs). The runtime's: no pipeline differs. | `pipeline_waits = PipelineWaitPolicy::Bounded`, `pipeline_creation_wait = 4.5 s`, `pipeline_commit_wait = 4.5 s` | `pipeline_waits = PipelineWaitPolicy::Exact`: the creation makes its predicted pipeline before it returns (a render state's first key on its own thread, the rest on the pool, joined; a compute state's on its own thread), an execution's settle makes its replayed draws' pipelines at the commit, and a command buffer waits for each draw's and dispatch's pipeline until it is made | A draw whose pipeline was still being made `pipeline_commit_wait` after its command buffer's commit renders nothing in that command buffer (only there: later ones draw it), where Metal's renders: content drawn once (a layer, a glyph cache) stays without it until redrawn. A creation returns after `pipeline_creation_wait` at most with its making in flight (`WorkCounts::creations_left_making`). `DrawDroppedStillMaking` (`draw-dropped-still-making`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `CommandBuffer::dropped_draw` names the first with `VK_TIMEOUT`; `WorkCounts::draws_dropped_still_making`; `deferred_calls::a_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` and `under_the_exact_wait_a_held_making_holds_its_command_buffer_until_it_lands`. A dispatch whose pipeline was still being made then writes nothing in that command buffer, where Metal's runs: `DispatchDroppedStillMaking` (`dispatch-dropped-still-making`), `WorkCounts::dispatches_dropped_still_making`, the first named by `dropped_draw`; `deferred_calls::a_dispatch_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing`, `a_compute_state_s_creation_waits_its_bound_for_its_predicted_making` and `a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` | No GPU cost. The exact form holds the creating thread, and the command buffer, for the whole compile: up to 11.59 s on the M2 Pro's cold boot (that boot's 2,483 render state creations, translation included: 300 over 16 ms, 151 over 100 ms, 14 over 250 ms, 3 over 1 s, the longest 11.59 s, 5.82 s and 1.17 s), where the default holds a creation for 4.5 s at most and a command buffer for 4.5 s from its commit, which drops the draws of the compiles that outlast those (2 of that boot's 2,483 were over 4.5 s) for the command buffers committed before they land; bounds of 1 s dropped 39 draws in a cold boot on the M2 Pro, and the guest's menu bar, drawn once, stayed half drawn |