diff --git a/crates/metal2vulkan-conformance/src/cases/buffer_texture_blits.rs b/crates/metal2vulkan-conformance/src/cases/buffer_texture_blits.rs index beaabd5aa..febcad4cb 100644 --- a/crates/metal2vulkan-conformance/src/cases/buffer_texture_blits.rs +++ b/crates/metal2vulkan-conformance/src/cases/buffer_texture_blits.rs @@ -158,6 +158,37 @@ impl Row { matches!(self.blit, Blit::IntoBuffer | Blit::OutOfBuffer) } + /// Whether the row's copy reads and writes **the same bytes of the buffer**, which is what + /// `overlapping-texel-copy` names: Vulkan's copy forbids it, so our side takes the rows through + /// a scratch buffer. + /// + /// This is the shape that decides the row's `overlapping-texel-copy` declaration, and nothing + /// else. It is read off the row's own numbers rather than its key, so a row added to a table, + /// or an offset moved, changes what the case declares by itself. + /// + /// A copy with an ordinary texture on one side shares nothing: that texture is not over the + /// buffer. Between two textures over the one buffer, the bytes are shared where the textures' + /// own byte ranges meet. Within one texture, a row of it holds its texels and nothing else, so + /// the bytes are shared only where the source and destination rectangles share a row **and** a + /// column: `onto-itself-disjoint` reads rows 0..2 and writes rows 2..4 and shares none. + fn copies_shared_bytes(&self) -> bool { + // The half-open byte range a texture at `at` covers: its last row's texels end it, not its + // pitch, so the bytes past the last row belong to neither texture. + let span = |at: u64| at..at + (SIDE - 1) * PITCH + ROW_BYTES; + match self.blit { + Blit::IntoBuffer | Blit::OutOfBuffer => false, + Blit::WithinBuffer { other, .. } => { + let (one, two) = (span(OFFSET), span(other)); + one.start < two.end && two.start < one.end + } + Blit::OntoItself => { + let meet = |from: u64, to: u64, size: u64| from < to + size && to < from + size; + meet(self.from[1], self.to[1], self.size[1]) + && meet(self.from[0], self.to[0], self.size[0]) + } + } + } + /// The buffer's bytes before the row's program runs. fn buffer_bytes(&self) -> Vec { let bytes = pattern(LEN as usize); @@ -476,19 +507,32 @@ impl Case for Blits { // is a thing Metal has to do, so the notices site differs and the notice itself is what // justifies it. // - // One allowance, not one per notice. `notice_allowance` loosens the whole `case/notices/*` - // subtree, so a second one at that path can never fire however many notices differ, and - // naming one per notice leaves a permanently unfired allowance in every run — noise of - // exactly the kind a real difference hides in. The notice named is the one every row of - // this family raises, because every row's pitch is wider than its row. + // One declaration per code, and a code is declared only where a row of this case can + // announce it. A declaration fires on its own code, so a code a case announces and declares + // nowhere is a divergence for an undeclared notice, and a code it declares but no row can + // announce is an allowance that fires on no venue — the noise a real difference hides in. + // Both halves matter, which is why the second code is read off the rows rather than named + // for the whole family. // - // The overlapping rows announce `overlapping-texel-copy` as well, which the same site - // covers. It is recorded here rather than in an allowance of its own because the suite has - // no per-notice allowance, and a reader looking for what this family announces should find - // both named somewhere. - vec![crate::replay::notice_allowance( + // `shadowed-texture` is every row's: each row's pitch is wider than its row, so the texture + // over the buffer is kept as a shadow image. + // + // `overlapping-texel-copy` is only the rows whose copy reads and writes the same bytes of + // the buffer ([`Row::copies_shared_bytes`]), which Vulkan's copy forbids and our side takes + // through a scratch buffer. The `to-and-from` table has no such row — both its sides are an + // ordinary texture and a texture over the buffer, which share nothing — so that case + // declares only the first code. Measured on Apple M3 Max: `buffer-texture-blits-overlapping` + // announced `overlapping-texel-copy` and declared it nowhere, while `to-and-from` compared + // justified in the same run. + let mut named = vec![crate::replay::notice_allowance( metal2vulkan_runtime::Degradation::ShadowedTexture.code(), - )] + )]; + if self.rows.iter().any(Row::copies_shared_bytes) { + named.push(crate::replay::notice_allowance( + metal2vulkan_runtime::Degradation::OverlappingTexelCopy.code(), + )); + } + named } fn inputs(&self) -> Result, String> { @@ -579,31 +623,128 @@ mod tests { } } - /// The rows of the overlapping case that say they overlap do, and the one that says it does not - /// does not. + /// The rows of the overlapping case that say they overlap do, and the ones that say they do not + /// do not — as [`Row::copies_shared_bytes`] reads them, which is what decides the case's + /// `overlapping-texel-copy` declaration. /// /// The point of those rows is that the source and destination bytes are the same bytes, so a /// row whose offsets had drifted apart would look like a passing overlap case while asking /// nothing. Its failure mode was exercised while writing it: pointing the second texture at /// `ELSEWHERE` instead of one pitch on fails here. + /// + /// The expectation is computed **independently of the method**, which is the whole value of the + /// test: the method intersects ranges, while this enumerates the actual buffer byte each texel + /// of the source and destination rectangles occupies and intersects the two sets. A test that + /// called the method to work out what to expect would pass whatever the method did. Every + /// variant of [`Blit`] is covered, not only the two textures over one buffer, because a copy + /// with an ordinary texture on one side must read as sharing nothing for the `to-and-from` case + /// to declare only the one code. #[test] fn the_overlapping_rows_bytes_overlap_and_the_disjoint_ones_do_not() { - let bytes_of = |offset: u64| offset..offset + (SIDE - 1) * PITCH + ROW_BYTES; - for row in &OVERLAPPING_ROWS { - let Blit::WithinBuffer { other, .. } = row.blit else { - continue; + // The buffer bytes a texel of the texture at `at` occupies, as the row pitch lays them. + let texel_bytes = |at: u64, x: u64, y: u64| { + let start = at + y * PITCH + x * (ROW_BYTES / SIDE); + start..start + ROW_BYTES / SIDE + }; + let rect = |at: u64, origin: [u64; 2], size: [u64; 2]| { + let mut bytes = std::collections::BTreeSet::new(); + for y in origin[1]..origin[1] + size[1] { + for x in origin[0]..origin[0] + size[0] { + bytes.extend(texel_bytes(at, x, y)); + } + } + bytes + }; + for row in OVERLAPPING_ROWS.iter().chain(&TO_AND_FROM_ROWS) { + // What the row's two sides really occupy. Only a side that is a texture **over the + // buffer** occupies any of it, so a side that is an ordinary texture contributes none. + let (read, written) = match row.blit { + Blit::IntoBuffer => ( + std::collections::BTreeSet::new(), + rect(OFFSET, row.to, row.size), + ), + Blit::OutOfBuffer => ( + rect(OFFSET, row.from, row.size), + std::collections::BTreeSet::new(), + ), + Blit::WithinBuffer { other, reverse } => { + let (from_at, to_at) = match reverse { + false => (OFFSET, other), + true => (other, OFFSET), + }; + ( + rect(from_at, row.from, row.size), + rect(to_at, row.to, row.size), + ) + } + Blit::OntoItself => ( + rect(OFFSET, row.from, row.size), + rect(OFFSET, row.to, row.size), + ), }; - let (first, second) = (bytes_of(OFFSET), bytes_of(other)); - let overlaps = first.start < second.end && second.start < first.end; - let expected = row.key.contains("a-row-on"); + let shares = read.intersection(&written).next().is_some(); assert_eq!( - overlaps, - expected, - "{}: the two textures' bytes {} overlap, which is not what the row is for", + row.copies_shared_bytes(), + shares, + "{}: the copy's bytes {} really shared, which is not what the row reads as, so the \ + case would declare the wrong set of notices", row.key, - if overlaps { "do" } else { "do not" } + if shares { "are" } else { "are not" } ); } + // And the family is not all of one kind, or the comparison above would hold vacuously. + let sharing = OVERLAPPING_ROWS + .iter() + .chain(&TO_AND_FROM_ROWS) + .filter(|row| row.copies_shared_bytes()) + .count(); + assert!( + sharing > 0 && sharing < OVERLAPPING_ROWS.len() + TO_AND_FROM_ROWS.len(), + "{sharing} rows share bytes: the tables must hold both kinds for this to check anything" + ); + } + + /// Each case declares exactly the notice codes a row of it can announce: both, where a row's + /// copy reads and writes the same bytes of the buffer, and the shadow alone where none does. + /// + /// The second direction is the one that costs a run its meaning. A declaration fires on its own + /// code, so a code declared where no row can announce it fires on no venue and names nothing + /// the run justifies — an allowance that sits in every report as noise a real difference can + /// hide in. So this asserts the whole set, equal, rather than that the codes are present. + #[test] + fn each_case_declares_exactly_the_notices_a_row_of_it_can_announce() { + use crate::allowance::Justification; + use metal2vulkan_runtime::Degradation; + for case in table() { + let codes: Vec = case + .allowances() + .iter() + .map(|allowance| { + assert_eq!( + allowance.path, + format!("case/{}/*", crate::replay::NOTICES_SITE), + "{}: an allowance outside the notices site", + case.name() + ); + match &allowance.justified_by { + Justification::Degradation(code) => code.clone(), + other => panic!("{}: an unexpected tolerance: {other:?}", case.name()), + } + }) + .collect(); + let mut wanted = vec![Degradation::ShadowedTexture.code().to_owned()]; + if case.rows.iter().any(Row::copies_shared_bytes) { + wanted.push(Degradation::OverlappingTexelCopy.code().to_owned()); + } + assert_eq!(codes, wanted, "{}", case.name()); + } + // The two cases must not declare the same set, or the row-shaped test above is decoration. + let sets: Vec = table().iter().map(|case| case.allowances().len()).collect(); + assert_eq!( + sets, + vec![1, 2], + "one case declares one code and the other two" + ); } /// Every texel of every set names itself, so no two texels of a program share a value. diff --git a/crates/metal2vulkan-conformance/src/cases/compressed_blits.rs b/crates/metal2vulkan-conformance/src/cases/compressed_blits.rs index cbdb81009..7bd857d57 100644 --- a/crates/metal2vulkan-conformance/src/cases/compressed_blits.rs +++ b/crates/metal2vulkan-conformance/src/cases/compressed_blits.rs @@ -589,23 +589,40 @@ impl Case for CompressedBlits { // Metal's: the only site loosened is the set of notices, which Metal holds empty, and the // allowance fails the case if the notice did not fire. // - // The shadowed-texture notice is deliberately not named, and four of these rows are - // **divergent** on both venues because of it: `bgra10xr`, `bgra10xr-srgb`, `rg11b10f` and - // `rgb9e5f` announce `shadowed-texture` on MoltenVK and on lavapipe alike, so their texture - // over a buffer does reach its bytes through a shadow image. The earlier reading that no - // venue announced it was - // taken through a comparison that could not see it -- one notice declaration unchecked the - // whole notices site, so the `staged-texture-copy` declaration above hid every other code - // the run announced. Every byte of all four still compares exactly with Metal. + // `shadowed-texture`, which every row of this family announces: its texture over a buffer + // reaches the buffer's bytes through a shadow image rather than an image aliasing them. // - // The rows stay divergent on purpose, which is what this comment always said should - // happen: it is a difference nobody has looked at, and naming the code here would turn an - // unexamined mechanism into a permanent excuse. Whoever takes it decides whether a shadow - // image is the right answer for these formats' texture-over-buffer, and declares the code - // or changes the runtime. - vec![crate::replay::notice_allowance( - Degradation::StagedTextureCopy.code(), - )] + // This comment used to leave the code undeclared and the rows divergent on purpose, on the + // grounds that naming an unexamined mechanism makes a permanent excuse of it, and it asked + // whoever took it to decide whether a shadow image is the right answer for these formats + // and then declare or change the runtime. The decision, and what it rests on: + // + // It is the right answer, because there is no other exact one. A texture over a buffer + // aliases the buffer's bytes with a linear image where the device can make one + // (`texture.rs`, `alias_image`); where it cannot, the only remaining way to reach those + // bytes exactly is to copy them into an image and back, which is this notice. These four + // are the formats the device makes no linear image of -- `BGRA10XR`, its sRGB twin, + // `RG11B10Float` and `RGB9E5Float`, whose linear tiling the device does not list + // (`linear_lack`) -- and Metal makes a texture over a buffer in all four, so refusing them + // is not open to us either. A cheaper exact form would have to come from the device + // gaining linear tiling for the format, not from a choice of ours. + // + // It is also the answer the suite has already made for this mechanism, not a new one: five + // cases across four other families declare `shadowed-texture` for a texture whose bytes no + // image can alias -- `two-plane-row-blits`, `texture-fills-heap-run-550-b5` and `-551-b5`, + // `surface-fills-over-planes-and-buffers`, and `buffer-texture-blits-to-and-from`. Leaving + // these four undeclared made them divergent at `case/notices` on every run while the same + // code was justified elsewhere, which is noise rather than an open question. + // + // It loosens no value. Every byte of all four rows compares exactly with Metal's; the whole + // difference the declaration covers is the announcement, which Metal holds empty because + // the copy is not a thing Metal has to do. Measured announced by all four rows on Apple + // M3 Max in the whole-set run this declaration was taken from; the earlier reading recorded + // the same code on lavapipe. + vec![ + crate::replay::notice_allowance(Degradation::StagedTextureCopy.code()), + crate::replay::notice_allowance(Degradation::ShadowedTexture.code()), + ] } fn inputs(&self) -> Result, String> { @@ -666,6 +683,41 @@ mod tests { assert_eq!(named.len(), FORMATS.len()); } + /// Every case of the family declares exactly the two notice codes it announces, and every + /// format declares the same two, because every row reaches its bytes the same way. + /// + /// Stated as the whole set rather than as "the codes are present", because a declaration fires + /// on its own code: a code announced and declared nowhere is a divergence at the notices site, + /// and a code declared that no row announces fires on no venue and names nothing the run + /// justifies. The set is the claim, in both directions. + #[test] + fn every_case_declares_exactly_the_two_notices_it_announces() { + use crate::allowance::Justification; + let wanted = vec![ + Degradation::StagedTextureCopy.code().to_owned(), + Degradation::ShadowedTexture.code().to_owned(), + ]; + for case in all() { + let codes: Vec = case + .allowances() + .iter() + .map(|allowance| { + assert_eq!( + allowance.path, + format!("case/{}/*", crate::replay::NOTICES_SITE), + "{}: an allowance outside the notices site", + case.name() + ); + match &allowance.justified_by { + Justification::Degradation(code) => code.clone(), + other => panic!("{}: an unexpected tolerance: {other:?}", case.name()), + } + }) + .collect(); + assert_eq!(codes, wanted, "{}", case.name()); + } + } + /// Every format of the family has a rule, so [`CompressedBlits::rule`] cannot panic. #[test] fn every_format_has_a_rule() { diff --git a/crates/metal2vulkan-conformance/src/record.rs b/crates/metal2vulkan-conformance/src/record.rs index 5544c148d..73cd27c73 100644 --- a/crates/metal2vulkan-conformance/src/record.rs +++ b/crates/metal2vulkan-conformance/src/record.rs @@ -31,6 +31,13 @@ pub enum RecordError { Case { case: String, why: String }, /// No run produced an answer. NoRuns { case: String }, + /// Metal's own run of the case **stopped** at a site, so the transcript holds part of the case + /// and not its answer. The site and the refusal, in the words a ledger row uses. + Refused { + case: String, + at: String, + refusal: String, + }, } impl std::fmt::Display for RecordError { @@ -48,6 +55,12 @@ impl std::fmt::Display for RecordError { RecordError::NoMetal => out.write_str("there is no Metal on this host"), RecordError::Case { case, why } => write!(out, "{case}: {why}"), RecordError::NoRuns { case } => write!(out, "{case}: no run produced an answer"), + RecordError::Refused { case, at, refusal } => write!( + out, + "{case}: Metal's own run stopped at {at} ({refusal}), so a recording taken here \ + would hold part of the case and not its answer. Fix what the Metal leg cannot \ + do, or state the answer by hand if Metal does not come back from the call" + ), } } } @@ -57,6 +70,18 @@ impl std::fmt::Display for RecordError { /// /// `side` must be a Metal side. The two Metal facts stay apart: the transcripts are plain Metal's, /// and `validated` is recorded beside them without ever being compared with our behaviour. +/// +/// A run that **stops** is refused rather than written down. [`crate::case::call`] aborts the whole +/// case, so the sites after it are never emitted, and a recording of a truncated Metal run is not a +/// recording of the case: on replay every site past the stop reads as one only our side observed, +/// which is a divergence the case never asked about. Worse, a recorded Metal `Err` our side happens +/// to match compares **exact**, so the case would report as passing where neither side did the +/// work. So the recording is refused, naming the site, and the author either fixes what the Metal +/// leg cannot do or states the answer by hand ([`never_returned`]). +/// +/// A refusal a [`crate::case::probe`] sweep records at its own site is the deliberate complement: +/// it emits every other site, so the transcript is the whole case with one query Metal answered nil +/// for, which is Metal's answer and compares as one. Only a stop truncates. pub fn record( case: &dyn Case, side: &mut dyn Side, @@ -79,7 +104,13 @@ pub fn record( for _ in 0..runs { let mut sites = Sites::new(); sites.push(crate::case::inputs_node(&inputs)); - let _ = case.run(side, &mut sites); + if let Err(stopped) = case.run(side, &mut sites) { + return Err(RecordError::Refused { + case: case.name().to_owned(), + at: stopped.at, + refusal: crate::diff::print(&stopped.failure.recorded()), + }); + } let announced = side.announced(); sites.notices(NOTICES_SITE, &announced); add(&mut outcomes, sites.finish()); diff --git a/crates/metal2vulkan-conformance/src/replay.rs b/crates/metal2vulkan-conformance/src/replay.rs index 32f231ef7..e4f89bb1b 100644 --- a/crates/metal2vulkan-conformance/src/replay.rs +++ b/crates/metal2vulkan-conformance/src/replay.rs @@ -146,6 +146,20 @@ pub fn replay_against_known( let mut sites = Sites::new(); sites.push(inputs_node(&inputs)); let abort = case.run(side, &mut sites).err(); + // The venue's own gap at the site that **stopped** the case, recorded for the comparison + // whichever way the case said it. + // + // [`crate::case::call`] records it as it emits the site, but 122 sites build their own + // `Abort` — every site whose answer is a tree of facts has to, since `call` hands back a + // value and not a node — and those record the typed error without the fact that it is the + // device's. A forgotten one reads as a refusal of ours, which is the one thing the + // `lacks-feature` verdict exists to prevent. One place reads the abort, so this is the one + // place that cannot forget; it is idempotent, so `call` having recorded it already is fine. + if let Some(stopped) = &abort { + if let Some(needs) = &stopped.failure.lacks { + sites.device_gap(&stopped.at, needs.clone()); + } + } let mut announced = side.announced(); sites.notices(NOTICES_SITE, &announced); let ours = sites.finish(); @@ -174,25 +188,34 @@ pub fn replay_against_known( } }; - // A run that stopped because the venue honestly lacks what the case needs is its own outcome: - // never a pass, never a failure, and never counted as coverage. - if let Some(lacks) = abort.as_ref().and_then(|abort| abort.failure.lacks.clone()) { - return Ok(Replayed { - case: name.to_owned(), - venue, - verdict: Verdict::LacksFeature { needs: lacks }, - allowances: Allowances::default(), - measured_on: answer.measured_elsewhere().map(str::to_owned), - ours, - }); - } - + // A run the venue stopped is still its own outcome — never a pass, never a failure, never + // counted as coverage — and that outcome is now the **comparison's** answer rather than a + // short circuit ahead of it. + // + // Why it moved: returning `LacksFeature` straight off the abort skipped the comparison + // entirely, so a refusal our side had already recorded at a site the run **did** reach + // vanished behind a *compliant* verdict — the worst form of a refusal going missing, since + // the run stayed green. `verdict.rs` already states the invariant this broke ("a divergence + // or a refusal anywhere else in the same case still fails, which is what makes this safe to + // be compliant"). It also hid a moved input fingerprint the same way, because + // [`inputs_differ`] is checked inside [`verdict_over`]. + // + // Letting [`Verdict::of`] decide holds the invariant by construction: the site that stopped + // the case records the venue's gap (above), the sites the run never reached are not + // divergences because the comparison is told the run stopped, and the device gaps are read + // **after** the divergences and the refusals, so anything worse outranks them. let (verdict, allowances) = verdict_over(case, answer, &ours, &announced, abort.is_some()); Ok(Replayed { case: name.to_owned(), venue, + // A venue that lacks the feature compared almost nothing, so the allowances its case + // named went unused for a reason that is not the suite's blind spot. Saying they never + // fired would be noise, which is what [`Replayed::allowances`] is empty for. + allowances: match &verdict { + Verdict::LacksFeature { .. } => Allowances::default(), + _ => allowances, + }, verdict, - allowances, measured_on: answer.measured_elsewhere().map(str::to_owned), ours, }) diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index f94d5e492..bb6a61fc7 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -32,8 +32,11 @@ struct StubSide { status: &'static str, /// The notice codes `announced` hands over, once. notices: Vec, - /// A call that fails, by its name, with the failure it gives. - refuse: Option<(&'static str, Failure)>, + /// The calls that fail, each by its name, with the failure it gives. A list rather than one, + /// because a case may record a refusal at a site it carries on past **and** stop at a later + /// call the venue cannot make, and the two together are a shape the verdicts have to get + /// right. + refuse: Vec<(&'static str, Failure)>, /// The device name the side's venue answers, so a test can hold a venue-scoped ledger row /// against one venue and not another. device: &'static str, @@ -46,7 +49,7 @@ impl StubSide { output, status: "Completed", notices: Vec::new(), - refuse: None, + refuse: Vec::new(), device: "stub", made: 0, } @@ -64,15 +67,15 @@ impl StubSide { } fn refusing(mut self, call: &'static str, failure: Failure) -> Self { - self.refuse = Some((call, failure)); + self.refuse.push((call, failure)); self } /// The failure the side was told to give at `call`, if any. fn refusal(&self, call: &str) -> Option { self.refuse - .as_ref() - .filter(|(named, _)| *named == call) + .iter() + .find(|(named, _)| *named == call) .map(|(_, failure)| failure.clone()) } @@ -1339,6 +1342,201 @@ fn a_venue_that_lacks_the_feature_is_its_own_outcome() { assert_eq!(replayed.verdict.word(), "lacks-feature"); } +/// A case that records a refusal at a site it **carries on past**, and then stops at a call the +/// venue honestly cannot make. +/// +/// This shape had no case in the tree, which is why the hole below went unreached: the only user +/// of [`crate::case::probe`] makes no abortable call after it, and every site that records a +/// failure by hand either runs to the end or aborts at once. So the shape is written here, where +/// it costs no device and cannot be refactored away by a case author. +/// +/// `hand_built` chooses how the case says it stopped: through [`made`], which records the venue's +/// gap as it emits the site, or through an `Abort` the case builds itself, which 122 sites in the +/// suite do and which records no such thing. Both have to reach the same verdict. +struct StoppedCase { + name: &'static str, + hand_built: bool, +} + +impl StoppedCase { + fn new(name: &'static str, hand_built: bool) -> Self { + Self { name, hand_built } + } + + /// The transcript a side that answered everything emits: Metal's answer for this case. + /// + /// It holds a site **after** the one that stops our run, so a green verdict here also says + /// the comparison was told the run stopped: without that, the site Metal alone reached would + /// be a divergence and no verdict of this case could ever be `lacks-feature`. + fn metal(&self) -> Transcript { + let mut sites = Sites::new(); + sites.push(crate::case::inputs_node(&self.inputs().unwrap())); + sites.value(SWEPT, Value::ok(Value::Uint(11))); + sites.value("library", Value::ok(Value::Absent)); + sites.value(STOPS, Value::ok(Value::Absent)); + sites.value("after", Value::Uint(13)); + sites.notices(NOTICES_SITE, &[] as &[&str]); + sites.finish() + } +} + +/// The site the case sweeps over and carries on past. +const SWEPT: &str = "swept"; + +/// The site the case stops at. +const STOPS: &str = "stops"; + +impl Case for StoppedCase { + fn name(&self) -> &'static str { + self.name + } + + fn metal_source(&self) -> MetalSource { + MetalSource::Run + } + + fn inputs(&self) -> Result, String> { + Ok(vec![Input::bytes("calls", b"one sweep and one stop")]) + } + + fn run(&self, side: &mut dyn Side, sites: &mut Sites) -> Result<(), Abort> { + // A sweep: one refused entry compares as a refusal at its own site and the run goes on. + crate::case::probe( + sites, + SWEPT, + side.texture_2d( + metal2vulkan::metal::PixelFormat::RGBA8Unorm, + [1, 1], + 4, + &[0u8; 4], + ), + |_| Value::Uint(11), + ); + let source = ShaderSource { + bitcode: &[], + air_text: "", + entry: "stop", + }; + let library = made(sites, "library", side.library(&source))?; + if !self.hand_built { + made(sites, STOPS, side.compute_pipeline(library, "stop"))?; + } else { + match side.compute_pipeline(library, "stop") { + Ok(_) => sites.value(STOPS, Value::ok(Value::Absent)), + Err(failure) => { + sites.push(Node::leaf(STOPS, Observed::value(failure.recorded()))); + return Err(Abort { + at: STOPS.to_owned(), + failure, + }); + } + } + } + sites.value("after", Value::Uint(13)); + Ok(()) + } +} + +/// A refusal of **ours** at a site the run carried on past outranks the venue's own gap at the +/// site that stopped it, and the ledger can name it. +/// +/// The hole this closes, which was the most severe form of a refusal going missing found in this +/// round: `replay` answered `LacksFeature` straight off the abort, **before** comparing anything, +/// so a refusal already recorded at an earlier site vanished behind a verdict that +/// [`Verdict::is_compliant`] answers true for. The run stayed green. `verdict.rs` states the +/// invariant it broke in as many words — "a divergence or a refusal anywhere else in the same case +/// still fails, which is what makes this safe to be compliant" — so this is also the test that +/// catches that claim being false. +/// +/// Both ways a case can say it stopped are exercised, because they record different things: the +/// hand-built `Abort` records the typed error and not the fact that the venue is what lacks it, +/// and without `replay` recording that fact at the one place it reads the abort, this case's +/// stopping site would itself read as a refusal of ours. +#[test] +fn a_refusal_before_the_venues_own_gap_outranks_it() { + use crate::known_gaps::{against, Expectation, Expects, KnownGap, EVERY_VENUE}; + let lacking = || { + let mut failure = Failure::named("Error::Unsupported", "no pipeline of that shape"); + failure.lacks = Some("the device enables no such capability".to_owned()); + failure + }; + for hand_built in [false, true] { + let case = StoppedCase::new("stopped-after-a-refusal", hand_built); + let recording = recording_of(&case, case.metal(), 3); + + // Only the venue's gap: the case is its own outcome, as it was before, and the allowances + // it never reached are not reported as a blind spot. + let mut lacks = StubSide::new(Vec::new()).refusing("pipeline", lacking()); + let only_lacking = replay_against(&case, &mut lacks, &recording).unwrap(); + assert_eq!( + only_lacking.verdict.word(), + "lacks-feature", + "hand_built {hand_built}: {}", + only_lacking.verdict + ); + assert!(only_lacking.verdict.is_compliant()); + assert!( + only_lacking + .verdict + .to_string() + .contains("no such capability"), + "{}", + only_lacking.verdict + ); + assert_eq!(only_lacking.allowances.unfired, Vec::new()); + + // And with a refusal of ours at the site the run carried on past, that refusal is the + // verdict: non-compliant, named at its own site, and the venue's gap still reported. + let mut both = StubSide::new(Vec::new()) + .refusing( + "texture", + Failure::named("Error::Invalid", "the runtime refuses this texture"), + ) + .refusing("pipeline", lacking()); + let replayed = replay_against(&case, &mut both, &recording).unwrap(); + assert_eq!( + replayed.verdict.word(), + "refused", + "hand_built {hand_built}: {}", + replayed.verdict + ); + assert!(!replayed.verdict.is_compliant()); + let Verdict::Refused { at, .. } = &replayed.verdict else { + panic!("{}", replayed.verdict); + }; + let [printed] = at.as_slice() else { + panic!("the swept site alone, not the stopping one: {at:?}"); + }; + let (site, answer) = printed.split_once(": ").expect("a site and an answer"); + let (site, answer) = (site.to_owned(), answer.to_owned()); + assert_eq!(site, "case/swept"); + assert!(answer.contains("Error::Invalid"), "{answer}"); + + // The ledger can name it, in both directions, which is what being `Refused` buys. + let rows = vec![replayed]; + let found = against(&rows, &[]); + let [Expectation::Unlisted { expects, .. }] = found.as_slice() else { + panic!("{found:?}"); + }; + assert_eq!(*expects, Expects::Refused); + let listed = vec![KnownGap { + case: "stopped-after-a-refusal".to_owned(), + venue: EVERY_VENUE.to_owned(), + expects: Expects::Refused, + site: site.clone(), + answer: answer.clone(), + waiting_on: "the stub refuses the swept texture, which is the point of the stub" + .to_owned(), + }]; + assert_eq!(against(&rows, &listed), Vec::new()); + let found = against(std::slice::from_ref(&only_lacking), &listed); + let [gone @ Expectation::NoLongerHeld { .. }] = found.as_slice() else { + panic!("{found:?}"); + }; + assert!(gone.to_string().contains("drop the row"), "{gone}"); + } +} + #[test] fn inputs_that_are_not_the_recordings_are_unrecorded_never_a_pass() { let recorded = WordsCase::new("words", 2); @@ -1444,6 +1642,75 @@ fn record_mode_refuses_a_case_that_must_not_be_re_recorded() { assert!(format!("{error}").contains("must not be re-recorded")); } +/// Record mode refuses a case whose **Metal** run stopped, rather than writing a recording of part +/// of it -- and still records the refusal a sweep carries past, which is Metal's answer. +/// +/// `crate::case::call` aborts the whole case, so the sites after it are never emitted. Writing that +/// down would be the suite blessing a recording nobody took: on replay, every site past the stop +/// reads as one only our side observed, a divergence the case never asked about, and a recorded +/// Metal `Err` our side happens to match compares **exact** -- the case reporting as passing where +/// neither side did the work. Nothing of that is reachable today, because zero of the committed +/// recordings hold any `Err` at all, which is also why it had to be closed before a case reached +/// it rather than after. +/// +/// `LedgerCase` carries both shapes, which is why it is the case here: it makes its library with +/// `made`, which stops the run, and its texture with a `call` whose refusal it carries past. So the +/// two directions are one case with one site moved, not two cases that could drift apart. +#[test] +fn record_mode_refuses_a_case_whose_metal_run_stopped() { + let case = LedgerCase::new("ledger-record-stopped"); + let refusal = Failure::named("Error::Nil", "newLibraryWithData returned nil"); + // Off macOS there is no Metal to record from, and that check comes first: both legs say so, + // so the test is honest about what it checked rather than appearing to check more. + #[cfg(not(target_os = "macos"))] + { + let mut stops = StubSide::new(words(&[7])).refusing("library", refusal.clone()); + assert_eq!( + record(&case, &mut stops, 1, MetalLevel::NEWEST, Validated::Ran).unwrap_err(), + RecordError::NoMetal + ); + } + #[cfg(target_os = "macos")] + { + // A refusal at the site the case makes with `made`: the run stops, and no recording is + // written. The site is named, and the refusal in the words a ledger row uses. + let mut stops = StubSide::new(words(&[7])).refusing("library", refusal.clone()); + let error = record(&case, &mut stops, 1, MetalLevel::NEWEST, Validated::Ran).unwrap_err(); + let RecordError::Refused { + case: named, + at, + refusal: said, + } = &error + else { + panic!("a stopped Metal run must refuse the recording, not write one: {error:?}"); + }; + assert_eq!(named, case.name()); + assert_eq!(at, "library"); + assert!(said.contains("Error::Nil"), "{said}"); + assert!( + format!("{error}").contains("would hold part of the case"), + "{error}" + ); + + // The other direction, so this cannot become a blanket ban on recording a refusal: the + // same case, the same refusal, at the site it carries past. The transcript is the whole + // case with one query Metal answered nil for, which is Metal's answer, so it records. + let mut carries = StubSide::new(words(&[7])).refusing("texture", refusal); + let answer = record(&case, &mut carries, 1, MetalLevel::NEWEST, Validated::Ran) + .expect("a refusal a sweep carries past is Metal's answer, not a truncated run"); + assert_eq!(answer.provenance, Provenance::MetalRun); + let printed = format!("{:?}", answer.outcomes[0].transcript); + assert!( + printed.contains("Error::Nil"), + "the recording holds the refusal at its own site: {printed}" + ); + assert!( + printed.contains("output"), + "and every site after it, which is what makes it the case's answer: {printed}" + ); + } +} + #[test] fn record_mode_counts_the_outcomes_it_saw_with_their_runs() { // Off macOS there is no Metal to record from, and record mode says so rather than writing a @@ -4521,6 +4788,70 @@ fn a_multisampled_sparse_texture_without_the_sample_count_is_the_devices_gap() { )); } +/// A device's gap is the device's gap in **every** variant that carries a typed refusal, and our +/// unbuilt work stays ours in every one of them. +/// +/// Which `Error` variant wraps an `Unsupported` says *where the refusal was decided*, never *whose +/// gap it is*: the plain form decides it as the call is made, `Error::Bind` as a dispatch or draw +/// is planned, and `Error::Compile` as a kernel the runtime dispatches for itself is built. Only +/// [`Unsupported::needs`] says whose gap it is, so the same `needs` must read the same way through +/// all three, and the carrier must not change the answer. +/// +/// `Error::Compile` was the one [`crate::verdict::device_gap`] did not read, and it is reachable: +/// an extended-range attachment's shadow load is built on demand through `owned_kernel`, whose 43 +/// builds wrap the compile layer's refusal in `Error::Compile`, and `extended_shadow_module` +/// refuses `Unsupported::needs(FramebufferFetch, c)` -- a `Needs::AnyOf`, the device's own gap -- +/// where the device's profile lacks a capability its module needs. +/// `render/extended_shadow.rs`'s pre-instance load hands that refusal to the caller with `?`, so +/// before this a device without the capability had its gap scored as a refusal of ours. +/// +/// Both halves over the same three carriers, because one direction alone is vacuous here: a test +/// that only checked the gaps would pass a `device_gap` that answered `Some` for everything. +#[test] +fn a_device_gap_reads_the_same_through_every_variant_that_carries_a_refusal() { + use metal2vulkan::device::VkFeature; + use metal2vulkan::error::{BindError, Capability, Error as CompileError, Feature, Unsupported}; + use metal2vulkan_runtime::Error; + // One `Unsupported` that is the device's gap, and one that is ours, each put through every + // carrier unchanged. Built once so the two directions cannot drift apart. + let theirs = Unsupported::needs( + Feature::FramebufferFetch, + Capability::Feature(VkFeature::ShaderInt8), + ); + let ours = Unsupported::not_implemented(Feature::FramebufferFetch); + /// One variant that carries a typed refusal: what to call it, and how it wraps one. + type Carrier = (&'static str, fn(Unsupported) -> Error); + let carriers: [Carrier; 3] = [ + ("Error::Unsupported", Error::Unsupported), + ("Error::Bind", |u| Error::Bind(BindError::Unsupported(u))), + ("Error::Compile", |u| { + Error::Compile(CompileError::Unsupported(u)) + }), + ]; + for (carrier, wrap) in carriers { + let gap = wrap(theirs.clone()); + assert!( + crate::verdict::device_gap(&gap).is_some(), + "{carrier} carries the same typed refusal, so a device's gap in it is the device's gap" + ); + // And through the one call every refusal of the suite passes: `Failure::of` is where + // `lacks` is set, so a carrier it does not read loses the fact for the whole run. + assert!( + Failure::of(&gap).lacks.is_some(), + "{carrier}: a refusal the venue cannot answer must reach the run as the venue's gap" + ); + let mine = wrap(ours.clone()); + assert!( + crate::verdict::device_gap(&mine).is_none(), + "{carrier}: what we have not built stays ours to answer for" + ); + assert!( + Failure::of(&mine).lacks.is_none(), + "{carrier}: our own unbuilt work must not be excused as the venue's gap" + ); + } +} + /// Every field of a [`crate::texture::TextureRequest`] reaches **both** sides' texture /// descriptors, checked field by field with no device, each at a value no other field holds. /// diff --git a/crates/metal2vulkan-conformance/src/transcript.rs b/crates/metal2vulkan-conformance/src/transcript.rs index d0dba4737..2e683b6eb 100644 --- a/crates/metal2vulkan-conformance/src/transcript.rs +++ b/crates/metal2vulkan-conformance/src/transcript.rs @@ -656,9 +656,15 @@ impl Sites { /// Every failing call goes through [`crate::case::call`], which records this whenever the /// typed error names capabilities a device could enable or a measured driver defect, so a /// case needs no code of its own and cannot forget to say it. + /// Recording the same site twice is a no-op, so the one place that reads a case's + /// [`Abort`](crate::case::Abort) may record the venue's gap at the site that stopped the case + /// without having to know whether [`crate::case::call`] already did. pub fn device_gap(&mut self, name: &str, needs: impl Into) { - self.device_gaps - .push((format!("case/{name}"), needs.into())); + let path = format!("case/{name}"); + if self.device_gaps.iter().any(|(site, _)| *site == path) { + return; + } + self.device_gaps.push((path, needs.into())); } /// Add the two sites that record what a device announced: the exact set of degrade-notice diff --git a/crates/metal2vulkan-conformance/src/verdict.rs b/crates/metal2vulkan-conformance/src/verdict.rs index 5f1d42241..41c4cdede 100644 --- a/crates/metal2vulkan-conformance/src/verdict.rs +++ b/crates/metal2vulkan-conformance/src/verdict.rs @@ -268,20 +268,41 @@ fn announced_fields(found: &Comparison) -> Vec { /// a device could enable, or a measured driver defect. A refusal the translator or the runtime has /// not built, and one Metal itself gives, is ours to answer for. /// -/// Two variants carry such a refusal, not one. `Error::Unsupported` is the plain form; a dispatch -/// or draw whose shape the device cannot take is refused by the **bind stage**, which wraps the -/// same typed `Unsupported` in `Error::Bind`, and that is where a device's threadgroup and -/// threadgroup-memory limits are met. Reading only the plain form made a device limit read as a -/// divergence or a refusal of ours, which is the one thing the `LacksFeature` verdict exists to -/// prevent (verified on lavapipe, whose emulated 32-lane simdgroups refuse a tile threadgroup of -/// 1024 threads that Metal runs). What the bind stage has **not built** — `Needs::NotImplemented` -/// and the rest — is still ours to answer for, by the same test as the plain form. +/// **Three** variants carry such a refusal, not one, and the typed `Unsupported` means the same +/// thing in each: which of them wraps it says where the refusal was decided, never whose gap it +/// is. So all three are read by the same test, and only `Unsupported::needs` decides. +/// +/// - `Error::Unsupported` is the plain form. +/// - A dispatch or draw whose shape the device cannot take is refused by the **bind stage**, which +/// wraps the same typed `Unsupported` in `Error::Bind`, and that is where a device's threadgroup +/// and threadgroup-memory limits are met. Reading only the plain form made a device limit read +/// as a divergence or a refusal of ours (verified on lavapipe, whose emulated 32-lane simdgroups +/// refuse a tile threadgroup of 1024 threads that Metal runs). +/// - A kernel the **runtime itself dispatches** for a Metal command with no single Vulkan command +/// is built by the compile layer on demand, and its refusal is wrapped in `Error::Compile` +/// (`owned_kernel.rs`, 43 such builds). An extended-range attachment's shadow load is the +/// reachable one: `extended_shadow_module` refuses `Unsupported::needs(FramebufferFetch, c)` +/// where the device's profile lacks the capability its module needs — a `Needs::AnyOf`, the +/// device's own gap — and `render/extended_shadow.rs` hands that to the caller with `?`. +/// +/// What any of the three has **not built** — `Needs::NotImplemented` and the rest — is still ours +/// to answer for, by the same test. +/// +/// **Open gap in the vocabulary.** `Error::SamplerLimit` is a device's lack by its own words — the +/// device's `maxSamplerAllocationCount` samplers are live — and it carries no typed `Unsupported`, +/// so this reads it as a refusal of ours. No case reaches it, because none exhausts a device's +/// samplers, and inventing a carrier for one variant would be the special case this function +/// exists to avoid. It is written down here rather than worked around: a case that ever does +/// exhaust them needs the vocabulary to say "the device ran out", not a third kind of refusal. pub fn device_gap(error: &Error) -> Option { match error { Error::Unsupported(unsupported) => device_gap_of(unsupported), Error::Bind(metal2vulkan::error::BindError::Unsupported(unsupported)) => { device_gap_of(unsupported) } + Error::Compile(metal2vulkan::error::Error::Unsupported(unsupported)) => { + device_gap_of(unsupported) + } _ => None, } } diff --git a/docs/CONFORMANCE-COVERAGE.md b/docs/CONFORMANCE-COVERAGE.md index ec676e6d5..a3bf2a0c3 100644 --- a/docs/CONFORMANCE-COVERAGE.md +++ b/docs/CONFORMANCE-COVERAGE.md @@ -10,8 +10,8 @@ The suite reaches Metal through `objc2-metal`, whose Rust name for a binding is Its limits, measured rather than asserted: -- **575 of 680 call sites** in the Metal leg resolve to an item of the SDK. 32 of those resolve because only one type in `objc2-metal` binds the name at all, so no typing was needed. -- **105 call sites' receivers did not type.** They cost the count 6 selectors, which the suite calls and which this attributes to no item: +- **576 of 682 call sites** in the Metal leg resolve to an item of the SDK. 33 of those resolve because only one type in `objc2-metal` binds the name at all, so no typing was needed. +- **106 call sites' receivers did not type.** They cost the count 6 selectors, which the suite calls and which this attributes to no item: - `count`, bound by `MTL4CounterHeap`, `MTL4CounterHeapDescriptor` - `executeCommandsInBuffer:withRange:`, bound by `MTL4ComputeCommandEncoder`, `MTL4RenderCommandEncoder`, `MTLComputeCommandEncoder`, `MTLRenderCommandEncoder` - `imageblockSampleLength`, bound by `MTL4RenderPassDescriptor`, `MTLRenderPassDescriptor`, `MTLRenderPipelineState` @@ -258,7 +258,7 @@ An implemented container no case's Metal leg touches. These are the families of | `Side` methods the Metal leg reaches an SDK item through | 55 | | SDK items a case's Metal leg reaches, median | 33 | | the same, least and most | 0 and 87 | -| Metal call sites in the leg | 680 | +| Metal call sites in the leg | 682 | | distinct selectors the leg sends | 285 | | of those, resolved to an item of the coverage map | 279 | | oracles the recordings name | `apple-m3-max` ×722 |