From 918a5e59fb908fe6ae17a34331ce5ae9cb611d0a Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 16 Nov 2026 01:27:38 -0800 Subject: [PATCH] RUNTIME 2435: Shadows: a rebind encodes an encoder with a host merge or splice again What: an encoder that left a splice's or a merge on the host's CPU part (Deferred::ShadowSplice) now keeps its log, and a rebind's encoding again replaces that segment with the one it leaves itself over the new pages (Deferred::left_again_by_an_encoding_again, in Segment::records_again and reencode.rs's splice_fits). The first segment is retained unrun, as a replaced pending dispatch's is. A rebind keeps the bytes' offset in their page, so the copies back cut alike and the encoding again's parts match the first's. This covers ShadowSplice only, not a staged scatter (Deferred::ScatterStage and ScatterDrain, host_ram/copy.rs). An encoder that left a staged scatter still keeps no log (Unlogged::Segments), so a rebind of its buffer fails the command buffer with EncodedUseRebound as before. Whether a scatter's encoding again over the new pages leaves segments of the same parts was not checked: its staging depends on the chunks and imports the new pages lie in. Why: after RUNTIME 2433 the rebind was no longer refused, but such an encoder kept no log (Unlogged::Segments), so its command buffer failed EncodedUseRebound. PHOENIX job m3-max-35745 at 343f4489d3 (RUNTIME 2433's tree) failed tests::shadow_runs::passes_merged_on_the_host_are_encoded_again_at_a_rebind ("Error Some(EncodedUseRebound); encoders encoded again 0"), and so did lavapipe job m3-max-35749. The other five tests that failed at RUNTIME 2432 passed there, and so did 340 of 341 PHOENIX suite tests and 268 of 269 lavapipe ones. Verified: cargo fmt only so far; the jobs reported with this tip run the tests. Degradation kinds added: none. Verified (fplend): msi m3-max-35769 at 4ac4c366b5 (same tree): clippy 0, clippy --cfg m2v_gpu 0, debug archive 0. lavapipe 35749 at RUNTIME 2433's tree: 268/269, the one failure the rebind test this fixes. PHOENIX shadow_runs / merge_scratch and the suites follow. --- .../src/command_buffer/reencode.rs | 14 +++++++++----- crates/metal2vulkan-runtime/src/deferred.rs | 9 +++++++++ crates/metal2vulkan-runtime/src/encoder.rs | 9 ++++++--- crates/metal2vulkan/src/cache/mod.rs | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs index 4d5473827..c828c877a 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs @@ -639,6 +639,7 @@ impl State { || segment.gpu_alone || segment.work.joins_a_run() || segment.work.recorded_by_an_encoding_again() + || segment.work.left_again_by_an_encoding_again() }) }; let unjudged = self.unjudged_parts(); @@ -667,9 +668,11 @@ impl State { /// not since they were made (which goes, the encoding again having recorded those draws, or /// 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`), or a staged gather (which - /// goes, the encoding again copying through the imports, `host_ram/copy.rs`), or its group - /// was submitted, or the command buffer completed. + /// 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 its group was submitted, or the command buffer + /// completed. pub(super) fn splice_replay( &mut self, at: usize, @@ -709,8 +712,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 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 and each splice's or merge on the host's place, and its work on + // the GPU alone in segments of its own, and recorded each 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(..) { diff --git a/crates/metal2vulkan-runtime/src/deferred.rs b/crates/metal2vulkan-runtime/src/deferred.rs index 9fa929632..6b4e2ced1 100644 --- a/crates/metal2vulkan-runtime/src/deferred.rs +++ b/crates/metal2vulkan-runtime/src/deferred.rs @@ -576,6 +576,15 @@ impl Deferred { } } + /// Whether a rebind's encoding again of its encoder leaves a segment of its own in its place + /// (`command_buffer/reencode.rs`): a splice's and a merge on the host's CPU part + /// (`shadow_splice.rs`), which the encoding again's copies back plan over the pages the + /// buffer lies in then and leave again, in a part as the first's (a rebind keeps the bytes' + /// offset in their page, `rebind.rs`, so the copies cut alike); the first's goes unrun. + pub(super) fn left_again_by_an_encoding_again(&self) -> bool { + matches!(self, Deferred::ShadowSplice(_)) + } + /// Whether a commit may record it on the GPU alone, for good /// ([`record_on_gpu`](Self::record_on_gpu)): an execution's, or a render pass's that executes /// render commands. diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index dde4b8aab..885aaef6e 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -310,14 +310,17 @@ impl Segment { /// pipelines were being made ([`pends`](Self::pends)), left as a segment again, work a /// commit may record on the GPU alone, recorded there again (`Deferred::record_on_gpu`), or a /// run's pass's merge, which the pass encoded again records after itself as a pass alone - /// does, leaving its run (`pass_runs.rs`), or a staged gather, which the encoding again - /// copies through the imports in its place (`Deferred::recorded_by_an_encoding_again`). Its - /// log is kept only where every segment does. + /// does, leaving its run (`pass_runs.rs`), a staged gather, which the encoding again + /// copies through the imports in its place (`Deferred::recorded_by_an_encoding_again`), or a + /// splice's or a merge on the host's CPU part, which the encoding again leaves again over the + /// new pages (`Deferred::left_again_by_an_encoding_again`). Its log is kept only where every + /// segment does. pub(super) fn records_again(&self) -> bool { self.pends() || self.work.may_run_on_gpu_alone() || self.work.joins_a_run() || self.work.recorded_by_an_encoding_again() + || self.work.left_again_by_an_encoding_again() } /// What its recording will use, on `device`, while `commit` left it to the host step for the diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index f7cce6f74..6f1f64f7c 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2434; +pub const RUNTIME_VERSION: u32 = 2435; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles