diff --git a/crates/metal2vulkan-validation/src/c3.rs b/crates/metal2vulkan-validation/src/c3.rs index bb0ab5fa2..2828d7772 100644 --- a/crates/metal2vulkan-validation/src/c3.rs +++ b/crates/metal2vulkan-validation/src/c3.rs @@ -863,15 +863,13 @@ fn near_equivalent_bound(note: PrecisionNote) -> &'static str { } } -/// The deferred near-equivalent `row` ran, if it records one: in its comparison class, which its -/// executed modules' precision notes derive. +/// The deferred near-equivalent `row` ran, if it records one: among its executed modules' +/// precision notes, whether a note explains a difference or is only recorded. fn deferred_note(row: &CandidateObservation) -> Option { - let ComparisonClass::Unbounded(notes) = &row.comparison else { - return None; - }; + let census = row.census.as_ref()?; DEFERRED_NEAR_EQUIVALENTS .into_iter() - .find(|note| notes.contains(note)) + .find(|note| census.all_notes().any(|recorded| recorded == *note)) } /// Why the product refuses one of `case`'s rasterization-rate maps (the render pass's, or a diff --git a/crates/metal2vulkan-validation/src/c3/tests.rs b/crates/metal2vulkan-validation/src/c3/tests.rs index da5879478..7271cbe86 100644 --- a/crates/metal2vulkan-validation/src/c3/tests.rs +++ b/crates/metal2vulkan-validation/src/c3/tests.rs @@ -1226,8 +1226,12 @@ fn deferred_and_never_reviewed(note: PrecisionNote, label: &str) { artifact: None, output_words: None, }); - row.comparison = ComparisonClass::Unbounded([note].into()); - row.status = noted_if_different(row.status); + // The class the census derives: unbounded by a note that explains a difference, exact + // under one only recorded, whose difference stays a mismatch. + row.comparison = row.census.as_ref().unwrap().comparison_class(); + if row.comparison != ComparisonClass::Exact { + row.status = noted_if_different(row.status); + } assert!(row.class_holds()); row }; @@ -2020,8 +2024,9 @@ fn unbounded_by(row: CandidateObservation, notes: &[PrecisionNote]) -> Candidate /// A row left unbounded by `HalfOutputFastMathBlend` (a fast-math function's `half` color output /// into a blend Metal's compiler fuses and regroups per pipeline) shows the fast-math regrouping -/// cause, as one left unbounded by `FastMathRewrites` does; one left unbounded by -/// `HalfOutputPrecision` alone (a module without fast math) does not. +/// cause, as one left unbounded by `FastMathRewrites` does; one that records only +/// `HalfOutputPrecision` (a module without fast math; a recorded note, its row's class exact) does +/// not. #[test] fn a_fast_math_blend_of_a_half_output_shows_the_regrouping_cause() { let blend = case(1, "half_blend"); @@ -2029,7 +2034,13 @@ fn a_fast_math_blend_of_a_half_output_shows_the_regrouping_cause() { let regrouping = Cause::FastMathRegrouping; assert!(regrouping.shown_by(&row(&[PrecisionNote::HalfOutputFastMathBlend]))); assert!(regrouping.shown_by(&row(&[PrecisionNote::FastMathRewrites]))); - assert!(!regrouping.shown_by(&row(&[PrecisionNote::HalfOutputPrecision]))); + let mut recorded = noting( + new_row(&blend, GPU, &DEVICE, &METAL), + &[PrecisionNote::HalfOutputPrecision], + ); + recorded.comparison = recorded.census.as_ref().unwrap().comparison_class(); + assert!(recorded.class_holds()); + assert!(!regrouping.shown_by(&recorded)); assert!(!Cause::AppleReading.shown_by(&row(&[PrecisionNote::HalfOutputFastMathBlend]))); } diff --git a/crates/metal2vulkan-validation/src/coverage.rs b/crates/metal2vulkan-validation/src/coverage.rs index cfcb952a5..64785f567 100644 --- a/crates/metal2vulkan-validation/src/coverage.rs +++ b/crates/metal2vulkan-validation/src/coverage.rs @@ -272,7 +272,8 @@ impl ExecutedCensus { }) } - fn all_notes(&self) -> impl Iterator + '_ { + /// Every note the run's modules and its rate-map pass recorded. + pub fn all_notes(&self) -> impl Iterator + '_ { self.modules .iter() .flat_map(|module| module.precision.iter().copied()) diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index becd4b442..5321cf900 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -5,7 +5,7 @@ //! that reaches it and allows its difference. Each note's row of the derivation table //! ([`allowance`]) says what it allows: a bound on a word of a structurally known float lane, within //! which the word matches; no bound, under which the word is a noted difference, recorded with the -//! notes that can explain it and counted apart (unless a C3 answer gap holds its case open); or +//! notes that can explain it and counted apart (unless an answer gap holds its case open); or //! nothing, the note being only recorded. A word no reaching note excuses is a mismatch //! (`crate::observation::CandidateStatus`). //! @@ -231,41 +231,50 @@ impl UlpTable { /// measured up to about `3e-4` off Metal's on the probes (more where the varying's range is /// wider), and the interpolated value is ordinary data later words use: a difference is a /// mismatch for review, never accepted or explained by the note. -/// - `ExtrapolatedInterpolation`: unbounded: the device's read of a perspective input at a sample -/// or an offset is first-order, off by the input's curvature across the distance (up to about -/// 1.0 on the pull-model lane's geometry), and the value is ordinary data later words use. +/// - `ExtrapolatedInterpolation`: [`Allowance::Recorded`]. The device's read of a perspective input +/// at a sample or an offset is first-order, off by the input's curvature across the distance (up +/// to about 1.0 on the pull-model lane's geometry), and the value is ordinary data later words +/// use: a difference is a mismatch for review. /// - `QuadsSplitByClipping`: [`Allowance::Recorded`]. A quad a clipping seam crosses runs once per /// piece, which moves a count, a ballot, or a reduction by whole lanes: a difference is a -/// mismatch for review, which C3 names as the answer gap of a case that meets it. -/// - `FragmentSimdgroupGrouping`: unbounded: a fragment function's simdgroup holds the pixels the -/// device's rasterizer packs together, not Apple's, which moves a sum, a ballot, or a shuffle by -/// whole pixels; and a quad of a function that discards holds every covered pixel where Apple's -/// GPU may run some as helpers, which moves a ballot of a helper query by whole lanes. +/// mismatch for review, which validation names as the answer gap of a case that meets it. +/// - `FragmentSimdgroupGrouping`: [`Allowance::Recorded`]. A fragment function's simdgroup holds +/// the pixels the device's rasterizer packs together, not Apple's, which moves a sum, a ballot, +/// or a shuffle by whole pixels; and a quad of a function that discards holds every covered pixel +/// where Apple's GPU may run some as helpers, which moves a ballot of a helper query by whole +/// lanes: a difference is a mismatch for review, deferred until an exact path exists. /// - `VertexSimdgroupGrouping`: unbounded: a vertex function's simdgroup or quad holds the vertices /// the device packs into a subgroup, not Apple's, which moves a sum, a vote, or a shuffle by /// whole vertices. -/// - `BlendedWriteRounding`: unbounded: a blended half-float channel under +/// - `BlendedWriteRounding`: [`Allowance::Recorded`]. A blended half-float channel under /// `textureWriteRoundingMode` 2 stores the device's rounding of the blend's result, which no -/// Vulkan blend states, where Metal rounds it to nearest even. -/// - `CoverageReadsRoundedAlpha`: unbounded: a fragment whose alpha lies near a coverage -/// threshold may cover one sample more or fewer than Metal's, which moves every channel a -/// resolve or a later blend reads there. -/// - `DeviceAlphaCoverage`: unbounded: the device's alpha to coverage may cover other samples -/// than Metal's, a whole fragment stored or dropped at one sample, which moves every channel a -/// resolve or a later blend reads there. -/// - `RotatedBlendRounding`: unbounded: an `ARGB8Unorm` attachment whose blend is not exact by -/// construction may store a channel one code apart from Metal's, which moves every later word -/// that reads it. +/// Vulkan blend states, where Metal rounds it to nearest even: a difference is a mismatch for +/// review, deferred until an exact path exists. +/// - `CoverageReadsRoundedAlpha`: [`Allowance::Recorded`]. A fragment whose alpha lies near a +/// coverage threshold may cover one sample more or fewer than Metal's, which moves every channel +/// a resolve or a later blend reads there: a difference is a mismatch for review, deferred until +/// an exact path exists. +/// - `DeviceAlphaCoverage`: [`Allowance::Recorded`]. The device's alpha to coverage may cover +/// other samples than Metal's, a whole fragment stored or dropped at one sample, which moves +/// every channel a resolve or a later blend reads there: a difference is a mismatch for review. +/// - `RotatedBlendRounding`: [`Allowance::Recorded`]. An `ARGB8Unorm` attachment whose blend is +/// not exact by construction may store a channel one code apart from Metal's, which moves every +/// later word that reads it: a difference is a mismatch for review, deferred until an exact path +/// exists. +/// - `HalfOutputPrecision`, `DevicePointSize`, `LoopedSampleOutputs`, `NativeLogicOperation` and +/// `UnorderedFetchWithinDraw`: [`Allowance::Recorded`]. Each note's documentation keeps a +/// difference a mismatch for review. /// - `DeviceDenormals`: [`Allowance::DenormalBoundary`]. The device's own arithmetic at the -/// denormal boundary (the owner's rule 1): Metal flushes before rounding on some operations (a -/// product, its negation and a fused multiply-add whose exact result lies just below `2^-126` -/// answer `+0`, where a device that rounds first answers `2^-126`) and keeps a denormal on -/// others (`sin`, `tan`, `asinh`), and the device may answer either. A word where both answers -/// lie at or below the smallest normal is excused; nothing above it is, though a flushed operand -/// can carry its difference to any later value. C3 tells which differing values it causes -/// ([`value_difference`]). -/// - `NativeNanEncoding`: [`Allowance::BothNan`]. A NaN result's sign and payload are the -/// device's: a word where both answers are NaNs is excused, and no other. +/// denormal boundary: Metal flushes before rounding on some operations (a product, a fused +/// multiply-add, `dot` and `mix` whose exact result lies just below `2^-126` answer a zero, +/// where a device that rounds first answers `2^-126`) and keeps a denormal on +/// others (`sin`, `tan`, `asin`, `sinh`, `asinh`, `atanh`), and the device may answer either. A +/// word where both answers lie at or below the smallest normal is excused; nothing above it is, +/// though a flushed operand can carry its difference to any later value. [`value_difference`] +/// tells which differing values it causes. +/// - `NativeNanEncoding`: [`Allowance::BothNan`]. A NaN's sign and payload are the device's, in a +/// result and in a payload moved through loads, stores and selects: a word where both answers +/// are NaNs is excused, and no other. /// - `DeviceNanEncoding`: [`Allowance::Recorded`]. Metal canonicalizes NaNs, a device need not, and /// every `float` operation the device performs is exposed to it; a `half` texel's NaN is the /// device's decode where Metal hands back the texel's own: a difference it causes stays a @@ -315,6 +324,18 @@ pub fn allowance(note: PrecisionNote) -> Allowance { N::LinkedSamplerNumbering => Allowance::Recorded, N::DeviceInterpolationOffset => Allowance::Recorded, N::DeviceInterpolation | N::QuadsSplitByClipping => Allowance::Recorded, + // Each note's documentation keeps a difference a mismatch for review. + N::ExtrapolatedInterpolation + | N::FragmentSimdgroupGrouping + | N::BlendedWriteRounding + | N::CoverageReadsRoundedAlpha + | N::DeviceAlphaCoverage + | N::RotatedBlendRounding + | N::HalfOutputPrecision + | N::DevicePointSize + | N::LoopedSampleOutputs + | N::UnorderedFetchWithinDraw + | N::NativeLogicOperation => Allowance::Recorded, N::GradFromBias | N::DeviceTranscendentals | N::PixelSamplerScaling @@ -339,18 +360,9 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::CubeGradientFootprint | N::SrgbTexelDecode | N::QuadsCountedBeforeDiscard - | N::ExtrapolatedInterpolation - | N::FragmentSimdgroupGrouping - | N::BlendedWriteRounding - | N::CoverageReadsRoundedAlpha - | N::DeviceAlphaCoverage - | N::RotatedBlendRounding - | N::HalfOutputPrecision | N::AnisotropicFilter | N::DeviceAnisotropicFilter - | N::DevicePointSize | N::ClippedCoverageSplit - | N::LoopedSampleOutputs | N::HalfOutputFastMathBlend | N::DeviceSampling | N::NativeTranscendentals @@ -364,8 +376,6 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::NativeDot | N::NativeMix | N::DevicePackConversion - | N::UnorderedFetchWithinDraw - | N::NativeLogicOperation | N::CappedLodBias | N::DeviceReconvergence | N::SimdgroupAccessOrder diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index f3f49ee1a..4ed67c063 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -62,15 +62,15 @@ fn every_precision_note_has_its_table_row() { (N::ViewBaseTexelOffset, Allowance::Recorded), (N::DeviceColorConversion, Allowance::Recorded), (N::DeviceInterpolation, Allowance::Recorded), - (N::ExtrapolatedInterpolation, Allowance::Unbounded), + (N::ExtrapolatedInterpolation, Allowance::Recorded), (N::QuadsSplitByClipping, Allowance::Recorded), - (N::FragmentSimdgroupGrouping, Allowance::Unbounded), - (N::BlendedWriteRounding, Allowance::Unbounded), - (N::CoverageReadsRoundedAlpha, Allowance::Unbounded), - (N::DeviceAlphaCoverage, Allowance::Unbounded), - (N::RotatedBlendRounding, Allowance::Unbounded), - (N::UnorderedFetchWithinDraw, Allowance::Unbounded), - (N::NativeLogicOperation, Allowance::Unbounded), + (N::FragmentSimdgroupGrouping, Allowance::Recorded), + (N::BlendedWriteRounding, Allowance::Recorded), + (N::CoverageReadsRoundedAlpha, Allowance::Recorded), + (N::DeviceAlphaCoverage, Allowance::Recorded), + (N::RotatedBlendRounding, Allowance::Recorded), + (N::UnorderedFetchWithinDraw, Allowance::Recorded), + (N::NativeLogicOperation, Allowance::Recorded), (N::CappedLodBias, Allowance::Unbounded), (N::DeviceReconvergence, Allowance::Unbounded), (N::SnormMinimumKept, Allowance::Unbounded), @@ -89,6 +89,9 @@ fn every_precision_note_has_its_table_row() { (N::RestrictedDepthUpload, Allowance::Unbounded), (N::StencilOutputOverlap, Allowance::Unbounded), (N::DeviceHalfDenormals, Allowance::Unbounded), + (N::HalfOutputPrecision, Allowance::Recorded), + (N::DevicePointSize, Allowance::Recorded), + (N::LoopedSampleOutputs, Allowance::Recorded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 5ecee5079..caa5a772d 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -1080,7 +1080,7 @@ pub enum PrecisionNote { /// the viewport is exact only within the viewport limits). /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, which C3 names as the answer gap of a case that meets it. + /// mismatch for review, which validation names as the answer gap of a case that meets it. QuadsSplitByClipping, /// A fragment function runs a simdgroup operation (a reduction, scan, vote, ballot, shuffle, /// broadcast or AGX multiply-add) or reads its `[[thread_index_in_simdgroup]]`, or discards, @@ -1116,7 +1116,7 @@ pub enum PrecisionNote { /// exists on such a device. /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, deferred in C3 until an exact path exists. + /// mismatch for review, deferred until an exact path exists. FragmentSimdgroupGrouping, /// A fragment function writes a float to a half-float color channel of a render pipeline /// under `TextureWriteRoundingMode::NearestEven` that blends with factors other than one and @@ -1128,7 +1128,7 @@ pub enum PrecisionNote { /// not built. /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, deferred in C3 until an exact path exists. + /// mismatch for review, deferred until an exact path exists. BlendedWriteRounding, /// A fragment function writes an attachment held with its channels rotated (`ARGB8Unorm`) /// whose blend is not exact by construction (`LoweringInputs::rotated_blends`): every blend but @@ -1139,7 +1139,7 @@ pub enum PrecisionNote { /// 440 swept blend states on an M4). No query states how a device's blend rounds. /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, deferred in C3 until an exact path exists. + /// mismatch for review, deferred until an exact path exists. RotatedBlendRounding, /// The sampler resource IDs a pipeline state takes for the constexpr samplers of the visible /// functions its stage links may be other than Metal's: two or more linked functions bring @@ -1212,7 +1212,7 @@ pub enum PrecisionNote { /// where a `float` output would otherwise store as written. /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, deferred in C3 until an exact path exists. + /// mismatch for review, deferred until an exact path exists. HalfOutputPrecision, /// The module samples a texture through an anisotropic sampler with Metal's anisotropic /// filter emulated by the device's samples at explicit levels (`lower::sampler::anisotropic`), @@ -1801,7 +1801,7 @@ pub enum PrecisionNote { /// Metal does (MoltenVK), and needs Metal's coverage pattern, which is not modelled. /// /// Validation derives no tolerance and no explanation from it: a difference stays a - /// mismatch for review, deferred in C3 until an exact path exists. + /// mismatch for review, deferred until an exact path exists. CoverageReadsRoundedAlpha, /// Native device coverage: a render pipeline covers by alpha (`alphaToCoverageEnabled`, kept /// where its fragment function writes a four-component float to attachment 0,