RUNTIME 2450: Shadows: a rebind encodes the encoder of a gated copy in again

An encoder that left a shadow's copy in to its batch's submission
(Deferred::GatedCopyIn: over host pages a consumer logs, the regions its
log decides; or a command buffer's first copy in of a shadow that may
stand across command buffers) kept no log (Unlogged::Segments): no
Segment::records_again test held for it. A rebind, before the command
buffer's first submission, of a buffer over host pages that encoder used
then failed the command buffer with EncodedUseRebound, where Metal
resolves the use at the submission. Keeping the log alone would not do:
the encoding again redoes the copy in for itself (a gate of the log
taken again, a standing decided at the submission, ended_encoders_wrote
answering false while replaying) and leaves a GatedCopyIn of its own, or
records the copy in in place, but finish_replay asked every other
segment to record on the GPU alone, which a gated copy in does not, and
refused the encoding again.

Now Deferred::left_again_by_an_encoding_again answers for GatedCopyIn
too: the encoder keeps its log, its place takes the encoding again
(splice_fits), finish_replay prepares the encoding again's segment as the
commit prepares one (no recording, StepInputs::None), and the batch's
submission records it (submit.rs's record_scrubs, which takes every
unrecorded such segment). The first's goes unrun, retained. A gated copy
in made by the encoding again holds a gate of the log made after the
commit's decisions (DirtyShadows::committed), whose decision is none, so
it copies every region (CopyInGate::regions): a superset of the rows the
log reports changed, read at the submission, after every CPU write before
the commit; the shadow's hold was advanced to the commit's stamp by the
first gate's decision, and its image then holds at least that. Its cost,
one whole copy in, falls only on a rebind of such an encoder. A standing
gate is decided at the submission (stands), as the first's would be. GPU
parts are unchanged: a gated copy in starts none.

Unlogged::Segments now names a GPU-written indirect dispatch's host step
and a scrub. Docs: deferred.rs, rebound_use.rs, encoder.rs, reencode.rs,
shadow.rs (GatedCopyIn).

Test: dirty_pages_device's
a_rebind_before_the_first_submission_encodes_a_gated_copy_in_s_encoder_again:
a kernel inverts a shadowed RGBA8 texture over a logged no-copy buffer
into a plain texture, behind a shared event only the host signals; the
buffer is detached and rebound over other pages, logged by the same log,
before the signal. Asserts the command buffer completes with no error,
the rebind encoded the encoder once, one gated copy in ran (the encoding
again's) and copied every row (dirty_copies_in_gated +1,
dirty_copies_in_whole +1), and the kernel read the new pages' texels. At
development's files it is expected to fail on the error
(EncodedUseRebound).

Degradation kinds added or removed: none.

Verified: m3-max-36334 at a7b5d28822 (same tree), clippy -D warnings of the runtime (all targets and features) 0. Rustdoc, the cfg clippy, both controls, the rebind tests and the touched suites run after the merge.
This commit is contained in:
Anees Iqbal committed 2026-11-16 05:23:18 -08:00
1 parent 3858812d69
commit 5410cd5cf4
7 files changed
+129 -22

No files matched your search

@@ -673,7 +673,9 @@ impl State {
/// imports would not copy it, `host_ram/copy.rs`), or a splice's or a merge on the host's CPU
/// part (which goes, the encoding again leaving its own over the new pages,
/// `shadow_splice.rs`), or a staged scatter's steps (which go, the encoding again staging it
/// again, `host_ram/copy.rs`), or its group was submitted, or the command buffer completed.
/// again, `host_ram/copy.rs`), or a shadow's gated copy in (which goes, the encoding again
/// copying in for itself, `shadow::GatedCopyIn`), or its group was submitted, or the command
/// buffer completed.
pub(super) fn splice_replay(
&mut self,
at: usize,
@@ -713,9 +715,9 @@ impl State {
recorded.raws = raws;
recorded.summary = summary;
// Its first segments go: the encoding again left a segment of its own in each
// pending dispatch's, each splice's or merge on the host's and each staged copy
// step's place it staged again, and its work on the GPU alone in segments of its
// own, and recorded each other staged gather's copy at once.
// pending dispatch's, each splice's or merge on the host's, each staged copy step's it
// staged again and each gated copy in's place, and its work on the GPU alone in
// segments of its own, and recorded each other staged gather's copy at once.
// What the commit recorded of one stays retained, never submitted, as the first
// recording does.
for segment in recorded.segments.drain(..) {