diff --git a/crates/metal2vulkan-conformance/src/cases/pass_start_reads.rs b/crates/metal2vulkan-conformance/src/cases/pass_start_reads.rs index ee8d6e46d..f43dd9d37 100644 --- a/crates/metal2vulkan-conformance/src/cases/pass_start_reads.rs +++ b/crates/metal2vulkan-conformance/src/cases/pass_start_reads.rs @@ -28,9 +28,12 @@ //! gives and the runtime orders (`fence.rs`), which the case states from what each draw writes: //! the clear where the barrier is the pass's first command, and the solid draw's color where that //! draw came before it. Its justification is `docs/API.md`'s accepted difference -//! [`MAC2_BARRIER`]. The rows with no barrier accept nothing else: a draw reads, at its own pixel, -//! the texels from before the pass on the M3 Max and on the runtime alike -//! (`texture/attached_reads.rs`). +//! [`MAC2_BARRIER`]. The rows that read at their own pixels with no barrier accept the clear too, +//! what the draws before the read wrote, an x86 Mac's answer, which the runtime reads where it +//! takes the read through a snapshot (a target over a buffer, on a device with the snapshot +//! route: `render/snapshot.rs`): `docs/API.md`'s accepted difference [`DRAWN_WITHOUT_BARRIER`]. +//! Elsewhere it reads the copy taken before the pass, the texels from before it, as the M3 Max +//! does (`texture/attached_reads.rs`). The rows that sample with no barrier accept nothing else. //! //! A texture's texels are recorded as their runs of equal rows, each row's texels as their runs //! of equal texels (`fresh_contents::texel_runs`): a lossless encoding whose size follows how often @@ -102,6 +105,9 @@ const BLENDED_STATE: [Option; 1] = [Some(ColorState::new(FORMAT).ble pub const MAC2_BARRIER: &str = "a-barrier-over-the-render-targets-orders-what-it-names-as-a-mac2-gpu-s-does"; +/// The slug of `docs/API.md`'s accepted difference the rows that read with no barrier name. +pub const DRAWN_WITHOUT_BARRIER: &str = "a-draw-that-reads-its-own-pass-s-color-attachment-at-its-own-pixels-reads-what-the-draws-before-it-wrote-with-no-barrier-too-where-the-runtime-takes-no-copy-for-it"; + /// The runs record mode takes each row over. const RUNS: u32 = 3; @@ -747,6 +753,21 @@ impl Row { Shape::Composited => vec![composited(|_, _| reordered(texel(CLEAR)))], }) } + + /// What the runtime answers for a row that reads at its own pixels with no barrier, where it + /// takes the read through a snapshot (the module docs): the clear, as the barrier's rows + /// answer. `None` for every other row. + fn drawn(&self) -> Option> { + match self.shape { + Shape::Small { + read: Small::Read, .. + } => Some(image([SMALL; 2], |x, y| match inside(AREA, x, y) { + true => reordered(texel(CLEAR)), + false => texel(CLEAR), + })), + _ => None, + } + } } /// The composited row's target after its passes, where the sample of itself wrote `sampled(x, @@ -827,6 +848,15 @@ impl Case for PassStartRead { ) }) .collect(); + // A read with no barrier may answer the clear where the runtime reads it through a + // snapshot (the module docs). + if let Some(bytes) = self.row.drawn() { + allowances.push(Allowance::new( + format!("case/{}", texels_site(0)), + Loosening::AnyOf(vec![texel_rows(&bytes, SMALL)]), + Justification::accepted(DRAWN_WITHOUT_BARRIER), + )); + } // The notices the runtime announces for the row's shape (the module docs). Each loosens // the notices site alone, so every texel still compares. if matches!( @@ -1057,9 +1087,14 @@ mod tests { fn every_row_has_a_name_of_its_own_and_a_barrier_row_an_answer_of_its_own() { let names: BTreeSet<&str> = ROWS.iter().map(|row| row.case).collect(); assert_eq!(names.len(), ROWS.len()); - assert!(crate::allowance::accepted_differences() - .iter() - .any(|slug| slug == MAC2_BARRIER)); + for named in [MAC2_BARRIER, DRAWN_WITHOUT_BARRIER] { + assert!( + crate::allowance::accepted_differences() + .iter() + .any(|slug| slug == named), + "{named}" + ); + } for row in &ROWS { let targets = row.targets(); match row.ordered() { diff --git a/crates/metal2vulkan-runtime/src/render/snapshot.rs b/crates/metal2vulkan-runtime/src/render/snapshot.rs index ce9eb01de..fde35afb8 100644 --- a/crates/metal2vulkan-runtime/src/render/snapshot.rs +++ b/crates/metal2vulkan-runtime/src/render/snapshot.rs @@ -1,12 +1,15 @@ -//! A draw that reads a texture its own render pass instance renders, after a memory barrier, -//! read through a snapshot inside the instance: two draws of one pipeline in the same subpass, -//! in place of a split of the pass (`texture/attached_reads.rs`). And a draw that writes nothing -//! of the color it reads so, read in place, with a barrier or without (in place, below). +//! A draw that reads, at its own pixels, a texture its own render pass instance renders, with a +//! memory barrier before it or not, read through a snapshot inside the instance: two draws of one +//! pipeline in the same subpass, in place of a split of the pass or of the copy taken before it +//! (`texture/attached_reads.rs`). And a draw that writes nothing of the color it reads so, read in +//! place (in place, below). //! //! - **What it replaces.** After a barrier inside an instance, a draw that samples a color //! attachment's texture records into a new instance, before which the texture's copy is taken //! (`WorkCounts::attachment_read_splits`). The split ends the render pass instance, copies the -//! texture and begins another, on every device. Here the draw stays in its instance. +//! texture and begins another, on every device. With no barrier, it reads a copy taken before +//! the pass, the texels from before it (`WorkCounts::attachment_reads_through_copies`). Here the +//! draw stays in its instance and takes no copy. //! - **The two draws.** The draw runs the variant whose fragment function reads each such slot //! through its snapshot (`BindState::snapshot_textures`, `VariantKey::snapshot_textures`), a //! pipeline made with `VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT` and the color @@ -58,7 +61,14 @@ //! another reader sees what that one wrote. (An M3 Max reads, at a draw's own pixel, what the //! texture held before the pass with a barrier or without: probe `readers.m`, two readers of a //! texture a draw wrote, barriers before each or not, 64 to 2048 pixels wide, 0 to 500 draws -//! between. Apple GPUs do not support that scope, so they are no answer for it.) +//! between. Apple GPUs do not support that scope, so they are no answer for it.) With no +//! barrier the pair is the same, and the reader reads what the draws before it wrote, as an +//! AMD Radeon Pro 5300M and an Intel UHD Graphics 630 read without one (probe `ownread.m`), +//! where an M3 Max reads the texels from before the pass, the copy's (`docs/API.md`'s accepted +//! differences): the Macs disagree, and the snapshot is the cheaper form where the route takes +//! the draw (a compositor's frame of six such readers over surfaces on the Radeon 780M, 3.41 ms +//! of GPU time against 4.07 with the copies, `runtime_lane::attachment_read_costs`'s +//! `backdrop_costs`). //! - **In place.** A draw whose fragment function reads such a texture at the fragment's own //! pixel alone (`StageModule::own_pixel_textures`), and that writes no channel of the color //! that renders it (no color of its state placed there has a write mask, and its routing zeroes @@ -84,7 +94,7 @@ //! after a barrier, Metal's answer on a Mac2 GPU; without one, an x86 Mac's, where an M3 Max //! answers the texels from before the pass (`docs/API.md`'s accepted differences). No snapshot, //! copy or split (`WorkCounts::reading_draws_in_place`). A draw that writes the color it reads -//! takes the checks below, after a barrier, else the copy. +//! takes the checks below, with a barrier before it or not. //! - **The snapshot** is a texture's storage image of its level-0 extent in the form the plan //! names for the slot (`VariantKey::snapshot_textures`, `SnapshotForm::of` the bound view: the //! texel's codes, whatever the device's decode, or the fetched lanes' bits), made at the first @@ -94,10 +104,11 @@ //! one's or a half-float one's, 16 for the bits (`SnapshotForm::format`). The draw's use of it //! is a fragment shader's storage read and write, so draws of other instances and encoders //! that take it are ordered as any image's. -//! - **Where it runs** (each check else the split, as before): the device enabled +//! - **Where it runs** (each check else the split, or with no barrier the copy, as before): the +//! device enabled //! `attachmentFeedbackLoopLayout`, `extendedDynamicState3ColorWriteMask` and -//! `fragmentShaderPixelInterlock` (`dynamic_state::ColorWriteMasks`); the draw follows a barrier -//! inside its instance, records no execution's command or reroute, and runs in a pass +//! `fragmentShaderPixelInterlock` (`dynamic_state::ColorWriteMasks`); the draw records no +//! execution's command or reroute, and runs in a pass //! with no visibility query active, no input attachment fetch, rasterization-rate map, views or //! more than one sample or layer; every slot of the draw that reads a color attachment's texture //! is a fragment slot its function can read through a snapshot (`StageModule::snapshot_textures`) diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 3c47d2aeb..484da5510 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -8761,11 +8761,14 @@ pub struct WorkCounts { /// color after an earlier one read them, each the draws' subpass's whole dependency on itself /// (`framebuffer_fetch.rs`). 0 on every other device. pub fetch_draw_barriers: u64, - /// Draws that sample a color attachment's texture after a memory barrier of their render - /// pass, each reading it through a snapshot inside its instance in place of a split: drawn - /// twice, first copying each fragment's texel into the snapshot, then reading the snapshot - /// (`render/snapshot.rs`). They count in neither `attachment_reads_through_copies` nor - /// `attachment_read_splits`. + /// Draws that sample a color attachment's texture of their render pass instance at their own + /// pixel, each reading it through a snapshot inside its instance in place of a split, after + /// a memory barrier of their render pass, or of the copy taken before the pass, with none: + /// drawn twice, first copying each fragment's texel into the snapshot, then reading the + /// snapshot (`render/snapshot.rs`). They count in neither `attachment_reads_through_copies` + /// nor `attachment_read_splits`. Without a memory barrier the draw reads what the draws + /// before it in the instance wrote, an x86 Mac's answer, where an M3 Max reads the texels + /// from before the pass (`docs/API.md`'s accepted differences). pub reading_draws_snapshotted: u64, /// Draws that sample a color attachment's texture of their render pass instance at their /// own pixel alone and write no channel of that color, each reading the attachment in place, diff --git a/crates/metal2vulkan-validation/src/runtime_lane/snapshot_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/snapshot_reads.rs index d1f267cd7..143e3acee 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/snapshot_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/snapshot_reads.rs @@ -67,10 +67,17 @@ //! color in place (an `RGBA8Unorm` one's on every such device; the counts printed say which //! others did). //! - [`without_a_barrier_the_readers_read_the_texels_from_before_the_pass`]: the same draws with -//! no barrier: every reader reads [`CLEARED`], the texel from before the pass at its own pixel, -//! through the copy taken before the pass: `FILL + 3 * CLEARED`, no snapshot. The M3 Max's +//! no barrier, through the block's scissor: every reader reads [`CLEARED`], the texel from +//! before the pass at its own pixel, through the copy taken before the pass, which the area +//! rule weighs cheaper than a snapshot there: `FILL + 3 * CLEARED`, no snapshot. The M3 Max's //! answer (probe `overlap.m` under macOS 27.0.1: 232 at every block pixel at sides 32, 256 //! and 1024, with the barriers or without, as Apple GPUs do not support that scope). +//! - [`without_a_barrier_a_surfaces_readers_take_the_snapshot`]: the same draws with no barrier +//! over the surface of [`a_surfaces_readers_take_the_snapshot_at_any_area`], through the whole +//! target's scissor: a snapshot for each reader where the device takes the path and the image +//! took feedback loop usage, each reading what the draws before it wrote (`6 * FILL`), the x86 +//! Macs' answer with no barrier (`docs/API.md`'s accepted differences); else the copy taken +//! before the pass for each (`FILL + 3 * CLEARED`), the M3 Max's. //! - [`with_a_feature_withheld_the_readers_take_the_split`]: the first test's draws, with each of //! the three features withheld in turn: the same answers, through a split for each reader. //! - [`a_reader_in_a_pass_with_depth_or_stencil_takes_the_split`]: F, a barrier and the reader in @@ -802,6 +809,31 @@ fn without_a_barrier_the_readers_read_the_texels_from_before_the_pass() { ); } +#[test] +fn without_a_barrier_a_surfaces_readers_take_the_snapshot() { + on_default_policy( + |_| {}, + |device| { + let queue = device.new_command_queue().unwrap(); + let format = PixelFormat::RGBA8Unorm; + let (bytes, moved, made) = + readers_over(device, &queue, format, false, None, true, READ); + eprintln!("snapshot reads, surface, no barrier: {made:?}, {moved:?}"); + let snapshotted = snapshots(device) && made.feedback && made.fetched; + let (want, counts) = match snapshotted { + true => (6 * FILL, (2, 0, 0)), + false => (FILL + 3 * CLEARED, (0, 0, 2)), + }; + holds("surface, no barrier", &bytes, want); + assert_eq!( + (moved.snapshotted, moved.splits, moved.copies), + counts, + "a surface's readers with no barrier: snapshots, splits, copies" + ); + }, + ); +} + #[test] fn with_a_feature_withheld_the_readers_take_the_split() { for withheld in &FEATURES[..3] {