RUNTIME 2261: a commit returns while its batch waits for a held VkQueue; kept draws carry only into passes of the same sample positions and layer count; the lavapipe and AMD lane failures

Runtime fixes, each with a test that fails before:
- A command buffer's queue slot lives apart from its state lock (d159e7a2f1, 78d5a44df2).
  commit() handed its slot over under the command buffer's state lock, which the scheduler
  thread held across vkQueueSubmit; that submit waited for a VkQueue someone else held (a
  compositor sharing the queue), so the program's commit waited as long as the queue was held
  (gdb, m3-max-28123: the lane's checked-commit tests ended in SendError after 60 s). Test:
  tests::scheduler_wakes::a_commit_returns_while_the_thread_submits_its_batch_to_a_held_vk_queue
  (lavapipe, fails before in 20 s: m3-max-28149).
- A render encoder at custom sample positions carries no kept draw (1da568fc43): a kept draw's
  VkPipeline has the positions baked in, and carry_ends never compared the ending pass's, so a draw
  kept from a pass at custom positions was carried into a later pass of the same shape at the
  default ones (runtime_lane::sample_positions on the XTX and the 780M, draw_again.rs:1320).
- A kept draw carries only into a pass of the same renderTargetArrayLength (430fad72b8): the
  layered passes' kept draws were carried across layer counts (runtime_lane::layered_passes, both
  tests, on lavapipe and AMD). The debug check that caught both now names the parts that differ
  and whether the draw was rebound or carried (8bfeebe929, 3973769b86, 9da59ae9e3).

