From cee5c7eeb3c237f23ea88dffecba19e65b3ce33c Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 4 Nov 2026 19:08:18 -0800 Subject: [PATCH] Name a draw's read behind a barrier as the cause in the render-pass-split notice What: a split made so a draw reads a color attachment's texture after a memory barrier (`Split::AttachedRead`, the pass-start barrier's split among them) is now counted for the split's degrade notice (`SplitCauses::attached_reads`), whose reason says so: "draws that read a color attachment's texture after a memory barrier read what its load actions and the draws before the barrier stored, in a Vulkan render pass instance after theirs, ending N of them". The `RenderPassSplit` declaration and docs/API.md's catalogue entry list the cause. Why: such a split counted neither as a barrier split (`self.barrier` is false for a render-target barrier before any draw, and for one between draws, which records in the instance) nor as any other cause, so the notice fell to its last reason, "its draws keep different attachments out of their subpass", which describes no part of this pass. The conformance replays of the pass-start barrier family showed the split announced on every barrier row (Apple M3 Max, lavapipe). How verified: builds (conformance binary, debug). The lane assertion added to `a_draw_after_a_barrier_at_the_pass_start_reads_the_clear` (the split's reason, and a notice exactly where a pass split) is NOT yet run; the runtime-sources pin is not re-hashed (the coordinator's). (cherry picked from commit 30b797c61b27d4dbe34386c36a27837bb3ed8ead) --- .../metal2vulkan-runtime/src/degradation.rs | 22 +++++++++++++---- crates/metal2vulkan-runtime/src/render.rs | 7 ++++++ .../src/render/executions.rs | 1 + .../src/runtime_lane/attachment_reads.rs | 24 ++++++++++++++++++- docs/API.md | 13 +++++----- 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 70a449096..2c7149f4a 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -526,9 +526,11 @@ degradations! { /// amplification as multiview, or a view mapping that moves a draw to one layer), each run /// of them in an instance over those layers; or a memory barrier over buffers or textures /// orders its draws after it behind those before it, which a barrier between instances - /// does. Not where the interlock alone splits the pass, on a device whose driver ran such a - /// pass no slower split than whole (`DriverFact::InterlockedPassSplitNoSlower`): its faster - /// form. + /// does; or a draw reads a color attachment's texture after a memory barrier, and reads + /// what the pass's load actions and earlier draws stored where the barrier orders them + /// (`texture/attached_reads.rs`). Not where the interlock alone splits the pass, on a + /// device whose driver ran such a pass no slower split than whole + /// (`DriverFact::InterlockedPassSplitNoSlower`): its faster form. RenderPassSplit = "render-pass-split", Performance, "each instance after the first loads the attachments and each before the last \ stores them, with a barrier from everything before to everything after between \ @@ -4473,6 +4475,10 @@ pub(super) struct SplitCauses { /// The splits between draws that reach the pass's tile threadgroup memory /// (`render/tile_memory.rs`). pub(super) tile_memory: usize, + /// The splits before a draw that reads a color attachment's texture after a memory barrier, + /// the pass's load actions included where the barrier came before its first draw + /// (`texture/attached_reads.rs`). + pub(super) attached_reads: usize, /// Some of its instances render some of its layers. pub(super) viewed: bool, } @@ -4501,6 +4507,7 @@ impl Device { dispatches, barriers, tile_memory, + attached_reads, viewed, } = causes; let instances = shapes.len(); @@ -4553,7 +4560,8 @@ impl Device { && !shader_tests && dispatches == 0 && barriers == 0 - && tile_memory == 0; + && tile_memory == 0 + && attached_reads == 0; if instances > 1 && !chosen { let color = changed.and_then(|(index, interlock)| { let color = layout.colors.get(index as usize)?.as_ref()?; @@ -4612,6 +4620,12 @@ impl Device { across render pass instances alone, ending {tile_memory} of them, so it \ runs as {instances} Vulkan render pass instances" ), + None if attached_reads > 0 => format!( + "draws that read a color attachment's texture after a memory barrier read \ + what its load actions and the draws before the barrier stored, in a \ + Vulkan render pass instance after theirs, ending {attached_reads} of \ + them, so it runs as {instances} Vulkan render pass instances" + ), None if viewed => format!( "some of its draws render some of its layers (vertex amplification as \ Vulkan multiview, or a view mapping that moves a draw to one layer), \ diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 750e2f645..020400e31 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -1481,6 +1481,9 @@ pub(crate) struct RenderLowering { loads_ordered: bool, /// The splits such barriers made, for the split's degrade notice. barrier_splits: usize, + /// The splits before a draw that reads a color attachment's texture after a memory barrier + /// (`Split::AttachedRead`), for the split's degrade notice. + attached_read_splits: usize, /// What MoltenVK restarts its Metal render pass for inside the subpass, storing the /// attachments there, was recorded: a barrier between draws whose destination reads input /// attachments (`barrier_between_draws`), or a tessellated draw (`Device::degrade_pass`). @@ -2087,6 +2090,7 @@ impl RenderLowering { barrier: false, loads_ordered: false, barrier_splits: 0, + attached_read_splits: 0, driver_restarts: false, tile_memory_splits: 0, tile_memory: tile_memory::TileMemory::default(), @@ -4116,6 +4120,7 @@ impl RenderLowering { depth_stand_in, imageblock, barrier_splits, + attached_read_splits, driver_restarts, tile_memory_splits, tile_memory, @@ -5953,6 +5958,7 @@ impl RenderLowering { dispatches: dispatch_count, barriers: barrier_splits, tile_memory: tile_memory_splits, + attached_reads: attached_read_splits, viewed: views, }, ); @@ -6847,6 +6853,7 @@ impl RenderLowering { let previous = std::mem::replace(&mut self.current, *instance); self.earlier.push(previous); self.barrier_splits += usize::from(self.barrier); + self.attached_read_splits += usize::from(cause == Split::AttachedRead); // The instance after the one that ran the pass's load actions behind a barrier // before its first draw follows that barrier too. if self.barrier || self.loads_ordered { diff --git a/crates/metal2vulkan-runtime/src/render/executions.rs b/crates/metal2vulkan-runtime/src/render/executions.rs index 3c14c28b1..47eb0cf8f 100644 --- a/crates/metal2vulkan-runtime/src/render/executions.rs +++ b/crates/metal2vulkan-runtime/src/render/executions.rs @@ -2477,6 +2477,7 @@ impl RenderExecution { barrier: false, loads_ordered: false, barrier_splits: 0, + attached_read_splits: 0, driver_restarts: false, tile_memory_splits: 0, // The pass's buffer of every tile's memory, with the arguments the encoder set at the diff --git a/crates/metal2vulkan-validation/src/runtime_lane/attachment_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/attachment_reads.rs index f8ce3a0ea..bebca3dbd 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/attachment_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/attachment_reads.rs @@ -979,17 +979,36 @@ const STARTS: [Start; 3] = [ /// (`reading_draws_snapshotted`). #[test] fn a_draw_after_a_barrier_at_the_pass_start_reads_the_clear() { - on_device(|device, _messages| { + on_device(|device, messages| { let queue = device.new_command_queue().unwrap(); + // Whether a pass split, and whether the device announced a split: once, at its first. + let (mut split_any, mut announced) = (false, false); for fragment in ["psb_read", "psb_sample"] { let state = psb_state(device, fragment); for start in STARTS { for (name, target, _buffer) in targets(device) { let name = format!("{name}, {fragment}, {start:?}"); + messages.take_notices(); let counted = device.work_counts(); let bytes = started_pass(&queue, &target, LoadAction::Clear, start, (&state, &target)); let after = device.work_counts(); + // The split's notice names the read behind the barrier as its cause. + let notice = messages + .take_notices() + .into_iter() + .filter_map(|message| message.degradation) + .find(|notice| notice.degradation == Degradation::RenderPassSplit); + if let Some(split) = ¬ice { + assert!( + split.reason.contains( + "draws that read a color attachment's texture after a memory \ + barrier read what its load actions" + ), + "{name}: {}", + split.reason + ); + } hold_area(&name, &bytes, reordered(CLEAR), CLEAR); let moved = moved(&counted, &after); let [splits, begun] = instances(&counted, &after); @@ -1003,9 +1022,12 @@ fn a_draw_after_a_barrier_at_the_pass_start_reads_the_clear() { assert_eq!(attached, moved.splits, "{name}: splits for the read"); assert_eq!(splits, moved.splits, "{name}: no other split"); } + split_any |= splits > 0; + announced |= notice.is_some(); } } } + assert_eq!(announced, split_any, "the split's notice"); }); } diff --git a/docs/API.md b/docs/API.md index a03757c13..a93851464 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1689,12 +1689,13 @@ bound. attachment of the later draws' subpass alone; or a tile dispatch runs between two instances; or some of its draws render some of its layers, each run of them in an instance over those layers; or a memory barrier over buffers or textures orders its draws after it behind those before it, which - a barrier between instances does. Not where the pixel interlock alone splits the pass on a device - whose driver ran such a pass no slower split than whole - (`DriverFact::InterlockedPassSplitNoSlower`): the split is then its faster form. Cost: each - instance after the first loads the attachments and each before the last stores them, with a - barrier from everything before to everything after between them: on a tiler, a tile flush per - split. + a barrier between instances does; or a draw reads a color attachment's texture after a memory + barrier, and reads what the pass's load actions and earlier draws stored where the barrier orders + them. Not where the pixel interlock alone splits the pass on a device whose driver ran such a pass + no slower split than whole (`DriverFact::InterlockedPassSplitNoSlower`): the split is then its + faster form. Cost: each instance after the first loads the attachments and each before the last + stores them, with a barrier from everything before to everything after between them: on a tiler, + a tile flush per split. - `metal2vulkan-degrade-amplification-draws` (performance). `AmplificationDraws`: A draw under vertex amplification that Vulkan multiview cannot express (view mappings that offset the viewport or name layers out of order, more amplifications than the device's views, or a pipeline that