diff --git a/crates/metal2vulkan-validation/src/runtime_lane/driver_deviations.rs b/crates/metal2vulkan-validation/src/runtime_lane/driver_deviations.rs index 642492743..759c62ac6 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/driver_deviations.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/driver_deviations.rs @@ -824,12 +824,13 @@ const DENORMAL_PROBES: [&str; 2] = [ ]; /// The words of a [`DENORMAL_PROBES`] thread whose operations read `float` denormals as Metal -/// does on every profile: `a + b`, `a - b`, `a * b`, `0 - a`, `a < b`, `a == b`, `floor`, `ceil`, -/// `trunc`, `rint`, `ldexp`, `step`, `(a * b) * c`, `a < b ? a : b`, `-(a * b)` and -/// `fabs(a - b)`; and `sqrt` and `rsqrt` ([`DENORMAL_PROBE_ROOTS`]) where Metal answers a zero, an -/// infinity or a NaN. Not `round` (15), C99's on every device (`NativeTranscendentals`), whose -/// zero below zero is `-0` where Metal answers `+0`; not `floor` and `ceil` (12, 13), whose reading -/// no device measured matches, the quotients (3, 40, 44), the device's division, the fused +/// does where the profile takes `DriverDeviation::MetalFloatDenormals`: `a + b`, `a - b`, `a * b`, +/// `0 - a`, `a < b`, `a == b`, `trunc`, `rint`, `ldexp`, `step`, `(a * b) * c`, `a < b ? a : b`, +/// `-(a * b)` and `fabs(a - b)`; and `sqrt` and `rsqrt` ([`DENORMAL_PROBE_ROOTS`]) where Metal +/// answers a zero, an infinity or a NaN. Not `round` (15), C99's on every device +/// (`NativeTranscendentals`), whose zero below zero is `-0` where Metal answers `+0`; not `-a`, +/// `fabs(a)`, `floor` and `ceil` ([`DENORMAL_PROBE_UNARY`]), the other deviation's; not the +/// quotients (3, 40, 44), the device's division, the fused /// multiply-adds (4, 5), `dot` and `length` (36, 37) and `mix` (38), the device's `OpDot` and /// `FMix`, whose sums Metal fuses and flushes at the tininess edge before rounding, nor the math /// library's functions. @@ -841,10 +842,18 @@ const DENORMAL_PROBE_WORDS: &[usize] = &[0, 1, 2, 7, 10, 11, 14, 16, 35, 39, 43, /// are an ulp below Metal's (the committed rows of 615.71.09, 16 lanes each). const DENORMAL_PROBE_ROOTS: &[usize] = &[20, 21]; +/// The words of a [`DENORMAL_PROBES`] thread whose operations read `float` denormals as Metal's do +/// where the profile takes `DriverDeviation::MetalUnaryDenormals`: `-a` (6), `fabs(a)` (8), +/// `floor(a)` (12) and `ceil(a)` (13). NVIDIA's 615.71.09 and lavapipe answer `floor` and `ceil` +/// of a denormal as `-1` and `1`, where Metal reads it as a zero. +const DENORMAL_PROBE_UNARY: &[usize] = &[6, 8, 12, 13]; + /// Both probes answer Metal's `float` denormals where the profile takes the deviation (the kernels /// then require `VkProperty::MetalFloatDenormals`): every word of [`DENORMAL_PROBE_WORDS`] and /// each word of [`DENORMAL_PROBE_ROOTS`] where Metal answers a zero, an infinity or a NaN is the -/// Metal row's of the same chip, but a NaN's bits, which are the device's where the profile does +/// Metal row's of the same chip; so is every word of [`DENORMAL_PROBE_UNARY`] where the profile +/// takes `DriverDeviation::MetalUnaryDenormals` (the kernels then require +/// `VkProperty::MetalUnaryDenormals`), but a NaN's bits, which are the device's where the profile does /// not take `DriverDeviation::MetalCanonicalNans` ([`float_word_holds`]): a root of a negative /// operand is then any NaN. Elsewhere the denormals are the device's and nothing is checked. The /// test prints how many words differ. @@ -856,6 +865,7 @@ fn float_denormals_read_as_metal_reads_them() { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); let name = device.name().to_owned(); let metals = takes(&device, DriverDeviation::MetalFloatDenormals); + let unary = takes(&device, DriverDeviation::MetalUnaryDenormals); let canonical = takes(&device, DriverDeviation::MetalCanonicalNans); let mut failures = Vec::new(); for case_name in DENORMAL_PROBES { @@ -866,6 +876,12 @@ fn float_denormals_read_as_metal_reads_them() { "{case_name} on {name}: the kernel leaves its denormals to the device exactly \ where the profile takes the deviation" ); + assert_eq!( + requires_property(&device, &case, VkProperty::MetalUnaryDenormals), + unary, + "{case_name} on {name}: the kernel leaves its sign moves', floors' and ceilings' \ + denormals to the device exactly where the profile takes that deviation" + ); let run = run_case(&device, &case).unwrap(); let metal = metal_row(&case, METAL_ENVIRONMENT); assert_eq!(run.output.len(), metal.len(), "{case_name} on {name}"); @@ -878,9 +894,10 @@ fn float_denormals_read_as_metal_reads_them() { for i in 0..metal.len() / 4 { let w = i % 48; let (got, want) = (word(&run.output, i), word(&metal, i)); - if metals + if (metals && (DENORMAL_PROBE_WORDS.contains(&w) - || (DENORMAL_PROBE_ROOTS.contains(&w) && special(want))) + || (DENORMAL_PROBE_ROOTS.contains(&w) && special(want)))) + || (unary && DENORMAL_PROBE_UNARY.contains(&w)) { checked += 1; if !float_word_holds(got, want, canonical) { @@ -893,7 +910,8 @@ fn float_denormals_read_as_metal_reads_them() { } } eprintln!( - "float denormals {case_name} on {name} (the device's, as Metal's: {metals}): {} of \ + "float denormals {case_name} on {name} (the device's, as Metal's: {metals}; its \ + sign moves, floors and ceilings: {unary}): {} of \ {checked} checked words differ from Metal, {nans} more NaNs of the device's bits; \ other words differing, by word: {by_word:?}", differ.len() @@ -1053,8 +1071,8 @@ const DFL_DENORMAL_CASES: [&str; 2] = [ /// The rows of a [`DFL_DENORMAL_CASES`] thread checked on every lane where the profile takes /// `DriverDeviation::MetalFloatDenormals`: `a + b`, `a - b`, `a * b`, `fma`, `a * b + c`, the six /// comparisons, `ldexp`, `(a * b) * c`, `float(n) * a - c`, the three comparisons of results, -/// `fmin(a, b) * c` and `step`. `floor` (6) and `ceil` (7) of a denormal are the device's own on -/// every profile (`denormal::Covered::Never`). The fused +/// `fmin(a, b) * c` and `step`. `floor` (6) and `ceil` (7) of a denormal are the other +/// deviation's ([`DFL_UNARY_ROWS`]). The fused /// rows' lanes are clear of the tininess edge before rounding: Metal's rows are the operands /// flushed, one rounding, and the result flushed, on every lane (and under fast math `a * b + c` is /// two roundings, the product having other uses). `sqrt` (8) and `rsqrt` (9) are checked where @@ -1066,6 +1084,10 @@ const DFL_DENORMAL_ROWS: &[usize] = &[0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]; /// device's roots' rounding, not their denormals. const DFL_ROOT_ROWS: &[usize] = &[8, 9]; +/// The `floor` and `ceil` rows of a [`DFL_DENORMAL_CASES`] thread: checked on every lane where the +/// profile takes `DriverDeviation::MetalUnaryDenormals`. +const DFL_UNARY_ROWS: &[usize] = &[6, 7]; + /// The `fmin(a, b) * c` row of a [`DFL_DENORMAL_CASES`] thread: where the stage records /// `PrecisionNote::NativeMinMax` (its `fmin` the device's `NMin`), a lane whose minimum picks /// between `+0` and `-0` (or two denormals the device flushes) answers either zero, its product a @@ -1090,7 +1112,8 @@ const DFL_TRIG_OPERAND: usize = 11; /// The owned fixtures answer Metal: in the denormal cases every lane of [`DFL_DENORMAL_ROWS`] and /// the special lanes of [`DFL_ROOT_ROWS`] where the profile takes -/// `DriverDeviation::MetalFloatDenormals` (elsewhere a denormal is the device's own, and the test +/// `DriverDeviation::MetalFloatDenormals`, and every lane of [`DFL_UNARY_ROWS`] where it takes +/// `DriverDeviation::MetalUnaryDenormals` (elsewhere a denormal is the device's own, and the test /// prints how many words differ), but a minimum's zero of either sign in [`DFL_MIN_ROW`] where the /// stage records `PrecisionNote::NativeMinMax`, which the runtime then announces, the kernels /// requiring `VkProperty::MetalFloatDenormals` exactly where the profile takes the deviation; in @@ -1123,7 +1146,13 @@ fn owned_float_fixtures_answer_metal() { // The notes whose answers a case gave, which the runtime must have announced. let mut announces = Vec::new(); let denormals = takes(&device, DriverDeviation::MetalFloatDenormals); + let unary = takes(&device, DriverDeviation::MetalUnaryDenormals); let canonical = takes(&device, DriverDeviation::MetalCanonicalNans); + // Whether a row's differences fail the run: its deviation's, where the profile takes it. + let gated = |row: usize| match DFL_UNARY_ROWS.contains(&row) { + true => unary, + false => denormals, + }; for case_name in DFL_DENORMAL_CASES { let case = public_case(case_name).unwrap(); assert_eq!( @@ -1132,6 +1161,12 @@ fn owned_float_fixtures_answer_metal() { "{case_name} on {name}: the kernel leaves its denormals to the device exactly \ where the profile takes the deviation" ); + assert_eq!( + requires_property(&device, &case, VkProperty::MetalUnaryDenormals), + unary, + "{case_name} on {name}: the kernel leaves its floors' and ceilings' denormals to \ + the device exactly where the profile takes that deviation" + ); // The minimum's pick of `+0` and `-0` (of two denormals flushed, too) is either zero // where the stage's `fmin` is the device's `NMin` (`PrecisionNote::NativeMinMax`). let native_min = case_notes(&device, &case).contains(&PrecisionNote::NativeMinMax); @@ -1144,7 +1179,8 @@ fn owned_float_fixtures_answer_metal() { let row = i % 64 / 4; let (got, want) = (word(&run.output, i), word(&metal, i)); let check = DFL_DENORMAL_ROWS.contains(&row) - || (DFL_ROOT_ROWS.contains(&row) && special(want)); + || (DFL_ROOT_ROWS.contains(&row) && special(want)) + || DFL_UNARY_ROWS.contains(&row); let zero = |w: u32| w & 0x7FFF_FFFF == 0; if check { checked += 1; @@ -1172,12 +1208,14 @@ fn owned_float_fixtures_answer_metal() { if zeros > 0 && native_min { announces.push((case_name, PrecisionNote::NativeMinMax)); } - if denormals && !differ.is_empty() { + // A word's row: its place in the thread's 64 words, four lanes a row. + let failing: Vec<_> = differ.iter().filter(|d| gated(d.1 / 4)).collect(); + if !failing.is_empty() { failures.push(format!( "{case_name} on {name}: {} words differ from Metal (thread, word, device, \ Metal): {:x?}", - differ.len(), - &differ[..differ.len().min(24)] + failing.len(), + &failing[..failing.len().min(24)] )); } } diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 8b6ad4c67..f37998c57 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1034,6 +1034,7 @@ codec_enum! { MetalFullQuads, ProvokingVertexModePerPipeline, DepthImageKeepsValuesOutsideUnitRange, MetalNormalizedVertexFetch, MetalAlphaCoverage, InterpolateAtOffsetFromSevenSixteenths, MetalNanMoves, MetalPackConversions, MetalHalfConversion, MetalSmallFloatNans, + MetalUnaryDenormals, } VkLimit { MaxComputeWorkGroupSize(f0), MaxComputeWorkGroupCount(f0), MaxComputeWorkGroupInvocations, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 386d59498..367b24de5 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 1960; +pub const SEMANTICS_VERSION: u32 = 1961; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 1960; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 485; +pub const ARTIFACT_FORMAT_VERSION: u32 = 486; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle diff --git a/crates/metal2vulkan/src/cache/tests.rs b/crates/metal2vulkan/src/cache/tests.rs index 19f9db63b..0aa33bf32 100644 --- a/crates/metal2vulkan/src/cache/tests.rs +++ b/crates/metal2vulkan/src/cache/tests.rs @@ -822,6 +822,16 @@ fn the_version_485_member_round_trips() { assert_ne!(encode(&key), encode(&SpecKey::NearestPixelSampler(slot))); } +/// The member format version 486 appends encodes and decodes as itself: the measured unary +/// operations' kept denormals, a property a module requires. +#[test] +fn the_version_486_member_round_trips() { + use crate::device::requirements::VkProperty; + let p = VkProperty::MetalUnaryDenormals; + assert_eq!(decode::(&encode(&p)), Ok(p)); + assert_ne!(encode(&p), encode(&VkProperty::MetalSmallFloatNans)); +} + /// The members format versions 153, 154, 155, 157 and 161 joined from every side encode and /// decode together in one render pipeline: `PrecisionNote::CubeGradientFootprint` and /// `CombinedSampler`, `RuntimeFact::InterlockedFramebufferFetch` and diff --git a/crates/metal2vulkan/src/device/derive.rs b/crates/metal2vulkan/src/device/derive.rs index 8872d59b9..b97d5c599 100644 --- a/crates/metal2vulkan/src/device/derive.rs +++ b/crates/metal2vulkan/src/device/derive.rs @@ -821,6 +821,9 @@ fn enabled_caps(desc: &DeviceDescription, deviations: &BTreeSet if deviations.contains(&DriverDeviation::MetalSmallFloatNans) { properties.insert(VkProperty::MetalSmallFloatNans); } + if deviations.contains(&DriverDeviation::MetalUnaryDenormals) { + properties.insert(VkProperty::MetalUnaryDenormals); + } if desc .driver_facts() .contains(&crate::device::DriverFact::DepthImageKeepsValuesOutsideUnitRange) diff --git a/crates/metal2vulkan/src/device/driver_facts.rs b/crates/metal2vulkan/src/device/driver_facts.rs index dbd8dd208..000ef7f43 100644 --- a/crates/metal2vulkan/src/device/driver_facts.rs +++ b/crates/metal2vulkan/src/device/driver_facts.rs @@ -472,6 +472,19 @@ pub(crate) fn among( /// and `RGBA16Float` a `half` NaN's payload differs (the device stores `0x7e00`), which /// `MetalHalfTexelWrites` would state, so outside it. One row per GPU, as measured. /// +/// `MetalUnaryDenormals`: MoltenVK 1.4.2's `OpFNegate`, `FAbs`, `Floor` and `Ceil` on 32-bit +/// floats, which SPIRV-Cross writes as Metal's `-x`, `fabs`, `floor` and `ceil`. On the M3 Max +/// under macOS 27.0.1, against plain Metal's rows: the gate lane +/// `runtime_lane::driver_deviations::float_denormals_read_as_metal_reads_them` checks the +/// denormal probes' (`nan_denormals`, `nan_denormals_fast`: 256 lanes of operand triples rich in +/// denormals of both signs and the smallest normals) words of `-a`, `fabs(a)`, `floor(a)` and +/// `ceil(a)` beside `0 - a` and `-(a * b)`, and +/// `runtime_lane::driver_deviations::owned_float_fixtures_answer_metal` the owned fixtures' +/// `floor` and `ceil` rows of every pair of a 32-value pool; the committed MoltenVK rows of all +/// four cases are Metal's, word for word. NVIDIA's 615.71.09 and lavapipe answer `floor` and `ceil` +/// of a denormal as `-1` and `1`, and RADV and ANV flush a negated denormal, so they are not +/// listed. One row per GPU, as measured. +/// /// Another driver has none of them, as Vulkan states, and a listed driver on another vendor's GPU /// (or another GPU than a row's) is unmeasured: the profile then takes each one's route without /// it, which the deviation's docs name (`derive.rs`). @@ -674,6 +687,10 @@ pub(crate) const DEVIATIONS: &[Measured] = &[ device: Some(APPLE9), ..moltenvk_on_apple(DriverDeviation::MetalSmallFloatNans) }, + Measured { + device: Some(APPLE9), + ..moltenvk_on_apple(DriverDeviation::MetalUnaryDenormals) + }, ]; /// NVIDIA's `vendorID`. diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index 87b8035b5..91661bd91 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -351,6 +351,10 @@ impl DeviceProfile { .enabled .properties .contains(&VkProperty::MetalSmallFloatNans), + DriverDeviation::MetalUnaryDenormals => f + .enabled + .properties + .contains(&VkProperty::MetalUnaryDenormals), } } diff --git a/crates/metal2vulkan/src/device/requirements.rs b/crates/metal2vulkan/src/device/requirements.rs index 8457cac8a..5ccd25402 100644 --- a/crates/metal2vulkan/src/device/requirements.rs +++ b/crates/metal2vulkan/src/device/requirements.rs @@ -868,6 +868,15 @@ pub enum VkProperty { /// [`PrecisionNote::DeviceNanEncoding`](crate::pipeline::PrecisionNote::DeviceNanEncoding) /// for it and requires it. MetalSmallFloatNans, + /// The device's `float` `OpFNegate` and `FAbs` keep an `f32` denormal and its `Floor` and + /// `Ceil` read one as the zero of its sign, as Metal's `-x`, `fabs`, `floor` and `ceil` do (the + /// driver's measured deviation + /// [`DriverDeviation::MetalUnaryDenormals`](crate::error::DriverDeviation::MetalUnaryDenormals)). + /// Vulkan lets a device keep or flush them. A module that leaves those operations' denormals to + /// the device records no + /// [`PrecisionNote::DeviceDenormals`](crate::pipeline::PrecisionNote::DeviceDenormals) for + /// them and requires it. + MetalUnaryDenormals, /// `GLSL.std.450 InterpolateAtOffset` at offset `v` reads Metal's `interpolate_at_offset` at /// `v + 7/16`, measured from the pixel's upper-left corner: a device whose description reports /// a MoltenVK driver, whose SPIRV-Cross hands the instruction to Metal so at any release diff --git a/crates/metal2vulkan/src/device/tests/driver_facts.rs b/crates/metal2vulkan/src/device/tests/driver_facts.rs index cfe457fa2..9cedce5b3 100644 --- a/crates/metal2vulkan/src/device/tests/driver_facts.rs +++ b/crates/metal2vulkan/src/device/tests/driver_facts.rs @@ -168,6 +168,10 @@ fn taken(p: &crate::device::DeviceProfile) -> Vec D::MetalSmallFloatNans, property(VkProperty::MetalSmallFloatNans), ), + ( + D::MetalUnaryDenormals, + property(VkProperty::MetalUnaryDenormals), + ), ] .into_iter() .inspect(|&(d, taken)| { @@ -182,7 +186,7 @@ fn taken(p: &crate::device::DeviceProfile) -> Vec /// at every release: every Apple GPU's (MoltenVK's lockstep, `float` functions, canonical NaNs, /// sampler, compute cube route and the rest of the seventeen), with the graphics cube route and the /// per-sample depth of macOS 27's Apple9 identity, that identity's normalized -/// storage writes, full quads, normalized vertex fetch, alpha to coverage, moved NaNs, pack conversions, half conversions and small-float NaN stores, and every Apple GPU's 16-bit unorm depth stores, interpolation +/// storage writes, full quads, normalized vertex fetch, alpha to coverage, moved NaNs, pack conversions, half conversions, small-float NaN stores and unary denormals, and every Apple GPU's 16-bit unorm depth stores, interpolation /// and first-vertex indices; lavapipe's `float` color NaNs and half-float storage writes; RADV's on /// the Radeon 780M, ANV's on the Iris Xe of RPL-P and the UHD 770 of RPL-S, and NVIDIA's on the /// RTX 3090 and the RTX 5080 Laptop GPU, as measured there; the 8-bit linear filter's bound where @@ -240,8 +244,8 @@ fn the_profile_takes_the_deviations_its_driver_is_measured_with() { list.push(D::MetalFirstVertexIndices); } // macOS 27's full quads, measured on the M4's identity alone, and its normalized vertex - // fetch, alpha to coverage, moved NaNs, pack conversions, half conversions and small-float NaN - // stores, measured on the M3 Max under it. + // fetch, alpha to coverage, moved NaNs, pack conversions, half conversions, small-float NaN + // stores and unary denormals, measured on the M3 Max under it. m4_measured.push(D::MetalFullQuads); m4_measured.push(D::MetalNormalizedVertexFetch); m4_measured.push(D::MetalAlphaCoverage); @@ -249,6 +253,7 @@ fn the_profile_takes_the_deviations_its_driver_is_measured_with() { m4_measured.push(D::MetalPackConversions); m4_measured.push(D::MetalHalfConversion); m4_measured.push(D::MetalSmallFloatNans); + m4_measured.push(D::MetalUnaryDenormals); let all_of = |d: &DeviceDescription| match d.device_id { crate::device::driver_facts::APPLE9 => m4_measured.clone(), _ => apple_all.clone(), diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 132ad7dc4..5d4846492 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -874,6 +874,15 @@ pub enum DriverDeviation { /// answers Metal's, a widened `half` written there moves its NaN as measured /// (`lower::arith::narrow::moves_unfolded`). Unmeasured, the write records the note. MetalSmallFloatNans, + /// The device's `float` negation, absolute value, floor and ceiling (`OpFNegate`, `FAbs`, + /// `Floor` and `Ceil`) read an `f32` denormal as Metal does (`VkProperty::MetalUnaryDenormals`): + /// a negation and an absolute value move the sign bit alone, keeping the denormal, and a floor + /// and a ceiling read it as the zero of its sign (`floor(-2^-149)` is `-0`, `ceil(2^-149)` is + /// `+0`). Where the profile takes it, those operations record no + /// `PrecisionNote::DeviceDenormals` and the module requires the property. A texel centre's + /// `floor` stays noted where its address mode parts texel -1 from texel 0: Metal's sampler + /// reads its coordinate unflushed. Unmeasured, each records the note. + MetalUnaryDenormals, } /// A defect of a device's driver in a command the runtime records for itself, never in a diff --git a/crates/metal2vulkan/src/lower/arith/denormal.rs b/crates/metal2vulkan/src/lower/arith/denormal.rs index e82a6071c..6c5623df6 100644 --- a/crates/metal2vulkan/src/lower/arith/denormal.rs +++ b/crates/metal2vulkan/src/lower/arith/denormal.rs @@ -1,8 +1,9 @@ //! How Metal reads `f32` denormals, per operation, against the device: where the device reads them //! as Metal does, an `f32` denormal operand as the zero of its sign and a denormal result flushed -//! to one (`DriverDeviation::MetalFloatDenormals`, a measured driver fact), the module leaves them -//! to it and requires the property; elsewhere they are the device's own, noted -//! (`PrecisionNote::DeviceDenormals`). Only `float` operations are listed: a widened `half` is +//! to one (`DriverDeviation::MetalFloatDenormals`, a measured driver fact), or, for a negation, an +//! absolute value, a floor and a ceiling, as Metal's (`DriverDeviation::MetalUnaryDenormals`), +//! the module leaves them to it and requires the property; elsewhere they are the device's own, +//! noted (`PrecisionNote::DeviceDenormals`). Only `float` operations are listed: a widened `half` is //! never an `f32` denormal, and Metal's `bfloat` and `double` environments are not measured. use crate::device::DeviceProfile; @@ -17,18 +18,49 @@ pub fn device_flushes(p: &DeviceProfile) -> bool { p.takes_driver_deviation(DriverDeviation::MetalFloatDenormals) } +/// Whether profile `p`'s device reads the denormals of the operations [`Covered::Unary`] names as +/// Metal does: a negation and an absolute value keep one, a floor and a ceiling read one as the +/// zero of its sign (`DriverDeviation::MetalUnaryDenormals`, a measured driver fact). Elsewhere +/// they are the device's own (`PrecisionNote::DeviceDenormals`). +pub fn unary_kept(p: &DeviceProfile) -> bool { + p.takes_driver_deviation(DriverDeviation::MetalUnaryDenormals) +} + /// Where an operation the device computes reads its `f32` denormals as Metal does. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Covered { /// On a device with the measured deviation ([`device_flushes`]); elsewhere they are the /// device's own. Deviation, - /// On no device measured: the device's own on every profile. `Floor` and `Ceil` of a denormal + /// On a device with the measured deviation of the sign moves and the floor and ceiling + /// ([`unary_kept`]); elsewhere they are the device's own. `Floor` and `Ceil` of a denormal /// give `-1` and `1` on NVIDIA's 615.71.09 and on lavapipe, where Metal reads the operand as a - /// zero (`floor(-2^-149)` is `-0`, `ceil(2^-149)` is `+0`). + /// zero (`floor(-2^-149)` is `-0`, `ceil(2^-149)` is `+0`), and RADV and ANV flush a negated + /// one, which Metal keeps. + Unary, + /// On no device measured: the device's own on every profile (a quotient). Never, } +impl Covered { + /// Whether a device whose readings `flushes` ([`device_flushes`]) and `unary` + /// ([`unary_kept`]) state reads an operation of this class's denormals as Metal does. + pub fn holds(self, flushes: bool, unary: bool) -> bool { + match self { + Covered::Deviation => flushes, + Covered::Unary => unary, + Covered::Never => false, + } + } +} + +/// Whether float function `op` moves its operand's sign bit alone, keeping a denormal where Metal's +/// does on a device measured to ([`Covered::Unary`]): `fabs`. Its notes otherwise follow the +/// device's own functions (`function_notes`). +pub fn moves_sign(op: FloatFn) -> bool { + op == FloatFn::Abs +} + /// Where the device's instruction for float function `op` (on `float` lanes, where the lowering /// leaves `op` to it) reads `f32` denormals as Metal, which reads each `float` operand of these /// as the zero of its sign and flushes a denormal result (the denormal probes, `nan_denormals` @@ -37,7 +69,7 @@ pub enum Covered { /// /// | function | where the device's reading is Metal's | /// |---|---| -/// | `floor`, `ceil` | no device measured | +/// | `floor`, `ceil` | the unary deviation | /// | `trunc`, `rint` | the deviation | /// | `sqrt`, `rsqrt`, `fast::rsqrt` | the deviation | /// | `dot` | the deviation | @@ -61,7 +93,7 @@ pub enum Covered { pub fn coverage(op: FloatFn) -> Option { use FloatFn as F; Some(match op { - F::Floor | F::Ceil => Covered::Never, + F::Floor | F::Ceil => Covered::Unary, F::Trunc | F::Rint | F::Sqrt diff --git a/crates/metal2vulkan/src/lower/arith/mod.rs b/crates/metal2vulkan/src/lower/arith/mod.rs index 697757d96..bbff1bd85 100644 --- a/crates/metal2vulkan/src/lower/arith/mod.rs +++ b/crates/metal2vulkan/src/lower/arith/mod.rs @@ -688,6 +688,10 @@ pub struct ArithPlan { /// reads them as Metal does ([`denormal::device_flushes`]), recorded at selection: the module /// then requires `VkProperty::MetalFloatDenormals`. pub device_denormals: bool, + /// Whether a `float` negation, absolute value, floor or ceiling leaves its `f32` denormals to + /// the device because the device reads them as Metal does ([`denormal::unary_kept`]), + /// recorded at selection: the module then requires `VkProperty::MetalUnaryDenormals`. + pub unary_denormals: bool, /// How the module rounds an `f32` to `half` ([`narrow::round`]), decided by [`finish`] from /// the profile ([`narrow::quantize_form`]): the device's conversion to 16 bits and its /// widening under the float controls that make it Metal's, else that conversion as it is @@ -1271,18 +1275,25 @@ fn note_native_nan(cx: &mut SelectCx<'_>, answer: Option) { /// Leave an operation's `f32` denormals (on `float` lanes of form `f`) to the device: where the /// device is measured to read them as Metal does and the operation is one the measured deviation -/// covers (`covered`, [`denormal::device_flushes`]), the module requires the property; elsewhere -/// they are the device's own, noted `DeviceDenormals` (as the operation's notes record it). +/// covers (`covered`: [`denormal::device_flushes`], or [`denormal::unary_kept`] for a negation, a +/// floor and a ceiling), the module requires the deviation's property; elsewhere they are the +/// device's own, noted `DeviceDenormals` (as the operation's notes record it). /// Another format leaves nothing: a `half` is held widened, never an `f32` denormal, and Metal's /// `bfloat` and `double` environments are not measured. pub(super) fn leave_denormals(cx: &mut SelectCx<'_>, f: Form, covered: denormal::Covered) { if f.float_fmt() != Some(FloatFmt::F32) { return; } - if covered == denormal::Covered::Deviation && denormal::device_flushes(cx.profile) { - cx.families.arith.device_denormals = true; - } else { - cx.precision.insert(PrecisionNote::DeviceDenormals); + match covered { + denormal::Covered::Deviation if denormal::device_flushes(cx.profile) => { + cx.families.arith.device_denormals = true; + } + denormal::Covered::Unary if denormal::unary_kept(cx.profile) => { + cx.families.arith.unary_denormals = true; + } + _ => { + cx.precision.insert(PrecisionNote::DeviceDenormals); + } } } @@ -1460,9 +1471,10 @@ fn select_in( let f = form_in(cx, *v, chunk)?; // The device's sign flip: it makes no NaN. Metal's `float` `fneg` flips the sign bit // alone, keeping a NaN's payload and a denormal, whatever the flags; Vulkan lets - // `OpFNegate` flush a denormal (`DeviceDenormals`), and states no NaN's bits, noted + // `OpFNegate` flush a denormal (`DeviceDenormals` but where the device is measured to + // keep it, [`denormal::Covered::Unary`]), and states no NaN's bits, noted // `NativeNanEncoding` where Metal answers one ([`nan::fneg_answer`]). - device_float(cx, f, true, false); + leave_denormals(cx, f, denormal::Covered::Unary); fp_env(cx, *fmf, f); let nan = f.float_fmt().and_then(nan::fneg_answer); // A `float` one's NaN is Metal's where the device's negation is measured to be @@ -1952,6 +1964,11 @@ fn select_float_fn( let arith = &mut cx.families.arith; arith.fmod_uses |= fmod; arith.device_min_max |= device_min_max(cx.profile, op, f); + // `fabs` keeps a denormal as Metal's does where the device is measured to + // ([`denormal::moves_sign`]): its notes leave it out ([`float_call_of`]). + arith.unary_denormals |= facts.unary_denormals + && denormal::moves_sign(op) + && f.float_fmt() == Some(FloatFmt::F32); } if facts.nan_moves && moves_nan(lowered.how, f) { match f.float_fmt() { @@ -2003,11 +2020,12 @@ fn call_coverage(how: FloatLowering, facts: FloatFacts) -> Option bool { f.float_fmt() == Some(FloatFmt::F32) && call_coverage(how, facts) - .is_some_and(|c| !(c == denormal::Covered::Deviation && facts.device_denormals)) + .is_some_and(|c| !c.holds(facts.device_denormals, facts.unary_denormals)) } /// Whether Metal's minimum and maximum function `op` on lanes of form `f` takes the device's @@ -2119,6 +2137,9 @@ struct FloatFacts { metal_functions: bool, /// Whether the device reads `f32` denormals as Metal does ([`denormal::device_flushes`]). device_denormals: bool, + /// Whether the device's negation, absolute value, floor and ceiling read `f32` denormals as + /// Metal's do ([`denormal::unary_kept`]). + unary_denormals: bool, /// Which NaN the device's arithmetic answers ([`nan::encoding`]). nans: NanEncoding, /// Whether Metal's minimum and maximum functions are the device's not measured to be Metal's: @@ -2136,6 +2157,7 @@ impl FloatFacts { routes: fma::routes(p), metal_functions: p.fields().float_functions == FloatFunctions::Metal, device_denormals: denormal::device_flushes(p), + unary_denormals: denormal::unary_kept(p), nans: nan::encoding(p), native_min_max: !p.takes_driver_deviation(crate::error::DriverDeviation::MetalMinMax), nan_moves: nan::moves_answered(p), @@ -2421,7 +2443,10 @@ fn float_call_of( f, metal_functions, ( - !op.metal_denormals() && denormal::coverage(op).is_none() && !fast_pi, + !op.metal_denormals() + && denormal::coverage(op).is_none() + && !fast_pi + && !(facts.unary_denormals && denormal::moves_sign(op)), !metal_nans && answer.is_none(), ), ); diff --git a/crates/metal2vulkan/src/lower/arith/tests.rs b/crates/metal2vulkan/src/lower/arith/tests.rs index fa5b8df27..a81fc7f8c 100644 --- a/crates/metal2vulkan/src/lower/arith/tests.rs +++ b/crates/metal2vulkan/src/lower/arith/tests.rs @@ -2460,6 +2460,7 @@ const KHR_FACTS: super::FloatFacts = super::FloatFacts { }, metal_functions: false, device_denormals: false, + unary_denormals: false, nans: crate::device::profile::NanEncoding::Native, native_min_max: false, nan_moves: false, @@ -2522,6 +2523,37 @@ fn precise_pow_notes_its_measured_nan_as_the_devices() { /// Class E: Metal's `float` `fneg` and `fabs` flip or clear the sign bit alone, a NaN's payload and /// a denormal kept (`nan_signbits`, `nan_signbits_fast`). The lowering takes the device's +/// `floor`, `ceil` and `fabs` on `float` leave their denormals to the device, noted +/// `DeviceDenormals`, but where the profile takes `DriverDeviation::MetalUnaryDenormals` +/// (`denormal::Covered::Unary`, `denormal::moves_sign`); `trunc` follows the other deviation +/// alone, in either mode. +#[test] +fn unary_denormals_follow_their_deviation() { + use crate::air::ir::FastMath; + use crate::pipeline::artifact::PrecisionNote; + let f = Form { + held: Held::Float(FloatFmt::F32), + lanes: 1, + }; + for unary in [false, true] { + let facts = super::FloatFacts { + unary_denormals: unary, + ..KHR_FACTS + }; + for op in [FloatFn::Floor, FloatFn::Ceil, FloatFn::Abs, FloatFn::Trunc] { + for fast in [false, true] { + let call = super::float_call(op, fast, FastMath::NONE, f, facts) + .unwrap_or_else(|| panic!("{op:?}: no float call")); + assert_eq!( + call.notes.always.contains(&PrecisionNote::DeviceDenormals), + !(unary && op != FloatFn::Trunc), + "{op:?}, fast {fast}, unary {unary}" + ); + } + } + } +} + /// `OpFNegate` and `FAbs` on every format, whose NaN is the device's: a `float` `fabs` answers /// Metal's operand NaN by none of its own, noted `NativeNanEncoding` (and a `half` one Metal's /// canonical NaN, class D), and off Metal's own functions records the device's precision and diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 102d90eed..01bfbc6d5 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -629,9 +629,10 @@ pub enum PrecisionNote { /// operation's denormals to a device not measured to read them as Metal does: `+ - *`, the /// comparisons, `fma`, `dot`, `sqrt`, `rsqrt`, `trunc`, `rint` and `ldexp` on `float` (by the /// device's products) but on a device that takes - /// the measured `DriverDeviation::MetalFloatDenormals`; and on every device the divisions and - /// the remainder, `floor`, `ceil` and `fneg`, the device's maths functions (`fast::fmod`'s - /// fused multiply-add, `fabs`, `sign` and `fract` among them), `mix` by `FMix`, `fast::sqrt` + /// the measured `DriverDeviation::MetalFloatDenormals`; `fneg`, `fabs`, `floor` and `ceil` on + /// `float` but on a device that takes the measured `DriverDeviation::MetalUnaryDenormals`; and + /// on every device the divisions and the remainder, the device's maths functions + /// (`fast::fmod`'s fused multiply-add, `sign` and `fract` among them), `mix` by `FMix`, `fast::sqrt` /// by `Sqrt`, `dot` of vectors of other than two to four lanes, whose chunks' products the /// device sums where Metal flushes each one below `2^-126`, beside their own notes, and a /// conversion to or from `double`, whose reading Metal's is not measured. The operations that diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 96b28f687..eb98d0f73 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -2860,6 +2860,13 @@ fn compile_kept( .properties .insert(crate::device::requirements::VkProperty::MetalFloatDenormals); } + // The negations, absolute values, floors and ceilings whose `float` denormals the device + // reads as Metal does. + if plan.families.arith.unary_denormals { + requirements + .properties + .insert(crate::device::requirements::VkProperty::MetalUnaryDenormals); + } // Center varyings read as they are as their pixel form, because the device reads them at // the pixel center as Metal does. if plan.families.stage_io.center_varyings_by_device { diff --git a/crates/metal2vulkan/src/tests/engine_arith.rs b/crates/metal2vulkan/src/tests/engine_arith.rs index fc7894587..daaebb032 100644 --- a/crates/metal2vulkan/src/tests/engine_arith.rs +++ b/crates/metal2vulkan/src/tests/engine_arith.rs @@ -4085,8 +4085,10 @@ fn half_conversions_are_metals_where_measured() { /// answers `0x7FFFFFFF`, RADV and ANV flush a denormal): no NaN is selected and nothing moves on /// the bits, the NaN noted `NativeNanEncoding` but where the device's are measured to be Metal's /// (`DriverDeviation::MetalNanMoves`, on `moltenvk-m3`), where the module requires that, and -/// `fneg`'s denormal `DeviceDenormals`. The interpreter keeps the payload and the denormal, as a -/// device may. +/// `fneg`'s denormal `DeviceDenormals` but where the device keeps it as Metal does +/// (`DriverDeviation::MetalUnaryDenormals`, on `moltenvk-m3`), where the module requires that and +/// `fabs` records no `DeviceDenormals` either. The interpreter keeps the payload and the +/// denormal, as a device may. #[test] fn float_sign_operations_are_the_devices_on_every_profile() { let snan = ob("x", 0x7F80_0001); @@ -4185,11 +4187,25 @@ fn float_sign_operations_are_the_devices_on_every_profile() { "{what}" ); } - if neg { - assert!( - a.precision.contains(&PrecisionNote::DeviceDenormals), - "{what}: {:?}", - a.precision + // A denormal is the device's but where it is measured to keep it as Metal does + // (`DriverDeviation::MetalUnaryDenormals`), which the module then requires. + if neg || abs { + let unary = + p.takes_driver_deviation(crate::error::DriverDeviation::MetalUnaryDenormals); + if neg || unary { + assert_eq!( + a.precision.contains(&PrecisionNote::DeviceDenormals), + !unary, + "{what}: {:?}", + a.precision + ); + } + assert_eq!( + a.requirements + .properties + .contains(&crate::device::requirements::VkProperty::MetalUnaryDenormals), + unary, + "{what}" ); } let got = interpret(&bitcode, kk.name, &p); diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 691eb7012..073833d48 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -13152,6 +13152,7 @@ variant metal2vulkan::device::VkProperty::MetalPackConversions MetalPackConversi variant metal2vulkan::device::VkProperty::MetalSampler MetalSampler variant metal2vulkan::device::VkProperty::MetalSmallFloatColorWrites MetalSmallFloatColorWrites variant metal2vulkan::device::VkProperty::MetalSmallFloatNans MetalSmallFloatNans +variant metal2vulkan::device::VkProperty::MetalUnaryDenormals MetalUnaryDenormals variant metal2vulkan::device::VkProperty::MetalVertexSimdgroups MetalVertexSimdgroups variant metal2vulkan::device::VkProperty::ProvokingVertexModePerPipeline ProvokingVertexModePerPipeline variant metal2vulkan::device::VkProperty::RequiredSubgroupSizeStage RequiredSubgroupSizeStage(Stage) @@ -13326,6 +13327,7 @@ variant metal2vulkan::error::DriverDeviation::MetalPackConversions MetalPackConv variant metal2vulkan::error::DriverDeviation::MetalSampler MetalSampler variant metal2vulkan::error::DriverDeviation::MetalSmallFloatColorWrites MetalSmallFloatColorWrites variant metal2vulkan::error::DriverDeviation::MetalSmallFloatNans MetalSmallFloatNans +variant metal2vulkan::error::DriverDeviation::MetalUnaryDenormals MetalUnaryDenormals variant metal2vulkan::error::DriverDeviation::MetalVertexSimdgroups MetalVertexSimdgroups variant metal2vulkan::error::DriverDeviation::SampleFragCoordDepth SampleFragCoordDepth variant metal2vulkan::error::DriverDeviation::SimdgroupLockstep SimdgroupLockstep diff --git a/docs/API.md b/docs/API.md index 85329f8f6..5f524b280 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3012,9 +3012,11 @@ bound. measured to read them as Metal does: `+ - *`, the comparisons, `fma`, `dot`, `sqrt`, `rsqrt`, `trunc`, `rint` and `ldexp` on `float` (by the device's products) but on a device that takes the measured - `DriverDeviation::MetalFloatDenormals`; and on every device the divisions and the remainder, - `floor`, `ceil` and `fneg`, the device's maths functions (`fast::fmod`'s fused multiply-add, - `fabs`, `sign` and `fract` among them), `mix` by `FMix`, `fast::sqrt` by `Sqrt`, `dot` of + `DriverDeviation::MetalFloatDenormals`; `fneg`, `fabs`, `floor` and `ceil` on `float` but on a + device that takes the measured `DriverDeviation::MetalUnaryDenormals` (MoltenVK on the Apple M3 + Max's macOS 27 identity, whose module then requires `VkProperty::MetalUnaryDenormals`); and on + every device the divisions and the remainder, the device's maths functions (`fast::fmod`'s fused + multiply-add, `sign` and `fract` among them), `mix` by `FMix`, `fast::sqrt` by `Sqrt`, `dot` of vectors of other than two to four lanes, whose chunks' products the device sums where Metal flushes each one below `2^-126`, and a conversion to or from `double`, where Metal's reading is not measured. The operations that read a denormal on its bits answer Metal on every device: diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index d045f8357..98635f62d 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -61,7 +61,7 @@ known. The rest of the differences are docs/API.md section 9's precision notes. | Fast-math sums, differences and products group, and a multiply contracts into an addition, as the device's compiler groups and fuses them, on every device, MoltenVK included: each operation is emitted in the AIR's order, one carrying both `contract` and `reassoc` undecorated and any other `NoContraction`. Metal's compiler takes its own grouping (its rank order of a sum's leaves, its pairing of a product's lane-uniform factors) and its own fusion pairs. | The device's grouping is the contract: what the AIR's flags allow, the device's compiler chooses; nothing reproduces Metal's choice. | Unbounded relative to the result where a sum of mixed signs is grouped otherwise, or a multiply-add is fused on one side alone; each operation kept apart is exact as written. `FastMathRewrites` (`fast-math-rewrites`) | | `air.pack` and `air.unpack` of a normalized format are the device's conversion: `GLSL.std.450`'s `Pack`/`Unpack` `Unorm4x8`, `Snorm4x8`, `Unorm2x16` and `Snorm2x16`, and for `rgb10a2` and `rgb565` their definition by the device's `NClamp`, multiply, `RoundEven` (a pack) and multiply by the reciprocal (an unpack); `unorm4x8_srgb`'s colour is the MSL transfer functions by the device's `Pow` around the 8-bit instruction, as is an 8-bit sRGB storage texture's write through its UNORM alias. A `float` one of the four named formats on MoltenVK reaches Metal's own; on MoltenVK on the Apple M3 Max's macOS 27 identity (`DriverDeviation::MetalPackConversions`) so do `rgb565` in `float` and, in `half`, `unorm4x8`, `snorm4x8`, `rgb10a2` and `rgb565` both ways and `unorm2x16` and `snorm2x16` packed, measured to answer Metal's at every code and every `half` (`runtime_lane::pack_conversions`). The same conversions serve an implicit imageblock access of a normalized attachment (a `half` load rounding the unpacked `float` once more), the interlocked storage form's 8-bit sRGB attachment and sRGB word, and a snapshot's normalized codes (`c` times the `f32` nearest `1/D`). So does every conversion of an extended-range, padded 10-bit or bfloat texel, which no Vulkan format holds (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12`, their sRGB twins, `RGB10A2Unorm_sRGB`, the bfloat formats; every device): a read `float(c - 384)` (a padded code's `float(c)`) times the `f32` nearest `1/510` (`1/1023`), a write `RoundEven` of the clamped value's `f32` product plus 384, an sRGB twin's colour the MSL transfer by the device's `Pow` on the magnitude, a `half` result the device's narrowing, a bfloat NaN as it is. | The device's conversion is the contract. | A packed code within one of Metal's, apart only where `clamp(c)·scale` lies within its rounding of a half-integer (`Round`'s tie is the device's); an unpacked value within 2.5 ulp of the correctly rounded quotient; a decoded sRGB colour within half a twelve-bit step (`1/8190`) of Metal's table step `k/4095`, beyond its `Pow`'s bound; a NaN channel's code the device's (Metal's: 0). An extended-range or padded value within one `f32` ulp of Metal's quotient, a code within one of Metal's exact product, an sRGB twin's decoded value within half a `2^-13` step of Metal's table (`R10Unorm_X6_sRGB`'s and `RGB10A2Unorm_sRGB`'s colour 1.64 steps) and its code within one (theirs within two below `0.0031308`, where Metal rounds the value to `2^-13` before its table), a `half` result within one `half` ulp (Metal rounds ties away from zero, a bfloat sample's `half` toward zero), a bfloat NaN the device's (Metal's: `0x7fc00000`, a write `0x7fc0`). `DevicePackConversion` (`device-pack-conversion`) | | Off MoltenVK a `float` multiply, a fused multiply-add by `OpFmaKHR`, and a `float` `ldexp` (whose result below `2^-126` is that multiply's product) round before Metal's flush: Metal flushes a result whose exact value lies below `2^-126` before rounding it, so a result whose exact value lies within half a unit below `2^-126` answers `2^-126` of its sign where Metal answers the zero of its sign. | Every device measured off MoltenVK (RADV, ANV, NVIDIA, lavapipe) rounds first; its multiply is the contract. | Announced once per device as it is made: `float-tininess-after-rounding` | -| `f32` denormals in a `float` operation on a device not measured to read them as Metal does (`DriverDeviation::MetalFloatDenormals`: lavapipe, and every unmeasured device), in `floor`, `ceil` and `fneg` on every device (a nearest pixel sample's texel `floor(x)` among them, which Metal's sampler reads from a subnormal `x` itself, a negative one as texel -1, where MoltenVK's `floor` reads it as the zero of its sign: recorded only where the `s` or `t` mode is repeat, clamp to zero or clamp to the border, which read texel -1 apart from texel 0, through a constexpr sampler of such a mode, through a runtime slot under a pipeline made for a nearest pixel state and announced where the bound state's mode is such, through an argument buffer as `argument-pixel-sampler-scaling`), in the maths functions (`fabs`, `sign` and `fract` among them, and the zero and sign tests of `pow`, `powr` and `atan2`) and the device's order of the rows above, and in a conversion to or from `double`. Metal reads them as zero and flushes a denormal result. | The device's reading is the contract: Vulkan lets each device keep or flush them, and Metal runs no `double`, so its reading of a conversion is not measured. | `DeviceDenormals` (`device-denormals`) | +| `f32` denormals in a `float` operation on a device not measured to read them as Metal does (`DriverDeviation::MetalFloatDenormals`: lavapipe, and every unmeasured device), in `floor`, `ceil`, `fneg` and `fabs` on a device not measured to read them as Metal's do (`DriverDeviation::MetalUnaryDenormals`: every device but MoltenVK on the Apple M3 Max's macOS 27 identity), and on every device in a nearest pixel sample's texel `floor(x)` (which Metal's sampler reads from a subnormal `x` itself, a negative one as texel -1, where MoltenVK's `floor` reads it as the zero of its sign: recorded only where the `s` or `t` mode is repeat, clamp to zero or clamp to the border, which read texel -1 apart from texel 0, through a constexpr sampler of such a mode, through a runtime slot under a pipeline made for a nearest pixel state and announced where the bound state's mode is such, through an argument buffer as `argument-pixel-sampler-scaling`), in the maths functions (`sign` and `fract` among them, and the zero and sign tests of `pow`, `powr` and `atan2`) and the device's order of the rows above, and in a conversion to or from `double`. Metal reads them as zero and flushes a denormal result. | The device's reading is the contract: Vulkan lets each device keep or flush them, and Metal runs no `double`, so its reading of a conversion is not measured. | `DeviceDenormals` (`device-denormals`) | | Samples, gathers, depth comparisons and level queries are the device's own sampler's on every device whose sampler is not Metal's (every device but MoltenVK): its filter, footprint, level, anisotropy, sRGB decode and comparison, its level clamp (the descriptor's as given, which Metal holds on a `1/64` grid) and its reading of a subnormal coordinate (which Metal reads as the zero of its sign before addressing). A sample's or gather's residency on a device with `shaderResourceResidency` is the device's `OpImageSparse*` word and non-resident value (`SparseResidency`); Metal's footprint rule answers it only where the device has no residency and the slot's tile map does. A two-plane YCbCr texture's linear sample is the device's filter of its texels (the device's own Y′CbCr conversion's where it converts the format, next row; Metal's reads exactly elsewhere); where the device's memory is the host's, a sample that reads the planes in place is Metal's filter exactly. An 8-bit sRGB format the device cannot sample (`R8_SRGB` on lavapipe, `R8G8_SRGB` on lavapipe, ANV and NVIDIA) is held as its UNORM twin, the device lacking its decode: a read, a sample, a fetch, a gather and a bicubic tap decode what the twin's view reads (one texel's codes, or the device's filter of them) by the MSL transfer through the device's `Pow`. | The device's sampler is the contract. | Linear filter within one code (1/255) on the measured devices, sRGB within 1.83, a two-plane YCbCr texture's within 1.183; levels, anisotropy, cubes, 3D, gathers and comparisons unmeasured. A twin's texel: the transfer within the device's `Pow` (MoltenVK's within 1.83e-7 through a storage alias, `runtime_lane::srgb_storage`) where Metal's table rounds it to a twelve-bit step (up to 1/8190 apart); a filtered sample decodes the filtered codes, up to 0.286 off for a blend of codes 0 and 255 (`SrgbTexelDecode`). `DeviceSampling` (`device-sampling`) | | A pixel-coordinate sampler's linear sample, gather, comparison and level query is the device's normalized sampler's at the coordinate divided by the texture's level-0 size in the shader, on every device, MoltenVK included, where no other form takes it: through a runtime sampler slot or an argument buffer's sampler, whose state the function does not know, and through a constexpr one of an array, a 3D texture or a texture whose residency the function observes. The device reads its texels and weights from that coordinate in its own arithmetic, where Metal's sampler reads the coordinate as given on its own sub-texel grid. A constexpr pixel sampler's sample or gather of a 1D or 2D texture that is no array hands the coordinate itself, moved by its offset, to the device's unnormalized sampler at level 0 (a nearest sample with an offset its texel's centre `floor(x) + 0.5 + k`), which reads it as Metal's does on MoltenVK; a nearest sample elsewhere hands the device's normalized sampler its texel's centre `floor(x) + 0.5` over the size, where the device reads exactly Metal's texel `floor(x)` (a runtime slot's behind its `NearestPixelSampler` specialization, an argument buffer's by its state's word); a constexpr sampler that filters nearest and clamps to the edge fetches its texel (`sampler.pixel_fetch`). | The device's sampler is the contract. Vulkan's unnormalized samplers take no offset operand, comparison, array, 3D image, mip level or anisotropy, and a runtime or argument buffer's state is not known when the function is made, so the shader scales the coordinate there; no path reproduces Metal's sub-texel grid. | The device answers as its normalized sampler at a coordinate within one `f32` ulp of the quotient on MoltenVK (10 of 800 cells of each mirror-clamp linear configuration move by it) and at the quotient itself on lavapipe (`runtime_lane::pixel_samplers`: 800 coordinates at and around each texel edge of a 5x3 texture, every filter and address mode); on MoltenVK a linear sample through a runtime or argument buffer's sampler, or of an array, reads another weight step than Metal's at under 1% of the coordinates at and around each texel edge of textures 258, 21 and 37 texels wide, where `x - 0.5` lies at a half step of Metal's `1/256` grid (`runtime_lane::pixel_edges`); a linear downscale by 8 of textures 1000 to 1920 texels wide within 1/255 of Metal's on MoltenVK and 2/255 on lavapipe (`runtime_lane::pixel_downscales`); other devices unmeasured. Every nearest access of those edge probes reads Metal's texel on MoltenVK and on lavapipe, and every constexpr sample and gather of a 1D or 2D texture answers Metal's on MoltenVK (`runtime_lane::pixel_edges`); elsewhere a constexpr linear sample is the device's own filter in unnormalized coordinates (`device-sampling`), which on lavapipe differs from its normalized filter in the last bits of 79 to 107 of 800 cells of clamp to zero and to the border (`runtime_lane::pixel_samplers`). `PixelSamplerScaling` (`pixel-sampler-scaling`), `ArgumentPixelSamplerScaling` (`argument-pixel-sampler-scaling`) | | A two-plane YCbCr texture's texels are the device's own sampler Y′CbCr conversion of its planes where the device converts their format (`ycbcr_device.rs`): unpacked 8- or 10-bit codes of a 4:2:0, 4:2:2 or 4:4:4 layout over plane 0 that form one image (no chroma codes 0, no rows past the buffer; a 4:4:4 layout read as codes aside, whose identity conversion converts nothing), on a device that enables `samplerYcbcrConversion` (a 4:4:4 layout also needs Vulkan 1.3 or `VK_EXT_ycbcr_2plane_444_formats`), reports the multi-planar format's conversion and, for a 4:2:0 or 4:2:2 layout, Metal's reconstruction (midpoint chroma through a linear chroma filter), and has no defect in the format; the planes are copied into an image of it and sampled once per texel into the texture's image (`bind::ycbcr_sample_module`), through the refresh's indirect arguments. The conversion takes the surface's matrix and range (the identity model for the code-reading formats), and Metal's reconstruction of a subsampled layout; a device's cosited or nearest reconstruction would move what the codes mean to Metal (cosited, up to 1340/2048 of random planes on lavapipe), a capability it lacks, so such a layout converts through Metal's arithmetic. A render pass's load stays Metal's arithmetic, which our store inverts, so a loaded texel no draw changes keeps its codes, as `MTLLoadActionLoad` keeps the attachment's contents. lavapipe (Mesa 26.0.8) converts the 8-bit 4:4:4 layout (its 4:2:0 and 4:2:2 ones are cosited only, and it reads 10-bit codes as 16-bit words, `RuntimeDriverDefect::TenBitCodesReadAsWords`); MoltenVK 1.4.2 converts none (its 4:2:0 and 4:2:2 reconstruction is misplaced, `RuntimeDriverDefect::TwoPlaneChromaMisplaced`, and it reports no 4:4:4 two-plane format). RADV (Mesa 26.2.4) reads 10-bit codes as 16-bit words too (measured on a linear image of the 4:2:0 format on the Radeon 780M), so its 10-bit layouts convert through Metal's arithmetic; so do NVIDIA's (615.71.09, RTX 5080 Laptop GPU), whose conversion reads a 10-bit code's six unused low bits as its fraction, and which converts the 8-bit 4:2:0, 4:2:2 and 4:4:4 layouts. Elsewhere, and for packed codes, chroma codes 0 and plane 1, Metal's fixed-point conversion stays as capability (`WorkCounts::ycbcr_device_conversions`). | The device's conversion is the contract: Vulkan states the reconstruction's weights and the model's matrices, the precision of each step at least the format's, and the clamp of the result into `[0, 1]` the implementation's. | Each channel within 0.04/2048 of Vulkan's conversion past the `half` its image stores on lavapipe's 8-bit 4:4:4 layout, and within 0.034/2048 on NVIDIA's 8-bit layouts; of Metal's read within 6/2048 where the result lies in `[0, 1]` on lavapipe, 12.4/2048 on NVIDIA's 4:2:0 (19.1 through an `_sRGB` twin's curve; Metal rounds each reconstructed chroma to a code), and unclamped outside it; a code-reading format's codes the nearest to Vulkan's reconstruction, NVIDIA's Metal's (random planes, every texel, `tests/ycbcr_device.rs`). `YCbCrFilterNotExact` (`ycbcr-filter-not-exact`) |