diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index bc78793b7..5e5bc2a43 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -8396,9 +8396,9 @@ impl RenderLowering { // The encoder's kept bind state, brought to the draw's (`live_bind.rs`), held for the // draw: no draw of the encoder runs inside another past here. // A draw that reads its pass's texture at its own pixels and writes nothing of it reads - // it in place, with a barrier or without; else, after a barrier inside its instance, it - // reads it through a snapshot where it can (`render/snapshot.rs`): asked of the plan, - // kept where the plan reads so, else `None` and the copy or the split. + // it in place; else it reads it through a snapshot where it can (`render/snapshot.rs`), + // each with a barrier before it or without: asked of the plan, kept where the plan reads + // so, else `None` and the copy or the split. let mut snapshot = self .in_place_wanted(&pipeline, &reformats, &routed.settings) .or_else(|| self.snapshot_wanted(&pipeline, &reformats)); @@ -11683,12 +11683,15 @@ impl RenderLowering { // the draw again (`LineRoute::refused`). Err(refused) if settings.line.refused(&refused).is_some() => return Err(refused), // A variant that reads through snapshots the compile or bind layer refuses: the - // draw takes the split (`render/snapshot.rs`). + // draw takes the split, or with no barrier before it the copy, counted under no + // split reason (`render/snapshot.rs`). Err(Error::Unsupported(_) | Error::Bind(BindError::Unsupported(_))) if snapshot.as_ref().is_some_and(|w| !w.in_place) => { - let reason = snapshot::SplitReason::VariantRefused; - snapshot::snapshot_fallback(self.core.device(), reason); + if snapshot.as_ref().is_some_and(|w| w.split_otherwise) { + let reason = snapshot::SplitReason::VariantRefused; + snapshot::snapshot_fallback(self.core.device(), reason); + } *snapshot = None; continue; } @@ -11721,10 +11724,11 @@ impl RenderLowering { } // A plan that does not read through every snapshot the draw asked for: the draw // takes the split, settled again without them. One that does not read in place as the - // draw asked takes the copy, counted under no split reason. + // draw asked, or through snapshots with no barrier before it, takes the copy, counted + // under no split reason. if let Some(wanted) = snapshot.as_ref() { if let Err(reason) = self.snapshot_holds(&settled, wanted) { - if !wanted.in_place { + if wanted.split_otherwise { snapshot::snapshot_fallback(self.core.device(), reason); } *snapshot = None; diff --git a/crates/metal2vulkan-runtime/src/render/snapshot.rs b/crates/metal2vulkan-runtime/src/render/snapshot.rs index 01c820e6c..ce9eb01de 100644 --- a/crates/metal2vulkan-runtime/src/render/snapshot.rs +++ b/crates/metal2vulkan-runtime/src/render/snapshot.rs @@ -214,6 +214,11 @@ pub(super) struct Wanted { /// The draw reads the slots' textures in place, drawn once, with no snapshot (the module /// docs' in place). pub(super) in_place: bool, + /// Without its snapshots the draw takes the split: it follows a barrier inside its + /// instance, or behind the pass's loads (`loads_ordered`) reads a color the pass clears. + /// Else it reads the copy taken before the pass (`texture/attached_reads.rs`), and gives up + /// its snapshots counted under no split reason. + pub(super) split_otherwise: bool, } /// The form `plan` keeps fragment texture slot `slot`'s snapshot in @@ -447,14 +452,14 @@ impl RenderLowering { pipeline: &DrawingState, reformats: &[Reformat], ) -> Option { - // After a barrier before the pass's first draw alone (`loads_ordered`), a slot reads - // through a snapshot only where its texture's color is one the pass clears: one the pass - // loads holds the texels from before the pass, which its copy holds - // (`texture/attached_reads.rs`). + // With a barrier before it or not: a draw that reads with none reads what the draws + // before it wrote, as with one (`docs/API.md`'s accepted differences), where it would + // read the copy taken before the pass, the texels from before it. let ordered = self.current.barriers || self.barrier; - if self.replaying || self.rerouting || !(ordered || self.loads_ordered) { + if self.replaying || self.rerouting { return None; } + let mut split = ordered; let base = pipeline.base(); let fragment = base .stages @@ -465,17 +470,17 @@ impl RenderLowering { let Some(texture) = self.fragment.textures.get(&slot) else { continue; }; - if !texture.attached_in(&self.layout) || !(ordered || texture.cleared_in(&self.layout)) - { + if !texture.attached_in(&self.layout) { continue; } + split |= self.loads_ordered && texture.cleared_in(&self.layout); let Some(index) = texture.snapshot_color(&self.layout) else { // On a device without the path no image takes the feedback loop usage. let reason = match self.core.device().shared().color_write_masks.is_none() { true => SplitReason::DeviceLacks, false => SplitReason::NotInPlace, }; - return self.snapshot_fallback(reason); + return self.fallback_if(split, reason); }; wanted.slots.insert(slot); wanted.feedback.0 |= 1 << index; @@ -498,15 +503,16 @@ impl RenderLowering { } return None; } + wanted.split_otherwise = split; let device = self.core.device(); if device.shared().color_write_masks.is_none() { - return self.snapshot_fallback(SplitReason::DeviceLacks); + return self.fallback_if(split, SplitReason::DeviceLacks); } if self.visibility.active() { - return self.snapshot_fallback(SplitReason::VisibilityQuery); + return self.fallback_if(split, SplitReason::VisibilityQuery); } if let Err(reason) = self.in_instance(pipeline, reformats, &mut wanted) { - return self.snapshot_fallback(reason); + return self.fallback_if(split, reason); } Some(wanted) } @@ -683,10 +689,11 @@ impl RenderLowering { Some((key, texture)) => self.readers.measure(self.core.device(), &texture, key)?, None => None, }; + let split = wanted.split_otherwise; let wanted = match (within, learned) { (true, _) => Some(wanted), - (false, Some(_)) => self.snapshot_fallback(SplitReason::Coverage), - (false, None) => self.snapshot_fallback(SplitReason::Area), + (false, Some(_)) => self.fallback_if(split, SplitReason::Coverage), + (false, None) => self.fallback_if(split, SplitReason::Area), }; Ok((wanted, query)) } @@ -947,6 +954,16 @@ impl RenderLowering { snapshot_fallback(self.core.device(), reason); None } + + /// [`snapshot_fallback`](Self::snapshot_fallback) where the draw takes the split without + /// its snapshots (`split`, [`Wanted::split_otherwise`]); else `None` alone, the draw reading + /// the copy taken before the pass. + fn fallback_if(&self, split: bool, reason: SplitReason) -> Option { + match split { + true => self.snapshot_fallback(reason), + false => None, + } + } } /// Whether the split's copy of `texture` for a draw that reads it at its own pixels is cut to the