Record a submission's first work and its staged copies in one command buffer

The steps this packet landed as, in order:
- Choose whether batches may group by the driver's fact, not by its name
- Re-bless the driver-facts goldens for the submission-merge fact
- Decide whether a queue's failures are relayed by the driver's fact, not its name

Content: the tree of `development` at 94416b2c77, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:16 +02:00
1 parent b2d385e461
commit 4490daffbd
12 files changed
+370 -123

No files matched your search

@@ -1,12 +1,13 @@
//! Batches that go to the driver in one kernel submission (`CompletionPolicy::Grouped`).
//!
//! On a driver whose queue is Mesa's common one, each `vkQueueSubmit`'s `VkSubmitInfo`s that
//! signal nothing merge into the next one's kernel submission (Mesa 26.2.4,
//! `vulkan/runtime/vk_queue.c`, `vk_queue_submits_merge`: "Don't merge if there are signals in
//! between"), and ANV chains the merged command buffers into one batch buffer
//! (`anv_queue_submit_cmd_buffers_locked`). Each kernel submission costs CPU time for every
//! `VkDeviceMemory` of the device: ANV on i915 lists each in every execbuffer
//! (`i915/anv_batch_chain.c`, `setup_execbuf_for_cmd_buffers`), RADV each in every CS.
//! On a driver measured to merge each `vkQueueSubmit`'s `VkSubmitInfo`s that signal nothing into
//! the next one's kernel submission ([`DriverFact::SubmissionsWithoutSignalsMerge`], whose
//! documentation holds what was measured where), batches that signal nothing but their queue's
//! timeline may wait and go in one call for the cost of one kernel submission. The question is
//! the driver's, and the fact answers it, never the driver's name: a driver without the fact
//! takes the ungrouped path, each batch its own `vkQueueSubmit`, which is what every batch took
//! before grouping and is exact alike -- a group changes when a `vkQueueSubmit` is made and
//! nothing it submits.
//!
//! - **What waits.** A batch the scheduler submits waits here, submitted by nothing yet, where it
//! signals nothing but its queue's timeline and its events' semaphores: no binary semaphore,
@@ -87,8 +88,8 @@ use crate::exit_guard::{self, Call};
use crate::gpu_time;
use crate::Device;
use ash::vk;
use metal2vulkan::device::CompletionPolicy;
use metal2vulkan::vk::DriverId;
use metal2vulkan::device::{CompletionPolicy, DriverFact};
use std::collections::BTreeSet;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@@ -104,11 +105,12 @@ const BATCH_INFOS: usize = 2;
const MOST_INFOS: usize = GROUP_BATCHES * BATCH_INFOS + 1 + BATCH_INFOS;
/// Whether `device`'s batches on `VkQueue` `queue` may wait in a group: its policy groups them,
/// its driver merges a submission that signals nothing into the next (the module docs), and the
/// queue's failures are not relayed (each relayed batch takes a fence, `device/relay.rs`).
/// its driver is measured to merge a submission that signals nothing into the next (the module
/// docs), and the queue's failures are not relayed (each relayed batch takes a fence,
/// `device/relay.rs`).
pub(crate) fn groups(device: &Device, queue: usize) -> bool {
device.compile_device().policy().completion == CompletionPolicy::Grouped
&& merges_submissions(device.properties().description.driver_id)
&& merges_submissions(&device.properties().driver_facts)
&& device.shared().flights(queue).is_none()
}
@@ -151,23 +153,12 @@ const IN_GROUP: u8 = 1;
/// A command buffer's `group_hold` bit: a thread waits for its completion.
const WAITED_FOR: u8 = 2;
/// Whether the driver's queue is Mesa's common one with kernel submissions of their own: the
/// drivers that merge a `VkSubmitInfo` that signals nothing into the next.
fn merges_submissions(driver: Option<DriverId>) -> bool {
matches!(
driver,
Some(
DriverId::MESA_RADV
| DriverId::INTEL_OPEN_SOURCE_MESA
| DriverId::MESA_LLVMPIPE
| DriverId::MESA_TURNIP
| DriverId::MESA_V3DV
| DriverId::MESA_PANVK
| DriverId::MESA_NVK
| DriverId::MESA_HONEYKRISP
| DriverId::IMAGINATION_OPEN_SOURCE_MESA
)
)
/// Whether the driver merges a `VkSubmitInfo` that signals nothing into the next one's kernel
/// submission ([`DriverFact::SubmissionsWithoutSignalsMerge`]): the driver's facts alone answer
/// it, and nothing of the driver's identity, so a test can hand it the facts of each committed
/// profile (`tests::batches::only_drivers_measured_to_merge_their_submissions_group_their_batches`).
pub(crate) fn merges_submissions(facts: &BTreeSet<DriverFact>) -> bool {
facts.contains(&DriverFact::SubmissionsWithoutSignalsMerge)
}
/// What sent a group held (`WorkCounts::group_ends_full` and kin).
@@ -50,6 +50,11 @@ mod submit;
pub(super) use completion::Completion;
pub(super) use first_submission::{NotedTable, ReplayTable};
/// Whether a driver's facts merge a submission that signals nothing into the next, for the test
/// that holds every committed profile to the fact
/// (`tests::batches::only_drivers_measured_to_merge_their_submissions_group_their_batches`).
#[cfg(test)]
pub(crate) use group::merges_submissions;
pub(super) use group::{Group, GroupEnd, GROUP_BATCHES};
use rebound_use::{ReboundUse, Unlogged};
pub(super) use submit::{BatchLists, Submitting};
@@ -115,8 +115,10 @@
//! of the batch, whether a use names the resource or not (a command may reach a texture through its
//! resource ID, a buffer through its address), and the batch holds what it worked on until it
//! completes. On a device of several `VkQueue`s every batch on another one waits for it until it
//! completed. It is a command buffer of its own, first in the batch's work's `VkSubmitInfo` (in
//! a batch with no work, its end's), so it waits for what the work waits for: Vulkan's
//! completed. It is recorded first in the command buffer that leads the batch's work's
//! `VkSubmitInfo` (in a batch with no work, its end's) -- its own, or, where the batch also has
//! host calls' staged copies, the one that holds the copies after it -- so it waits for what the
//! work waits for: Vulkan's
//! submission order puts it before every command of the batch ("the order in which command
//! buffers are specified in the pCommandBuffers member of VkSubmitInfo ... determines their
//! submission order", the Vulkan specification, Submission Order), and its last barrier,
@@ -681,26 +683,47 @@ impl CommandBufferShared {
work.extend(&state.recorded[start + offset].raws);
}
// The first work goes first in the batch's work, or in a batch with no work in its end
// (the module docs). Host calls' staged copies go at the batch's start, after it.
let lead = match first_work.has_first() {
true => Some(self.record_raw(&mut state, |_, buffer| {
// SAFETY: the command buffer is recording, outside a render pass; it is
// submitted first in the batch, before any later one, and every batch on
// another `VkQueue` waits for the batch (`FirstMoves::waits`).
unsafe { first_work.record(raw, buffer, shared.queue_flags_of(queue)) };
Ok(())
})?),
false => None,
// (the module docs). Host calls' staged copies go at the batch's start, after it, in the
// same command buffer: the two went in two command buffers of one `VkSubmitInfo`, which
// puts them in the same submission order one command buffer's recording order does ("the
// order in which command buffers are specified in the pCommandBuffers member of
// VkSubmitInfo ... determines their submission order", the Vulkan specification,
// Submission Order; inside one command buffer, the order they were recorded), and a
// command buffer boundary is no dependency of its own, so the copies' own leading barrier
// (`FirstMoves::record_staged`) covers the moves recorded before it either way. One
// command buffer where the batch has both (counted:
// `WorkCounts::command_buffers_begun_batch_work`).
let has_first = first_work.has_first();
let has_staged = first_work.has_staged();
let recorded = (has_first || has_staged)
.then(|| {
self.record_raw(&mut state, |_, buffer| {
if has_first {
// SAFETY: the command buffer is recording, outside a render pass; it is
// submitted first in the batch, before any later one, and every batch on
// another `VkQueue` waits for the batch (`FirstMoves::waits`).
unsafe { first_work.record(raw, buffer, shared.queue_flags_of(queue)) };
}
if has_staged {
// SAFETY: the command buffer is recording, outside a render pass; every
// image's move is in this command buffer, before it, or a submission
// before.
unsafe { first_work.record_staged(raw, buffer) };
}
Ok(())
})
})
.transpose()?;
// Where it holds staged copies it goes at the batch's start, as they did, so the batch
// has work; the first work alone goes first in the work, or in the end where the batch
// has none (below).
let lead = match has_staged {
true => {
work.insert(0, recorded.expect("recorded where there are staged copies"));
None
}
false => recorded,
};
if first_work.has_staged() {
let staged = self.record_raw(&mut state, |_, buffer| {
// SAFETY: the command buffer is recording, outside a render pass; every image's
// move is in the first work's command buffer, before it, or a submission before.
unsafe { first_work.record_staged(raw, buffer) };
Ok(())
})?;
work.insert(0, staged);
}
let BatchWaits {
semaphores: wait_semaphores,
values: wait_values,
+13 -4
View File
@@ -1605,11 +1605,18 @@ impl Device {
.collect();
exit_guard::register_device(identity);
let in_process = properties.kind == DeviceKind::Cpu;
// A device on MoltenVK whose instance has the relay has its queues' failures relayed
// to the command buffers that failed (`relay.rs`), from its first batch on.
// A device whose driver reports a command buffer's execution failure through the
// instance's messenger alone, and whose instance has the relay, has its queues' failures
// relayed to the command buffers that failed (`relay.rs`), from its first batch on. The
// question is the driver's, and the fact answers it, never the driver's name: a defect
// fact, so a driver with a row takes it at every release and on every GPU.
let lost = Arc::new(AtomicBool::new(false));
let relays = (properties.description.driver_facts())
.contains(&metal2vulkan::device::DriverFact::QueueFailuresReportedByMessenger);
// Read before the properties move into the device's shared state (below): still keyed on
// the driver's name, for the scheduler's wait alone.
let moltenvk = properties.description.driver_id == Some(DriverId::MOLTENVK);
if let (Some(relay), true) = (instance.relay(), moltenvk) {
if let (Some(relay), true) = (instance.relay(), relays) {
for slot in &queues {
let queue = slot.with(|queue| queue);
// SAFETY: the queue is the device's, live, and its word was put back just now.
@@ -1756,7 +1763,9 @@ impl Device {
}
// The scheduler's thread waits for the GPU itself where heads wait for signals to land,
// but on MoltenVK, whose wait for any of several semaphores loses a signal that lands
// while it registers a later one (`command_buffer/completion.rs`).
// while it registers a later one (`command_buffer/completion.rs`). Still keyed on the
// driver's name: its home is a `RuntimeDriverDefect` beside
// `ReadsCommandBuffersAfterTheirSignal`, which this commit does not open.
if !moltenvk {
(shared.scheduler).wait_on_gpu(Functions::clone(&shared.functions), shared.nudge);
}
@@ -8,8 +8,8 @@
//! instead (`command_buffer/submit.rs`). Each first does the
//! new resources' first GPU work that waits (`texture/first_move.rs`), after the batches on other
//! `VkQueue`s that did such work: no new resource waits for one, so making one waits for no GPU
//! work. That work goes in a command buffer of its own, first in the work's `VkSubmitInfo`, as a
//! batch's does (`command_buffer/submit.rs`).
//! work. That work is recorded first in the submission's one command buffer, before the host
//! calls' staged copies and the work, as a batch's is in its own (`command_buffer/submit.rs`).
//!
//! The one submission no one waits for is a no-copy buffer's sparse binding of its dma-bufs
//! (`dma_buf.rs`), on the same queue and timeline: it would wait behind the queue's work in
@@ -71,9 +71,9 @@ impl OwnTimeline {
/// The command pool, command buffers and fence of internal submissions, made on first use.
pub(super) struct Internal {
pool: vk::CommandPool,
/// The one command buffer a submission records: its first work, the host calls' staged
/// copies and its work, in that order (`submit_internal_naming`).
buffer: vk::CommandBuffer,
/// The command buffer of a submission's first work, first in the work's `VkSubmitInfo`.
first: vk::CommandBuffer,
fence: vk::Fence,
/// The timeline each submission signals, and the value the last one signalled: a batch on
/// another `VkQueue` waits for one that did first work (`texture/first_move.rs`).
@@ -96,9 +96,9 @@ impl Internal {
let allocate = vk::CommandBufferAllocateInfo::default()
.command_pool(pool)
.level(vk::CommandBufferLevel::PRIMARY)
.command_buffer_count(2);
.command_buffer_count(1);
let buffers = device.allocate_command_buffers(&allocate)?;
let (buffer, first) = (buffers[0], buffers[1]);
let buffer = buffers[0];
// SAFETY: the device is live.
let fence = unsafe { raw.create_fence(&vk::FenceCreateInfo::default(), None) }
.map_err(vulkan)?;
@@ -119,7 +119,6 @@ impl Internal {
Ok(Internal {
pool,
buffer,
first,
fence,
timeline,
signalled: 0,
@@ -183,36 +182,35 @@ impl Device {
let waits = firsts.waits(0, |point| {
shared.queues[point.queue].completed_value() >= point.value
});
// The first work goes in a command buffer of its own, first in the work's `VkSubmitInfo`
// (`command_buffer/submit.rs`: MoltenVK runs each `VkSubmitInfo` as a Metal command
// buffer of its own).
let lead = taken.has_first();
if lead {
// SAFETY: as below, for the first work's command buffer.
unsafe { raw.begin_command_buffer(objects.first, &begin) }.map_err(vulkan)?;
shared.counts.command_buffer_begun(Begun::Internal);
// SAFETY: recording, outside a render pass, for the queue family; it is submitted
// first in the work's submission, which is waited for before anything that uses the
// resources is submitted after it.
unsafe { taken.record(raw, objects.first, shared.queue_flags_of(0)) };
// SAFETY: as above.
unsafe { raw.end_command_buffer(objects.first) }.map_err(vulkan)?;
}
// SAFETY: the command buffer is not pending (every submission is waited for below) and
// the internal lock is held; beginning it resets it (the pool resets command buffers).
unsafe { raw.begin_command_buffer(objects.buffer, &begin) }.map_err(vulkan)?;
shared.counts.command_buffer_begun(Begun::Internal);
// Host calls' staged copies, after the first work's command buffer, before the work.
// SAFETY: recording, outside a render pass; every image's move is in the first work's
// submission or one before.
// The new resources' first work goes first in this command buffer, then the host calls'
// staged copies, then the work. The first work had a command buffer of its own, first in
// the same `VkSubmitInfo`, which put it in the same submission order recording it first
// here does ("the order in which command buffers are specified in the pCommandBuffers
// member of VkSubmitInfo ... determines their submission order", the Vulkan
// specification, Submission Order; inside one command buffer, the order they were
// recorded), and a command buffer boundary is no dependency of its own, so what each
// records and the barriers between them are unchanged. Counted:
// `WorkCounts::command_buffers_begun_internal`.
if taken.has_first() {
// SAFETY: recording, outside a render pass, for the queue family; it is submitted
// first in the work's submission, which is waited for before anything that uses the
// resources is submitted after it.
unsafe { taken.record(raw, objects.buffer, shared.queue_flags_of(0)) };
}
// Host calls' staged copies, after the first work, before the work.
// SAFETY: recording, outside a render pass; every image's move is recorded before it
// here, or in a submission before.
unsafe { taken.record_staged(raw, objects.buffer) };
record(raw, objects.buffer);
// SAFETY: as above.
unsafe { raw.end_command_buffer(objects.buffer) }.map_err(vulkan)?;
// SAFETY: the fence is unsignaled or signaled and not pending.
unsafe { raw.reset_fences(&[objects.fence]) }.map_err(vulkan)?;
let buffers = [objects.first, objects.buffer];
let buffers = &buffers[usize::from(!lead)..];
let buffers = [objects.buffer];
// And the last binding of a no-copy buffer's dma-bufs, until it completed.
let waits: Vec<(vk::Semaphore, u64)> = (waits.iter())
.map(|point| (shared.queues[point.queue].timeline, point.value))
@@ -232,7 +230,7 @@ impl Device {
let submit = vk::SubmitInfo::default()
.wait_semaphores(&wait_semaphores)
.wait_dst_stage_mask(&wait_stages)
.command_buffers(buffers)
.command_buffers(&buffers)
.signal_semaphores(&signal_semaphores)
.push_next(&mut timeline);
// The first work waits as the work's does (a heap's fill another queue did comes before
@@ -1,7 +1,12 @@
//! A command buffer's batches (`command_buffer/batches.rs`): where event waits and signals, and
//! binary semaphore waits and signals, split its encoders.
//! binary semaphore waits and signals, split its encoders; which drivers' batches may wait in
//! a group (`command_buffer/group.rs`); and which drivers' queue failures are relayed
//! (`device/relay.rs`).
use crate::command_buffer::batches::{Batch, Batches};
use crate::command_buffer::merges_submissions;
use metal2vulkan::device::{DeviceDescription, DriverFact};
use metal2vulkan::vk::DriverId;
fn batch(waits: &[(char, u64)], end: usize, signals: &[(char, u64)]) -> Batch<char, u8> {
Batch {
@@ -238,3 +243,106 @@ fn signals_after_a_failing_encoder_are_dropped() {
]
);
}
/// Whether a driver's batches may wait in one kernel submission is the driver's **fact**, never
/// its name (`command_buffer/group.rs`): a driver measured to merge a `vkQueueSubmit`'s
/// `VkSubmitInfo`s that signal nothing into the next one's kernel submission
/// (`DriverFact::SubmissionsWithoutSignalsMerge`) groups its batches; every other driver takes the
/// ungrouped path, each batch its own call, which is exact alike.
///
/// The check over every committed profile: a profile groups only where its driver is one the fact
/// is measured of, so a decision that read the driver's name -- the Mesa drivers no lane measured
/// read alike there -- would answer otherwise for one of them. A `MEASURED` row written without a
/// measurement would show here as a MoltenVK, NVIDIA or SwiftShader profile that groups.
#[test]
fn only_drivers_measured_to_merge_their_submissions_group_their_batches() {
let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../metal2vulkan-validation/profiles");
let mut read = 0;
let mut grouped = 0;
for entry in std::fs::read_dir(&dir).expect("validation/profiles is readable") {
let path = entry.expect("directory entry").path();
if path.extension().is_none_or(|x| x != "json") {
continue;
}
let text = std::fs::read_to_string(&path).expect("profile is readable");
let description =
DeviceDescription::from_khronos_json(&text, None).expect("profile parses");
let merges = merges_submissions(&description.driver_facts());
if merges {
// Only a driver the fact is measured of: Mesa's RADV, ANV and llvmpipe.
assert!(
matches!(
description.driver_id,
Some(
DriverId::MESA_RADV
| DriverId::INTEL_OPEN_SOURCE_MESA
| DriverId::MESA_LLVMPIPE
)
),
"{} groups its batches with no row of its driver",
path.display()
);
grouped += 1;
}
read += 1;
}
assert!(read > 1, "profiles read: {read}");
// The grouped form is reachable, and the fact alone chooses it.
assert!(grouped > 0, "profiles that group: {grouped}");
assert!(merges_submissions(
&[DriverFact::SubmissionsWithoutSignalsMerge]
.into_iter()
.collect()
));
assert!(!merges_submissions(&Default::default()));
}
/// Whether a device's queue failures are relayed to the command buffers that failed is the
/// driver's **fact**, never its name (`device/mod.rs`, `device/relay.rs`): a driver that reports
/// a command buffer's execution failure through the instance's messenger alone, and loses the
/// whole device for it, takes the relay
/// (`DriverFact::QueueFailuresReportedByMessenger`); every other driver takes none, and its
/// batches take a fence only where their command buffer ends at one.
///
/// It is a **defect** fact, so a driver with a row takes it at every release and on every GPU
/// (`DriverFact::assumed_where_unmeasured`): that is what makes the fact answer exactly as the
/// driver's name did, and the check is that MoltenVK's profiles take it while every other
/// committed profile -- RADV's, ANV's, NVIDIA's, lavapipe's and SwiftShader's -- does not,
/// including at a release and on a GPU no lane measured.
#[test]
fn only_drivers_that_report_their_failures_by_messenger_relay_them() {
let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../metal2vulkan-validation/profiles");
let mut moltenvk = 0;
let mut other = 0;
for entry in std::fs::read_dir(&dir).expect("validation/profiles is readable") {
let path = entry.expect("directory entry").path();
if path.extension().is_none_or(|x| x != "json") {
continue;
}
let text = std::fs::read_to_string(&path).expect("profile is readable");
let mut description =
DeviceDescription::from_khronos_json(&text, None).expect("profile parses");
let is_moltenvk = description.driver_id == Some(DriverId::MOLTENVK);
for release in [description.driver_version, 0x4242] {
description.driver_version = release;
let relays = (description.driver_facts())
.contains(&DriverFact::QueueFailuresReportedByMessenger);
assert_eq!(
relays,
is_moltenvk,
"{} relays {relays} at {release:#x}",
path.display()
);
}
match is_moltenvk {
true => moltenvk += 1,
false => other += 1,
}
}
assert!(
moltenvk > 0 && other > 1,
"{moltenvk} MoltenVK, {other} other"
);
}
@@ -41,10 +41,11 @@
//! takes such a move whatever its
//! commands name, so no command reads the image before its move; an internal submission, whose
//! commands are the runtime's own, takes it only where they name the image's key (a host call
//! on its texture, whose contract orders the program's GPU work on it). The work goes in
//! a command buffer of its own, first in the submission's `VkSubmitInfo`, waiting for what
//! the submission waits for: MoltenVK runs each `VkSubmitInfo` as a Metal command buffer of its
//! own, so it adds none (`command_buffer/submit.rs`).
//! on its texture, whose contract orders the program's GPU work on it). The work is recorded
//! first in the command buffer that leads the submission's `VkSubmitInfo` -- a batch's own, or
//! the one that holds the staged copies after it; an internal submission's one command buffer
//! -- waiting for what the submission waits for: MoltenVK runs each `VkSubmitInfo` as a Metal
//! command buffer of its own, so it adds none (`command_buffer/submit.rs`).
//! - **Staged copies**. `replace_region` of a texture whose `VkImage` is its own for good (in
//! memory of its own, or a heap's own pages) and takes no host copies stages the bytes
//! ([`TexelCopy`], [`FirstMoves::register_texels`]): the next submission copies them in at
@@ -1367,13 +1368,14 @@ impl Taken<'_> {
}
/// Record the host calls' staged copies it took into `command_buffer`, each after every
/// write before it (the first work, which a command buffer submitted before it records; the
/// copy before), then the barrier that makes them visible to every command after and to the
/// host.
/// write before it (the first work, which [`record`](Self::record) records into this command
/// buffer before it or a submission before records; the copy before), then the barrier that
/// makes them visible to every command after and to the host.
///
/// # Safety
///
/// As [`record`](Self::record)'s; every image's first move was submitted before.
/// As [`record`](Self::record)'s; every image's first move is recorded before it in
/// submission order -- earlier in this command buffer, or in a submission before.
pub(crate) unsafe fn record_staged(&self, device: &Vk, command_buffer: vk::CommandBuffer) {
let staged = self.held.iter().filter_map(|held| match held {
Held::Texels(_, copy) => Some(copy),
@@ -4,9 +4,10 @@
//! [`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
//! `CompletionPolicy::Grouped`, on a driver whose queue merges a submission that signals nothing
//! into the next one (Mesa's: ANV, RADV, lavapipe and kin), they go in `vkQueueSubmit` calls of up
//! to four batches each, only the last of each signalling (`WorkCounts::grouped_submissions`,
//! `CompletionPolicy::Grouped`, on a driver measured to merge a submission that signals nothing
//! into the next one (`DriverFact::SubmissionsWithoutSignalsMerge`), they go in `vkQueueSubmit`
//! calls of up to four batches each, only the last of each signalling
//! (`WorkCounts::grouped_submissions`,
//! `WorkCounts::batches_grouped`), announced once ([`GROUPED`]); under `CompletionPolicy::Exact`,
//! and on every other driver, each alone, announcing nothing. Either way every command buffer
//! completes without error, each buffer holds its own value, and the layer reports nothing. Each
@@ -43,8 +44,7 @@
use super::degrade_notices::counts;
use super::{loader, open_device, validated_device_with, Messages, ScratchCache, WAIT};
use crate::gpu::TEST_DEVICE;
use metal2vulkan::device::CompletionPolicy;
use metal2vulkan::vk::DriverId;
use metal2vulkan::device::{CompletionPolicy, DeviceDescription, DriverFact};
use metal2vulkan_runtime::{
Buffer, CommandBuffer, CommandBufferStatus, Degradation, DeviceOptions, EventRef,
ResourceOptions, ShaderCacheOptions, WorkCounts,
@@ -79,23 +79,12 @@ fn group_ends(before: &WorkCounts, after: &WorkCounts) -> [u64; 7] {
std::array::from_fn(|at| after[at] - before[at])
}
/// Whether the device's driver merges a submission that signals nothing into the next: its queue
/// is Mesa's common one (the runtime's `group.rs`).
fn merges(driver: Option<DriverId>) -> bool {
matches!(
driver,
Some(
DriverId::MESA_RADV
| DriverId::INTEL_OPEN_SOURCE_MESA
| DriverId::MESA_LLVMPIPE
| DriverId::MESA_TURNIP
| DriverId::MESA_V3DV
| DriverId::MESA_PANVK
| DriverId::MESA_NVK
| DriverId::MESA_HONEYKRISP
| DriverId::IMAGINATION_OPEN_SOURCE_MESA
)
)
/// Whether the device's driver merges a submission that signals nothing into the next: the
/// driver's fact answers it, never its name, and the runtime reads the same fact
/// (`DriverFact::SubmissionsWithoutSignalsMerge`, the runtime's `group.rs`), so a device whose
/// identity no lane measured takes the ungrouped path and this lane expects it.
fn merges(description: &DeviceDescription) -> bool {
(description.driver_facts()).contains(&DriverFact::SubmissionsWithoutSignalsMerge)
}
/// Wait until the scheduler's thread has taken in every command buffer committed before the call:
@@ -132,7 +121,7 @@ fn run(completion: CompletionPolicy, checked: bool) -> (u64, u64, u64, usize, bo
options.policy.completion = completion;
})
.unwrap();
let merging = merges(device.properties().description.driver_id);
let merging = merges(&device.properties().description);
let queue = device.new_command_queue().unwrap();
let event = device.new_shared_event().unwrap();
let buffers: Vec<Buffer> = (0..BATCHES)
@@ -394,7 +383,7 @@ fn event_scenario(completion: CompletionPolicy, steps: &[Step], last: u64) -> Sc
options.policy.completion = completion;
})
.unwrap();
let merging = merges(device.properties().description.driver_id);
let merging = merges(&device.properties().description);
let queues = [
device.new_command_queue().unwrap(),
device.new_command_queue().unwrap(),
@@ -863,7 +852,7 @@ fn behind_running_work(completion: CompletionPolicy, stretch: usize, carried: Ca
options.policy.completion = completion;
})
.unwrap();
let merging = merges(device.properties().description.driver_id);
let merging = merges(&device.properties().description);
let queue = device.new_command_queue().unwrap();
let large = device
.new_buffer(RUNNING_FILL, ResourceOptions::private())
+1 -1
View File
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 448;
/// 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 = 1552;
pub const RUNTIME_VERSION: u32 = 1554;
/// 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
@@ -1543,6 +1543,57 @@ pub enum DriverFact {
/// with a 1 made a second `VkPipeline` there (Metal's specialization and pipeline compile,
/// 5.6 to 24.5 ms).
ConstantOffsetUniformReadsPreloaded,
/// A cost fact (the module docs): the driver's queue is Mesa's common one, where each
/// `vkQueueSubmit`'s `VkSubmitInfo`s that signal nothing merge into the next one's kernel
/// submission, so batches that signal nothing but their queue's timeline may wait and go in
/// one call for the cost of one kernel submission (Mesa 26.2.4, `vulkan/runtime/vk_queue.c`,
/// `vk_queue_submits_merge`: "Don't merge if there are signals in between"; ANV chains the
/// merged command buffers into one batch buffer,
/// `anv_queue_submit_cmd_buffers_locked`). Each kernel submission costs CPU time for every
/// `VkDeviceMemory` of the device there: ANV on i915 lists each in every execbuffer
/// (`i915/anv_batch_chain.c`, `setup_execbuf_for_cmd_buffers`), RADV each in every CS. On a
/// driver without it each batch takes its own `vkQueueSubmit`, which is the exact path and
/// the one every batch took before grouping: a group changes when a batch's `vkQueueSubmit`
/// is made and nothing it submits (`command_buffer/group.rs` in the runtime).
///
/// Counted where the merge pays, on Mesa 26.2.4's ANV on the Intel UHD 770: 24 kernel
/// submissions a frame grouped against 30 ungrouped, at 67 command buffers a frame committed
/// 1 ms apart behind 1.3 ms of GPU work each, the GPU as idle either way (0.62 ms a frame).
///
/// Measured without it, so not listed: MoltenVK, whose queue is its own and merges nothing
/// -- it commits a Metal command buffer for each `VkSubmitInfo` of a call and one for a call
/// of none with a fence (`MVKQueue::submit`), about 65 us of a thread of Metal's on an Apple
/// M3 Max whether or not the info holds work -- and NVIDIA's proprietary driver, which has
/// no Mesa queue. The Mesa drivers no lane measures (Turnip, V3DV, PanVK, NVK, Honeykrisp,
/// PowerVR) take no row: the merge is in the common queue they share, but no identity of
/// theirs was measured, so each takes the ungrouped exact path.
SubmissionsWithoutSignalsMerge,
/// A defect fact (the module docs): the driver reports a command buffer's execution failure
/// only to the instance's debug-utils messengers, naming the `VkQueue` and not the
/// submission, and by default marks the whole `VkDevice` lost for it, where Metal fails the
/// command buffer it struck and runs the queue on. The runtime's workaround is the relay
/// (`device/relay.rs`): its instance asks the driver not to lose the device
/// (`MVK_CONFIG_RESUME_LOST_DEVICE`), each `VkQueue` keeps its submissions in flight in
/// submission order with a fence each, and a failure heard on a queue is given to the first
/// submission whose fence is unsignaled, so the command buffer whose batch it was finishes
/// with that error and the queue's other command buffers complete, as Metal's do.
///
/// Measured on MoltenVK 1.4.1: `handleMTLCommandBufferError` in `MVKQueue.mm` reports
/// `"<result>: Lost|Resumed VkDevice after MTLCommandBuffer \"<label>\" execution failed
/// (code <n>): <description>"` before the handler that signals the submission's fence and
/// inline semaphores, and Metal runs one queue's completed handlers in order on one thread
/// (the probe's `handlers` and `handlers_fault`: 600 handlers, failures among them, none out
/// of order), which is what lets the first unsignaled fence name the failed submission.
/// Against Metal, which the probe measured on an M4 with macOS 27.0.1: a blit into a buffer
/// over read-only pages failed with `MTLCommandBufferErrorInternal`, as did the command
/// buffer committed after it while it ran, the later ones completing; an execution range past
/// its buffer failed with `PageFault`, the next command buffer completing.
///
/// A defect fact, so MoltenVK takes it at every release and on every GPU
/// ([`DriverFact::assumed_where_unmeasured`]): the workaround, never the path a measurement
/// has not cleared. A driver without it relays nothing, and each of its batches takes a fence
/// only where its command buffer ends at one (`command_buffer/fences.rs`).
QueueFailuresReportedByMessenger,
/// The driver answers a format's linear-tiling attachment features from memory it has not
/// yet initialized, so they differ between instances of one process: MoltenVK 1.4.1 builds
/// its format table in `MVKPhysicalDevice`'s member initializers, where
@@ -1715,6 +1766,7 @@ impl DriverFact {
| Self::PositionedDepthReadAtStandardPositions
| Self::TimestampPoolsAreCounterSampleBuffers
| Self::LinearTilingFeaturesUninitialized
| Self::QueueFailuresReportedByMessenger
)
}
@@ -2569,6 +2621,14 @@ pub(crate) const MEASURED: &[Measured<DriverFact>] = &[
first: moltenvk(1, 4, 1),
last: moltenvk(1, 4, 1),
},
Measured {
fact: DriverFact::QueueFailuresReportedByMessenger,
driver: DriverId::MOLTENVK,
vendor: None,
device: None,
first: moltenvk(1, 4, 1),
last: moltenvk(1, 4, 1),
},
Measured {
fact: DriverFact::LinearTilingFeaturesUninitialized,
driver: DriverId::MOLTENVK,
@@ -2753,6 +2813,46 @@ pub(crate) const MEASURED: &[Measured<DriverFact>] = &[
first: nvidia(615, 71, 9),
last: nvidia(615, 71, 9),
},
Measured {
fact: DriverFact::SubmissionsWithoutSignalsMerge,
driver: DriverId::MESA_LLVMPIPE,
vendor: None,
device: None,
first: mesa(26, 2, 4),
last: mesa(26, 2, 4),
},
Measured {
fact: DriverFact::SubmissionsWithoutSignalsMerge,
driver: DriverId::MESA_RADV,
vendor: Some(AMD_VENDOR_ID),
device: Some(AMD_RADEON_780M),
first: mesa(26, 2, 4),
last: mesa(26, 2, 4),
},
Measured {
fact: DriverFact::SubmissionsWithoutSignalsMerge,
driver: DriverId::MESA_RADV,
vendor: Some(AMD_VENDOR_ID),
device: Some(AMD_RX_7900_XTX),
first: mesa(26, 2, 4),
last: mesa(26, 2, 4),
},
Measured {
fact: DriverFact::SubmissionsWithoutSignalsMerge,
driver: DriverId::INTEL_OPEN_SOURCE_MESA,
vendor: Some(INTEL_VENDOR_ID),
device: Some(INTEL_IRIS_XE_RPL_P),
first: mesa(26, 2, 4),
last: mesa(26, 2, 4),
},
Measured {
fact: DriverFact::SubmissionsWithoutSignalsMerge,
driver: DriverId::INTEL_OPEN_SOURCE_MESA,
vendor: Some(INTEL_VENDOR_ID),
device: Some(INTEL_UHD_770_RPL_S),
first: mesa(26, 2, 4),
last: mesa(26, 2, 4),
},
Measured {
fact: DriverFact::SampledDepthKeepsHiZ,
driver: DriverId::INTEL_OPEN_SOURCE_MESA,
@@ -567,6 +567,8 @@ const ONE_OF_METALS: DriverFact = DriverFact::DontCareStoreIsOneOfMetals;
const COPY_BACK: DriverFact = DriverFact::ShadowCopyBackDispatchFaster;
const COPY_IN: DriverFact = DriverFact::ShadowCopyInDispatchFaster;
const ROWS: DriverFact = DriverFact::RowCopiesDispatchFaster;
const MERGES: DriverFact = DriverFact::SubmissionsWithoutSignalsMerge;
const MESSENGER: DriverFact = DriverFact::QueueFailuresReportedByMessenger;
const LINEAR_UNINITIALIZED: DriverFact = DriverFact::LinearTilingFeaturesUninitialized;
const STALL: DriverFact = DriverFact::SemaphoreOperationsStallSubmits;
const SAMPLED_HIZ: DriverFact = DriverFact::SampledDepthKeepsHiZ;
@@ -635,6 +637,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
BC6H,
BC7,
ONE_OF_METALS,
MERGES,
FOLLOWS,
],
),
@@ -648,6 +651,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
BC6H,
BC7,
ONE_OF_METALS,
MERGES,
FOLLOWS,
],
),
@@ -674,6 +678,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
ONE_OF_METALS,
COPY_BACK,
ROWS,
MERGES,
SAMPLED_HIZ,
MSAA_DEPTH,
FOLLOWS,
@@ -693,6 +698,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
COPY_BACK,
COPY_IN,
ROWS,
MERGES,
],
),
(
@@ -716,6 +722,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
BC6H,
BC7,
SCARCE_POOLS,
MESSENGER,
LINEAR_UNINITIALIZED,
TILE_STORE,
],
@@ -741,6 +748,7 @@ fn the_committed_profiles_drivers_have_their_facts() {
BC6H,
BC7,
SCARCE_POOLS,
MESSENGER,
LINEAR_UNINITIALIZED,
TILE_STORE,
],
@@ -763,8 +771,8 @@ fn the_committed_profiles_drivers_have_their_facts() {
/// A release or GPU not measured is an unmeasured identity: it takes none of its driver's answer
/// facts, and its driver's defects stand at every release and on every GPU of the driver. The M4
/// at MoltenVK 1.4.2, or at 1.4.0, or another Apple GPU at 1.4.1, takes MoltenVK's defects alone
/// (its depth images apart and GPU-optimized, its scarce timestamp pools, its uninitialized
/// linear-tiling features); the RPL-S at ANV 26.2.5, or another Intel GPU at 26.2.4, takes
/// (its depth images apart and GPU-optimized, its scarce timestamp pools, its queue failures
/// reported by the messenger, its uninitialized linear-tiling features); the RPL-S at ANV 26.2.5, or another Intel GPU at 26.2.4, takes
/// ANV's hidden aliased writes alone; the RTX 5080 Laptop GPU at another release takes NVIDIA's
/// custom-position depth alone. No driver takes another driver's defects.
#[test]
@@ -783,7 +791,14 @@ fn an_unmeasured_identity_takes_its_drivers_defects_alone() {
assert!(!desc.measured_identity());
assert_eq!(
desc.driver_facts(),
[APART, OPTIMIZED, SCARCE_POOLS, LINEAR_UNINITIALIZED].into()
[
APART,
OPTIMIZED,
SCARCE_POOLS,
MESSENGER,
LINEAR_UNINITIALIZED
]
.into()
);
}
let mut desc = read("moltenvk-m4");
@@ -791,7 +806,14 @@ fn an_unmeasured_identity_takes_its_drivers_defects_alone() {
assert!(!desc.measured_identity());
assert_eq!(
desc.driver_facts(),
[APART, OPTIMIZED, SCARCE_POOLS, LINEAR_UNINITIALIZED].into()
[
APART,
OPTIMIZED,
SCARCE_POOLS,
MESSENGER,
LINEAR_UNINITIALIZED
]
.into()
);
let mut desc = read("intel-uhd770-rpls-anv");
@@ -1026,7 +1048,7 @@ fn the_rx_7900_xtx_at_mesa_26_2_4_takes_the_facts_measured_on_it() {
navi31.device_id = AMD_RX_7900_XTX;
assert!(navi31.measured_identity());
let measured =
std::collections::BTreeSet::from([FOLLOWS, DriverFact::RobustIndexFetchReadsZero]);
std::collections::BTreeSet::from([FOLLOWS, MERGES, DriverFact::RobustIndexFetchReadsZero]);
assert_eq!(navi31.driver_facts(), measured);
assert!(navi31.driver_facts_withheld().is_empty());
for release in [mesa(26, 2, 3), mesa(26, 0, 8)] {
+1 -1
View File
@@ -49,7 +49,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 |
| A signed normalized color attachment (`R8Snorm`, `RG8Snorm`, `RGBA8Snorm`, `R16Snorm`, `RG16Snorm`, `RGBA16Snorm`) or an `RGB9E5Float` one, single-sampled and loaded by a pass that draws, keeps the texels its draws do not write as they were, where Metal's tile store writes each 32x32 tile a draw reaches back through its values: a channel's minimum code (-128, or -32768) as the code above it (-127, -32767), and a shared-exponent word whose largest mantissa is below 256 under an exponent above 0 normalized (its mantissas shifted up as the exponent steps down). The runtime's: no pipeline differs. Not on a driver whose pass stores them as Metal's (`DriverFact::TileStoreIsMetals`: MoltenVK on Apple's GPUs), under either value, with no load pass and no notice. | `tile_store = TileStorePolicy::Device` | `tile_store = TileStorePolicy::Exact`: the extended-range attachments' load pass (`render/unused_bits_load.rs`) takes such an attachment too, raising each minimum code and normalizing each word in the tiles the pass's draws reach (`bind::unused_bits_module` of the format); one it cannot take (a texture held as a shadow, a sparse one, or one whose image the device does not copy both ways) keeps the device's, announced | One code, only at a minimum code, which no Metal write leaves (uploaded or copied bytes); none in value for a shared-exponent word (another encoding of the same value). Within Metal's contract: `MTLLoadAction.load` is documented as "The GPU preserves the existing contents", which the kept texels are; the rewrite is Apple's tile store's own. `SnormMinimumKept` (`snorm-minimum-kept`) and `SharedExponentKept` (`shared-exponent-kept`), announced at each such draw; `runtime_lane::snorm_tile_store` | The load pass before each such pass: the render area copied into a scratch buffer and back, with a dispatch. Timed for the extended-range attachments, whose load pass runs under both values: at 1920x1080 on the Radeon 780M (RADV), a pass that loads one and draws a full-screen triangle takes 1,959 us of GPU time for `BGRA10_XR` against 135 us for `RGBA16Float`, and 1,341 us for `BGR10_XR` and 1,378 us for `RG16Bfloat` against 69 us for `RGBA8Unorm`: about 1.3 ms a loaded attachment for a 4-byte texel and 1.8 ms for an 8-byte one. Under `Exact` a snorm or `RGB9E5Float` attachment takes the same pass (not timed) |
| A multisampled color attachment whose format has Metal's resolve rule at its sample count (unorm, snorm, sRGB, 32-bit float and packed 16-bit unorm formats at every count; 16-bit float, `RG11B10Float` and `RGB9E5Float` ones at 2 and 4) resolves by the device's `AVERAGE` in the pass, which leaves the average's rounding, an sRGB average's space and what a NaN or infinite sample makes of it to the device. The runtime's: no pipeline differs. Not on a driver whose average is Metal's (`DriverFact::ColorResolveAverageIsMetals`: MoltenVK on Apple's GPUs, at 2 and 4 samples), under either value, with no notice; nor for an attachment a fetching pass's sample planes hold as it ends, which resolves from them by Metal's rule under either value. | `resolve = ResolvePolicy::Device` | `resolve = ResolvePolicy::Exact`: after the pass, one render pass instance per resolved attachment, between barriers, reads its samples (as an input attachment, or from a copy of them into a scratch image where its image takes no input attachment usage) and writes Metal's rule (`color_resolve.rs`), announced `shader-resolve` | At 2 and 4 samples, every unorm, snorm and packed 16-bit unorm channel within one code of Metal's and an sRGB channel within two (NVIDIA's at 4 samples; one elsewhere), on RADV (Mesa 26.0.8, the Radeon 780M and the RX 7900 XTX), ANV (Mesa 26.2.4, the Iris Xe), NVIDIA (615.71, the RTX 5080 Laptop GPU) and lavapipe (Mesa 26.2.4, at 4 samples). Each rounds an 8-bit unorm tie down (RADV and ANV: 32512 of `R8Unorm`'s 65536 pairs of samples one code below at 2 samples; NVIDIA 31872; lavapipe 8205 of 131072 texels at 4). A float channel differs in its last bits (counted, not bounded), and wholly at a NaN or infinite sample. `DeviceRoundedResolve` (`device-rounded-resolve`), announced at the first such pass; `runtime_lane::resolve_rounding::the_device_resolve_rounds_as_announced` | The extra pass per resolved attachment. A 1920x1080 frame of 97 command buffers of one pass of 4 indexed draws, every 4th pass resolving an `RGBA8Unorm` x4 attachment (`runtime_lane::frame_costs::frame_costs_scout_gpu`), GPU busy a frame, exact against the device's: the Iris Xe (ANV) 2.52 and 2.41 ms against 1.92 ms (a resolved pass's command buffer 77 against 51 us; the guest's queues and imports 3.04 and 2.77 against 2.43 ms); the Radeon 780M (RADV) 2.33 to 2.78 against 2.00 to 2.13 ms (63 to 75 against 45 to 48 us); the RX 7900 XTX 1.38 against 1.36 ms. Untimed, the frames were bound by the encoding thread's CPU, which neither changed |
| 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 whose queue merges a submission that signals nothing into the next (Mesa's: ANV, RADV, lavapipe, NVK, Turnip and kin): 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 eLine 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, 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 GLine 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) |
All at once: `DevicePolicy::exact_answers()` sets every switch above but sampling's (validation