Test fixes (the expectation follows the runtime's documented behaviour):
- runtime_lane::degrade_notices::dispatches_degrade_once_per_kind expects a split where the device
  splits the ragged grid (1b58b69953's partial-threadgroups variant runs it whole elsewhere).
- handed_objects x2 and host_memory: a held import's deallocator runs once its command buffer
  completed, posted to the free thread (41b5430f6a) or not, as Metal's may run after the waiters.
- queue_order's host-step order test commits B once A's gate was taken (b46459080d: a batch whose
  host step has not taken its gate gives way, the order the x86 Macs keep).
- The two dispatches past 2^32 threads compile only under m2v_gpu: a CPU device runs each past the
  watchdog's 20.2 s (docs/VALIDATION.md).
- The held-wakes tests begin once the device's own checks answered.

Verified: lavapipe suite at 430fad72b8 6019/6020 (m3-max-28179; the one failure the runtime-sources
pin this landing re-pins). The XTX and 780M legs (m3-max-28177, 28178) run after the landing.
This commit is contained in:
Anees Iqbal committed 2026-11-13 21:59:11 -08:00
1 parent fa9799ce9e
commit b3d844f9fb
16 files changed
+495 -107

No files matched your search

-9
View File
@@ -69,15 +69,6 @@ threads-required = 'num-test-threads'
filter = 'package(metal2vulkan-validation) & test(/^runtime_lane::mesh_draws::object_grids_run_as_metal_runs_them$/)'
threads-required = 'num-test-threads'
# The two dispatches past 2^32 threads run alone. Each runs all of its 4.3 billion threads, so on a
# CPU device it takes every CPU thread: lavapipe (LLVM 23.1.4) on a 16-thread Ryzen 7 7840HS
# completed each in 24 s alone, and one passed the lane's 60 s wait beside a parallel runtime lane
# on 20 threads (Iris Xe host, round 6898863f3f). Their wait for completion is their own
# (`PAST_2_32_WAIT`).
[[profile.default.overrides]]
filter = 'package(metal2vulkan-validation) & test(/^runtime_lane::indirect_dispatches::(a_direct_dispatch_past_2_32_threads_keeps_the_flat_variant_s_64_bit_count|a_flat_dispatch_switches_to_its_64_bit_count_at_the_workgroup_that_passes_2_32)$/)'
threads-required = 'num-test-threads'
# The runtime's isolation tests of command queues sharing `VkQueue`s run alone. Each holds a
# compositor's 99th percentile of commit-to-completion latency under 5 ms, and its stalls over
# 10 ms to at most one, beside an application's 30 ms command buffers: a bound of the GPU's time,
@@ -1650,10 +1650,13 @@ pub(crate) mod trace {
/// batch's end where it may) and before it hands the batches to the scheduler
/// (`CommandBuffer::commit`).
Committing,
/// A committing thread, once it handed the batches to the scheduler and before it hands
/// over its queue's slot (`CommandBuffer::commit`).
Handed,
}
/// Of each [`Point`]: whether a test holds threads there, and whether one reached it since.
static POINTS: Mutex<[(bool, bool); 4]> = Mutex::new([(false, false); 4]);
static POINTS: Mutex<[(bool, bool); 5]> = Mutex::new([(false, false); 5]);
static POINTS_CHANGED: std::sync::Condvar = std::sync::Condvar::new();
/// Hold every thread that reaches `point` from now on, until [`release`].
@@ -263,6 +263,12 @@ pub(super) struct CommandBufferShared {
/// Its queue (`commandQueue`).
root: CommandQueue,
state: Mutex<State>,
/// The slot of its queue it holds until it completes, or is dropped uncommitted
/// (`queue.rs`). Apart from the state, which a submission of its batches holds through
/// `vkQueueSubmit` (`submit.rs`): its commit hands the slot over once its batches are the
/// scheduler's ([`Slot::handed`]), and so returns while another thread holds the `VkQueue`,
/// as Metal's `commit` returns at once.
slot: Mutex<Option<Slot>>,
/// Signaled when the command buffer's status changes (`wait_until_scheduled` waits on it).
changed: Condvar,
/// What `wait_until_completed` waits for: the command buffer finished, and the runtime's
@@ -966,9 +972,6 @@ pub(super) struct State {
report: Option<StatusReport>,
/// Its GPU and kernel times (`gpu_time.rs`).
times: Times,
/// The slot of its queue it holds until it completes, or is dropped uncommitted
/// (`queue.rs`).
slot: Option<Slot>,
/// The heaps its ended encoders' commands used, which its commit marks used
/// (`Heap::set_purgeable_state`).
used_heaps: Vec<Heap>,
@@ -2530,7 +2533,6 @@ impl CommandBuffer {
relayed_description: None,
report: None,
times: Times::default(),
slot: Some(slot),
used_heaps: Vec::new(),
holds: Vec::new(),
residency: None,
@@ -2566,6 +2568,7 @@ impl CommandBuffer {
#[cfg(unix)]
sync_file: None,
}),
slot: Mutex::new(Some(slot)),
changed: Condvar::new(),
gate: Arc::default(),
relayed: Arc::default(),
@@ -2827,6 +2830,13 @@ impl CommandBuffer {
lock(&self.0.state)
}
/// Whether another thread holds its state's lock now, as a submission of its batch holds it
/// through `vkQueueSubmit` (`submit.rs`): a device test's (`tests::scheduler_wakes`).
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) fn state_held(&self) -> bool {
matches!(self.0.state.try_lock(), Err(TryLockError::WouldBlock))
}
/// Batch `index`'s footprint as the scheduler asks for it
/// ([`CommandBufferShared::footprint`]): a device test's (`tests::footprint_locks`).
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
@@ -4127,7 +4137,7 @@ impl CommandBuffer {
if reset.0 {
self.0.mark_reencode();
}
if let Some(slot) = &mut state.slot {
if let Some(slot) = lock(&self.0.slot).as_mut() {
slot.committed();
}
self.0.time(&mut state);
@@ -4233,12 +4243,16 @@ impl CommandBuffer {
.shared()
.scheduler
.commit(&self.0, self.0.queue.id(), waits, hand);
// A device test holds the commit here, its batches the scheduler's and its slot not
// handed over (`completion::trace::Point::Handed`).
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
completion::trace::at(completion::trace::Point::Handed);
// Only now, its batches the scheduler's, it leaves the device's uncommitted command
// buffers (`queue.rs`'s `Uncommitted`): until then no texture's face turns and no storage
// form switches beside it, whose commands, recorded for good and their batches' ends
// folded where they may, would meet the turn's copies or the switch as their batches are
// submitted.
if let Some(slot) = &mut self.state().slot {
if let Some(slot) = lock(&self.0.slot).as_mut() {
slot.handed();
}
// Its passes that took a rasterization-rate map since reset, encoded again in this call
@@ -6306,7 +6320,7 @@ impl CommandBufferShared {
// released below (a no-copy buffer's deallocator may run long there); a make after
// `wait_until_completed` returned never blocks (probe `slotdealloc`:
// `queue.rs`).
let slot = lock(&self.state).slot.take();
let slot = lock(&self.slot).take();
drop(slot);
let nanos = u64::try_from(handled.elapsed().as_nanos()).unwrap_or(u64::MAX);
self.device.shared().counts.slot_returned(nanos);
@@ -8,15 +8,13 @@ use crate::encoder::{EncoderCore, Recorded};
use crate::texture::storage_form::Riding;
impl State {
/// Whether its commit may take a switch (`texture/storage_form.rs`): it may be committed, it
/// holds a slot of its queue (so it counts among the device's uncommitted command buffers)
/// and ended an encoder; every encoder of it may run; it waits for no event or binary
/// semaphore and leaves no segment and no sparse update to a host step, so the scheduler
/// submits all of it once its submission checks (if it has any) ran; and it bound no heap
/// set.
/// Whether its commit may take a switch (`texture/storage_form.rs`), as far as its state
/// tells: it may be committed and ended an encoder; every encoder of it may run; it waits for
/// no event or binary semaphore and leaves no segment and no sparse update to a host step, so
/// the scheduler submits all of it once its submission checks (if it has any) ran; and it
/// bound no heap set.
fn takes_storage_forms(&self) -> bool {
self.refusal().is_none()
&& self.slot.is_some()
&& !self.ended.is_empty()
&& self.fails_from.is_none()
&& self.faulted.is_empty()
@@ -42,9 +40,11 @@ impl CommandBuffer {
if injected || !device.storage_forms_wanted() {
return false;
}
// It holds a slot of its queue too, so it counts among the device's uncommitted command
// buffers.
let parts = {
let state = self.state();
if !state.takes_storage_forms() {
if !state.takes_storage_forms() || lock(&self.0.slot).is_none() {
return false;
}
state.recorded.len()
@@ -12,7 +12,7 @@
//! apart from those an attachment of its pass renders (`render/attached_levels.rs`; else it is
//! let go, `WorkCounts::kept_draws_uncarried_attached`), under a depth/stencil state that does
//! not fail every fragment (whose draw takes every step once restated, `restated.rs`), in a pass
//! of no color groups, rasterization-rate map or replay, its command
//! of no color groups, rasterization-rate map, custom sample positions or replay, its command
//! buffer holds the bind state, with the settle, and the kept draw ([`Carried`]) in place of
//! giving the state to its device's spares (`live_bind::SpareLiveBinds`). With it go the kept
//! draws its bind state set aside with the states of other pipeline states (`LiveBind::select`)
@@ -36,13 +36,14 @@
//! (`WorkCounts::kept_draws_carry_dropped_between`): only the opening of a render encoder takes
//! it. That encoder takes it ([`carried_fits`]) where its pass is the ended one's in everything the
//! kept draw's settle and recording read: the same [`PassShape`] (formats, samples,
//! resolves, input attachments, view mask) and layers, no memoryless color, visibility buffer,
//! custom sample positions, extended-range color, rasterization-rate map, color groups or
//! encoding of an ended encoder again (`kept_draws_carry_dropped_layout`); and where what the
//! kept draw read that changes with no call is as it was: no no-copy buffer moved, the device's
//! sampler IDs' slots as they were, and its residency of the generation the ended encoder's
//! had (`kept_draws_carry_dropped_under`). Else it lets it go, counted, and starts from a
//! spare, as any encoder.
//! resolves, input attachments, view mask) and layers (the layout's, and the descriptor's
//! `renderTargetArrayLength`, 0 or those, which the draw's bind shape holds), no memoryless
//! color, visibility buffer, custom sample positions, extended-range color, rasterization-rate
//! map, color groups or encoding of an ended encoder again (`kept_draws_carry_dropped_layout`);
//! and where what the kept draw read that changes with no call is as it was: no no-copy buffer
//! moved, the device's sampler IDs' slots as they were, and its residency of the generation the
//! ended encoder's had (`kept_draws_carry_dropped_under`). Else it lets it go, counted, and
//! starts from a spare, as any encoder.
//! - **Across a commit.** The commit hands it to its queue's place (`queue.rs`), which holds one:
//! the one it held, which no render encoder took, is let go
//! (`WorkCounts::kept_draws_carry_dropped_commit`). A render encoder of a later command buffer
@@ -130,9 +131,10 @@ const CARRIED_STATES: usize = 4;
pub(crate) struct Carried {
live: Box<LiveBind>,
kept: Kept,
/// The ended encoder's pass's shape and layers, and its residency's generation.
/// The ended encoder's pass's shape and layers (the layout's, and the descriptor's
/// `renderTargetArrayLength` as the encoder keeps it), and its residency's generation.
shape: PassShape,
layers: u32,
layers: Layers,
residency: u64,
/// Whether its command buffer was committed, and its queue holds it for a later command
/// buffer's render encoder ([`across`](Carried::across)).
@@ -163,7 +165,7 @@ impl Carried {
/// docs): its pass's shape and layers, and what changes with no call as it ended.
pub(crate) struct NoneKept {
shape: PassShape,
layers: u32,
layers: Layers,
/// The no-copy buffers' moves, its residency's generation and its device's sampler IDs'
/// slots' changes, at its end.
under: (u64, u64, u64),
@@ -217,12 +219,36 @@ pub(super) enum Start {
Spare(Box<LiveBind>),
}
/// A pass's layers, as a kept draw's settle and recording read them: its layout's, and its
/// descriptor's `renderTargetArrayLength` as its encoder keeps it (0, or the layout's), which the
/// draw's bind shape holds (`BindShape::render_target_array_length`): a pass of one layer reads 0
/// or 1 there.
#[derive(Clone, Copy, PartialEq, Eq)]
struct Layers {
layout: u32,
array_length: u32,
}
impl Layers {
/// The layers `lowering`'s pass draws.
fn of(lowering: &RenderLowering) -> Layers {
Layers {
layout: lowering.layout.layers,
array_length: lowering.render_target_array_length,
}
}
}
/// Whether the render encoder `opening` opens draws a pass of `shape` and `layers` in everything
/// a kept draw's settle and recording read (the module docs).
fn same_pass(shape: &PassShape, layers: u32, opening: &Opening) -> bool {
fn same_pass(shape: &PassShape, layers: Layers, opening: &Opening) -> bool {
let layout = &opening.layout;
let opened = Layers {
layout: layout.layers,
array_length: opening.render_target_array_length,
};
opening.shape == *shape
&& layout.layers == layers
&& opened == layers
&& opening.rate_map.is_none()
&& opening.grouped.is_none()
&& layout.visibility.is_none()
@@ -301,7 +327,7 @@ impl RenderLowering {
Ok(()) => {
let none_kept = Box::new(NoneKept {
shape: (*self.current.shape).clone(),
layers: self.layout.layers,
layers: Layers::of(self),
under: (
crate::buffer::host_cells_moved(),
self.residency.generation(),
@@ -325,8 +351,13 @@ impl RenderLowering {
self.earlier.is_empty() && current.pieces.is_empty(),
Uncarried::Split,
),
// A kept draw's `VkPipeline` holds its pass's custom sample positions
// (`render/draw_shape.rs`'s `PipelineInputs`), which an opening of the same shape
// may not set.
(
self.grouped.is_none() && self.rate_map.is_none(),
self.grouped.is_none()
&& self.rate_map.is_none()
&& self.layout.sample_positions.is_empty(),
Uncarried::Pass,
),
(!self.replaying && !self.rerouting, Uncarried::Replay),
@@ -404,7 +435,7 @@ impl Lowering {
live,
kept,
shape: (*lowering.current.shape).clone(),
layers: lowering.layout.layers,
layers: Layers::of(&lowering),
residency: lowering.residency.generation(),
across: false,
#[cfg(debug_assertions)]
@@ -431,6 +431,85 @@ impl Kept {
let under = &last.under;
self.epoch == last.epoch && self.carried_under(under.moved, under.residency, under.samplers)
}
/// The parts of the draw that are not `other`'s, by name: what the check of a draw again
/// that kept another draw names ([`Checked`]).
#[cfg(debug_assertions)]
fn differences(&self, other: &Kept) -> Vec<&'static str> {
let Kept {
pipeline,
epoch,
stated,
settings,
between,
call,
assembly,
draw,
index,
under,
command_buffer,
command,
again,
pushes_set_zero,
last_vertex,
through_copies,
narrowed,
reads_images,
execution,
reads,
rasterizes,
depth_writes,
draw_alone,
stamps,
rebinds,
settled,
carried,
across,
made,
reader,
} = self;
let [executed, shape, created] = match (execution, &other.execution) {
(Some(execution), Some(other)) => execution.same_parts(other),
(execution, other) => [execution.is_none() && other.is_none(); 3],
};
[
("pipeline", *pipeline == other.pipeline),
("epoch", *epoch == other.epoch),
("stated", *stated == other.stated),
("settings", *settings == other.settings),
("between", *between == other.between),
("call", *call == other.call),
("assembly", *assembly == other.assembly),
("draw", *draw == other.draw),
("index", *index == other.index),
("under", *under == other.under),
("command_buffer", *command_buffer == other.command_buffer),
("command", *command == other.command),
("again", *again == other.again),
("pushes_set_zero", *pushes_set_zero == other.pushes_set_zero),
("last_vertex", *last_vertex == other.last_vertex),
("through_copies", *through_copies == other.through_copies),
("narrowed", *narrowed == other.narrowed),
("reads_images", *reads_images == other.reads_images),
("execution's pipeline", executed),
("execution's shape", shape),
("execution's creation times", created),
("reads", *reads == other.reads),
("rasterizes", *rasterizes == other.rasterizes),
("depth_writes", *depth_writes == other.depth_writes),
("draw_alone", *draw_alone == other.draw_alone),
("stamps", *stamps == other.stamps),
("rebinds", *rebinds == other.rebinds),
("settled", *settled == other.settled),
("carried", *carried == other.carried),
("across", *across == other.across),
("made", *made == other.made),
("reader", *reader == other.reader),
]
.into_iter()
.filter_map(|(part, same)| (!same).then_some(part))
.collect()
}
}
/// An index source as a kept draw read it in place: the Metal buffer, by key, and offset, and
@@ -501,14 +580,22 @@ pub(super) struct KeptExecution {
pub(super) created: Vec<Duration>,
}
impl PartialEq for KeptExecution {
fn eq(&self, other: &KeptExecution) -> bool {
impl KeptExecution {
/// Whether its pipeline, its shape and its creation times are `other`'s, each.
fn same_parts(&self, other: &KeptExecution) -> [bool; 3] {
let pipeline = match (&self.pipeline, &other.pipeline) {
(ExecutedPipeline::Render(a), ExecutedPipeline::Render(b)) => Arc::ptr_eq(a, b),
(ExecutedPipeline::Compute(a), ExecutedPipeline::Compute(b)) => Arc::ptr_eq(a, b),
_ => false,
};
pipeline && Arc::ptr_eq(&self.shape, &other.shape) && self.created == other.created
let shape = Arc::ptr_eq(&self.shape, &other.shape);
[pipeline, shape, self.created == other.created]
}
}
impl PartialEq for KeptExecution {
fn eq(&self, other: &KeptExecution) -> bool {
self.same_parts(other).into_iter().all(|same| same)
}
}
@@ -1317,7 +1404,18 @@ impl Checked {
(again.command_buffer, again.carried) = (kept.command_buffer, kept.carried);
again.across = kept.across;
}
assert!(*again == kept, "a draw again kept another draw");
// The shapes' values where only their objects may differ.
let shapes = match (&again.execution, &kept.execution) {
(Some(again), Some(kept)) => Some(*again.shape == *kept.shape),
_ => None,
};
assert!(
*again == kept,
"a draw again kept another draw: its {:?} differ (rebound {rebound}, carried {}, \
execution shapes equal in value {shapes:?})",
again.differences(&kept),
kept.carried
);
(again.draw_alone, again.stamps, again.under) = (draw_alone, stamps, under);
(again.settled, again.between, again.stated) = (settled, between, stated);
(again.command_buffer, again.carried) = (command_buffer, carried);
@@ -36,9 +36,15 @@ use std::time::{Duration, Instant};
/// How long a held thread, or a command buffer, is waited for.
const BOUND: Duration = Duration::from_secs(5);
/// How long the device's own checks are waited for before a test.
const SETTLE: Duration = Duration::from_secs(120);
/// The device the cfg selects, its batches grouping where `merge`: a CPU device under
/// `m2v_cpu_icd`, else a GPU. Its command queues stay on the `VkQueue`s they were made on
/// (`QueueSharingPolicy::PerQueue`).
/// (`QueueSharingPolicy::PerQueue`). Its own checks have answered: the in-place check commits
/// command buffers of its own (`in_place_check.rs`), which a pass of the scheduler's takes in, and
/// a pass after a slice that takes a commit in is no rescue; and the submission checks hold its
/// first `VkQueue` for their calls (`submit_check.rs`).
fn device(merge: bool) -> Device {
let mut options = DeviceOptions {
kinds: match cfg!(m2v_cpu_icd) {
@@ -53,7 +59,14 @@ fn device(merge: bool) -> Device {
..DeviceOptions::default()
};
options.policy.queue_sharing = QueueSharingPolicy::PerQueue;
Device::system_default_with(&options).unwrap()
let device = Device::system_default_with(&options).unwrap();
// False where the device runs no in-place check (its policy keeps no texture in place).
let _ = device.settle_in_place_checks(SETTLE);
assert!(
device.settle_submit_checks(SETTLE),
"the submission checks never answered"
);
device
}
/// A command buffer of `queue` that fills `target` whole with `value`.
@@ -187,9 +200,17 @@ fn a_held_batch_whose_wake_never_came_goes_at_the_next_slice() {
let after = device.work_counts();
let rescues = after.scheduler_slice_rescues - before.scheduler_slice_rescues;
let slices = after.scheduler_sleep_slices - before.scheduler_sleep_slices;
let delta = |of: fn(&crate::WorkCounts) -> u64| of(&after) - of(&before);
println!(
"HELD-WAKES lost wake: completed {took:?} after the completions were published; \
{slices} slices, {rescues} slice rescues"
{slices} slices, {rescues} slice rescues; wakes by commit {}, completion {}, host {}; \
commits taken in {}, passes {}, by waiters {}",
delta(|counts| counts.scheduler_wakes_commit),
delta(|counts| counts.scheduler_wakes_completion),
delta(|counts| counts.scheduler_wakes_host),
delta(|counts| counts.commits_taken_in),
delta(|counts| counts.scheduler_passes),
delta(|counts| counts.scheduler_passes_by_waiters),
);
assert!(rescues > 0, "the kept group went with no slice's pass");
}
@@ -17,17 +17,20 @@
//! itself"): the thread sleeps and wakes as it does where such batches are its own.
//! - **Never behind a submission.** A commit that finds no pass under way wakes the thread without
//! the lock a pass holds across its `vkQueueSubmit`: with the `VkQueue` held and that lock held,
//! no pass counted, a commit from another thread returns at once.
//! no pass counted, a commit from another thread returns at once. Nor behind its own: a commit
//! whose batch the thread's pass took and submits, waiting for the held `VkQueue` under the
//! command buffer's state lock, returns at once too (its queue's slot is apart from that lock).
//!
//! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
//! `m2v_cpu_icd`), on the kind of device the cfg selects.
use crate::command_buffer::completion::trace::{self, Point};
use crate::tests::SETTLE;
use crate::{
Buffer, CommandBuffer, CommandQueue, Device, DeviceKind, DeviceOptions, ResourceOptions,
WorkCounts,
};
use metal2vulkan::device::CompletionPolicy;
use metal2vulkan::device::{CompletionPolicy, DevicePolicy};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{mpsc, Arc};
use std::time::{Duration, Instant};
@@ -47,7 +50,13 @@ const IN_FLIGHT: u64 = 8;
/// The device the cfg selects: a CPU device under `m2v_cpu_icd`, else a GPU.
fn device() -> Device {
device_with(DevicePolicy::default())
}
/// [`device`] of `policy`.
fn device_with(policy: DevicePolicy) -> Device {
let options = DeviceOptions {
policy,
kinds: match cfg!(m2v_cpu_icd) {
true => vec![DeviceKind::Cpu],
false => vec![
@@ -312,3 +321,91 @@ fn a_commit_returns_while_the_lock_a_submission_holds_is_held() {
settle(&completed, 1, "the commit made while the lock was held");
assert_eq!(command_buffer.error(), None);
}
/// Lets go of the commits held at [`Point::Handed`] as it drops, a failing test's unwinding too.
struct HeldHanded;
impl Drop for HeldHanded {
fn drop(&mut self) {
trace::release(Point::Handed);
}
}
/// A commit held once it handed its batch to the scheduler (`Point::Handed`), while the
/// `VkQueue` is held: the thread's pass takes the batch and submits it, waiting for the `VkQueue`
/// under the command buffer's state lock (`submit.rs`). Let go, the commit hands over its queue's
/// slot and returns at once, as Metal's does: the slot is apart from that lock. (It waited for
/// the `VkQueue` there: `runtime_lane::queue_order`'s taken-up rounds hung until their holder's
/// timeout on lavapipe beside the runtime lane, the commit in `CommandBuffer::state`.) Once the
/// `VkQueue` is let go, the command buffer completes. Under `CompletionPolicy::Exact`, so the
/// batch goes in a submission of its own, made under that lock, on every driver; and once the
/// device's own checks answered, so the thread's submission is this one's.
#[test]
fn a_commit_returns_while_the_thread_submits_its_batch_to_a_held_vk_queue() {
let mut policy = DevicePolicy::default();
policy.completion = CompletionPolicy::Exact;
let device = device_with(policy);
let _ = device.settle_in_place_checks(SETTLE);
assert!(
device.settle_submit_checks(SETTLE),
"the submission checks never answered"
);
let queue = device.new_command_queue().unwrap();
let target = device.new_buffer(256, ResourceOptions::private()).unwrap();
let completed = Arc::new(AtomicU64::new(0));
let command_buffer = counted_fill(&queue, &target, 1, &completed);
let (held, holding) = mpsc::channel();
let (release, released) = mpsc::channel::<()>();
let holder = {
let queue = queue.clone();
std::thread::spawn(move || {
// SAFETY: the closure keeps no handle and calls nothing of the runtime's; it waits
// only for this test's release, past the commit's bound.
unsafe {
queue.with_vk_queue(|_, _, _| {
held.send(()).unwrap();
let _ = released.recv_timeout(2 * BOUND);
})
}
})
};
holding.recv_timeout(BOUND).unwrap();
trace::hold_at(Point::Handed);
let handed = HeldHanded;
let (done, returns) = mpsc::channel();
let committer = {
let command_buffer = command_buffer.clone();
std::thread::spawn(move || {
command_buffer.commit().unwrap();
// Gone where the test stopped waiting for it.
let _ = done.send(());
})
};
assert!(
trace::reached(Point::Handed, BOUND),
"the commit reached its hold"
);
let since = Instant::now();
while !command_buffer.state_held() {
assert!(
since.elapsed() < BOUND,
"the thread's submission never took the command buffer's state"
);
std::thread::sleep(Duration::from_millis(1));
}
drop(handed);
let returned = returns.recv_timeout(BOUND).is_ok();
release.send(()).unwrap();
holder.join().unwrap();
committer.join().unwrap();
assert!(
returned,
"the commit waited for the submission of its own batch"
);
settle(
&completed,
1,
"the commit made while its batch was submitted",
);
assert_eq!(command_buffer.error(), None);
}
@@ -920,7 +920,8 @@ pub(crate) enum Uncarried {
Unsettled,
/// Its pass split: an instance before the current one, or pieces of the current one.
Split,
/// Its pass is drawn in color groups or over a rasterization-rate map.
/// Its pass is drawn in color groups, over a rasterization-rate map, or at custom sample
/// positions.
Pass,
/// It encoded an ended encoder again, or recorded a draw again into another instance.
Replay,
@@ -7298,7 +7299,8 @@ pub struct WorkCounts {
pub encoders_uncarried_unsettled: u64,
/// Their pass split: an instance before the current one, or pieces of the current one.
pub encoders_uncarried_split: u64,
/// Their pass is drawn in color groups or over a rasterization-rate map.
/// Their pass is drawn in color groups, over a rasterization-rate map, or at custom sample
/// positions.
pub encoders_uncarried_pass: u64,
/// They encoded an ended encoder again, or recorded a draw again into another instance.
pub encoders_uncarried_replay: u64,
@@ -253,7 +253,7 @@ use crate::candidate::engine::compute_shape;
use crate::candidate::engine::resources::pixel_format;
use crate::candidate::engine::variants::compile_compute_for_shape;
use crate::gpu::TEST_DEVICE;
use metal2vulkan::bind::{AstcDecode, SamplerDescriptor};
use metal2vulkan::bind::{AstcDecode, Dispatch, SamplerDescriptor};
use metal2vulkan::cache::VariantKey;
use metal2vulkan::device::VkExtension;
use metal2vulkan::device::{DriverFact, DriverWorkaround, OpBits, VkFeature, VkProperty};
@@ -306,8 +306,8 @@ const BLITS: [Degradation; 3] = [
Degradation::StagedTextureCopy,
];
/// The kinds [`dispatches_degrade_once_per_kind`] takes (the second where the device pins the
/// kernel's subgroup size).
/// The kinds [`dispatches_degrade_once_per_kind`] takes (the first where the device splits the
/// ragged grid, the second where it pins the kernel's subgroup size).
const DISPATCHES: [Degradation; 2] = [Degradation::SplitDispatch, Degradation::EmulatedSimdgroups];
/// The kinds [`passes_degrade_once_per_kind`] takes (the second where the device resolves a
@@ -1393,10 +1393,65 @@ fn emulates_simdgroups(device: &Device, case: &PublicCase) -> bool {
key.emulated_simdgroups
}
/// A non-uniform grid runs twice (split into regions), and a kernel of simdgroup shuffles twice
/// in threadgroups of 8 threads: each kind is announced once, the emulated simdgroups exactly
/// where the compile layer settles the dispatch on that variant (a device whose kernels' simdgroups
/// run on pinned subgroups wider than 8).
/// Whether `case`'s ragged `dispatchThreads` grid (one that is not a whole number of threadgroups)
/// runs split on `device`, an edge region at each remainder's threadgroup size, Vulkan dispatching
/// whole workgroups. Its kernel observes its threadgroup partition, so no flat variant runs it
/// (`compute.rs`'s `flat_direct`); the runtime runs it at the call's threadgroup size alone on the
/// kernel's partial-threadgroups variant (`partial_direct`), of the key the state's plan names for
/// a dispatch of one threadgroup of that size with `VariantKey::partial_threadgroups` set, and
/// keeps the split where that key's simdgroups are emulated or the compile layer refuses the
/// variant (`ComputePipelineState::settle_partial`). The same compile answers here, as the
/// compile layer settles the key ([`emulates_simdgroups`]'s).
fn splits_ragged(device: &Device, case: &PublicCase) -> bool {
let compile = device.compile_device();
let addressed = compile.profile().descriptors().buffer_device_address;
let shape = compute_shape(&case.compute, addressed).unwrap();
let library = Library::from_air(&case.bitcode).unwrap();
let function = FunctionDescriptor::new(library.function(&case.compute.entry).unwrap());
let Dispatch::Threads {
threads,
threads_per_group,
} = case.compute.dispatch
else {
panic!("{}: not a dispatch of threads", case.compute.entry);
};
assert!(
(0..3).any(|i| !threads[i].is_multiple_of(threads_per_group[i])),
"{}: a whole number of threadgroups",
case.compute.entry
);
let group = Dispatch::Threadgroups {
groups: [1, 1, 1],
threads_per_group,
};
let budget = Budget::standard();
let (_, mut key) =
compile_compute_for_shape(compile, &function, &shape, Some(&group), None, &budget).unwrap();
if key.emulated_simdgroups {
return true;
}
key.partial_threadgroups = true;
let variant = compile
.compile_function(&function, &key.lowering_inputs(Stage::Kernel), &budget)
.and_then(|compiled| {
let descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
compile.compile_compute_pipeline(&descriptor, &budget)
});
match variant {
Ok(_) => false,
Err(metal2vulkan::error::Error::Unsupported(_)) => true,
Err(error) => panic!(
"the partial-threadgroups variant of {}: {error}",
case.compute.entry
),
}
}
/// A non-uniform grid runs twice, split into regions where the device splits it
/// ([`splits_ragged`]), and a kernel of simdgroup shuffles twice in threadgroups of 8 threads: each
/// kind is announced once, the emulated simdgroups exactly where the compile layer settles the
/// dispatch on that variant (a device whose kernels' simdgroups run on pinned subgroups wider than
/// 8).
#[test]
fn dispatches_degrade_once_per_kind() {
on_device_with(at_plan, |device, messages| {
@@ -1405,23 +1460,23 @@ fn dispatches_degrade_once_per_kind() {
for case in [&ragged, &ragged, &partial, &partial] {
run_case(device, case).unwrap();
}
let split = splits_ragged(device, &ragged);
let emulated = emulates_simdgroups(device, &partial);
eprintln!("{PARTIAL_SIMDGROUPS}: emulated simdgroups: {emulated}");
let expected: &[Degradation] = if emulated {
&DISPATCHES
} else {
&DISPATCHES[..1]
};
eprintln!(
"{RAGGED}: split: {split}; {PARTIAL_SIMDGROUPS}: emulated simdgroups: {emulated}"
);
let expected: Vec<Degradation> = [(DISPATCHES[0], split), (DISPATCHES[1], emulated)]
.into_iter()
.filter_map(|(kind, forced)| forced.then_some(kind))
.collect();
// Beside them, what the cases' makings and `Shared` buffers force on the device.
let mut first = shared_kinds(device);
first.extend(case_making_kinds(device, &ragged));
first.extend(case_making_kinds(device, &partial));
let counts = assert_made_once(messages, expected, &first);
assert_eq!(
counts.contains_key(&Degradation::EmulatedSimdgroups),
emulated,
"{counts:?}"
);
let counts = assert_made_once(messages, &expected, &first);
for (kind, forced) in [(DISPATCHES[0], split), (DISPATCHES[1], emulated)] {
assert_eq!(counts.contains_key(&kind), forced, "{kind:?}: {counts:?}");
}
});
}
@@ -10,8 +10,13 @@
//!
//! Each test binds no-copy buffers so, and a texture over one, releases its own handles while the
//! command buffer waits for an event, and checks that no deallocator ran until the command buffer
//! completed, and that each ran once by the time its wait returned, on a thread of the runtime's
//! (its command buffer's release); or, never committed, once it was released.
//! completed, and that each ran once from then on, on a thread of the runtime's; or, never
//! committed, once it was released. A completed command buffer that held a host import last posts
//! its free, which a deallocator waits for, to the device's free thread, where the deallocator runs
//! after it, possibly after the command buffer's waiters returned (the runtime's `free_thread.rs`):
//! so a deallocator that had not run as the wait returned is one whose free was posted
//! (`WorkCounts::host_import_frees_posted`). Metal's own deallocator ran after its command buffer's
//! wait returned now and then on an M4 (`host_memory.rs`).
use super::host_memory::{
no_copy, not_importable, on_device, recording, Mapping, Seen, GUEST_PAGE,
@@ -72,16 +77,31 @@ fn none_ran(seen: &[(&str, &Arc<Seen>)], when: &str) {
}
}
/// Each deallocator of `seen` ran once, as `command_buffer`'s wait returned: on a thread of the
/// runtime's, not this one.
fn each_ran_at_completion(seen: &[(&str, &Arc<Seen>)], command_buffer: &CommandBuffer) {
/// Signal `event`, which `command_buffer` of `device` waits for: once the command buffer's wait
/// returned, each deallocator of `seen` runs once, on a thread of the runtime's, not this one; and
/// each that had not run as the wait returned had its free posted to the device's free thread (the
/// module docs).
fn each_runs_once_completed(
device: &Device,
event: &SharedEvent,
seen: &[(&str, &Arc<Seen>)],
command_buffer: &CommandBuffer,
) {
let posted = || device.work_counts().host_import_frees_posted;
let before = posted();
event.set_signaled_value(1);
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(command_buffer.error(), None);
let late: Vec<&str> = (seen.iter())
.filter(|(_, seen)| seen.runs.load(Ordering::SeqCst) == 0)
.map(|(what, _)| *what)
.collect();
for (what, seen) in seen {
deallocated(seen);
assert_eq!(
seen.runs.load(Ordering::SeqCst),
1,
"{what}'s deallocator ran once by the completion"
"{what}'s deallocator ran once"
);
assert_ne!(
*seen.thread.lock().unwrap(),
@@ -89,6 +109,16 @@ fn each_ran_at_completion(seen: &[(&str, &Arc<Seen>)], command_buffer: &CommandB
"{what}'s deallocator ran on the program's thread"
);
}
// Read once every deallocator ran: each posted free was posted before its deallocator ran.
let posted = posted() - before;
eprintln!(
"HANDED on {}: ran after the wait returned {late:?}, import frees posted {posted}",
device.name()
);
assert!(
posted >= late.len() as u64,
"{late:?} ran after the wait returned, {posted} import frees posted"
);
}
/// A command buffer of a new queue of `device`'s that waits for `event` before its work.
@@ -128,8 +158,7 @@ fn a_compute_encoder_s_bindings_no_dispatch_used_live_until_its_command_buffer_c
drop((replaced, after));
let seen = [("replaced", &replaced_seen), ("after", &after_seen)];
none_ran(&seen, "while its command buffer waited");
event.set_signaled_value(1);
each_ran_at_completion(&seen, &command_buffer);
each_runs_once_completed(device, &event, &seen, &command_buffer);
});
}
@@ -179,8 +208,7 @@ fn a_render_encoder_s_bindings_no_draw_used_live_until_its_command_buffer_comple
("after", &after_seen),
];
none_ran(&seen, "while its command buffer waited");
event.set_signaled_value(1);
each_ran_at_completion(&seen, &command_buffer);
each_runs_once_completed(device, &event, &seen, &command_buffer);
});
}
@@ -11,6 +11,7 @@
#[cfg(any(m2v_cpu_icd, m2v_gpu_hazards))]
use super::layer_reported_nothing;
use super::rebind_reach::deallocated;
use super::{
at_plan, buffer_with, encode_case, pipeline_state, public_case, read_buffer,
validated_device_with, CaseResources, Messages, ScratchCache,
@@ -585,8 +586,11 @@ fn the_consumer_s_task_memory_takes_gpu_and_cpu_writes() {
/// Metal's answers for a buffer a pending command buffer holds (`dealloc_held`): with the program's
/// handle dropped, the deallocator has not run while the command buffer waits for an event; it runs
/// once, after the command buffer completed and its completed handlers ran, on a thread of the
/// runtime, with the pointer and the length, and sees the GPU's writes. Here it has run by the time
/// `wait_until_completed` returns, as on the M3 (the M4 raced it).
/// runtime, with the pointer and the length, and sees the GPU's writes. Metal's had run by the time
/// `wait_until_completed` returned on the M3, and raced that return on the M4. Here it runs by
/// then, or after it where the completed command buffer's release posted the import's free, which
/// the deallocator waits for, to the device's free thread (the runtime's `free_thread.rs`,
/// `WorkCounts::host_import_frees_posted`).
#[test]
fn a_waiting_command_buffer_holds_its_buffer_until_it_completed() {
on_device(|device| {
@@ -635,11 +639,21 @@ fn a_waiting_command_buffer_holds_its_buffer_until_it_completed() {
0,
"the deallocator ran while its command buffer waited"
);
let posted = || device.work_counts().host_import_frees_posted;
let before = posted();
event.set_signaled_value(1);
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(command_buffer.error(), None);
assert_eq!(in_handler.load(Ordering::SeqCst), 0);
let late = seen.runs.load(Ordering::SeqCst) == 0;
deallocated(&seen);
assert_eq!(seen.runs.load(Ordering::SeqCst), 1);
// Read once the deallocator ran, which a posted free runs after.
let posted = posted() - before;
assert!(
!late || posted > 0,
"the deallocator ran after the wait returned, {posted} import frees posted"
);
assert_eq!(seen.dropped.load(Ordering::SeqCst), 0);
assert_eq!(
*seen.args.lock().unwrap(),
@@ -217,21 +217,8 @@ impl Fixture {
/// Commit `command_buffer`, wait for it, and check it completed.
fn complete(command_buffer: &CommandBuffer, what: &str) {
complete_within(command_buffer, what, WAIT);
}
/// How long a dispatch past 2^32 threads may take to complete. Every one of its 4.3 billion
/// threads runs, so a CPU device spends all its threads on it: lavapipe (llvmpipe, LLVM 23.1.4) on
/// a 16-thread Ryzen 7 7840HS completed each of the two such dispatches here in 24 s alone, past
/// [`WAIT`] beside a parallel runtime lane on 20 threads, and a runner with a quarter of the
/// threads takes about four times as long. A GPU completes them well inside a second. The tests run
/// alone (`.config/nextest.toml`).
const PAST_2_32_WAIT: std::time::Duration = std::time::Duration::from_secs(600);
/// [`complete`], waiting at most `wait`.
fn complete_within(command_buffer: &CommandBuffer, what: &str, wait: std::time::Duration) {
command_buffer.commit().unwrap();
command_buffer.wait_until_completed_for(wait).unwrap();
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(
command_buffer.status(),
CommandBufferStatus::Completed,
@@ -845,6 +832,15 @@ fn a_ragged_direct_dispatch_runs_each_thread_once_on_the_flat_variant() {
/// into `out[y]`, the thread at `y = gy - 1` into `out[gy + x]`. Over a grid of more than 2^32
/// threads only these edges are stored, and a position counted in 32 bits would wrap the rows past
/// 2^32 threads onto the first ones (those counted twice, the last never).
///
/// Its dispatches past 2^32 threads run on a GPU alone (`m2v_gpu`, docs/VALIDATION.md). Every one
/// of their 4.3 billion threads runs: a GPU completes each well inside a second (0.1 to 0.3 s on
/// the RX 7900 XTX and the 780M), and a CPU device takes longer than Metal's bound on a command
/// buffer, which the runtime's watchdog keeps (a front batch 20.2 s without its timeline advancing
/// fails as Metal's timed-out command buffer, `GpuHang`: the runtime's `stall.rs`). lavapipe
/// (llvmpipe, LLVM 23.1.4) took 24 s for each on a 16-thread Ryzen 7 7840HS to itself, and the
/// watchdog failed each at 22 s on a 24-thread Core Ultra 9 275HX beside the parallel suite.
#[cfg(m2v_gpu)]
const FLAT_EDGES: &str = r#"define void @flat_edges(ptr addrspace(1) noundef "air-buffer-no-alias" %b0, <3 x i32> noundef %p, <3 x i32> noundef %g) {
entry:
%px = extractelement <3 x i32> %p, i64 0
@@ -890,6 +886,7 @@ done:
/// flat variant's 64-bit arm, and every thread of the last column and the last row runs once at
/// its own position, the rows past 2^32 included: the 32-bit count is taken only when the whole
/// dispatch fits it.
#[cfg(m2v_gpu)]
#[test]
fn a_direct_dispatch_past_2_32_threads_keeps_the_flat_variant_s_64_bit_count() {
edges_counted_once([65_536, 65_601, 1], [32, 32, 1]);
@@ -900,6 +897,7 @@ fn a_direct_dispatch_past_2_32_threads_keeps_the_flat_variant_s_64_bit_count() {
/// threadgroup of 105 threads (7 x 5 x 3, not a power of two) the first 64-bit workgroup starts
/// inside a row, so the last column and the last row are each counted once only where both arms
/// meet exactly there.
#[cfg(m2v_gpu)]
#[test]
fn a_flat_dispatch_switches_to_its_64_bit_count_at_the_workgroup_that_passes_2_32() {
edges_counted_once([65_536, 65_601, 1], [7, 5, 3]);
@@ -907,6 +905,7 @@ fn a_flat_dispatch_switches_to_its_64_bit_count_at_the_workgroup_that_passes_2_3
/// Dispatch [`FLAT_EDGES`] over `grid` (more than 2^32 threads) in threadgroups of `group`: it
/// runs on the flat variant and marks every thread of the last column and the last row once.
#[cfg(m2v_gpu)]
fn edges_counted_once(grid: [u32; 3], group: [u32; 3]) {
on_device(|device, messages| {
let library = device
@@ -932,11 +931,7 @@ fn edges_counted_once(grid: [u32; 3], group: [u32; 3]) {
encoder.set_buffer(Some(&out), 0, 0).unwrap();
encoder.dispatch_threads(size(grid), size(group)).unwrap();
encoder.end_encoding().unwrap();
complete_within(
&command_buffer,
&format!("past 2^32 {grid:?} {group:?}"),
PAST_2_32_WAIT,
);
complete(&command_buffer, &format!("past 2^32 {grid:?} {group:?}"));
let flat = command_buffer
.executions()
.iter()
@@ -8,7 +8,8 @@
//! - **Ready at its commit.** A's write is a blit fill.
//! - **Held for its host step.** A's write is an execution of commands a kernel of A wrote
//! (`indirect_host_steps.rs`), behind fills of a ballast: its batch waits at its gate for A's
//! earlier work to complete, and for its host step, while B commits.
//! earlier work to complete, and for its host step, while B commits (once the gate was taken:
//! before that the batch gives way).
//! - **Held for its submission check.** A's fill has a check that waits until B committed.
//!
//! And within one queue, commits from two threads while the scheduler thread's submission waits
@@ -30,7 +31,7 @@ use metal2vulkan_runtime::{
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::mpsc;
use std::sync::{Arc, Mutex, OnceLock};
use std::time::Duration;
use std::time::{Duration, Instant};
/// The bytes A's fill writes.
const FILLED: u8 = 0x5a;
@@ -101,13 +102,20 @@ fn a_copy_committed_after_a_write_on_another_queue_holds_it() {
}
/// A's execution of commands its kernel wrote waits for its host step, behind fills of a
/// ballast; B's copy of what the commands write, committed meanwhile, holds their writes: the
/// held batch keeps its place.
/// ballast; B's copy of what the commands write, committed once the scheduler took the step's gate
/// (`WorkCounts::heads_waiting_at_their_gate` moved) or submitted the batch, holds their writes:
/// a batch whose gate was taken keeps its place. Before its gate is taken it gives way to a later
/// commit of another queue (the scheduler's `order.rs`, **Held batches give way**), as an x86
/// Mac's GPU may take that one first, and a commit made at once after A's meets it so: its own
/// submission, at the commit, comes before the scheduler's thread passes.
#[test]
fn a_copy_committed_while_a_write_waits_for_its_host_step_holds_it() {
on_device_with(at_plan, |device, messages| {
let (a, b) = queues(device);
let setup = Setup::new(device, 2);
let held_behind = || device.work_counts().heads_held_for_earlier_commits;
let at_gate = || device.work_counts().heads_waiting_at_their_gate;
let (before, gated) = (held_behind(), at_gate());
let (reader, copy) = copy_first(&b, setup.out());
let ballast = device
.new_buffer(BALLAST, ResourceOptions::private())
@@ -125,8 +133,32 @@ fn a_copy_committed_while_a_write_waits_for_its_host_step_holds_it() {
setup.execute(&mut encoder);
encoder.end_encoding().unwrap();
writer.commit().unwrap();
let since = Instant::now();
let at_its_gate = loop {
if at_gate() > gated {
break true;
}
if writer.status() != CommandBufferStatus::Committed {
break false;
}
assert!(
since.elapsed() < WAIT,
"the scheduler never took up A's execution"
);
std::thread::sleep(Duration::from_millis(1));
};
reader.commit().unwrap();
completed(&[&writer, &reader]);
eprintln!(
"QUEUE-ORDER host step on {}: B committed with A's batch {}, heads held behind an \
earlier commit {}",
device.name(),
match at_its_gate {
true => "at its gate",
false => "submitted",
},
held_behind() - before
);
assert_eq!(setup.output(), expected());
let copied: Vec<u32> = read_buffer(&copy, 0, copy.length())
.unwrap()
+1 -1
View File
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 522;
/// 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 = 2260;
pub const RUNTIME_VERSION: u32 = 2261;
/// 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
+7
View File
@@ -77,6 +77,13 @@ CARGO_TARGET_DIR=target/gpuhazards RUSTFLAGS='--cfg m2v_gpu --cfg m2v_gpu_hazard
-E 'test(=runtime_lane::host_memory::a_gpu_fault_fails_its_command_buffer_and_the_queue_runs_on)'
```
**Work past a CPU device's reach** compiles only under `m2v_gpu`: a device test whose command
buffer a CPU device cannot run within Metal's bound on one. The runtime's watchdog fails a queue's
front batch that goes 20.2 s without its timeline advancing as Metal's timed-out command buffer
(`GpuHang`, the runtime's `command_buffer/stall.rs`), on every device. The two dispatches past
2^32 threads in `runtime_lane::indirect_dispatches` are such tests: each took 24 s on lavapipe
with 16 CPU threads to itself, and 0.1 to 0.3 s on an RX 7900 XTX and a Radeon 780M.
- **Device selection is an argument.** Every device-opening binary takes `--device-type cpu|gpu`,
with no default. `cpu` matches only a CPU device and never falls back to a GPU; `gpu` takes the
loader's first GPU. `corpus-metal` takes only `gpu`.