diff --git a/crates/metal2vulkan-conformance/recordings/mesh-commands-unordered-draws.json b/crates/metal2vulkan-conformance/recordings/mesh-commands-unordered-draws.json index c0ad47456..ae2369ff8 100644 --- a/crates/metal2vulkan-conformance/recordings/mesh-commands-unordered-draws.json +++ b/crates/metal2vulkan-conformance/recordings/mesh-commands-unordered-draws.json @@ -260,6 +260,44 @@ } } }, + { + "name": "attachment", + "observed": { + "value": { + "bytes": "AAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqqoAAAAAAAAAAAAAAAAAAA==" + }, + "shape": { + "bytes": { + "region": { + "texture": { + "level": 0, + "slice": 0, + "aspect": "color", + "sample": 0, + "origin": [ + 0, + 0, + 0 + ], + "size": [ + 8, + 8, + 1 + ] + } + }, + "element": "u32", + "row_offset": 0, + "row_elements": 32, + "row_pitch": 128, + "rows": 8, + "image_pitch": 1024, + "images": 1, + "gaps": "compared" + } + } + } + }, { "name": "control-after", "observed": { diff --git a/crates/metal2vulkan-conformance/src/allowance.rs b/crates/metal2vulkan-conformance/src/allowance.rs index d82021ed5..419e68006 100644 --- a/crates/metal2vulkan-conformance/src/allowance.rs +++ b/crates/metal2vulkan-conformance/src/allowance.rs @@ -346,12 +346,28 @@ pub fn accepted_differences() -> &'static [String] { .split_once(ACCEPTED_HEADING) .map(|(_, rest)| rest.split("\n## ").next().unwrap_or(rest)) .unwrap_or_default(); - section - .lines() - .filter_map(|line| line.strip_prefix("- **")) - .filter_map(|rest| rest.split_once("**")) - .map(|(lead, _)| accepted_slug(lead)) - .collect() + // An entry's bold lead-in may wrap onto the next lines, so the words are taken until the + // closing `**` rather than from the first line alone. Reading only the first line made + // every wrapped entry invisible, and an allowance naming one of those could never be + // justified. + let mut entries = Vec::new(); + let mut lead_in: Option = None; + for line in section.lines() { + let rest = match (&mut lead_in, line.strip_prefix("- **")) { + (None, Some(start)) => start, + (Some(_), _) => line.trim_start(), + (None, None) => continue, + }; + let words = lead_in.take().map_or_else(String::new, |mut so_far| { + so_far.push(' '); + so_far + }); + match rest.split_once("**") { + Some((last, _)) => entries.push(accepted_slug(&(words + last))), + None => lead_in = Some(words + rest), + } + } + entries }) } diff --git a/crates/metal2vulkan-conformance/src/cases/mesh_commands.rs b/crates/metal2vulkan-conformance/src/cases/mesh_commands.rs index 70ca2bf4b..93ecf215f 100644 --- a/crates/metal2vulkan-conformance/src/cases/mesh_commands.rs +++ b/crates/metal2vulkan-conformance/src/cases/mesh_commands.rs @@ -52,7 +52,7 @@ //! left. (A resource ID is a device-local 64-bit value and must never enter a transcript; it is //! an input to the kernel and nothing else.) -use crate::allowance::Allowance; +use crate::allowance::{Allowance, Justification, Loosening}; use crate::case::{ Abort, Case, CommandDraw, Failure, Input, MeshCommand, MeshFunctions, MetalSource, Side, TARGET_TEXEL, @@ -365,17 +365,19 @@ impl Case for MeshCommands { /// also every run: the emulation records the reader's object dispatch after the writer's mesh /// dispatch, so the reader reads `(3, 2, 1, 7)`, draws its 3 by 2 threadgroups and `drawn` is 7. /// -/// So the reader's texels are **not observed**. A recording can only sample an order Metal's own -/// contract leaves open, and comparing against one sample would make this chip's scheduling of -/// the moment into our requirement; the outcome set the plan gives racy rows cannot close that, -/// because it can hold only the orders Metal happened to produce. What the contract *does* -/// determine is compared, exactly: the writer's own texel at (7, 7), the control words the pass -/// leaves behind, the calls of the pass, and the command buffer's status and error. +/// So the reader's texels are **recorded but not compared**. A recording can only sample an order +/// Metal's own contract leaves open, and comparing against one sample would make this chip's +/// scheduling of the moment into our requirement; the outcome set the plan gives racy rows cannot +/// close that, because it can hold only the orders Metal happened to produce. What the contract +/// *does* determine is compared, exactly: the writer's own texel at (7, 7), the control words the +/// pass leaves behind, the calls of the pass, and the command buffer's status and error. /// -/// The difference in the reader's texels is a finding, not an allowance: it is reported with these -/// numbers, and closing it means either announcing that the emulation orders what Metal leaves -/// unordered, or writing it down as an accepted difference. Neither is this case's to decide, and -/// until one of them happens no case may compare that field. +/// The whole attachment is still a site of the transcript, loosened to [`Loosening::Unchecked`] +/// and justified by the accepted difference `docs/API.md` section 10 now carries for the order +/// ([`ORDER_IS_ACCEPTED`]). Two reasons it is a site rather than nothing: the recording then holds +/// **Metal's own texels** for every one of the 30 runs, so the next macOS is read against them +/// instead of against a memory of them; and the loosening has to name a document entry, so the day +/// we announce the order or withdraw the entry, this case fails and says which. pub const UNORDERED_DRAWS: &str = "mesh-commands-unordered-draws"; /// The owned fixture the racy row runs: `mesh_barrier`'s writer and object reader, the same @@ -405,6 +407,15 @@ const UNORDERED_ROW: &str = "cpu_nobarrier"; /// The texel the writer's fragment function covers, whichever order the two draws run in. const COVER: [u32; 2] = [7, 7]; +/// The bold lead-in of the accepted difference in `docs/API.md` section 10 that the order rests +/// on: the runtime's emulation of mesh draws orders two unbarriered draws of one pass, where Metal +/// orders nothing. The slug of these words must be an entry of the document or the case fails. +const ORDER_IS_ACCEPTED: &str = + "Two mesh draws of one pass with no barrier between them run in order."; + +/// The site the whole attachment is recorded at, under the row. +const ATTACHMENT_SITE: &str = "attachment"; + /// The layout the writer's own texel is read under: the one texel at [`COVER`] of level 0 of /// slice 0, as four 32-bit words, so a diff names the word inside the texel the writer wrote. fn cover_layout() -> ByteLayout { @@ -428,6 +439,29 @@ fn cover_layout() -> ByteLayout { } } +/// The layout the whole attachment is read under: level 0 of slice 0, 8 by 8 texels of four +/// 32-bit words each, rows adjacent, so a diff names the texel and the word inside it. +fn whole_layout() -> ByteLayout { + ByteLayout { + region: Region::Texture { + level: 0, + slice: 0, + aspect: Aspect::Color, + sample: 0, + origin: [0, 0, 0], + size: [SIDE, SIDE, 1], + }, + element: Element::U32, + row_offset: 0, + row_elements: SIDE * TARGET_TEXEL / 4, + row_pitch: SIDE * TARGET_TEXEL, + rows: SIDE, + image_pitch: SIDE * SIDE * TARGET_TEXEL, + images: 1, + gaps: Gaps::Compared, + } +} + /// The runs the racy row's recording stands on. /// /// Two draws of one pass with no barrier between them are ordered by nothing, so one run says @@ -487,7 +521,13 @@ impl Case for UnorderedDraws { } fn allowances(&self) -> Vec { - super::mesh_draws::mesh_notice_allowances() + let mut allowances = super::mesh_draws::mesh_notice_allowances(); + allowances.push(Allowance::new( + format!("case/{UNORDERED_ROW}/{ATTACHMENT_SITE}"), + Loosening::Unchecked, + Justification::accepted(crate::allowance::accepted_slug(ORDER_IS_ACCEPTED)), + )); + allowances } fn shaders(&self) -> Result, String> { @@ -629,9 +669,11 @@ impl Case for UnorderedDraws { let texels = side .read_texture(target, [SIDE, SIDE], SIDE * TARGET_TEXEL) .map_err(|failure| stop(format!("{UNORDERED_ROW}/attachment"), failure))?; - // Only the writer's own texel is compared, and the reader's are not observed at all: see - // the case's documentation. The whole level is read, as the probe read it, and the texel - // is named by its origin so a reader of a diff sees which texel this is. + // Only the writer's own texel is compared; the whole level is a site of its own, loosened + // by the accepted difference the order rests on, so the recording keeps Metal's texels + // without this chip's scheduling becoming a requirement. See the case's documentation. + // The whole level is read, as the probe read it, and the texel is named by its origin so + // a reader of a diff sees which texel this is. let at = (COVER[1] * SIDE + COVER[0]) as usize * TARGET_TEXEL as usize; let cover = texels .get(at..at + TARGET_TEXEL as usize) @@ -646,6 +688,10 @@ impl Case for UnorderedDraws { })? .to_vec(); node = node.with(Node::leaf("cover", Observed::bytes(cover, cover_layout()))); + node = node.with(Node::leaf( + ATTACHMENT_SITE, + Observed::bytes(texels, whole_layout()), + )); let after = side .read_buffer(control, 0, words.len()) .map_err(|failure| stop(format!("{UNORDERED_ROW}/control-after"), failure))?; diff --git a/crates/metal2vulkan-conformance/src/cases/rgb10a2_srgb.rs b/crates/metal2vulkan-conformance/src/cases/rgb10a2_srgb.rs index 2ecc04140..067fc5110 100644 --- a/crates/metal2vulkan-conformance/src/cases/rgb10a2_srgb.rs +++ b/crates/metal2vulkan-conformance/src/cases/rgb10a2_srgb.rs @@ -21,13 +21,14 @@ //! //! - A 64-bit projection of a formatted string is weaker than the bytes. These cases record the //! words and the results themselves, so the comparison names the code or the sample. -//! - **The writes question never compared 4,079 of the words the kernel wrote.** The lane dispatches -//! a 4096 by 5 grid, so the kernel writes all 20,480 texels, but the lane formats only +//! - **The writes question compared 4,079 fewer words than the kernel wrote.** The lane dispatches +//! a 4096 by 5 grid, so the kernel writes all 20,480 texels, and the lane formatted only //! `got.iter().take(n)` of them, `n` being 16,401 — the 16,385 ramp values plus the sixteen -//! specials. The remaining 4,079 texels are written from the input buffer's zero padding and never -//! appear in the digest, inside a passing test. This case records all 20,480 words, so what the -//! padding stores is Metal's measured answer rather than a gap. (It is the same shape batch 1a -//! found in `surface_fills`, whose formatter truncated each run at 24 bytes.) +//! specials. The remaining 4,079 texels are written from the input buffer's zero padding and +//! appeared in no digest, inside a passing test. This case records all 20,480 words, so what the +//! padding stores is Metal's measured answer rather than a gap; the lane now digests the whole +//! grid too, against the digest of these recorded words. (It is the same shape batch 1a found in +//! `surface_fills`, whose formatter truncated each run at 24 bytes.) //! //! Left to the lane, and why: the clears, the stores and the loads, which are render passes, and the //! `isRGB10A2GammaSupported` check, which is a device property rather than an observation. The case @@ -610,8 +611,8 @@ mod tests { assert_eq!(padding.len(), 4); } - /// The write case's grid is larger than its sweep, which is the defect the port closes: the - /// kernel writes 20,480 texels and the lane's formatter looks at 16,401 of them. + /// The write case's grid is larger than its sweep, which is the defect the port closed: the + /// kernel writes 20,480 texels and the lane's formatter looked at 16,401 of them. #[test] fn the_write_grid_covers_more_texels_than_the_sweep() { let texels = (WRITE_WIDTH * WRITE_HEIGHT) as usize; @@ -621,7 +622,7 @@ mod tests { assert_eq!(texels - WRITE_VALUES, 4_079); // The input buffer covers the whole grid, so every one of those texels is written. assert_eq!(write_values().len(), texels * 16); - // The site's layout covers all of them, where the lane's digest covers 16,401. + // The site's layout covers all of them, as the lane's digest now does. assert_eq!( texture_layout(WRITE_WIDTH, WRITE_HEIGHT).extent(), texels * WORD_BYTES as usize diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index 0c57c9a1b..ddc992f48 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -533,6 +533,22 @@ fn the_accepted_differences_are_read_from_the_document() { assert!(!entries.contains(&"nothing-of-the-sort".to_owned())); } +/// An entry whose bold lead-in wraps onto the next line is an entry. Reading the first line alone +/// made those invisible, so an allowance naming one could never be justified. The first of these +/// wraps in the document today; the second, on one line, is the control. +#[test] +fn an_entry_whose_lead_in_wraps_is_read_whole() { + let entries = accepted_differences(); + for lead_in in [ + "An object grid of more than 2^29 threadgroups fails its command buffer by its count, at \ + once", + "A mesh grid of 1,048,577 to 2,097,151 threadgroups draws nothing", + ] { + let slug = accepted_slug(lead_in); + assert!(entries.contains(&slug), "{slug} is not an entry"); + } +} + #[test] fn a_typed_error_where_metal_answered_is_refused_not_divergent() { let case = WordsCase::new("words", 2); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs b/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs index bc95bb04f..4f0aa758f 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs @@ -10,7 +10,8 @@ //! `, the `float` lanes' bits. //! - **Writes.** A kernel's write (`fpv_bfloat_write`) of `k / 16384` in red, green and blue and //! `(k mod 4096) / 4095` in alpha, `k` from 0 to 16384, then 16 specials in every channel, into a -//! texture 4096 texels wide: `write `. +//! texture 4096 texels wide: `write `. The grid is 4096 by 5, so it writes 20,480 +//! texels and the 4,079 past the sweep take the input's zeros; every one of them is digested. //! - **Samples.** A 16 x 16 texture of the probe's xorshift words, sampled through a runtime //! sampler (clamp to edge, nearest and linear) at 4096 of its positions `(n, m) / 4096`, with //! `float` and `half` results (`xr_sample_runtime`, `xr_sample_runtime_half`): `s @@ -21,7 +22,10 @@ //! `half`. //! - **Stores.** A full-screen draw of the owned fixture `rt6_samples`'s fill (`float4` and //! `half4` outputs) of the writes' values into a new 4096 x 5 target: `store -//! `. A `float` output rounds to `half` toward zero first. +//! `. A `float` output rounds to `half` toward zero first. The digest holds the 16,405 +//! texels of the sweep and its specials; Metal's words for the 4,075 past them were never +//! recorded, so the lane asserts they are zero on the device it runs rather than claiming +//! Metal's. Closing that needs a fresh Metal probe of the whole target. //! - **Loads.** A 1024 x 4 target holding every color code in each channel and each alpha code, //! loaded and stored by a pass whose draw writes another attachment alone: `load //! `. Each color code moves as `R10Unorm_X6_sRGB`'s does (`ExtendedRange::load_code`, @@ -51,7 +55,10 @@ const PF: PixelFormat = PixelFormat::RGB10A2UnormSRGB; /// Metal's digests: reads, writes, samples (nearest `float`, nearest `half`, linear `float`, /// linear `half`), clears (1 x 1, 64 x 64), stores (`float`, `half`) and loads. const READS: &str = "492c1e326a4685c8"; -const WRITES: &str = "631db99cd110dab6"; +/// The writes' digest over the whole 4096 by 5 grid, from the 20,480 words the conformance +/// recording `rgb10a2-srgb-writes` holds of this chip's Metal run (the first 16,401 of them +/// digest to `631db99cd110dab6`, the digest this lane compared while it printed only those). +const WRITES: &str = "59cd54549c914e4e"; const SAMPLES: [[&str; 2]; 2] = [ ["5f73627c39064d55", "4460054d432720d8"], ["36b79f318a83d9ac", "e1978cceb4591a05"], @@ -60,6 +67,17 @@ const CLEARS: [&str; 2] = ["325c8263917a086f", "8b361b1736bc7625"]; const STORES: [&str; 2] = ["27b2e44d676d4976", "26b22082a3e6db54"]; const LOADS: &str = "308f150fdcbbb82a"; +/// Every word `question` read back has a line in `text`, the string its digest is taken over: a +/// formatter that prints fewer lines than the readback holds digests less than it appears to, and +/// the question then passes whatever lies past the last line it printed. +fn covers(text: &str, read_back: usize, question: &str) { + assert_eq!( + text.lines().count(), + read_back, + "{question}: the digested lines do not cover every word read back" + ); +} + /// The first 16 hex digits of the SHA-256 of `text`. fn digest(text: &str) -> String { Sha256::digest(text.as_bytes()) @@ -262,6 +280,7 @@ fn kernels_read_write_and_sample_rgb10a2_srgb_as_metal_does() { ) .unwrap(); } + covers(&text, got.len() / 4, "reads"); if digest(&text) != READS { wrong.push(format!("reads {} (Metal's {READS})", digest(&text))); } @@ -286,9 +305,10 @@ fn kernels_read_write_and_sample_rgb10a2_srgb_as_metal_does() { ); let got = words_of(&t, (4096, height)); let mut text = String::new(); - for (k, w) in got.iter().take(n).enumerate() { + for (k, w) in got.iter().enumerate() { writeln!(text, "write {k} {w:08x}").unwrap(); } + covers(&text, got.len(), "writes"); if digest(&text) != WRITES { wrong.push(format!("writes {} (Metal's {WRITES})", digest(&text))); } @@ -360,6 +380,7 @@ fn kernels_read_write_and_sample_rgb10a2_srgb_as_metal_does() { } .unwrap(); } + covers(&text, bytes.len() / size, "samples"); let want = SAMPLES[linear][half]; if digest(&text) != want { wrong.push(format!( @@ -510,6 +531,7 @@ fn passes_clear_store_and_load_rgb10a2_srgb_as_metal_does() { for (k, w) in got.iter().enumerate() { writeln!(text, "clear {shape_index} {k} {w:08x}").unwrap(); } + covers(&text, got.len(), "clears"); let want = CLEARS[shape_index]; if digest(&text) != want { wrong.push(format!( @@ -562,6 +584,22 @@ fn passes_clear_store_and_load_rgb10a2_srgb_as_metal_does() { for (k, w) in got.iter().take(n).enumerate() { writeln!(text, "store {kind} {k} {w:08x}").unwrap(); } + covers(&text, n, "stores"); + // The target's texels past the sweep, whose inputs are zeros. Metal's words there were + // never recorded, so the lane holds the device to zero and claims nothing of Metal's; a + // probe of the whole target would let the digest cover them instead. + let past: Vec<(usize, u32)> = (got.iter().enumerate().skip(n)) + .filter(|(_, &w)| w != 0) + .map(|(k, &w)| (k, w)) + .collect(); + assert!( + past.is_empty(), + "stores {kind}: {} of the {} texels past the sweep are not zero, the first {:08x?}; \ + Metal's words there are unrecorded", + past.len(), + got.len() - n, + &past[..past.len().min(4)] + ); if digest(&text) != STORES[half] { wrong.push(format!( "stores {kind}: {} (Metal's {})", @@ -625,6 +663,7 @@ fn passes_clear_store_and_load_rgb10a2_srgb_as_metal_does() { for (i, (b, a)) in before.iter().zip(&after).enumerate() { writeln!(text, "load {i} {b:08x} {a:08x}").unwrap(); } + covers(&text, after.len(), "loads"); if digest(&text) != LOADS { wrong.push(format!("loads {} (Metal's {LOADS})", digest(&text))); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs index d9a5d76b6..9333ff6e3 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs @@ -327,6 +327,13 @@ fn printed(bytes: &[u8]) -> String { /// The probe's lines of every sample `bytes` holds (the readback's layout: texels in rows, each /// texel's samples, `unit` bytes each) of slice `slice`, labelled `label`. fn lines(label: &str, slice: u64, bytes: &[u8], samples: usize, unit: usize) -> Vec { + // The lines print every sample of every texel: a readback longer than that would hold bytes + // the digest never saw. + assert_eq!( + bytes.len(), + HEIGHT as usize * WIDTH as usize * samples * unit, + "{label}s{slice}: the printed samples do not cover every byte read back" + ); (0..HEIGHT as usize) .map(|y| { let mut line = format!("{label} s{slice} y{y}:"); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs index cdbd6610f..730959182 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs @@ -6,8 +6,10 @@ //! - **Over a surface's plane, or a buffer.** A two-plane YCbCr texture over plane 0 or 1 of a //! CoreVideo surface, the buffer here standing for the surface with its planes where the //! surface's lie, and a padded 10-bit texture over a buffer, every byte first `0xEE`: the runs -//! of bytes one fill changed, as the probe printed them. A YCbCr texture's unit is its plane's -//! code, and a packed one's texels each take one zero byte at the texel's `x` of its row. +//! of bytes one fill changed, every byte of every run. A YCbCr texture's unit is its plane's +//! code, and a packed one's texels each take one zero byte at the texel's `x` of its row. The +//! `579 p70` row's bytes are `probes/surface_buffer_fills.m`'s, because `surface.m` printed at +//! most 24 bytes of a run and that row's runs are 32 bytes each. //! - **Two-plane extended-range.** A `Shared` texture of its own memory, or at byte 0 of a //! placement heap of Metal's size, every texel's color word set to its index (each slice's and //! level's own top bits) by `replace_region`, one fill of `a1 a2 a3 a4`, and the texels whose @@ -129,8 +131,11 @@ const OVER: [Over; 19] = [ buf(577, [7, 3], 32, "b4", " [0+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x20+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x40+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02]"), buf(578, [8, 4], 64, "r3", " [0x44+8: 01 02 03 01 01 02 03 01]"), + // Each row's 32 bytes are the packed color eight times. `surface.m`'s form cut every run at + // 24, so the last eight bytes of each were in no comparison; `probes/surface_buffer_fills.m` + // measured the row whole on this chip (three runs, the same bytes each time). buf(579, [8, 4], 64, "p70", - " [0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0x40+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0x80+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0xc0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..]"), + " [0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff] [0x40+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff] [0x80+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff] [0xc0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff]"), ]; /// One fill of a two-plane extended-range texture (`tp.m`'s arguments): its format, extent, @@ -210,8 +215,10 @@ fn format(raw: u32) -> PixelFormat { PixelFormat::try_from(raw).unwrap() } -/// `bytes`' runs of bytes other than `0xEE`, as `surface.m` prints them: each ` [+:`, -/// at most 24 of its bytes, ` ..` past them, and `]`. +/// `bytes`' runs of bytes other than `0xEE`, as `probes/surface_buffer_fills.m` prints them: each +/// ` [+:`, every one of its bytes, and `]`. Printing all of them is the point: the form +/// `surface.m` printed cut each run at 24 bytes and wrote ` ..`, so the bytes past the 24th of a +/// 32-byte run were compared by nothing, inside a passing test. fn runs(bytes: &[u8]) -> String { let mut out = String::new(); let mut i = 0; @@ -230,18 +237,41 @@ fn runs(bytes: &[u8]) -> String { format!("{i:#x}") }; out += &format!(" [{at}+{}:", j - i); - for b in &bytes[i..j.min(i + 24)] { + for b in &bytes[i..j] { out += &format!(" {b:02x}"); } - if j - i > 24 { - out += " .."; - } out += "]"; i = j; } out } +/// Every byte of `bytes` that a fill changed has a two-digit number in `runs`' `text`: the +/// property a truncating formatter breaks. +fn covers(text: &str, bytes: &[u8], case: &str) { + // A run prints ` [+:` and then one number a byte, so the numbers after a run's colon + // are the bytes of it the comparison holds. + let printed: usize = text + .split('[') + .skip(1) + .map(|run| { + run.split_once(':').map_or(0, |(_, listed)| { + (listed.split_whitespace()) + .filter(|word| { + let word = word.strip_suffix(']').unwrap_or(word); + word.len() == 2 && word.bytes().all(|b| b.is_ascii_hexdigit()) + }) + .count() + }) + }) + .sum(); + let changed = bytes.iter().filter(|&&b| b != 0xee).count(); + assert_eq!( + printed, changed, + "{case}: the compared runs print {printed} of the {changed} bytes the fill changed" + ); +} + /// The fill `case` (as [`Over::case`] reads) into `texture` of `width` by `height`. fn fill_case( blit: &mut metal2vulkan_runtime::BlitCommandEncoder, @@ -336,7 +366,9 @@ fn fills_over_surfaces_and_buffers_write_metal_s_bytes() { blit.end_encoding().unwrap(); command_buffer.commit().unwrap(); command_buffer.wait_until_completed_for(WAIT).unwrap(); - let ours = runs(&read_buffer(&surface, 0, over.length).unwrap()); + let read = read_buffer(&surface, 0, over.length).unwrap(); + let ours = runs(&read); + covers(&ours, &read, over.case); if ours != over.metal { println!( "SURFACE-FILLS-DIFFERS {} {}:{ours} (Metal's{})", diff --git a/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs index 4e43a7a57..81aee4876 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs @@ -394,6 +394,9 @@ fn two_plane_case( while j < got.len() && got[j] != 0xee { j += 1; } + // The digest holds the run's first 64 bytes and its length. The `b5` cases of 550 and + // 551 have a 92-byte run, so 28 of its bytes are in no comparison; Metal's words there + // were never recorded and closing it needs a probe of the whole run, not a guess. let shown = hex(&got[i..j.min(i + 64)]); let more = if j - i > 64 { format!("...({})", j - i) @@ -519,6 +522,18 @@ fn texture_case( panic!("{raw} {name}: a fill refused: {error}"); } let got = read_buffer(&readback, 0, total).unwrap(); + // Every byte of the readback lies in a part, whose line digests it, or in the 16-byte + // padding between parts, which no copy writes and which stays as the buffer was made: a + // part the lines missed would leave device bytes in no comparison. + let mut digested = vec![false; total as usize]; + for &(_, _, _, unit, _, _, (across, down), at) in &parts { + let n = (across * down * unit) as usize; + digested[at as usize..at as usize + n].fill(true); + } + assert!( + (0..total as usize).all(|i| digested[i] || got[i] == 0), + "{raw} {name}: a byte outside the digested parts changed" + ); let lines: Vec = parts .iter() .map(|&(level, slice, _, unit, aspect, _, (across, down), at)| { diff --git a/crates/metal2vulkan-validation/tests/integration/main.rs b/crates/metal2vulkan-validation/tests/integration/main.rs index 07f9965bb..e7b930af9 100644 --- a/crates/metal2vulkan-validation/tests/integration/main.rs +++ b/crates/metal2vulkan-validation/tests/integration/main.rs @@ -21,6 +21,7 @@ mod fast_trig_within_apples_bound; mod fixtures_assemble_with_the_pinned_llvm; mod linux_gate_policy; mod metal_coverage; +mod no_conflict_markers; mod pipeline_selection; mod private_corpus_root; mod public_entry_rows; diff --git a/crates/metal2vulkan-validation/tests/integration/no_conflict_markers.rs b/crates/metal2vulkan-validation/tests/integration/no_conflict_markers.rs new file mode 100644 index 000000000..8603f1f35 --- /dev/null +++ b/crates/metal2vulkan-validation/tests/integration/no_conflict_markers.rs @@ -0,0 +1,102 @@ +//! No merge-conflict marker reaches the tree. A landing that resolves a conflict by hand can leave +//! `git`'s markers behind, and nothing else notices where the file is one no compiler reads: on +//! 2026-10-23 a crate's README carried a pair of them for an hour. The check walks the tree rather +//! than asking `git`, so it holds in a packaged crate and in a tree without git. + +use std::fs; +use std::path::{Path, PathBuf}; + +/// The directories under the repository's root that hold what we write by hand. The root's own +/// files are read too, without descending into anything this list does not name. +const ROOTS: [&str; 4] = ["crates", "docs", "scripts", ".github"]; + +/// The directories the walk does not descend into, by their path from the root. They are +/// generated, assembled or committed whole, never hand-resolved, and walking the corpus alone is +/// hundreds of thousands of entries. +const SKIP: [&str; 5] = [ + "crates/metal2vulkan-validation/corpus", + "crates/metal2vulkan-validation/fixtures", + "crates/metal2vulkan-conformance/recordings", + "target", + ".git", +]; + +/// The extensions of the files the check reads: what a conflict could reach and a human wrote. +const EXTENSIONS: [&str; 11] = [ + "rs", "md", "toml", "tsv", "yml", "yaml", "sh", "py", "txt", "sha256", "ll", +]; + +/// `git`'s labelled markers, each at the start of a line and followed by the side it names: the +/// two a merge writes and the third `diff3` adds. The separator between the sides is seven `=` +/// alone, which is also Markdown's underline for a heading, so the check leaves it to these three. +/// Each is built rather than written out, so this file is not itself a hit. +fn markers() -> [String; 3] { + [ + format!("{} ", "<".repeat(7)), + format!("{} ", ">".repeat(7)), + format!("{} ", "|".repeat(7)), + ] +} + +/// Whether the check reads a file of this name. +fn reads(path: &Path) -> bool { + path.extension() + .is_some_and(|ext| EXTENSIONS.contains(&ext.to_string_lossy().as_ref())) +} + +/// Every file under `dir` the check reads, depth first, skipping [`SKIP`]'s directories. With +/// `descend` false only the files directly in `dir` are taken, which is how the root is read. +fn walk(root: &Path, dir: &Path, descend: bool, found: &mut Vec) { + let Ok(entries) = fs::read_dir(dir) else { + return; + }; + for entry in entries.filter_map(Result::ok) { + let path = entry.path(); + if entry.file_type().is_ok_and(|kind| kind.is_dir()) { + let relative = path.strip_prefix(root).unwrap_or(&path).to_string_lossy(); + if descend && !SKIP.contains(&relative.as_ref()) { + walk(root, &path, true, found); + } + } else if reads(&path) { + found.push(path); + } + } +} + +#[test] +fn no_conflict_markers_in_the_tree() { + let root = fs::canonicalize(Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")) + .expect("the repository's root"); + let markers = markers(); + let mut files = Vec::new(); + walk(&root, &root, false, &mut files); + for dir in ROOTS { + walk(&root, &root.join(dir), true, &mut files); + } + assert!( + files.len() > 2000, + "the walk read only {} files, so it is looking in the wrong place", + files.len() + ); + let mut hits = Vec::new(); + for file in &files { + let Ok(text) = fs::read_to_string(file) else { + continue; + }; + for (number, line) in text.lines().enumerate() { + if markers.iter().any(|marker| line.starts_with(marker)) { + hits.push(format!( + "{}:{}: {line}", + file.strip_prefix(&root).unwrap_or(file).display(), + number + 1 + )); + } + } + } + assert!( + hits.is_empty(), + "{} conflict marker lines reached the tree:\n{}", + hits.len(), + hits.join("\n") + ); +} diff --git a/docs/API.md b/docs/API.md index 1cd6cb7b0..0fc0916af 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3178,6 +3178,16 @@ each item named states the rule in full. which decides it. A pass that renders such a texture in place otherwise announces `dont-care-store`. +- **Two mesh draws of one pass with no barrier between them run in order.** Where a later draw's + object or mesh function reads a buffer an earlier draw wrote, and no `memoryBarrier` stands + between them, Metal orders nothing: on an M3 Max (macOS 27.0.1) the reader read the host's words + in 30 runs of 30, through an indirect command buffer's two commands. The runtime's emulation of + mesh draws (MoltenVK, ANV on the Iris Xe) records the reader's dispatches after the writer's, so + the reader reads the writer's words every run. Nothing is slower or approximate for the order, so + no notice says so, and every field the pass does determine is Metal's: the conformance case + `mesh-commands-unordered-draws` compares those exactly and keeps Metal's own texels beside them, + for the next macOS to be read against. + **GPU hangs and faults** (a draw of private primitive type 9, `DrawPrimitiveType::Nine`) - **A hang reads `Scheduled` 5.06 ms after its commit and completes no sooner than 27.5 ms after diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index d1e5ee3c3..f21fd059e 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -464,14 +464,6 @@ driver's. Each is open work. the command buffer of an indirect one past the compute limits with `CommandBufferError::MeshGridPastLimits` (ANV's y and z axes stop at 65,535; MoltenVK's limits pass every grid Metal runs). -- **Two mesh draws of one pass with no barrier between them are ordered by the emulation and not - by Metal.** Where a later draw's object or mesh function reads a buffer an earlier draw wrote, - and no `memoryBarrier` stands between them, Metal orders nothing: on the M3 Max (macOS 27.0.1) - the reader read the host's words in 30 runs of 30, through an indirect command buffer's two - commands. The emulation (MoltenVK, ANV on the Iris Xe) records the reader's dispatches after the - writer's, so the reader reads the writer's words every run. Nothing announces it. The - conformance case `mesh-commands-unordered-draws` holds Metal's measurement and compares the - fields the pass does determine, not the reader's texels. - **An object threadgroup that sets a mesh grid Metal launches nothing for keeps its own writes.** On the M3 Max such a threadgroup's device writes (an atomic add before the set) do not land either, while the draw's other threadgroups run; the runtime runs the threadgroup and launches