RUNTIME 2405: Grouped submissions: a group's summed expected GPU run stays within 16 ms

What: a batch joins a held group only where its queue's expected run is known and keeps the
group's expected runs, summed, within GROUP_RUN (16 ms). Otherwise the group goes first
(GroupEnd::Long, WorkCounts::group_ends_long), and the batch leads the next group where its own
run is known and within the bound, else goes alone. The expected run is unshared_hold::Expected,
which was fed only on a VkQueue an unshared queue holds. It is now fed on every VkQueue whose
batches group: Device::flies enters each batch there in the Flight. The hold's decisions still
read the Flight only where other queues' batches are held back.

Why: the driver runs a group as one kernel job, and Linux's amdgpu ends a job past its 2 s default
timeout with no error the device reports. On a Radeon 780M a single 3.2 s command buffer was ended
and the one behind it dropped. Four batches that each finish alone could cross the timeout
merged. With the bound, merging adds at most 16 ms of the others' expected work to any job. 16 ms
is the owner's line for an intolerable wait, and it also caps how late grouping makes a member's
completion seen (the FAST-PATHS row said about 20 ms behind a 20 ms batch). A queue none of whose
batches was seen complete has no expected run, so its batches go ungrouped until one completes.

Tests:
- tests::group_run: the admission rule (unknown, alone, a full group of quarters, 12 + 5 ms,
  overflow).
- runtime_lane::grouped_submissions::a_queue_s_batches_group_within_their_run: on a grouping
  device with one VkQueue, behind running work on another queue, a fresh queue's batches group
  none, a warmed one's group, and none after a 40 ms command buffer of its own.
- The grouped lane scenarios, and submit_check_device's paths test, warm each grouping queue with
  one completed fill first. The behind-running-work tests measure the fills' rate on a queue of
  its own, so the B queue's expected run stays its first fill's.
- Every place that sums the group ends counts the new end, and frame_costs prints it.

Docs: group.rs and unshared_hold.rs module docs, the grouping FAST-PATHS row (its bound and its
cost line), and WorkCounts::group_ends_long.

Verified in the lane (m3-max-34508, tip 37b1ca8563): clippy -D warnings with m2v_cpu_icd, runtime and
validation, all targets and features. Still running when landed: lavapipe tests (group_run, the
grouped lane, unshared_hold, submit_check_device, kernel_end_device, commit_and_submit,
queue_share_device, frame_costs), clippy plain and m2v_gpu, rustdoc, and the 780M before/after.
Expected, unverified: conformance cost records' grouping counts (not the cases' own, never gated)
may drop in cases that commit on fresh queues.

API: adds the field WorkCounts::group_ends_long (additive; api_signatures blessed at landing).
This commit is contained in:
Anees Iqbal committed 2026-11-15 18:29:57 -08:00
1 parent 7ed19b94bb
commit 5021e3b4ac
15 files changed
+323 -52

No files matched your search

