Revoke a queue at its second caused GPU error, as Metal does
The steps this packet landed as, in order: - Draw private types in a pulled list form where the indexed list differs from Metal Content: the tree of `development` at d3fc3a5794, unchanged.
This commit is contained in:
1 parent
a3a4cf756d
commit
027451fc5f
45 files changed
+1843
-227
No files matched your search
@@ -42,6 +42,7 @@ pub(super) mod own;
|
||||
pub(super) mod rebound_use;
|
||||
mod reencode;
|
||||
pub(super) mod rerun;
|
||||
pub(super) mod revocation;
|
||||
mod storage_form;
|
||||
mod submit;
|
||||
|
||||
@@ -342,6 +343,17 @@ pub(super) enum FailedSignals {
|
||||
}
|
||||
|
||||
impl Failure {
|
||||
/// The failure of a command buffer committed on a queue Metal revoked (`revocation.rs`): no
|
||||
/// encoder runs, no event signal fires, and it completes with
|
||||
/// `CommandBufferError::AccessRevoked`.
|
||||
pub(super) fn revoked() -> Failure {
|
||||
Failure {
|
||||
encoders: FailedEncoders::From(0),
|
||||
signals: FailedSignals::Dropped,
|
||||
error: Some(CommandBufferError::AccessRevoked),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether ended encoder `encoder` runs under `failure`: every one does but those it fails.
|
||||
pub(super) fn runs(failure: Option<&Failure>, encoder: usize) -> bool {
|
||||
failure.is_none_or(|failure| !failure.encoders.fails(encoder))
|
||||
@@ -2343,14 +2355,20 @@ impl CommandBuffer {
|
||||
// hang hangs where its encoder runs and its signals fire under what it was committed
|
||||
// as (`hang.rs`).
|
||||
// Either reads `Scheduled` early, from the hang's on, once its waits are met.
|
||||
// One committed on a queue Metal revoked runs nothing and completes at once, its
|
||||
// signals dropped (`revocation.rs`).
|
||||
let revoked = run != CommitRun::Refused && self.0.queue.errors().revoked();
|
||||
let event_waits = state.batches.events().0;
|
||||
let discarded = match failure {
|
||||
None if run != CommitRun::Refused => hang::discarded(&self.0.queue, event_waits),
|
||||
None if run != CommitRun::Refused && !revoked => {
|
||||
hang::discarded(&self.0.queue, event_waits)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let joins = discarded.is_some();
|
||||
let failure = failure.or(discarded);
|
||||
let behind = run != CommitRun::Refused
|
||||
&& !revoked
|
||||
&& failure.is_none()
|
||||
&& event_waits > 0
|
||||
&& hang::in_flight(&self.0.queue);
|
||||
@@ -2368,6 +2386,7 @@ impl CommandBuffer {
|
||||
hang::join(&self.0, &mut state, waits);
|
||||
}
|
||||
let hangs = run != CommitRun::Refused
|
||||
&& !revoked
|
||||
&& matches!(state.fails_from, Some((at, CommandBufferError::GpuHang))
|
||||
if failure.as_ref().is_none_or(|f| f.signals && !f.encoders.fails(at)));
|
||||
if let (true, Some(hang)) = (hangs, &state.hang) {
|
||||
@@ -2376,6 +2395,10 @@ impl CommandBuffer {
|
||||
}
|
||||
let failure = Failure::of(failure, state.fails_from, ended);
|
||||
let failure = Failure::with_faults(failure, &state.faulted, ended);
|
||||
let failure = match revoked {
|
||||
true => Some(Failure::revoked()),
|
||||
false => failure,
|
||||
};
|
||||
// The encoders that run: all but those `failure` fails.
|
||||
let runs = |encoder: usize| Failure::runs(failure.as_ref(), encoder);
|
||||
state.committing = true;
|
||||
@@ -4032,6 +4055,10 @@ impl CommandBufferShared {
|
||||
state.error = Some(error);
|
||||
}
|
||||
}
|
||||
// A GPU error the command buffer caused counts against its queue, which Metal revokes
|
||||
// at the second, from before its status reads final (`revocation.rs`); a relayed one
|
||||
// is the driver's queue's.
|
||||
self.queue.errors().completed(state.failure);
|
||||
// The final status, with its error, once: a read sees no `Completed` that a decoded
|
||||
// failure turns to `Error`.
|
||||
self.answer(&state);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
//! A queue Metal stops serving after GPU errors its command buffers caused.
|
||||
//!
|
||||
//! Measured on the M3 Max with macOS 27.0.1 (about sixty command buffers over five runs; each a
|
||||
//! blit, a pass of one draw of primitive type 9, a blit, an event signal and a blit, then one
|
||||
//! committed at once, one committed some milliseconds on, and one committed after the first
|
||||
//! completed, on queues used in turn):
|
||||
//!
|
||||
//! - **Caused errors count, per queue.** A command buffer that fails with
|
||||
//! `MTLCommandBufferErrorPageFault` (3) or `MTLCommandBufferErrorTimeout` (2, a GPU hang)
|
||||
//! counts against its queue. One that fails as a victim of the GPU's recovery
|
||||
//! (`MTLCommandBufferErrorInternal`, "Discarded (victim of GPU error/recovery)") does not:
|
||||
//! three on one queue, and a victim then a fault, left the queue serving.
|
||||
//! - **The second one revokes the queue.** Once the queue's second command buffer with a caused
|
||||
//! error completes (two faults, two hangs, a hang then a fault), every command buffer committed
|
||||
//! on the queue after that fails at its commit: `Scheduled` and completed 0.02 to 0.06 ms after
|
||||
//! its commit, with status `Error` and `MTLCommandBufferErrorAccessRevoked` (4, "Ignored (for
|
||||
//! causing prior/excessive GPU errors)
|
||||
//! (00000004:kIOGPUCommandBufferCallbackErrorSubmissionsIgnored)"); none of its work runs, none
|
||||
//! of its event signals fires, and its GPU and kernel times span nothing. Two seconds on it was
|
||||
//! so still. One committed before that completion, 4.5 ms into the second fault, ran; one
|
||||
//! committed 0.5 ms after it, and later ones, did not.
|
||||
//! - **Other queues serve on.** A new queue of the same device ran normally after others were
|
||||
//! revoked, its own first fault or hang leaving it serving.
|
||||
//! - The second faulting command buffer itself answers as the first did (its other encoders ran
|
||||
//! in 9 of 11 runs, nothing of it in 2), as does one committed at once after it.
|
||||
//!
|
||||
//! The runtime counts the command buffers of a queue that complete with a failure of its own
|
||||
//! making that Metal's GPU causes: [`CommandBufferError::PageFault`] as the runtime fails an
|
||||
//! encoder Metal's GPU faults (a draw of primitive type 9 over indices, a render encoder's
|
||||
//! execution of an indirect command buffer under a state it cannot inherit), and
|
||||
//! [`CommandBufferError::GpuHang`]. A failure the driver relays is the driver's own queue's,
|
||||
//! which Metal counts itself under MoltenVK. From the completion of the second one, before its
|
||||
//! status reads final, the queue is revoked: a command buffer committed on it then fails with
|
||||
//! [`CommandBufferError::AccessRevoked`] as its commit's work, from its first encoder, its event
|
||||
//! signals dropped (`commit_now`). One committed before runs as committed, whatever its event
|
||||
//! waits (Metal's answer for one held by a wait across the revocation is not measured).
|
||||
|
||||
use crate::error::CommandBufferError;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
/// The command buffers whose GPU error Metal counts against their queue that revoke it.
|
||||
const REVOKING: u32 = 2;
|
||||
|
||||
/// A queue's count of its command buffers that completed with a GPU error they caused (the
|
||||
/// module docs).
|
||||
#[derive(Default)]
|
||||
pub(crate) struct QueueErrors {
|
||||
caused: AtomicU32,
|
||||
}
|
||||
|
||||
impl QueueErrors {
|
||||
/// A command buffer of the queue completes with `error` (`None` for none), before its status
|
||||
/// reads final: counted where the GPU caused it.
|
||||
pub(super) fn completed(&self, error: Option<CommandBufferError>) {
|
||||
if matches!(
|
||||
error,
|
||||
Some(CommandBufferError::PageFault | CommandBufferError::GpuHang)
|
||||
) {
|
||||
self.caused.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether Metal ignores the queue's command buffers committed now: its second command buffer
|
||||
/// with a caused error completed.
|
||||
pub(super) fn revoked(&self) -> bool {
|
||||
self.caused.load(Ordering::SeqCst) >= REVOKING
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user