RUNTIME 2272: a failure inside a group of folded compute encoders fails only the encoders it names

RUNTIME 2268 failed a whole group of compute encoders recorded into one
VkCommandBuffer when a failure (commit_failed's From(n) or Set, a fault, a
recording failure) named only some of them. Metal runs every encoder the
failure leaves, so a From(n) inside a group dropped the work of the
encoders before n: a consumer's protection probe (a compute encoder, then
one made under protection options it fails From) read the first encoder's
words as never written.

Now every compute encoder logs its calls (replay.rs), a closed group keeps
its members' logs until the commit, and the commit splits a group its
failure fails in part (State::split_failure): the members that run are
encoded again from their logs, each into VkCommandBuffers of its own, in
the commit's call before the scheduler sees the batches (the rebind's
encode-again path, held by the same mark); the shared VkCommandBuffer is
never submitted and the failed members run nothing. Groups no failure
splits give their logs back at the commit. The split also works in a
command buffer that used command predication where its encoders are alone.
The one remaining difference (docs/API.md section 10, FAST-PATHS known
gaps): a group whose predication unit later laid a loop
(encode_start_while / encode_start_do_while) or left a record unbalanced
still fails whole.

pending_rebind's test reaches its no-log case through an If opened by the
encoder before (Unlogged::Predicated), since compute encoders now always
log; Unlogged::NoCalls's doc and notice text name what logs nothing now.

Cost (dchain, 5080 node CPU, dispatch_chain --host 20 --runs 9 --only
encoders --dispatches 2300, no host-page buffer, ABAB, ns a dispatch):
thread_cpu 3393/3396 -> 3539/3809; commit 113-126 -> 221-223 (logs held
until commit; a follow-up gives them back under one lock and keeps them as
spares); bind 49-50 -> 96-97 (the log itself, stays).

RUNTIME_VERSION 2272: folded groups split at a partial failure.

Verified (dchain): lavapipe full runtime suite at c118ca6fb6 (m3-max-28648)
2581 passed, 1 failed (host_ram_copy_device private-bit, the same at
09068993d6, owned by roip); pending_rebind negative control (guard removed)
fails on VUID-VkDescriptorBufferInfo-buffer-parameter; RTX 5080 208/208
(encoder_fold, rebind, reencode, command_buffer, dispatch, predication,
replay, fence, indirect, compute, failed); negative control at dd286c7304
(m3-max-28590): the four failure tests fail, the consumer-shaped one
included.

Squashed from steelbrain/dchain2 89480ccfd3..c118ca6fb6.
This commit is contained in:
Anees Iqbal committed 2026-11-14 01:59:11 -08:00
1 parent 2af00f020b
commit 7af3c4228a
14 files changed
+433 -122

No files matched your search

@@ -62,6 +62,12 @@
//! (`encoder_fold.rs`) are encoded again together: a rebind that moves one encodes each again,
//! into `VkCommandBuffer`s of its own, and puts them in their places together, or puts none
//! where one of them kept no log, is refused or does not fit its place.
//! - **Split at the commit.** A commit whose failure fails some of a group's encoders and not the
//! others (`encoder_fold.rs`'s **Failed**) marks the command buffer as a rebind does, and its
//! own call encodes the group's encoders that run again, each into `VkCommandBuffer`s of its
//! own, before the scheduler sees its batches; where one cannot be encoded again or does not
//! fit its place, those encoders run nothing after all (`State::fail_unsplit`), as the whole
//! group would have.
//! - **What cannot be encoded again stays as before.** An encoder whose log is gone (a compute
//! encoder of a command buffer that used command predication whose unit laid a step before it
//! opened, or one of its own that the unit's later encoders read, or a loop, or left work out;
@@ -124,7 +130,9 @@ impl CommandBufferShared {
// So are those whose pass took a rasterization-rate map since reset; one that kept no
// log draws by the map as it took it, announced (`rate_mapped_pass.rs`).
let mut unencoded = Vec::new();
let units: Vec<Vec<(usize, Arc<Replay>)>> = {
// Each unit with whether the commit's failure split it from its group: its encoders run
// nothing where they cannot all be encoded again (`encoder_fold.rs`'s **Failed**).
let units: Vec<(bool, Vec<(usize, Arc<Replay>)>)> = {
let mut state = lock(&self.state);
match state.finished() {
true => Vec::new(),
@@ -132,9 +140,24 @@ impl CommandBufferShared {
let open: BTreeSet<usize> = (state.recorded[state.unjudged_parts()..].iter())
.map(|part| part.encoder)
.collect();
let split: Vec<Vec<usize>> = state.split_units.drain(..).collect();
let splitting: BTreeSet<usize> = split.iter().flatten().copied().collect();
let mut units = Vec::new();
for unit in split {
let logs: Option<Vec<(usize, Arc<Replay>)>> = (unit.iter())
.map(|&at| {
let log = state.ended.get(at)?.replay.as_ref()?;
Some((at, Arc::clone(log)))
})
.collect();
match logs {
Some(logs) => units.push((true, logs)),
None => state.fail_unsplit(&unit),
}
}
let submitting = device.shared().rebinds.submitting();
let moved: Vec<(usize, Arc<Replay>)> = (state.ended.iter().enumerate())
.filter(|(at, _)| open.contains(at))
.filter(|(at, _)| open.contains(at) && !splitting.contains(at))
.filter_map(|(at, record)| {
let reset = record.taken.rate_map_reset();
let Some(replay) = record.replay.as_ref() else {
@@ -147,7 +170,9 @@ impl CommandBufferShared {
moved.then(|| (at, Arc::clone(replay)))
})
.collect();
state.encoded_together(moved, &device.shared().counts)
let together = state.encoded_together(moved, &device.shared().counts);
units.extend(together.into_iter().map(|unit| (false, unit)));
units
}
}
};
@@ -160,7 +185,8 @@ impl CommandBufferShared {
// Each unit's encoders are encoded again before any takes its place: a group of compute
// encoders recorded into one `VkCommandBuffer` takes its places whole or not at all
// (`encoder_fold.rs`).
for unit in units {
for (split, unit) in units {
let members: Vec<usize> = unit.iter().map(|(at, _)| *at).collect();
let mut again = Vec::new();
for (at, replay) in &unit {
match self.encode_again(&handle, *at, replay) {
@@ -169,7 +195,9 @@ impl CommandBufferShared {
}
}
if again.len() < unit.len() {
if unit.len() > 1 {
if split {
lock(&self.state).fail_unsplit(&members);
} else if unit.len() > 1 {
let mut state = lock(&self.state);
for (at, _) in &unit {
let record = &mut state.ended[*at];
@@ -215,6 +243,9 @@ impl CommandBufferShared {
Err(unspliced) => {
counts.reencode_refused();
state.ended[done.at].refused = Some(UNFIT.to_owned());
if split {
state.fail_unsplit(&[done.at]);
}
drop(unspliced);
}
}
@@ -227,6 +258,9 @@ impl CommandBufferShared {
Vec::new()
}
false => {
if split {
state.fail_unsplit(&members);
}
for done in &again {
counts.reencode_refused();
let refusal = match unit.len() {