@@ -1672,6 +1672,7 @@ impl Gpu for Runtime {
("group_ends_wait", c.group_ends_wait),
("group_ends_apart", c.group_ends_apart),
("group_ends_first_work", c.group_ends_first_work),
("group_ends_long", c.group_ends_long),
("group_ends_drained", c.group_ends_drained),
("group_ends_checks", c.group_ends_checks),
("group_ends_held", c.group_ends_held),
@@ -25,6 +25,18 @@
//! be seen complete at that batch's end, however long, and kept, behind the batch the hold let
//! go meanwhile.
//! A group goes at once when it holds [`GROUP_BATCHES`], so no submission holds more.
//! - **Bounded by its expected run.** The driver runs a group as one kernel job, which a kernel's
//! job timeout ends as a whole: Linux's amdgpu ends one past 2 s by default, with no error the
//! device reports (`gpu_time.rs`), where each batch alone may finish within it. So a batch joins
//! only where its queue's expected run is known (`unshared_hold::Expected`, fed on
//! every `VkQueue` whose batches group) and keeps the group's expected runs, summed, within
//! [`GROUP_RUN`] (16 ms): merging adds at most that much of the others' expected work to any
//! batch's job. Otherwise the group goes first (`GroupEnd::Long`), and the batch leads the next
//! group where its own run is known and within the bound, else goes alone: a queue whose batches
//! none was seen complete yet, or whose recent ones ran longer, groups none until it has a run
//! within the bound. An expected run is a few recent batches' (raised at once by a longer one,
//! halved toward a shorter one), so a batch longer than its queue's recent ones may still join
//! a group; the others' expected runs it then carries stay within the bound.
//! - **Checked ahead.** A batch with submission checks is ready only once they ran
//! (`checks.rs`), which the scheduler does for each line's head; here it runs those of the
//! batches right behind a head that goes too, so a line of checked batches (the consumer checks
@@ -119,6 +131,14 @@ use std::sync::Arc;
/// of at most this many less one.
pub(crate) const GROUP_BATCHES: usize = 4;
/// The most expected GPU run, in nanoseconds, of the batches one group holds, summed (the module
/// docs, "Bounded by its expected run"): 16 ms, the owner's line for an intolerable wait, which no
/// member's completion is then seen late by for the others' expected runs. It is 1/125 of the job
/// timeout Linux's amdgpu ends a kernel job at by default (2 s, its `lockup_timeout`, Linux 7.3.3),
/// past which a Radeon 780M's kernel ended a single command buffer of 3.2 s and dropped the one
/// behind it (`gpu_time.rs`).
pub(crate) const GROUP_RUN: u64 = 16_000_000;
/// The most `VkSubmitInfo`s a batch names: its work's and its finale's (`submit.rs`).
const BATCH_INFOS: usize = 2;
@@ -219,6 +239,13 @@ const IN_GROUP: u8 = 1;
/// A command buffer's `group_hold` bit: a thread waits for its completion.
const WAITED_FOR: u8 = 2;
/// Whether a batch of expected run `run` (nanoseconds; `None` where its queue has none yet) may
/// join batches whose expected runs sum to `held`: its run is known and the sum stays within
/// [`GROUP_RUN`] (the module docs, "Bounded by its expected run").
pub(crate) fn within_run(held: u64, run: Option<u64>) -> bool {
run.is_some_and(|run| held.saturating_add(run) <= GROUP_RUN)
}
/// What sent a group held (`WorkCounts::group_ends_full` and kin).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum GroupEnd {
@@ -233,6 +260,9 @@ pub(crate) enum GroupEnd {
/// A batch that may join did first work or names a wrapped image: it went last in the group's
/// call.
FirstWork,
/// A batch that may otherwise join is of unknown length, or would take the group's expected
/// run past [`GROUP_RUN`].
Long,
/// The pass found no batch left to submit.
Drained,
/// The pass found none ready, with submission checks or host steps left for the thread to run.
@@ -278,12 +308,14 @@ impl Info {
}
}
/// A batch held: its `VkSubmitInfo`s, how many command buffers they hold, and its submission,
/// published once the group is submitted.
/// A batch held: its `VkSubmitInfo`s, how many command buffers they hold, its submission,
/// published once the group is submitted, and its queue's expected run as it was held, in
/// nanoseconds.
struct Member {
infos: Vec<Info>,
buffers: usize,
submission: Submission,
run: u64,
}
/// The batches held for one kernel submission on one `VkQueue` (the module docs), in the
@@ -347,6 +379,12 @@ impl Group {
|| (joins && self.queue == queue && self.members.len() < GROUP_BATCHES)
}
/// Whether a batch of expected run `run` (nanoseconds; `None` where unknown) may wait in the
/// group as far as its run goes ([`within_run`]).
pub(crate) fn fits(&self, run: Option<u64>) -> bool {
within_run(self.members.iter().map(|member| member.run).sum(), run)
}
/// Whether a batch held signals the event of `semaphore` to `index` or above: only the group's
/// end meets a wait for it, so a batch with that wait goes after the group, in a submission
/// of its own (the module docs). A lower index was signalled before the group.
@@ -374,9 +412,15 @@ impl Group {
/// The batch [`open`](Group::open) took: its `VkSubmitInfo`s are `infos` (at most
/// [`BATCH_INFOS`]), with `buffers` command buffers, and its submission is published once the
/// group's is made. It signals each event's semaphore it names to its index, which the
/// group's end signals instead.
pub(crate) fn hold(&mut self, infos: &[InfoParts<'_>], buffers: usize, submission: Submission) {
/// group's is made; `run` its queue's expected run ([`fits`](Group::fits)). It signals each
/// event's semaphore it names to its index, which the group's end signals instead.
pub(crate) fn hold(
&mut self,
infos: &[InfoParts<'_>],
buffers: usize,
submission: Submission,
run: u64,
) {
for (semaphore, index) in submission.event_signals() {
match self.events.iter_mut().find(|(held, ..)| *held == semaphore) {
Some((_, lowest, highest)) => {
@@ -395,6 +439,7 @@ impl Group {
infos: held,
buffers,
submission,
run,
});
}
@@ -63,7 +63,9 @@ pub(super) use completion::Completion;
use copies_again::CopiesAgain;
pub(super) use first_submission::{NotedTable, ReplayTable};
use follow::{Follow, Release};
pub(super) use group::{Group, GroupEnd, GROUP_BATCHES};
pub(super) use group::{groups, Group, GroupEnd, GROUP_BATCHES};
#[cfg(test)]
pub(super) use group::{within_run, GROUP_RUN};
use rebound_use::{ReboundUse, Unlogged};
use spare_states::{KeptState, Room};
pub(crate) use stall::Stop;
@@ -479,7 +479,7 @@ impl CommandBufferShared {
.flat_map(|recorded| &recorded.segments)
.filter_map(|segment| segment.recorded.as_ref())
.any(|done| !done.piece_ends.is_empty());
let joins = {
let may_join = {
let sync = &state.batches.all()[index];
!alone
&& !pieced
@@ -491,10 +491,17 @@ impl CommandBufferShared {
&& (state.recorded[state.batch_range(index)].iter())
.all(|recorded| recorded.sparse.is_empty())
};
// Its queue's expected run: a batch of unknown length, or one that would take the group's
// past `GROUP_RUN`, joins none (`group.rs`).
let run = self.queue.expected().nanos();
let fits = scheduler.group.fits(run);
let joins = may_join && fits;
if !scheduler.group.admits(queue, joins) {
let end = match met {
true => GroupEnd::Wait,
false => GroupEnd::Apart,
let long = may_join && !fits && scheduler.group.queue() == queue;
let end = match (met, long) {
(true, _) => GroupEnd::Wait,
(false, true) => GroupEnd::Long,
(false, false) => GroupEnd::Apart,
};
return Ok(Submitting::AfterGroup(end));
}
@@ -1670,7 +1677,9 @@ impl CommandBufferShared {
(false, true) => &parts[..1],
(false, false) => &parts[..],
};
scheduler.group.hold(parts, buffers, submission);
scheduler
.group
.hold(parts, buffers, submission, run.unwrap_or(0));
Ok(Submitting::Grouped)
}
@@ -0,0 +1,32 @@
//! A group's bound on its batches' expected runs (`command_buffer/group.rs`, `GROUP_RUN`): a
//! batch joins only where its queue's expected run is known, and the group's expected runs,
//! summed with its own, stay within 16 ms.
use crate::command_buffer::{within_run, GROUP_BATCHES, GROUP_RUN};
/// A millisecond, in nanoseconds.
const MS: u64 = 1_000_000;
#[test]
fn a_batch_joins_only_with_a_known_run_within_the_bound() {
assert_eq!(GROUP_RUN, 16 * MS);
// A batch of a queue none of whose batches was seen complete: none.
assert!(!within_run(0, None));
assert!(!within_run(4 * MS, None));
// The first batch of a group: within the bound alone, or not.
assert!(within_run(0, Some(16 * MS)));
assert!(!within_run(0, Some(16 * MS + 1)));
// A full group, a quarter of the bound each.
let quarter = GROUP_RUN / GROUP_BATCHES as u64;
let mut held = 0;
for _ in 0..GROUP_BATCHES {
assert!(within_run(held, Some(quarter)), "{held} held");
held += quarter;
}
assert!(!within_run(held, Some(1)));
// 12 ms held: a batch of 5 ms waits for the next group, one of 4 ms joins.
assert!(!within_run(12 * MS, Some(5 * MS)));
assert!(within_run(12 * MS, Some(4 * MS)));
// No overflow.
assert!(!within_run(u64::MAX, Some(1)));
}
@@ -216,13 +216,14 @@ fn queue_times_are_noted_in_the_order_of_a_queue_s_submissions_and_only_where_as
}
/// The groups of batches held for one kernel submission `device` sent so far, each counted once
/// by what sent it (`WorkCounts::group_ends_full` and the six after it).
/// by what sent it (`WorkCounts::group_ends_full` and the seven after it).
fn groups_ended(device: &Device) -> u64 {
let counts = device.work_counts();
counts.group_ends_full
+ counts.group_ends_wait
+ counts.group_ends_apart
+ counts.group_ends_first_work
+ counts.group_ends_long
+ counts.group_ends_drained
+ counts.group_ends_checks
+ counts.group_ends_held
@@ -310,6 +310,7 @@ mod grid_classes;
mod grid_widths;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod group_resolve_apart;
mod group_run;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod hand_out_waits;
#[cfg(unix)]
@@ -512,6 +512,14 @@ fn the_paths_follow_the_verdicts() {
let queue = device.new_command_queue().unwrap();
let event = device.new_shared_event().unwrap();
let target = device.new_buffer(4096, ResourceOptions::private()).unwrap();
// The queue's first command buffer alone: a queue none of whose batches was seen complete has
// no expected run, and its batches wait in no group (`command_buffer/group.rs`, `GROUP_RUN`).
let first = queue.command_buffer().unwrap();
let mut blit = first.blit_command_encoder().unwrap();
blit.fill_buffer(&target, 0..4096, 0).unwrap();
blit.end_encoding().unwrap();
first.commit().unwrap();
assert!(first.wait_until_completed_for(WAIT).is_ok());
let before = device.work_counts();
let mut last = None;
for round in 0..8u8 {
@@ -42,7 +42,9 @@
//! once by a longer one and halved toward a shorter one, so a queue whose batches got shorter
//! takes its new length within a few batches, while one long batch counts at once. A run several
//! batches complete in shares among the other queues' batches among them; an unshared queue's
//! takes no share.
//! takes no share. Fed on a `VkQueue` an unshared queue holds, and on one whose batches may
//! wait in a group, whose expected run it bounds (`command_buffer/group.rs`, `GROUP_RUN`): there
//! every batch takes a place in the [`Flight`], which only the former holds batches back by.
//! - **Unknown length.** A batch of a queue with no run seen yet may be of any length: while one
//! is in flight, no other batch of the other queues goes there until it is seen complete, which
//! gives its queue a run. So an application that commits several command buffers at once does
@@ -370,14 +372,18 @@ impl crate::Device {
}
/// How a batch of a command queue (`unshared` where made so) taken on `VkQueue` `index` enters
/// its flight, `expected` its queue's expected run.
/// its flight, `expected` its queue's expected run: where other queues' batches are held back
/// from it, or where its batches may wait in a group, whose expected run is bounded
/// (`command_buffer/group.rs`, `GROUP_RUN`).
pub(crate) fn flies<'a>(
&self,
index: usize,
unshared: bool,
expected: &'a Arc<Expected>,
) -> Flies<'a> {
match (self.holds_back_for_unshared(index), unshared) {
let flown =
self.holds_back_for_unshared(index) || crate::command_buffer::groups(self, index);
match (flown, unshared) {
(false, _) => Flies::Not,
(true, true) => Flies::Unshared,
(true, false) => Flies::Other(expected),
@@ -304,7 +304,7 @@ pub(crate) struct Counters {
grouped_submissions: AtomicU64,
batches_grouped: AtomicU64,
/// By `GroupEnd`, in its order.
group_ends: [AtomicU64; 7],
group_ends: [AtomicU64; 8],
texture_faces_made: AtomicU64,
attached_read_swaps: AtomicU64,
attached_read_swap_reads: AtomicU64,
@@ -7754,7 +7754,7 @@ pub struct WorkCounts {
/// The batches those calls submitted.
pub batches_grouped: u64,
/// Groups of batches held for one kernel submission (`CompletionPolicy::Grouped`) that went
/// holding the most they may (four), each group counted once by what sent it; with the six
/// holding the most they may (four), each group counted once by what sent it; with the seven
/// fields after this one, every group. Their spread says why a device's groups hold fewer.
pub group_ends_full: u64,
/// Groups that went before a batch that waits for an event value a batch they held signals,
@@ -7768,6 +7768,11 @@ pub struct WorkCounts {
/// Groups that went in the call of a batch that could join but did first work or names a
/// texture over the caller's image, submitted last.
pub group_ends_first_work: u64,
/// Groups that went before a batch that could otherwise join but whose queue's expected run
/// is unknown (none of its batches seen complete yet) or would take the group's summed
/// expected run past 16 ms (`command_buffer/group.rs`, `GROUP_RUN`): that batch leads the
/// next group where its own run is known and within the bound, else goes alone.
pub group_ends_long: u64,
/// Groups that went when the scheduler found no batch left to submit.
pub group_ends_drained: u64,
/// Groups that went when the scheduler found no batch ready, with submission checks or host
@@ -12035,6 +12040,7 @@ impl Device {
group_ends_wait: group_end(GroupEnd::Wait),
group_ends_apart: group_end(GroupEnd::Apart),
group_ends_first_work: group_end(GroupEnd::FirstWork),
group_ends_long: group_end(GroupEnd::Long),
group_ends_drained: group_end(GroupEnd::Drained),
group_ends_checks: group_end(GroupEnd::Checks),
group_ends_held: group_end(GroupEnd::Held),
@@ -1940,7 +1940,8 @@ fn measure(runs: &[Run]) {
eprintln!(
"FRAME-COST {name} {label}: a frame's groups of batches by what sent them: {:.1} \
full, {:.1} before a wait for a signal held, {:.1} before a batch apart, {:.1} with \
first work, {:.1} with no batch left, {:.1} with checks or steps left, {:.1} with the \
first work, {:.1} before a batch of unknown or too long an expected run, {:.1} with \
no batch left, {:.1} with checks or steps left, {:.1} with the \
rest held back; {:.1} of them kept for their queue's earlier work, {:.1} of those \
sent by a wait; its batches by the earlier ones of their queue pending as each went: \
{:.1} none, {:.1} one, {:.1} two or three, {:.1} four or more",
@@ -1948,6 +1949,7 @@ fn measure(runs: &[Run]) {
per_frame(|c| c.group_ends_wait),
per_frame(|c| c.group_ends_apart),
per_frame(|c| c.group_ends_first_work),
per_frame(|c| c.group_ends_long),
per_frame(|c| c.group_ends_drained),
per_frame(|c| c.group_ends_checks),
per_frame(|c| c.group_ends_held),
@@ -2458,6 +2460,7 @@ fn a_frame_s_passes_and_commits_begin_their_command_buffers_within_their_bound()
+ begun(|c| c.group_ends_wait)
+ begun(|c| c.group_ends_apart)
+ begun(|c| c.group_ends_first_work)
+ begun(|c| c.group_ends_long)
+ begun(|c| c.group_ends_drained)
+ begun(|c| c.group_ends_checks)
+ begun(|c| c.group_ends_held);
@@ -3,7 +3,11 @@
//!
//! [`BATCHES`] command buffers committed on one queue, each filling a buffer of its own with a
//! value of its own, the first after a wait for an event the host has not raised, all wait behind
//! that wait; once the host raises it the scheduler finds them ready together. Under the default
//! that wait; once the host raises it the scheduler finds them ready together. The queue's first
//! command buffer runs alone before them ([`warm`]), as every queue's in these tests that groups:
//! a queue none of whose batches was seen complete has no expected run, and its batches wait in no
//! group, nor do those of a queue whose recent batches ran past 16 ms
//! ([`a_queue_s_batches_group_within_their_run`]). Under the default
//! `CompletionPolicy::Grouped`, on a device whose check found a submission that signals nothing
//! merged into the next one (the runtime's `submit_check.rs`) and whose queues' failures are not
//! relayed (MoltenVK's are: `device/relay.rs`), they go in `vkQueueSubmit`
@@ -66,7 +70,7 @@ use super::{
use crate::gpu::TEST_DEVICE;
use metal2vulkan::device::CompletionPolicy;
use metal2vulkan_runtime::{
Buffer, CommandBuffer, CommandBufferStatus, Degradation, DeviceOptions, EventRef,
Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, Degradation, DeviceOptions, EventRef,
ResourceOptions, ShaderCacheOptions, WorkCounts,
};
use std::sync::{Arc, Mutex};
@@ -82,8 +86,9 @@ pub(super) const GROUPED: [Degradation; 1] = [Degradation::GroupedCompletion];
/// The groups that went between `before` and `after`, by what sent them: full, before a wait for
/// a held signal, before a batch apart, with first work, drained, for checks or steps left, held
/// back (`WorkCounts::group_ends_full` and kin).
fn group_ends(before: &WorkCounts, after: &WorkCounts) -> [u64; 7] {
/// back, before a batch of unknown or too long an expected run (`WorkCounts::group_ends_full` and
/// kin).
fn group_ends(before: &WorkCounts, after: &WorkCounts) -> [u64; 8] {
let ends = |counts: &WorkCounts| {
[
counts.group_ends_full,
@@ -93,6 +98,7 @@ fn group_ends(before: &WorkCounts, after: &WorkCounts) -> [u64; 7] {
counts.group_ends_drained,
counts.group_ends_checks,
counts.group_ends_held,
counts.group_ends_long,
]
};
let (before, after) = (ends(before), ends(after));
@@ -142,6 +148,24 @@ fn taken_in(device: &metal2vulkan_runtime::Device) {
}
}
/// Commit `queue`'s first command buffer, a fill of a buffer of its own, and wait for it: a queue
/// none of whose batches was seen complete has no expected run, and its batches wait in no group
/// (the runtime's `command_buffer/group.rs`, `GROUP_RUN`).
fn warm(device: &metal2vulkan_runtime::Device, queue: &CommandQueue) {
let buffer = device.new_buffer(BYTES, ResourceOptions::shared()).unwrap();
let command_buffer = queue.command_buffer().unwrap();
let mut blit = command_buffer.blit_command_encoder().unwrap();
blit.fill_buffer(&buffer, 0..BYTES, 0).unwrap();
blit.end_encoding().unwrap();
command_buffer.commit().unwrap();
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(
command_buffer.error(),
None,
"the queue's first command buffer"
);
}
/// The bytes of a host-visible buffer.
fn bytes_of(buffer: &Buffer) -> Vec<u8> {
let contents = buffer.contents().expect("a host-visible buffer");
@@ -153,7 +177,7 @@ fn bytes_of(buffer: &Buffer) -> Vec<u8> {
/// The module docs' run under `completion`, each command buffer `checked` or not: the
/// `vkQueueSubmit` calls that held several batches, the batches they held, the kernel submissions
/// in all, the grouped-completion notices, and whether the device groups its batches ([`groups`]).
fn run(completion: CompletionPolicy, checked: bool) -> (u64, u64, u64, usize, bool, [u64; 7]) {
fn run(completion: CompletionPolicy, checked: bool) -> (u64, u64, u64, usize, bool, [u64; 8]) {
let messages = Messages::default();
let cache = ScratchCache::new().unwrap();
let (grouped, batches, submissions, grouping, ends) = {
@@ -163,6 +187,7 @@ fn run(completion: CompletionPolicy, checked: bool) -> (u64, u64, u64, usize, bo
.unwrap();
let grouping = groups(&device);
let queue = device.new_command_queue().unwrap();
warm(&device, &queue);
let event = device.new_shared_event().unwrap();
let buffers: Vec<Buffer> = (0..BATCHES)
.map(|_| device.new_buffer(BYTES, ResourceOptions::shared()).unwrap())
@@ -265,7 +290,7 @@ fn grouped_where_merging(checked: bool) {
"groups by what sent them {ends:?}, {grouped} calls"
);
} else {
assert_eq!((grouped, batches, heard, ends), (0, 0, 0, [0; 7]));
assert_eq!((grouped, batches, heard, ends), (0, 0, 0, [0; 8]));
}
}
@@ -371,7 +396,7 @@ fn completions_wake_the_scheduler_only_once_a_head_may_go() {
fn the_exact_completion_submits_each_batch_alone() {
for checked in [false, true] {
let (grouped, batches, submissions, heard, _, ends) = run(CompletionPolicy::Exact, checked);
assert_eq!((grouped, batches, heard, ends), (0, 0, 0, [0; 7]));
assert_eq!((grouped, batches, heard, ends), (0, 0, 0, [0; 8]));
assert!(submissions >= BATCHES as u64, "{submissions} calls");
}
}
@@ -401,7 +426,7 @@ struct Scenario {
/// Whether the device groups its batches ([`groups`]).
grouping: bool,
/// The groups by what sent them ([`group_ends`]).
ends: [u64; 7],
ends: [u64; 8],
/// The event waits found met as the scheduler took their batches
/// (`WorkCounts::event_waits_met`), the first step's wait for the gate among them.
met: u64,
@@ -427,6 +452,9 @@ fn event_scenario(completion: CompletionPolicy, steps: &[Step], last: u64) -> Sc
device.new_command_queue().unwrap(),
device.new_command_queue().unwrap(),
];
for queue in &queues {
warm(&device, queue);
}
let gate = device.new_shared_event().unwrap();
let event = device.new_event().unwrap();
let large = (steps.iter().any(|step| step.fills > 0)).then(|| {
@@ -544,10 +572,10 @@ fn both_policies(steps: &[Step], last: u64, waits: bool) {
"groups by what sent them {ends:?}: none before a wait"
);
} else {
assert_eq!((grouped, ends), (0, [0; 7]));
assert_eq!((grouped, ends), (0, [0; 8]));
}
let run = event_scenario(CompletionPolicy::Exact, steps, last);
assert_eq!((run.grouped, run.batches, run.ends), (0, 0, [0; 7]));
assert_eq!((run.grouped, run.batches, run.ends), (0, 0, [0; 8]));
}
/// Command buffers that each signal `E` with the next value ride in groups, `E`'s signals moved to
@@ -664,10 +692,10 @@ fn a_command_buffer_that_waits_leads_its_group() {
"groups by what sent them {ends:?}, {met} event waits met (the gate's among them): a \
command buffer that waits for a value not seen complete joined a group"
),
false => assert_eq!(ends, [0; 7]),
false => assert_eq!(ends, [0; 8]),
}
let run = event_scenario(CompletionPolicy::Exact, &steps, 1);
assert_eq!((run.grouped, run.batches, run.ends), (0, 0, [0; 7]));
assert_eq!((run.grouped, run.batches, run.ends), (0, 0, [0; 8]));
}
/// The bytes each command buffer of `grouped_completion_delays` fills: about 0.1 to 0.2 ms of the
@@ -697,6 +725,7 @@ fn host_seconds() -> f64 {
/// times, in microseconds, by place.
fn delay_round(device: &metal2vulkan_runtime::Device, buffers: &[Buffer]) -> Vec<(f64, f64)> {
let queue = device.new_command_queue().unwrap();
warm(device, &queue);
let event = device.new_shared_event().unwrap();
let handled: Vec<Arc<Mutex<f64>>> = buffers.iter().map(|_| Arc::default()).collect();
let committed: Vec<CommandBuffer> = (buffers.iter().zip(&handled).enumerate())
@@ -925,6 +954,121 @@ fn a_stretched_command_buffer_stays_within_its_job_bound() {
assert_eq!(slow.stretched(1), 100);
}
/// The GPU work, at the measured rate, of the command buffer that takes the queue of
/// [`a_queue_s_batches_group_within_their_run`] past the bound: 40 ms, past [`GROUP_RUN`].
const PAST_GROUP_RUN: std::time::Duration = std::time::Duration::from_millis(40);
/// The runtime's bound on a group's expected runs, summed (`command_buffer/group.rs`).
const GROUP_RUN: std::time::Duration = std::time::Duration::from_millis(16);
/// A queue's batches wait in a group only where its expected run is known and keeps the group's
/// within [`GROUP_RUN`] (the runtime's `command_buffer/group.rs`). In each round, a command
/// buffer of fills on one queue runs about 90 ms while [`BATCHES`] small fills are committed on
/// another queue of the same `VkQueue`, each taken in before the next. On a fresh queue, none of
/// whose batches was seen complete, they go alone; once one was, they wait in a group behind the
/// running work; after a command buffer of the queue's own ran [`PAST_GROUP_RUN`], alone again.
/// Every command buffer completes with its own fill, and the layer reports nothing. Where the device
/// groups nothing, or the two queues submit to different `VkQueue`s, no round's count is checked.
#[test]
fn a_queue_s_batches_group_within_their_run() {
let messages = Messages::default();
let cache = ScratchCache::new().unwrap();
let (grouping, shared, rounds, past) = {
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| {
options.policy.completion = CompletionPolicy::Grouped;
at_plan(options)
})
.unwrap();
let grouping = groups(&device);
let (running, queue) = (
device.new_command_queue().unwrap(),
device.new_command_queue().unwrap(),
);
let large = device
.new_buffer(RUNNING_FILL, ResourceOptions::private())
.unwrap();
let rate = running_fills(&running, &large, std::time::Duration::from_millis(30));
let shared = running.vk_queue_sharing().0 == queue.vk_queue_sharing().0;
let buffers: Vec<Buffer> = (0..BATCHES)
.map(|_| device.new_buffer(BYTES, ResourceOptions::shared()).unwrap())
.collect();
// One round, its fills of `value` and up: the grouped submissions it made.
let round = |value: u8| {
let before = device.work_counts();
let blocker = running.command_buffer().unwrap();
let mut blit = blocker.blit_command_encoder().unwrap();
for fill in 0..rate.fills {
blit.fill_buffer(&large, 0..RUNNING_FILL, fill as u8)
.unwrap();
}
blit.end_encoding().unwrap();
blocker.commit().unwrap();
taken_in(&device);
let committed: Vec<CommandBuffer> = (buffers.iter().enumerate())
.map(|(at, buffer)| {
let command_buffer = queue.command_buffer().unwrap();
let mut blit = command_buffer.blit_command_encoder().unwrap();
blit.fill_buffer(buffer, 0..BYTES, value + at as u8)
.unwrap();
blit.end_encoding().unwrap();
command_buffer.commit().unwrap();
taken_in(&device);
command_buffer
})
.collect();
for command_buffer in committed.iter().chain([&blocker]) {
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(command_buffer.error(), None, "round of {value}");
}
for (at, buffer) in buffers.iter().enumerate() {
let wrong = (bytes_of(buffer).iter())
.filter(|&&byte| byte != value + at as u8)
.count();
assert_eq!(
wrong, 0,
"round of {value}, buffer {at}: bytes off its fill"
);
}
device.work_counts().grouped_submissions - before.grouped_submissions
};
let unknown = round(1);
let known = round(11);
// A command buffer of the queue's own past the bound: its queue's expected run takes a
// longer run at once.
let long = queue.command_buffer().unwrap();
let fills = (PAST_GROUP_RUN.as_nanos() / rate.each.as_nanos().max(1)) as usize + 1;
let mut blit = long.blit_command_encoder().unwrap();
for fill in 0..fills {
blit.fill_buffer(&large, 0..RUNNING_FILL, fill as u8)
.unwrap();
}
blit.end_encoding().unwrap();
let start = std::time::Instant::now();
long.commit().unwrap();
long.wait_until_completed_for(WAIT).unwrap();
assert_eq!(long.error(), None, "the long command buffer");
let past = gpu_took(&long, start.elapsed());
let over = round(21);
(grouping, shared, [unknown, known, over], past)
};
layer_reported_nothing_at_all(&messages);
eprintln!(
"GROUPED-RUN grouping {grouping}, one VkQueue {shared}: grouped submissions with the run \
unknown, known and past the bound (after {past:?} of the queue's own) {rounds:?}"
);
if !(grouping && shared) {
return;
}
assert!(past > GROUP_RUN, "the long command buffer ran {past:?}");
let [unknown, known, over] = rounds;
assert_eq!(unknown, 0, "grouped before the queue had a run: {rounds:?}");
assert!(
known >= 1,
"none grouped with the queue's run known: {rounds:?}"
);
assert_eq!(over, 0, "grouped past the bound: {rounds:?}");
}
/// What each command buffer behind `A` carries in [`behind_running_work`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Carried {
@@ -967,7 +1111,7 @@ struct Behind {
/// `A` still ran as the wait for the last sent its group, where it did.
a_ran_at_send: bool,
/// The groups by what sent them ([`group_ends`]).
ends: [u64; 7],
ends: [u64; 8],
/// The submission checks run.
checks: u64,
}
@@ -984,12 +1128,15 @@ fn behind_running_work(completion: CompletionPolicy, stretch: usize, carried: Ca
.unwrap();
let grouping = groups(&device);
let queue = device.new_command_queue().unwrap();
warm(&device, &queue);
let large = device
.new_buffer(RUNNING_FILL, ResourceOptions::private())
.unwrap();
// Its first fill alone (first work goes at once), then enough to run 300 ms or more, at
// most `A_MOST`.
let rate = running_fills(&queue, &large, std::time::Duration::from_millis(100));
// most `A_MOST`: measured on a queue of its own, so the `B`s' queue's expected run stays
// its first fill's (the runtime's `command_buffer/group.rs`, `GROUP_RUN`).
let calibrating = device.new_command_queue().unwrap();
let rate = running_fills(&calibrating, &large, std::time::Duration::from_millis(100));
let fills = rate.stretched(stretch);
let buffers: Vec<Buffer> = (0..BEHIND)
.map(|_| device.new_buffer(BYTES, ResourceOptions::shared()).unwrap())
@@ -1203,7 +1350,7 @@ fn held_behind_running_work(carried: Carried) {
} else {
assert_eq!(
(seen.kept, seen.sent, seen.ends),
(0, 0, [0; 7]),
(0, 0, [0; 8]),
"{seen:?}"
);
}
@@ -1220,7 +1367,7 @@ fn the_exact_completion_keeps_no_group_behind_running_work() {
}
assert_eq!(
(seen.kept, seen.sent, seen.ends),
(0, 0, [0; 7]),
(0, 0, [0; 8]),
"{seen:?}"
);
}
@@ -1248,7 +1395,7 @@ struct HandlerWait {
reached: bool,
waited: std::time::Duration,
/// The groups by what sent them, from `Y`'s commit on ([`group_ends`]).
ends: [u64; 7],
ends: [u64; 8],
/// What the device counted since `A`'s commit, once `A` was taken in, `B` scheduled and `X`
/// scheduled.
steps: [StepCounts; 3],
@@ -1270,7 +1417,7 @@ struct StepCounts {
/// more.
pending: [u64; 3],
/// The groups by what sent them ([`group_ends`]).
ends: [u64; 7],
ends: [u64; 8],
}
impl StepCounts {
@@ -1345,11 +1492,15 @@ fn behind_another_queue_s_handler(stretch: usize) -> HandlerWait {
blit.end_encoding().unwrap();
command_buffer
};
// Each queue's first command buffer, and the device's first work, before `A`.
let warm = fill(&second, 2);
warm.commit().unwrap();
warm.wait_until_completed_for(WAIT).unwrap();
let rate = running_fills(&first, &large, std::time::Duration::from_millis(100));
// Each queue's first command buffer, and the device's first work, before `A`; the fills'
// rate measured on a queue of its own, so the first queue's expected run stays its first
// fill's (the runtime's `command_buffer/group.rs`, `GROUP_RUN`).
warm(&device, &first);
let warmed = fill(&second, 2);
warmed.commit().unwrap();
warmed.wait_until_completed_for(WAIT).unwrap();
let calibrating = device.new_command_queue().unwrap();
let rate = running_fills(&calibrating, &large, std::time::Duration::from_millis(100));
let fills = rate.stretched(stretch);
let running = first.command_buffer().unwrap();
let mut blit = running.blit_command_encoder().unwrap();
@@ -1533,7 +1684,7 @@ struct KeptSignalWait {
/// From `X`'s completed handler to `Y`'s.
y_after_x: Option<std::time::Duration>,
/// The groups from `Y`'s take-in by what sent them ([`group_ends`]).
ends: [u64; 7],
ends: [u64; 8],
}
/// Two long command buffers `A` then `B` on one queue, of `stretch` times the fills the
@@ -1568,14 +1719,19 @@ fn behind_a_kept_signal(stretch: usize) -> KeptSignalWait {
.map(|_| device.new_buffer(BYTES, ResourceOptions::shared()).unwrap())
.collect();
let event = device.new_shared_event().unwrap();
// The second queue's first command buffer, and the device's first work, before `A`.
let warm = second.command_buffer().unwrap();
let mut blit = warm.blit_command_encoder().unwrap();
// The second queue's first command buffer, and the device's first work, before `A`; the
// first queue's too, and the fills' rate measured on a queue of its own, so the first
// queue's expected run stays its first fill's (the runtime's `command_buffer/group.rs`,
// `GROUP_RUN`).
let warmed = second.command_buffer().unwrap();
let mut blit = warmed.blit_command_encoder().unwrap();
blit.fill_buffer(&buffers[1], 0..BYTES, 0).unwrap();
blit.end_encoding().unwrap();
warm.commit().unwrap();
warm.wait_until_completed_for(WAIT).unwrap();
let rate = running_fills(&first, &large, std::time::Duration::from_millis(100));
warmed.commit().unwrap();
warmed.wait_until_completed_for(WAIT).unwrap();
warm(&device, &first);
let calibrating = device.new_command_queue().unwrap();
let rate = running_fills(&calibrating, &large, std::time::Duration::from_millis(100));
let fills = rate.stretched(stretch);
let long = || {
let command_buffer = first.command_buffer().unwrap();
@@ -1714,7 +1870,7 @@ fn a_shared_event_wait_for_a_kept_group_s_signal_ends_at_the_next_completion_tur
if !seen.grouping {
assert_eq!(
(seen.kept, seen.ends),
(0, [0; 7]),
(0, [0; 8]),
"a group on a device that groups none: {seen:?}"
);
} else if seen.shared {
+1 -1
View File
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523;
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
/// keeps no history.
pub const RUNTIME_VERSION: u32 = 2404;
pub const RUNTIME_VERSION: u32 = 2405;
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
@@ -3112,6 +3112,7 @@ field metal2vulkan-runtime::WorkCounts.group_ends_drained pub group_ends_drained
field metal2vulkan-runtime::WorkCounts.group_ends_first_work pub group_ends_first_work: u64
field metal2vulkan-runtime::WorkCounts.group_ends_full pub group_ends_full: u64
field metal2vulkan-runtime::WorkCounts.group_ends_held pub group_ends_held: u64
field metal2vulkan-runtime::WorkCounts.group_ends_long pub group_ends_long: u64
field metal2vulkan-runtime::WorkCounts.group_ends_wait pub group_ends_wait: u64
field metal2vulkan-runtime::WorkCounts.grouped_submissions pub grouped_submissions: u64
field metal2vulkan-runtime::WorkCounts.groups_kept_pending pub groups_kept_pending: u64
Can't render this file because it is too large.
+1 -1
View File
@@ -35,7 +35,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X
| A blend into a packed 16-bit attachment the device renders through its word view (`A1BGR5Unorm`, `ABGR4Unorm` on the RTX 5080; `WordAttachment`), which the function computes in the interlocked storage form, reads the attachment's codes, where Metal's tile holds the pass's clear and each earlier blend's result as a `half`, finer; under fast math it also sums a few states otherwise than Metal. Every device rendering such an attachment. | The in-shader blend over the codes (no switch) | **Not built yet:** the extended-range attachments' `half` shadow (`render/extended_shadow.rs`, `VariantKey::extended_shadows`) taken by word attachments: the runtime's shadow start and end, its load of the codes and the clear's halves, and the word's shadowed variant in `lower::fragment::fetch`, for a single-sampled pass and a multisampled one (an extended-range color's shadow holds per sample, from the pass's clear). Fast math's regrouped sums have no model | One code: without fast math exact over a loaded attachment (the 2,891 states of the M3 sweep, every channel), under fast math 3,527 of 94,732,288 channels a code apart; after a clear or an earlier blend in the pass, a code apart where the two readings store different codes. `DeviceColorConversion` (`device-color-conversion`) | Not measured. Expected from the shadow's form: an `R16G16B16A16_SFLOAT` image of the pass's extent per such color (8 bytes a pixel, 16.6 MB at 1920x1080), set at the draw it starts by a fill or a load dispatch, and an 8-byte storage read and write per blended fragment inside the interlock beside the word's |
| 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. The compressed image lies in the heap only where the heap's answer holds it (`heap_answers = HeapAnswerPolicy::Device`, the next row). This 2048x2048 texture's does not under either answer policy, so it takes the linear image under either compression value: a clear 963.5 us against 958.4 us under `heap_answers = HeapAnswerPolicy::Metal`, 955.3 us against 971.4 us under the default, the copy 488-496 us |
| A heap texture whose image of the route the device takes for it needs more bytes or a coarser alignment of the heap than Metal's answer (each of a guest compositor's 22 heap shapes, `RGBA16Float` 2D arrays of one slice and 2D textures to 456x255: on ANV, whose compressed images align to 64 KiB; on the RTX 3090 at 1024; on the RX 7900 XTX at 256 to 64 KiB, where Metal answers 128 for each but the 299x299 array's 16 KiB): the size query (`heapTextureSizeAndAlign`) answers the larger of Metal's answer and that image's, and the texture lies in that image in the heap's bytes. A `Shared` texture's answer also holds the linear image a heap over host pages binds for it. Its alignment is the device's up to a heap's memory's own, 256 KiB, past which no image binds there (on the RX 7900 XTX, 128 KiB for a depth image and 256 KiB for a 4-sample render target past 128 texels a side). Where that image's alignment is past 256 KiB, or past both 4 KiB and the texture's size, the texture's image that a 4 KiB alignment holds takes its place (host-transfer usage, else linear), the answer that one's; else Metal's answer, as under the switch. A multisample texture takes it too and lies in its image in the heap's bytes, in the driver's layout of its samples, where under the switch it is a shadow of its samples in Metal's tiles (`heap_placed_targets`: a frame's 4-sample `RGBA16Float` and `Depth32Float` targets placed in a tracked `Private` heap). Metal's measured answers (4:2:2, one-plane YCbCr, two-plane extended-range, `X32_Stencil8`, `BlockWritesOnly` textures) and textures whose image lies in memory of its own keep Metal's answer. The runtime's choice: no pipeline differs. | `heap_answers = HeapAnswerPolicy::Device` | `heap_answers = HeapAnswerPolicy::Metal`: Metal's answer; the texture lies in an image that fits it (host-transfer usage, else linear: `heap-texture-host-transfer`, `heap-texture-linear`), else is a shadow of the heap's bytes in Metal's tiles, copied in before and out after the commands that use it (`shadowed-texture`) | A heap holds fewer such textures than Metal's: of the 22 shapes, the small arrays answer 4096 bytes where Metal answers 128 to 2176 (on ANV and the XTX; the XTX's 1x1 answers 256), and the 22 answers take 3769962 bytes of heaps placed one after another on ANV and 4155498 on the XTX, against Metal's 3656426 (`heap_texture_images`, `HEAP-COUNT`). A program that places a heap's resources by sizes of its own rather than the query's may overlap the texture with its neighbour; Metal's answer differs by GPU too (65536 on an AMD Radeon Pro 5300M, 4096 on an Intel UHD 630, 128 on an M3). `HeapTextureLargerThanMetal` (`heap-texture-larger-than-metal`), announced once per device; `tests::heap`, `tests::heap_placed_targets`, `heap_shadow_costs::heap_texture_images` | Of the 22 shapes made in heaps under the switch (`heap_texture_images`), on ANV (Iris Xe of RPL-P) 14 lie in an image put in place of their first one and 7 are shadows in Metal's tiles; on the RX 7900 XTX (RADV) 1 and 8, every other answer Metal's; under the default none on either. ANV (`heap_shadow_costs::heap_texture_shadow_costs`), a 1x1 `RGBA16Float` array held as a shadow: a frame that clears it and blits it 34.7 us in the heap against 8.2 us outside |
| 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 device whose own check finds a submission that signals nothing merged into the next (`submit_check.rs`, once per driver, release and kernel: one `vkQueueSubmit` of four empty infos against four calls of one, merged where the one costs at most 0.6 of the four; Mesa 26.2.6's RADV on the Radeon 780M, the RX 7900 XTX and the RX 550 at 0.33-0.38, ANV on the Iris Xe of RPL-P at 0.39, MoltenVK 1.4.2 on the M3 Max at 0.98; a device whose check has not answered, or that does not merge, 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; nor are they kept where the scheduler's thread runs next a submission handler of another queue's command buffer: they go first, as Metal schedules a queue's command buffers whatever another queue's handler does (an M3 Max, probe `cross_queue_handler_waits`); 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 batch a committing thread submits (`CommandBuffer::commit_and_submit`) goes alone where its `VkQueue` runs at most one earlier submission not seen complete, as the pass that held it would send the group at once; where two or more run it is left to the scheduler's thread, which holds it. 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 6Line truncated
| 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 and at most 16 ms of their queues' expected GPU runs summed (`GROUP_RUN`, `command_buffer/group.rs`: a kernel job that a timeout ends as a whole, as Linux's amdgpu ends one past 2 s by default, never carries more of the others' expected work than that), only the last signalling the queue's timeline, on a device whose own check finds a submission that signals nothing merged into the next (`submit_check.rs`, once per driver, release and kernel: one `vkQueueSubmit` of four empty infos against four calls of one, merged where the one costs at most 0.6 of the four; Mesa 26.2.6's RADV on the Radeon 780M, the RX 7900 XTX and the RX 550 at 0.33-0.38, ANV on the Iris Xe of RPL-P at 0.39, MoltenVK 1.4.2 on the M3 Max at 0.98; a device whose check has not answered, or that does not merge, 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 does a batch whose queue's expected run is unknown (none of its batches seen complete yet) or would take the group past 16 ms (`WorkCounts::group_ends_long`), leading the next group where its own run is within the bound; an expected run is the queue's recent batches' runs as their `VkQueue`'s oldest (`unshared_hold::Expected`, raised at once by a longer one, halved toward a shorter 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; nor are they kept where the scheduler's thread runs next a submission handler of another queue's command buffer: they go first, as Metal schedules a queue's command buffers whatever another queue's handler does (an M3 Max, probe `cross_queue_handler_waits`); 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 batch a committing thread submits (`CommandBuffer::commit_and_submit`) goes alone where its `VkQueue` runs at most one earlier submission not seen complete, as the pass that held it would send the group at once; where two or more run it is left to the scheduler's thread, which holds it. 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), at most 16 ms of their expected runs, 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, Line truncated
| 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`: 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 one of whose command buffers ran on the GPU for over 2 ms, by its own timestamps (not the host's view of how long it ran as its `VkQueue`'s oldest, which also holds its wait for the GPU to start it and the waiter's lateness to see it complete), or held its `VkQueue` for over 2 ms from the submission of a batch that waited on the GPU for another `VkQueue`'s work (an `MTLEvent`'s signal, the tracker's wait, new resources' first work) to its own GPU end, 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`. Under either value, as a queue is made, it takes the round robin's `VkQueue` the fewest live command queues hold, of those no unshared queue holds, in turn among equals, and an unshared queue one no command queue holds where one is free (one pass over the `VkQueue`s' counts; one that finds none shares the one the fewest hold, `WorkCounts::unshared_queues_sharing_a_vk_queue`). 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; so does every queue of a device whose command buffers write no GPU timestamps it reads (`gpu_times_from_host`, or a driver whose timestamps wait for every queue's), which does not share and is counted (`WorkCounts::queue_sharing_untimed`). 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 (the fewest live queues' as above), 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 26.4 to 30.1 ms, in each of 3 runs of each of two such shapes (one join each), against none over 10 ms under `PerQueue` in those 6 runs (at most 5.6 to 9.7 ms); with 2 ms of draws between long command buffers, none over 10 ms in 3 runs (at most 5.7 to 9.8 ms) against 7, 0 and 0 under `PerQueue` (at most 6.9 to 11.2 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, the default against `PerQueue`, runs after a lock hold's first: 8 threads with 3 in flight 50.7k to 54.7k against 27.4k to 28.0k (5 runs each); 8 threads with 1 in flight 47.0k to 50.1k against 13.9k to 14.3k (5); 2 threads with 3 in flight 28.0k to 53.7k against 21.4k to 28.0k (10 each, in turn, the default above `PerQueue` in each pair; no thread's queue marked long), and beside another process's 30 ms command buffers 5.1k to 6.7k against 4.0k to 4.1k (3 each; the host's view marked a thread's queue long in 1 of 3 runs, which then ran at `PerQueue`'s 4.1k); 2 threads with 1 in flight 16.9k to 20.7k against 10.1k to 11.5k (5); one thread over 16 queues in turn 21.7k to 43.3k against 10.2k to 11.1k, over 2,048 20.0k to 39.2k against 10.2k to 11.2k (4). Beside an application whose queue never shared 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 |