RUNTIME 2449: Host RAM: a rebind encodes the encoder of a gather staged past the imports again

An encoder that left a gather from a guest RAM staged through the CPU
kept no log (Unlogged::Segments) where an encoding again could not copy
the gather through the imports in its place: over a chunk that takes no
import while it runs (Staging::cpu_only: a chunk the device refuses, or
one an object's own import of its pages holds back), or in a part of its
own after the GPU completed the work before it (Staging::after_the_gpu:
a copy into those chunks was recorded, or a buffer over host pages lies
over the bytes), which a copy through the imports would not start. 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 runs it over the new pages.

Now such a gather is staged again as its first encoding staged it, as
RUNTIME 2448 does for a staged scatter: HostRamCall::staged_again answers
the first encoding's Staging for a gather that is not
Staging::through_imports (StagedGather::encoded_again_through_imports),
and Deferred::left_again_by_an_encoding_again answers for such a
GatherStage, so the encoder keeps its log, its place takes the encoding
again, and finish_replay leaves the step for its host step. Every other
staged gather is copied through the imports by an encoding again, as
before (Deferred::recorded_by_an_encoding_again).

Unlogged::Segments now names a GPU-written indirect dispatch's host
step, a scrub, and a shadow's copy in left to its batch's submission
(shadow::GatedCopyIn, which no Segment::records_again test holds
either; the doc did not name it). Docs: host_ram/copy.rs (First touch,
the gather; Staging; StagedGather), deferred.rs, encoder.rs,
reencode.rs, rebound_use.rs, and docs/HOWTO.md's two sentences on a
gather's rebind.

Test: host_ram_copy_device's
a_rebind_before_the_first_submission_encodes_a_gather_staged_after_the_gpu_again,
on the shape of a_first_gather_over_chunks_a_scatter_wrote_waits_for_no_import
(each chunk import held in flight 300 ms by making_pause): one encoder
scatters into scattered pages, gathers them back (staged after the GPU,
the scatter having written the chunks) and fills a no-copy buffer,
behind a shared event; the buffer is detached and rebound before the
signal. Asserts the command buffer completes with no error, the first
encoding staged both copies, the rebind encoded the encoder once and
staged both again, the fill is in the new pages alone, the RAM's runs
hold the scatter's bytes, and the gather's buffer holds them too. At
RUNTIME 2448's files it is expected to fail on the error
(EncodedUseRebound): the gather's step keeps the encoder from keeping
its log.

Degradation kinds added or removed: none.

Verified: m3-max-36303 at 75b7873bc2 (same tree), clippy -D warnings of the runtime (all targets and features) 0 and rustdoc -D warnings 0. The cfg clippy, the lavapipe control at the old files, the staged rebind tests and the touched suites run after the merge.
This commit is contained in:
Anees Iqbal committed 2026-11-16 05:14:10 -08:00
1 parent eb57e734d7
commit dcac15a5c6
8 files changed
+195 -52

No files matched your search

@@ -669,11 +669,11 @@ impl State {
/// left a segment of its own where it found them still being made), work its commit recorded
/// on the GPU alone, a run's merge (which
/// goes, the encoding again merging after itself, `pass_runs.rs`), a staged gather (which
/// goes, the encoding again copying through the imports, `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.
/// goes, the encoding again copying through the imports, or staging it again where the
/// 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.
pub(super) fn splice_replay(
&mut self,
at: usize,
@@ -713,9 +713,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 scatter
// step's place, and its work on the GPU alone in segments of its own, and recorded
// each staged gather's copy at once.
// 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.
// What the commit recorded of one stays retained, never submitted, as the first
// recording does.
for segment in recorded.segments.drain(..) {