RUNTIME 2470: Rebinds: a rebind before the submission of an encoder no rebind encodes again is refused

A rebind between a command buffer's commit and the submission of its last
event group, of a buffer an encoder of it named that keeps no log (a compute
encoder its unit of command predication reaches past, a loop's laying, a
render encoder opened while no buffer over host pages existed), failed that
submission EncodedUseRebound: the commit let go of its holds, and nothing
encodes the encoder again. The consumer's answer table ends the VM on that
kind. Now the rebind is refused instead (EncodedUses), and the command buffer
runs over the pages it was encoded over.

- State::keep_replays also answers whether an encoder that keeps no log
  (not one its commit fails, which runs nothing) named a buffer over host
  pages, by its own commands or by work it left for later not recorded on
  the GPU alone (State::unlogged_names_a_pin).
- Where so, the commit keeps the command buffer's holds
  (State::held_to_submission) instead of letting them go:
  Holds::hold_to_submission moves each from Entry::pending to a new
  Entry::unsubmitted under one lock of `buffers`, so no rebind falls
  between. They go as the last event group's first batch is submitted
  (State::first_submission, State::later_group), or at completion; a
  rebind after that keeps the old pages for the submitted work, as before.
- replace and the rebind's first check refuse while `unsubmitted > 0`,
  counted as their own reason: WorkCounts::rebinds_refused_unsubmitted.
- Cost: nothing new for a command buffer whose encoders a rebind encodes
  again (one pass over its ended encoders' flags at the commit, inside
  keep_replays). A host-step command buffer keeps holding to completion
  (steps_hold), unchanged.

Deadlock audit, by lock:

- Commit: hold_to_submission takes `buffers` under the command buffer's
  `state` lock: state -> buffers, the order encode_moved's Submitting and
  the commit's own clear of its holds already take.
- Submission: the holds go under the scheduler's lock and `state`, after
  the `Submitting` guard (`buffers`) was dropped; each Holds' drop takes
  `buffers` alone: scheduler -> state -> buffers, the order the
  submission's judging already takes. Never under `buffers` itself.
- Completion: moved out of `state` and dropped after its lock, with the
  submitted holds.
- Nothing waits on them: a rebind finds `unsubmitted` and is refused; no
  wait is added anywhere, so no cycle can form.

Tests (lavapipe): rebind_races gains a control (the predicated family
committed behind an unsignaled shared-event wait, rebound before the
signal: refused, completes over the old page, refused-unsubmitted 1), and
the threaded run asserts no command buffer fails EncodedUseRebound. Tests
that asserted the old outcome of such a rebind now assert the refusal and
a completion over the old pages: pending_rebind, rebind_loop_check's
rebind before the laying's submission, tile_rebind_making_wait's
unlogged tile pass, and validation's rebind_reach test of a unit's
encoder that laid its first step. The validation lane no longer has a test
that announces encoded-use-rebound (degrade_notices says so).

Docs: rebind.rs module docs (ordering rule, a predicated loop's laying),
Buffer::rebind_bytes_no_copy, RebindProblem::EncodedUses, the
encoded-use-rebound catalogue entry and its declaration, runtime README;
api_signatures blessed.

Follow-ups in the same landing: Rebinds: a state's reset takes held_to_submission fresh too; Rebinds: clippy (append, take) in the hold-to-submission moves.

Checks (lane rebindsafe2): clippy plain (runtime, validation) 0 at 5bfab2beaa in m3-max-37364; lavapipe runtime tests 356/356 at a0fc57f283 (m3-max-37354: rebind, detach, host_page, host_step, indirect, predication, pending, holds, encoder_fold, deferred_calls), the new control refused with refused-unsubmitted 1 and the threaded run asserting 0 EncodedUseRebound. Validation lavapipe (m3-max-37365), rustdoc and the cfg clippy runs follow on development.
This commit is contained in:
Anees Iqbal committed 2026-11-16 11:23:09 -08:00
1 parent 4806a79c68
commit 3a3d31c374
17 files changed
+397 -161

No files matched your search

@@ -869,13 +869,34 @@ impl State {
keys.dedup();
maps.sort_unstable();
maps.dedup();
let to_submission = self.unlogged_names_a_pin();
KeptReplays {
gone,
keys: keys.into_boxed_slice(),
maps: maps.into_boxed_slice(),
to_submission,
}
}
/// Whether an encoder that keeps no log, once its replays are kept ([`State::keep_replays`]),
/// named a buffer over host pages, by a command of its own or by work it left for later that
/// its commit did not record on the GPU alone: no rebind encodes or records that again, so the
/// command buffer holds its encoders' holds until its last event group is submitted
/// (`held_to_submission`), refusing a rebind meanwhile, which would fail that submission.
fn unlogged_names_a_pin(&self) -> bool {
// One its commit fails runs nothing whatever the rebind: it holds nothing past the commit.
let held =
|r: &super::EncoderRecord| r.replay.is_none() && r.unlogged != Some(Unlogged::Fails);
let unlogged = |at: usize| self.ended.get(at).is_some_and(held);
let own = (self.ended.iter()).any(|r| held(r) && r.taken.names_a_pin());
own || (self.recorded.iter())
.filter(|part| unlogged(part.encoder))
.flat_map(|part| &part.segments)
.filter(|segment| !segment.gpu_alone)
.filter_map(|segment| segment.recorded.as_ref())
.any(|done| done.taken.names_a_pin())
}
/// As it commits, once its replays are kept ([`State::keep_replays`]): whether an encoder a
/// call of which raced a rebind of a buffer it took (`Taken::raced`) is to be encoded again,
/// in the commit's call, before its first submission, its log kept. One that kept none keeps
@@ -923,6 +944,9 @@ pub(super) struct KeptReplays {
pub(super) keys: Box<[ResourceKey]>,
/// The identities of the rasterization-rate maps its encoders' passes are over.
pub(super) maps: Box<[usize]>,
/// An encoder that keeps no log named a buffer over host pages
/// (`State::unlogged_names_a_pin`): its holds stay until its last group's submission.
pub(super) to_submission: bool,
}
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]