diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 077e901c0..ad4f4285b 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -814,8 +814,10 @@ yes where the device has `sampleRateShading` (and, on MoltenVK, the portability `shaderSampleRateInterpolationFunctions`): an `interpolant` input is then read at its centroid, a sample and an offset through Vulkan's interpolation functions; without them only `interpolate_at_center` compiles. An offset is read within the device's range and on its grid -(`device-interpolation-offset`), and a draw at custom sample positions through a function that -reads at a sample is refused (`RuntimeGap::InterpolateAtSampleWithPositions`). +(`device-interpolation-offset`); on RADV a perspective interpolant read at a sample or an offset +is the driver's extrapolation from the pixel center, off by the value's curvature across the +distance (`extrapolated-interpolation`); and a draw at custom sample positions through a +function that reads at a sample is refused (`RuntimeGap::InterpolateAtSampleWithPositions`). `Device::minimum_linear_texture_alignment_for_pixel_format` (`minimumLinearTextureAlignmentForPixelFormat:`) answers, per pixel format, the alignment of a diff --git a/crates/metal2vulkan-runtime/src/capabilities.rs b/crates/metal2vulkan-runtime/src/capabilities.rs index 23ee9f22a..3ac3b6282 100644 --- a/crates/metal2vulkan-runtime/src/capabilities.rs +++ b/crates/metal2vulkan-runtime/src/capabilities.rs @@ -429,8 +429,10 @@ impl DeviceProperties { /// otherwise is refused, `Unsupported(PullModelInterpolation)`. What differs from Metal: an /// offset is read on the device's grid and within its range /// (`PrecisionNote::DeviceInterpolationOffset`), a centroid where Vulkan puts it - /// (`PrecisionNote::MultisamplePosition`), and a draw at custom sample positions through a - /// function that reads at a sample is refused + /// (`PrecisionNote::MultisamplePosition`), a perspective interpolant read at a sample or an + /// offset on RADV is the driver's extrapolation from the pixel center + /// (`PrecisionNote::ExtrapolatedInterpolation`), and a draw at custom sample positions through + /// a function that reads at a sample is refused /// ([`RuntimeGap::InterpolateAtSampleWithPositions`]). pub fn supports_pull_model_interpolation(&self) -> Result { Query::PullModelInterpolation.answer(self.pull_model_interpolation) diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index a28e4381e..24d98635d 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2477,6 +2477,7 @@ degradations! { DeviceColorConversion = "device-color-conversion"; DeviceInterpolation = "device-interpolation"; DeviceInterpolationOffset = "device-interpolation-offset"; + ExtrapolatedInterpolation = "extrapolated-interpolation"; QuadsSplitByClipping = "quads-split-by-clipping"; VertexSimdgroupGrouping = "vertex-simdgroup-grouping"; FragmentSimdgroupGrouping = "fragment-simdgroup-grouping"; diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/pull_model_interpolants.metal b/crates/metal2vulkan-validation/fixtures/public/engine/pull_model_interpolants.metal index f4a454370..742fbb066 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/pull_model_interpolants.metal +++ b/crates/metal2vulkan-validation/fixtures/public/engine/pull_model_interpolants.metal @@ -3,8 +3,9 @@ // and `interpolate_at_offset(float2)`. `pm_place` places vertex v at the clip-space position // buffer 0 holds for it and hands it buffer 1's value as every varying. Each `PmPair` function // returns what one form interpolates of a perspective and a no-perspective `float4` input, into -// color attachments 0 and 1; `pm_narrow` and `pm_half` read every form of `float2`, `float`, -// `half` and `half4` inputs. `pm_offset_after_discard` reads at an offset after a discard, where +// color attachments 0 and 1; `pm_linear` reads the no-perspective one alone, at a sample and at an +// offset; `pm_narrow` and `pm_half` read every form of `float2`, `float`, `half` and `half4` +// inputs. `pm_offset_after_discard` reads at an offset after a discard, where // some invocations of the pixel's quad may have left. `pm_selected` reads an interpolant chosen at // run time, a form the translator refuses. `pm_read_samples` reads a multisampled attachment back, // sample by sample. @@ -77,6 +78,16 @@ fragment PmPair pm_offset_sweep(PmIn in [[stage_in]], float4 position [[position return {in.p.interpolate_at_offset(offset), in.n.interpolate_at_offset(offset)}; } +struct PmLinear { + interpolant n; +}; + +// The no-perspective interpolant alone, read at a sample and at an offset. +fragment PmPair pm_linear(PmLinear in [[stage_in]], constant uint &sample [[buffer(0)]], + constant float2 &offset [[buffer(1)]]) { + return {in.n.interpolate_at_sample(sample), in.n.interpolate_at_offset(offset)}; +} + // `pm_offset`'s reads after a discard of the fragments whose offset's x is past 1. fragment PmPair pm_offset_after_discard(PmIn in [[stage_in]], constant float2 &offset [[buffer(0)]]) { if (offset.x > 1.0f) { diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index e0fd414be..346e77221 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -208,6 +208,9 @@ impl UlpTable { /// 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, so no word's difference is bounded by /// it. +/// - `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. /// - `QuadsSplitByClipping`: unbounded: a quad a clipping seam crosses runs once per piece, which /// moves a count, a ballot, or a reduction by whole lanes. /// - `VertexSimdgroupGrouping`: unbounded: a vertex function's simdgroup holds the device's group @@ -300,6 +303,7 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::FloatSampleFilter | N::QuadsCountedBeforeDiscard | N::DeviceInterpolation + | N::ExtrapolatedInterpolation | N::ComputedSampleDepth | N::QuadsSplitByClipping | N::VertexSimdgroupGrouping diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index 8c81f2544..b3b47f356 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -67,6 +67,7 @@ fn every_precision_note_has_its_table_row() { (N::ViewBaseTexelOffset, Allowance::Recorded), (N::DeviceColorConversion, Allowance::Recorded), (N::DeviceInterpolation, Allowance::Unbounded), + (N::ExtrapolatedInterpolation, Allowance::Unbounded), (N::QuadsSplitByClipping, Allowance::Unbounded), (N::VertexSimdgroupGrouping, Allowance::Unbounded), (N::FragmentSimdgroupGrouping, Allowance::Unbounded), diff --git a/crates/metal2vulkan-validation/src/runtime_lane/pull_model_interpolation.rs b/crates/metal2vulkan-validation/src/runtime_lane/pull_model_interpolation.rs index 5dce2c8d5..36bbff677 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/pull_model_interpolation.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/pull_model_interpolation.rs @@ -34,6 +34,12 @@ //! (`PrecisionNote::DeviceInterpolationOffset`), each bounded by the value's change from pixel to //! pixel in Metal's reading ([`Slopes`]). Every sample covers where Metal's covers, on every device. //! The lane's offsets lie inside the range every Vulkan device takes, so no clamp moves them. On a +//! driver that answers a perspective read at a sample or an offset with the pixel center's value +//! extrapolated along the quad's coarse derivatives +//! (`DriverWorkaround::PerspectiveReadsExtrapolated`: RADV, whose reads lie up to about 1.0 from +//! Metal's here), each such value lies within the same bound of Metal's value plus the +//! extrapolation's own error, which the lane computes from its geometry ([`extrapolation_error`]), +//! and the pipelines that read so record `PrecisionNote::ExtrapolatedInterpolation`. On a //! driver that shades a triangle it clips as several //! (`DriverWorkaround::ClippedTrianglesSplitPixelFragments`: lavapipe) a centroid read of a //! multisampled pixel is refused as a centroid varying is, and those draws are not drawn. @@ -118,15 +124,104 @@ enum Lanes { Half, } +impl Lanes { + /// Whether lane `c` of an attachment holding these lanes is a perspective input's. + fn perspective(self, c: usize) -> bool { + match self { + Lanes::Perspective | Lanes::Half => true, + Lanes::NoPerspective => false, + // `p2.xy` (perspective), `s` and `hn` (no perspective). + Lanes::Narrow => c < 2, + } + } +} + /// One draw of the lane: the name Metal's reading gives it, the fragment function, its /// attachments' format, how each attachment is read and which lanes it holds, and the fragment -/// bytes at buffers 0 and 1. +/// bytes at buffers 0 and 1; the sample index its sample reads name (`None`: each invocation's +/// own, `[[sample_id]]`), and the offset its offset reads give, from the pixel's upper-left +/// corner. struct Draw { what: String, function: &'static str, format: PixelFormat, reads: Vec<(Read, Lanes)>, bytes: Vec>, + index: Option, + offset: [f32; 2], +} + +impl Draw { + /// Where a read `read` of sample `s` at `n` samples lies from the pixel's center: a sample's + /// standard position, or the offset, less the center. + fn distance(&self, read: Read, n: u32, s: u32) -> [f64; 2] { + let from_corner = match read { + Read::Sample => { + let i = self.index.unwrap_or(s) & (n - 1); + match n { + 1 => [0.5, 0.5], + _ => FOUR_POSITIONS[i as usize], + } + } + Read::Offset => self.offset.map(f64::from), + Read::Center | Read::Centroid => [0.5, 0.5], + }; + from_corner.map(|v| v - 0.5) + } +} + +/// Vulkan's standard positions of 4 samples in a pixel, from its upper-left corner, where Metal's +/// reading reads them too. +const FOUR_POSITIONS: [[f64; 2]; 4] = [ + [0.375, 0.125], + [0.875, 0.375], + [0.125, 0.625], + [0.625, 0.875], +]; + +/// Lane `c` of the perspective interpolation of [`VALUES`] over the triangle at framebuffer +/// location `p` (pixels from the target's upper-left corner, `y` down, as Metal's viewport maps +/// [`POSITIONS`]): the vertices' values weighted by their framebuffer barycentrics over their +/// clip `w`. +fn perspective_at(p: [f64; 2], c: usize) -> f64 { + let side = SIDE as f64; + let v = POSITIONS.map(|[x, y, _, w]| { + let (x, y, w) = (f64::from(x), f64::from(y), f64::from(w)); + [(x / w + 1.0) / 2.0 * side, (1.0 - y / w) / 2.0 * side, w] + }); + let area = |a: [f64; 2], b: [f64; 2], q: [f64; 2]| { + (b[0] - a[0]) * (q[1] - a[1]) - (b[1] - a[1]) * (q[0] - a[0]) + }; + let xy = |i: usize| [v[i][0], v[i][1]]; + let whole = area(xy(0), xy(1), xy(2)); + let weights = [ + area(xy(1), xy(2), p) / whole, + area(xy(2), xy(0), p) / whole, + area(xy(0), xy(1), p) / whole, + ]; + let over_w: Vec = (0..3).map(|i| weights[i] / v[i][2]).collect(); + let sum: f64 = over_w.iter().sum(); + (0..3) + .map(|i| over_w[i] / sum * f64::from(VALUES[i][c])) + .sum() +} + +/// How far a driver that extrapolates a perspective read along the quad's coarse derivatives +/// (`DriverWorkaround::PerspectiveReadsExtrapolated`) answers from the perspective value, in lane +/// `c` of pixel `(x, y)` read at `d` from its center: `f(center) + (f(tr) - f(tl)) * d.x + +/// (f(bl) - f(tl)) * d.y`, less `f(center + d)`, each `f` the exact [`perspective_at`] and `tl`, +/// `tr`, `bl` the centers of the top-left, top-right and bottom-left pixels of the pixel's quad. +/// Of second order in `d`, so the vertices' snapping, which moves Metal's values and the +/// device's alike, leaves it within the lane's bound. +fn extrapolation_error(x: u64, y: u64, d: [f64; 2], c: usize) -> f32 { + let f = |px: f64, py: f64| perspective_at([px + 0.5, py + 0.5], c); + let (x, y) = (x as f64, y as f64); + let (qx, qy) = ((x / 2.0).floor() * 2.0, (y / 2.0).floor() * 2.0); + let tl = f(qx, qy); + let ddx = f(qx + 1.0, qy) - tl; + let ddy = f(qx, qy + 1.0) - tl; + let first_order = f(x, y) + ddx * d[0] + ddy * d[1]; + (first_order - f(x + d[0], y + d[1])) as f32 } /// `words`' little-endian bytes. @@ -148,6 +243,8 @@ fn draws(n: u32) -> Vec { format: PixelFormat::RGBA32Float, reads: pair(read), bytes: Vec::new(), + index: None, + offset: [0.5, 0.5], }; let mut out = vec![ plain("center", "pm_center", Read::Center), @@ -156,6 +253,7 @@ fn draws(n: u32) -> Vec { for i in 0..n { out.push(Draw { bytes: vec![bytes_of(&[i])], + index: Some(i), ..plain(&format!("sample {i}"), "pm_sample", Read::Sample) }); } @@ -164,6 +262,7 @@ fn draws(n: u32) -> Vec { let what = format!("offset {:08x} {:08x}", x.to_bits(), y.to_bits()); out.push(Draw { bytes: vec![bytes_of(&[x.to_bits(), y.to_bits()])], + offset: [x, y], ..plain(&what, "pm_offset", Read::Offset) }); } @@ -183,6 +282,8 @@ fn draws(n: u32) -> Vec { format: PixelFormat::RGBA32Float, reads: every(Lanes::Narrow), bytes: narrow.clone(), + index: Some(NARROW_SAMPLE), + offset: NARROW_OFFSET, }); out.push(Draw { what: "half".to_owned(), @@ -190,6 +291,8 @@ fn draws(n: u32) -> Vec { format: PixelFormat::RGBA16Float, reads: every(Lanes::Half), bytes: narrow, + index: Some(NARROW_SAMPLE), + offset: NARROW_OFFSET, }); out } @@ -549,7 +652,10 @@ fn read_single(target: &Texture, format: PixelFormat) -> Vec<[f32; 4]> { /// elsewhere, as does a pipeline of more than one sample that reads at the center where that read /// is `InterpolateAtOffset` at offset 0 (a device with the centered origin that does not read a /// center varying at the pixel center itself, `VkProperty::MetalCenterVaryings`: the NVIDIA RTX -/// 5080 Laptop). +/// 5080 Laptop). On a driver that extrapolates a perspective read at a sample or an offset +/// (`DriverWorkaround::PerspectiveReadsExtrapolated`: RADV) the pipelines that read so, and those +/// alone, record `PrecisionNote::ExtrapolatedInterpolation`, and their perspective lanes lie within +/// the bound of Metal's value plus the extrapolation's error ([`extrapolation_error`]). #[test] fn interpolants_read_metal_s_values() { let messages = Messages::default(); @@ -576,7 +682,11 @@ fn interpolants_read_metal_s_values() { && !properties.contains(&VkProperty::MetalCenterVaryings); println!( "PM {name}: MetalInterpolation {exact}, offsets from {origin:?}, center reads at the \ - pixel center by an offset {pixel_form}" + pixel center by an offset {pixel_form}, perspective reads at a sample or offset \ + extrapolated {}", + profile + .workarounds() + .contains(&DriverWorkaround::PerspectiveReadsExtrapolated) ); let reading = metal_reading(); let slopes = Slopes::of(&reading[&("center".to_owned(), 1)]); @@ -594,6 +704,9 @@ fn interpolants_read_metal_s_values() { let split = profile .workarounds() .contains(&DriverWorkaround::ClippedTrianglesSplitPixelFragments); + let extrapolates = profile + .workarounds() + .contains(&DriverWorkaround::PerspectiveReadsExtrapolated); let (mut drawn, mut refused) = (0, 0); for &n in &counts { for draw in draws(n) { @@ -627,6 +740,19 @@ fn interpolants_read_metal_s_values() { let centers = n > 1 && pixel_form && draw.reads.iter().any(|(read, _)| *read == Read::Center); assert_eq!(noted, offsets, "{name} {what}: the offset note"); + // A read at a sample or an offset of the lane's perspective inputs, which every + // such draw reads. + let beyond = (draw.reads.iter()) + .any(|(read, _)| matches!(read, Read::Sample | Read::Offset)); + let extrapolation_noted = compiled.stages.iter().any(|s| { + s.precision_notes + .contains(&PrecisionNote::ExtrapolatedInterpolation) + }); + assert_eq!( + extrapolation_noted, + extrapolates && beyond, + "{name} {what}: the extrapolation note" + ); assert_eq!( compiled.requirements.properties.contains(&origin), offsets || centers, @@ -649,12 +775,25 @@ fn interpolants_read_metal_s_values() { for c in 0..4 { let (o, m) = (f32::from_bits(ours[c]), f32::from_bits(metal[c])); most = most.max((o - m).abs()); + // Where the driver extrapolates the read, Metal's value moved by the + // extrapolation's own error. + let expected = match extrapolates + && matches!(read, Read::Sample | Read::Offset) + && lanes.perspective(c) + { + true => { + let d = draw.distance(read, n, at.2); + m + extrapolation_error(at.0, at.1, d, c) + } + false => m, + }; let agrees = match exact { true => ours[c] == metal[c], false => { let slope = slopes.of_lane(lanes, c); let range = range_of(c); - (o - m).abs() <= device_bound(m, range, read, lanes, slope, n) + let bound = device_bound(m, range, read, lanes, slope, n); + (o - expected).abs() <= bound } }; if !agrees { diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index fd4f62bd4..87d326d90 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1474,6 +1474,7 @@ codec_enum! { DeviceVertexConversion, DeviceAlphaCoverage, DeviceInterpolationOffset, + ExtrapolatedInterpolation, } BindingSource { Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler }, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 4a01e4410..f11d8bd56 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 = 1999; +pub const SEMANTICS_VERSION: u32 = 2000; /// 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 = 1999; /// 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 = 496; +pub const ARTIFACT_FORMAT_VERSION: u32 = 497; /// 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/device/driver_facts.rs b/crates/metal2vulkan/src/device/driver_facts.rs index 5a1557495..ac4467538 100644 --- a/crates/metal2vulkan/src/device/driver_facts.rs +++ b/crates/metal2vulkan/src/device/driver_facts.rs @@ -796,6 +796,12 @@ const fn moltenvk_on_apple(fact: F) -> Measured { /// nonzero offset, in control flow the helper invocations of the pixel's quad had left (a bare /// Vulkan program; the RTX 3090 and ANV answered every variant right). The row names no vendor: /// RADV runs only AMD's GPUs. +/// - `PerspectiveReadsExtrapolated`: RADV on the Radeon 780M, Mesa 26.2.6 (Arch's), answered +/// `runtime_lane::pull_model_interpolation`'s perspective reads at a sample or an offset as the +/// pixel center's value extrapolated along the quad's coarse derivatives: a model of that form, +/// from the lane's geometry, gave each of the 1113 values off Metal's within 0.005, and the +/// form with fine derivatives was up to 0.98 off. The row names no vendor: RADV runs only AMD's +/// GPUs. /// - `MeshIndexComponentStoresMisplaced`: lavapipe, Mesa 26.0.8 (Ubuntu's, x86, the Linux gate's), /// drew none of `runtime_lane::mesh_draws`'s triangles, whose indices the mesh function writes /// one at a time. The row names no vendor: the defect is the driver's @@ -847,6 +853,12 @@ pub(crate) const DEFECTS: &[Measured] = &[ vendor: None, device: None, }, + Measured { + fact: DriverWorkaround::PerspectiveReadsExtrapolated, + driver: DriverId::MESA_RADV, + vendor: None, + device: None, + }, Measured { fact: DriverWorkaround::MeshIndexComponentStoresMisplaced, driver: DriverId::MESA_LLVMPIPE, diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index 90c2909eb..2bbc9df8b 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -1286,6 +1286,23 @@ pub enum DriverWorkaround { /// loop, where the whole quad runs, and each pass reads its sample's value /// (`lower::fragment::coverage`). InterpolationNeedsTheWholeQuad, + /// The driver's `InterpolateAtSample` and `InterpolateAtOffset` of a perspective input are its + /// value at the pixel center extrapolated along the quad's coarse derivatives, + /// `f(center) + (f(tr) - f(tl)) * dx + (f(bl) - f(tl)) * dy` (`tl`, `tr`, `bl` the centers of + /// the quad's top-left, top-right and bottom-left pixels, `(dx, dy)` the read's distance from + /// the pixel center), not the perspective interpolation at that location: a first-order + /// answer, off by the input's curvature across the distance. A no-perspective input is linear + /// in the framebuffer, so its extrapolation is exact. Measured on RADV + /// (`VK_DRIVER_ID_MESA_RADV`), Mesa 26.2.6, on the Radeon 780M: of + /// `runtime_lane::pull_model_interpolation`'s values (a triangle of clip `w` 1, 2 and 4 over a + /// 6x6 target), the 52 offset reads and 1061 sample reads off Metal's were that form's, within + /// 0.005, and up to about 1.0 from Metal's in a lane whose vertices hand 3, -2 and 0.5; + /// the same reads of the no-perspective inputs were Metal's within the device's interpolation. + /// Vulkan states no precision for interpolation, so the answer is the device's own (no form + /// interpolates otherwise): a fragment function that reads a perspective input at a sample or + /// an offset there records `PrecisionNote::ExtrapolatedInterpolation` (`lower::stage_io::plan`). + /// It is keyed on the driver's release (`device::driver_facts`). + PerspectiveReadsExtrapolated, /// The driver reads a mesh shader's store into one component of a vector output (an /// `OpAccessChain` to a component of `PrimitiveLineIndicesEXT` or /// `PrimitiveTriangleIndicesEXT`) as a store into a later output slot, so the primitive keeps diff --git a/crates/metal2vulkan/src/device/tests/profile.rs b/crates/metal2vulkan/src/device/tests/profile.rs index 4ff5491a9..c9f14b089 100644 --- a/crates/metal2vulkan/src/device/tests/profile.rs +++ b/crates/metal2vulkan/src/device/tests/profile.rs @@ -723,11 +723,12 @@ fn moltenvk_on_apple_carries_the_early_tests_image_write_defect() { desc.driver_id = Some(vk::DriverId::MESA_RADV); // Every rasterizer but Apple's hands a clipped primitive's fragments other coverage than // Metal's pieces, and every tessellator but Apple's orders a patch's triangles its own way; - // RADV's own interpolation defect holds on any vendor. + // RADV's own interpolation facts hold on any vendor. assert_eq!( workarounds(&desc), [ W::InterpolationNeedsTheWholeQuad, + W::PerspectiveReadsExtrapolated, W::ClippedCoverageNotMetals, W::TessellatorNotMetals ] @@ -814,34 +815,39 @@ fn moltenvk_on_apple_carries_the_per_sample_writer_defect_at_every_release() { } } -/// `DriverWorkaround::InterpolationNeedsTheWholeQuad` is keyed on RADV by the measured table -/// (`driver_facts::DEFECTS`): carried at every release, whatever the vendor ID (the row names +/// `DriverWorkaround::InterpolationNeedsTheWholeQuad` and +/// `DriverWorkaround::PerspectiveReadsExtrapolated` are keyed on RADV by the measured table +/// (`driver_facts::DEFECTS`): each carried at every release, whatever the vendor ID (the rows name /// none), and not by another driver. #[test] -fn radv_carries_the_whole_quad_interpolation_defect_at_every_release() { +fn radv_carries_its_interpolation_facts_at_every_release() { use crate::device::profile::DriverWorkaround; - let defect = DriverWorkaround::InterpolationNeedsTheWholeQuad; - let carries = |desc: &DeviceDescription| { - Device::new(desc.clone(), DevicePolicy::default()) - .unwrap() - .profile() - .fields() - .workarounds - .contains(&defect) - }; - let mut desc = profile("amd-780m-radv"); - assert_eq!(desc.driver_id, Some(vk::DriverId::MESA_RADV)); - assert!(carries(&desc)); - desc.driver_version += 1; - assert!(carries(&desc), "at another release"); - desc.vendor_id = 0x8086; - assert!(carries(&desc), "on another vendor's ID"); - desc.driver_id = Some(vk::DriverId::INTEL_OPEN_SOURCE_MESA); - assert!(!carries(&desc), "under ANV"); - for (stem, text) in committed_profiles() { - let desc = DeviceDescription::from_khronos_json(&text, None).unwrap(); - let radv = desc.driver_id == Some(vk::DriverId::MESA_RADV); - assert_eq!(carries(&desc), radv, "{stem}"); + for fact in [ + DriverWorkaround::InterpolationNeedsTheWholeQuad, + DriverWorkaround::PerspectiveReadsExtrapolated, + ] { + let carries = |desc: &DeviceDescription| { + Device::new(desc.clone(), DevicePolicy::default()) + .unwrap() + .profile() + .fields() + .workarounds + .contains(&fact) + }; + let mut desc = profile("amd-780m-radv"); + assert_eq!(desc.driver_id, Some(vk::DriverId::MESA_RADV)); + assert!(carries(&desc), "{fact:?}"); + desc.driver_version += 1; + assert!(carries(&desc), "{fact:?} at another release"); + desc.vendor_id = 0x8086; + assert!(carries(&desc), "{fact:?} on another vendor's ID"); + desc.driver_id = Some(vk::DriverId::INTEL_OPEN_SOURCE_MESA); + assert!(!carries(&desc), "{fact:?} under ANV"); + for (stem, text) in committed_profiles() { + let desc = DeviceDescription::from_khronos_json(&text, None).unwrap(); + let radv = desc.driver_id == Some(vk::DriverId::MESA_RADV); + assert_eq!(carries(&desc), radv, "{fact:?} on {stem}"); + } } } diff --git a/crates/metal2vulkan/src/lower/fragment/coverage.rs b/crates/metal2vulkan/src/lower/fragment/coverage.rs index 85c1614ce..5cee88f86 100644 --- a/crates/metal2vulkan/src/lower/fragment/coverage.rs +++ b/crates/metal2vulkan/src/lower/fragment/coverage.rs @@ -31,7 +31,10 @@ //! (`DriverWorkaround::InterpolationNeedsTheWholeQuad`, RADV), the entry reads each //! sample-qualified varying at every sample a pipeline of the device may have before the loop, //! where the whole quad runs, into a `Private` array (`stage_io::read_at_every_sample`), and each -//! pass reads its sample's element. +//! pass reads its sample's element. That driver answers a perspective varying's read at a sample +//! with the pixel center's value extrapolated along the quad's derivatives +//! (`DriverWorkaround::PerspectiveReadsExtrapolated`), its own interpolation, which the module +//! records (`PrecisionNote::ExtrapolatedInterpolation`). //! //! Metal writes each covered sample's outputs (color, depth, stencil) from that sample's own run, //! and keeps the sample only where the run's `[[sample_mask]]` output has the sample's bit (an M3 diff --git a/crates/metal2vulkan/src/lower/fragment/interpolate.rs b/crates/metal2vulkan/src/lower/fragment/interpolate.rs index e3e671e47..385ecfdb4 100644 --- a/crates/metal2vulkan/src/lower/fragment/interpolate.rs +++ b/crates/metal2vulkan/src/lower/fragment/interpolate.rs @@ -16,6 +16,11 @@ //! rest is the device's (`PrecisionNote::DeviceInterpolationOffset`). //! - `interpolate_at_sample(i)` reads sample `i mod n` of a pipeline of `n` samples, every index //! (`stage_io::InterpolantAt::Sample`); the positions are Vulkan's standard ones. +//! - A perspective interpolant's read at a sample or an offset is, on RADV, the driver's value at +//! the pixel center extrapolated along the quad's coarse derivatives, a first-order answer +//! (`DriverWorkaround::PerspectiveReadsExtrapolated`): the device's own interpolation, which the +//! plan records (`PrecisionNote::ExtrapolatedInterpolation`, `stage_io::plan`). A +//! no-perspective one's is exact there. //! - `interpolate_at_centroid` reads the pixel's center where the primitive covers the whole pixel, //! else the location of its lowest covered sample. Vulkan's centroid is a location in the pixel //! and the primitive the device chooses: in a multisampled pipeline the compile layer notes diff --git a/crates/metal2vulkan/src/lower/stage_io/plan.rs b/crates/metal2vulkan/src/lower/stage_io/plan.rs index e246b936f..c25606458 100644 --- a/crates/metal2vulkan/src/lower/stage_io/plan.rs +++ b/crates/metal2vulkan/src/lower/stage_io/plan.rs @@ -445,6 +445,11 @@ fn interpolant(cx: &mut SelectCx<'_>, b: &ParamBinding, v: &Varying) -> Result<( perspective, }; note_device_interpolation(cx, interp); + if perspective + && (reads.contains(&InterpolateAt::Sample) || reads.contains(&InterpolateAt::Offset)) + { + note_extrapolated_read(cx); + } // The center read's pixel form, as a center varying's. let at_center = center && cx.inputs.multisampled; let by_device = at_center && device_reads_center_varyings_at_pixel(cx); @@ -732,6 +737,18 @@ pub fn param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result<(), Error> { .. } ); + // Each pass reads it through `InterpolateAtSample` at its sample. + if at_loop_sample + && matches!( + interp, + Interpolation::Smooth { + perspective: true, + .. + } + ) + { + note_extrapolated_read(cx); + } let center = cx.inputs.multisampled && matches!( interp, @@ -1785,6 +1802,24 @@ fn note_device_interpolation(cx: &mut SelectCx<'_>, interp: Interpolation) { } } +/// Records that the fragment function reads a perspective input at a sample or an offset other +/// than the pixel center (`InterpolateAtSample`, `InterpolateAtOffset`) on a device whose driver +/// answers such a read with the pixel center's value extrapolated along the quad's derivatives +/// (`DriverWorkaround::PerspectiveReadsExtrapolated`): the device's answer, which the module +/// records. The pixel-center form of a center read (`InterpolateAtOffset` at offset 0) moves +/// nothing and records nothing. +fn note_extrapolated_read(cx: &mut SelectCx<'_>) { + if cx + .profile + .fields() + .workarounds + .contains(&DriverWorkaround::PerspectiveReadsExtrapolated) + { + cx.precision + .insert(PrecisionNote::ExtrapolatedInterpolation); + } +} + /// The raw index's flat `uint` variable in direction `dir`: a vertex function's output, or the /// input of a fragment function compiled under `LoweringInputs::viewport_index_varying` or /// `LoweringInputs::render_target_array_index_varying`. Its type is fixed, so a `ushort` index on diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 1f1671aa9..891e84bf4 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2185,6 +2185,25 @@ pub enum PrecisionNote { /// Validation derives no tolerance and no explanation from it: a difference stays a /// mismatch for review. DeviceInterpolationOffset, + /// A fragment function reads a perspective input at a sample or an offset other than the + /// pixel center (`interpolate_at_sample`, `interpolate_at_offset`, or a sample-qualified + /// varying a function looping over its covered samples reads at each pass's sample: `GLSL.std.450 + /// InterpolateAtSample` or `InterpolateAtOffset`) on a device whose driver answers such a read + /// as the pixel center's value extrapolated along the quad's coarse derivatives + /// ([`DriverWorkaround::PerspectiveReadsExtrapolated`]: RADV). Metal interpolates in + /// perspective at the location itself. The extrapolation is first-order, so the read is off + /// by the input's curvature across the distance, which grows with the triangle's spread of + /// clip `w` and the distance from the quad's top-left pixel: on a triangle of `w` 1, 2 and 4 + /// over a 6x6 target, up to about 1.0 in a lane whose vertices hand 3, -2 and 0.5 (the + /// Radeon 780M, Mesa 26.2.6). A no-perspective input is linear in the framebuffer, so its + /// read is exact and records nothing. The answer is the device's own interpolation, which + /// Vulkan states no precision for; no form computes it otherwise. + /// + /// Validation derives no tolerance and no explanation from it: a difference stays a + /// mismatch for review. + /// + /// [`DriverWorkaround::PerspectiveReadsExtrapolated`]: crate::device::DriverWorkaround::PerspectiveReadsExtrapolated + ExtrapolatedInterpolation, } /// The math mode of an entry's module, which decides, on a device whose `float` functions are diff --git a/crates/metal2vulkan/src/tests/engine_coverage_loop.rs b/crates/metal2vulkan/src/tests/engine_coverage_loop.rs index edae43921..1871b1bfb 100644 --- a/crates/metal2vulkan/src/tests/engine_coverage_loop.rs +++ b/crates/metal2vulkan/src/tests/engine_coverage_loop.rs @@ -672,7 +672,10 @@ fn a_per_sample_driver_runs_the_natural_functions_as_written() { /// varying is read before the loop, at every sample a pipeline of the device may have, each by a /// constant (`coverage_loop`'s `cov_loop_varying`, and `coverage_natural`'s `nat_varying`, at 2 /// and 4 samples); everywhere else that loops it is read once, at the pass's sample, which the -/// loop computes. +/// loop computes. Each varying is perspective (`sample_perspective`), so on that driver, which +/// answers a perspective read at a sample by extrapolating from the pixel center +/// (`DriverWorkaround::PerspectiveReadsExtrapolated`), the module records +/// `PrecisionNote::ExtrapolatedInterpolation`, and nowhere else. #[test] fn where_interpolation_needs_the_whole_quad_the_varyings_are_read_before_the_loop() { let (Some(loop_lib), Some(natural_lib)) = @@ -685,6 +688,8 @@ fn where_interpolation_needs_the_whole_quad_the_varyings_are_read_before_the_loo for stem in stems() { let dev = device(&stem); let whole_quad = dev.profile().fields().workarounds.contains(&defect); + let extrapolates = (dev.profile().fields().workarounds) + .contains(&DriverWorkaround::PerspectiveReadsExtrapolated); for (lib, f) in [(&loop_lib, COV_VARYING), (&natural_lib, "nat_varying")] { for samples in [2, 4] { let what = format!("{f} at {samples} on {stem}"); @@ -699,6 +704,14 @@ fn where_interpolation_needs_the_whole_quad_the_varyings_are_read_before_the_loo continue; } let reads = interpolated_samples(words); + let extrapolation_noted = p.stages.iter().any(|m| { + m.precision_notes + .contains(&PrecisionNote::ExtrapolatedInterpolation) + }); + assert_eq!( + extrapolation_noted, extrapolates, + "{what}: the extrapolation note" + ); if whole_quad { before += 1; let every: Vec<_> = (0..most_samples(&dev)).map(Some).collect(); diff --git a/crates/metal2vulkan/src/tests/engine_pull_model.rs b/crates/metal2vulkan/src/tests/engine_pull_model.rs index 23eda5631..74a9c4954 100644 --- a/crates/metal2vulkan/src/tests/engine_pull_model.rs +++ b/crates/metal2vulkan/src/tests/engine_pull_model.rs @@ -15,6 +15,12 @@ //! range: by 7/16 on MoltenVK, whose SPIRV-Cross adds 7/16 back, requiring //! `InterpolateAtOffsetFromSevenSixteenths`; by a half elsewhere, requiring //! `InterpolateAtOffsetCentered`. The function records `PrecisionNote::DeviceInterpolationOffset`. +//! - On RADV, whose driver answers a perspective read at a sample or an offset with the pixel +//! center's value extrapolated along the quad's derivatives +//! (`DriverWorkaround::PerspectiveReadsExtrapolated`), a function that reads a perspective +//! interpolant at a sample or an offset records `PrecisionNote::ExtrapolatedInterpolation`, and +//! one that reads its no-perspective interpolants alone so (`pm_linear`), or reads only at the +//! center or the centroid, records nothing; no other profile records it. //! - On RADV (`DriverWorkaround::InterpolationNeedsTheWholeQuad`) an offset read after a discard //! is refused, where some of the quad's invocations may have left; on a driver that shades a //! triangle it clips as several (`DriverWorkaround::ClippedTrianglesSplitPixelFragments`: @@ -45,6 +51,10 @@ use crate::vk::ShaderStage; const VERTEX: &str = "pm_place"; +/// The fragment function that reads its no-perspective interpolant alone, at a sample and an +/// offset. +const LINEAR: &str = "pm_linear"; + /// `GLSL.std.450` instruction numbers. const INTERPOLATE_AT_CENTROID: u32 = 76; const INTERPOLATE_AT_SAMPLE: u32 = 77; @@ -65,7 +75,13 @@ enum At { /// Each fragment function of the fixture that compiles somewhere, its color attachments' format /// and count, and where it reads. -const FRAGMENTS: [(&str, PixelFormat, usize, &[At]); 9] = [ +const FRAGMENTS: [(&str, PixelFormat, usize, &[At]); 10] = [ + ( + LINEAR, + PixelFormat::RGBA32Float, + 2, + &[At::Sample, At::Offset], + ), ("pm_center", PixelFormat::RGBA32Float, 2, &[At::Center]), ("pm_centroid", PixelFormat::RGBA32Float, 2, &[At::Centroid]), ("pm_sample", PixelFormat::RGBA32Float, 2, &[At::Sample]), @@ -166,6 +182,7 @@ fn interpolants_read_where_their_functions_say_or_are_refused() { return; }; let mut compiled = 0usize; + let mut extrapolations = 0usize; let mut refused = Vec::new(); for stem in stems() { let dev = Device::new(description(&stem), DevicePolicy::default()).expect("device"); @@ -182,6 +199,9 @@ fn interpolants_read_where_their_functions_say_or_are_refused() { let whole_quad = fields .workarounds .contains(&DriverWorkaround::InterpolationNeedsTheWholeQuad); + let extrapolates = fields + .workarounds + .contains(&DriverWorkaround::PerspectiveReadsExtrapolated); let ends_at_seven = fields.limits.max_interpolation_offset_bits == SEVEN_SIXTEENTHS; let split = fields .workarounds @@ -269,6 +289,15 @@ fn interpolants_read_where_their_functions_say_or_are_refused() { reads_at(At::Offset), "{what}: the offset note" ); + let perspective_beyond = + fragment != LINEAR && (reads_at(At::Sample) || reads_at(At::Offset)); + let extrapolation_noted = noted(&p, PrecisionNote::ExtrapolatedInterpolation); + assert_eq!( + extrapolation_noted, + extrapolates && perspective_beyond, + "{what}: the extrapolation note" + ); + extrapolations += usize::from(extrapolation_noted); assert_eq!( p.requirements.properties.contains(&origin), reads_at(At::Offset) || (pixel_center && centered), @@ -309,6 +338,12 @@ fn interpolants_read_where_their_functions_say_or_are_refused() { .any(|r| r.starts_with("amd-780m-radv pm_offset_after_discard")), "RADV refuses an offset read after a discard: {refused:?}" ); + // pm_sample, pm_sample_id, pm_offset, pm_offset_sweep, pm_narrow and pm_half at 1 and 4 + // samples on the RADV profile. + assert!( + extrapolations >= 12, + "{extrapolations} pipelines recorded the extrapolation" + ); } /// An interpolant chosen at run time, a `select` of two interpolant handles (`pm_selected`), is diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index 19279ffcf..aa37a1f92 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -144,6 +144,7 @@ fn notes() -> Vec<(&'static str, Ledger)> { DeviceSignedZeroInfNan, DeviceInterpolation, DeviceInterpolationOffset, + ExtrapolatedInterpolation, DeviceAlphaCoverage, HalfOutputFastMathBlend, UnmeasuredFetchBlend, diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 8cda80a66..9e56d9c84 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -5421,6 +5421,7 @@ macro-member metal2vulkan-runtime::Degradation::ExtendedRangeBlendSource Extende macro-member metal2vulkan-runtime::Degradation::ExtendedRangeBlendsStoredCodes ExtendedRangeBlendsStoredCodes = "extended-range-blends-stored-codes", Precision, macro-member metal2vulkan-runtime::Degradation::ExtendedRangeFloatBlendSource ExtendedRangeFloatBlendSource = "extended-range-float-blend-source"; macro-member metal2vulkan-runtime::Degradation::ExtendedRangeResolve ExtendedRangeResolve = "extended-range-resolve", Precision, +macro-member metal2vulkan-runtime::Degradation::ExtrapolatedInterpolation ExtrapolatedInterpolation = "extrapolated-interpolation"; macro-member metal2vulkan-runtime::Degradation::F16FmaDoubleRounding F16FmaDoubleRounding = "f16-fma-double-rounding"; macro-member metal2vulkan-runtime::Degradation::F16IntConvDoubleRounding F16IntConvDoubleRounding = "f16-int-conv-double-rounding"; macro-member metal2vulkan-runtime::Degradation::FastMathRewrites FastMathRewrites = "fast-math-rewrites"; @@ -13091,6 +13092,7 @@ variant metal2vulkan::device::DriverWorkaround::LocalizedLoadsForwardedPastAtomi variant metal2vulkan::device::DriverWorkaround::MemoryWritingFragmentsRunPerSample MemoryWritingFragmentsRunPerSample variant metal2vulkan::device::DriverWorkaround::MeshIndexComponentStoresMisplaced MeshIndexComponentStoresMisplaced variant metal2vulkan::device::DriverWorkaround::NarrowMaskAfterSignedClamp NarrowMaskAfterSignedClamp +variant metal2vulkan::device::DriverWorkaround::PerspectiveReadsExtrapolated PerspectiveReadsExtrapolated variant metal2vulkan::device::DriverWorkaround::RegisterAllocatorOverflowsLargeModules RegisterAllocatorOverflowsLargeModules variant metal2vulkan::device::DriverWorkaround::TessellatorNotMetals TessellatorNotMetals variant metal2vulkan::device::DriverWorkaround::VertexGroupingNotApples VertexGroupingNotApples @@ -14230,6 +14232,7 @@ variant metal2vulkan::pipeline::PrecisionNote::DeviceVertexConversion DeviceVert variant metal2vulkan::pipeline::PrecisionNote::DiscardDropsSimdgroupStores DiscardDropsSimdgroupStores variant metal2vulkan::pipeline::PrecisionNote::ExtendedRangeBlendSource ExtendedRangeBlendSource variant metal2vulkan::pipeline::PrecisionNote::ExtendedRangeFloatBlendSource ExtendedRangeFloatBlendSource +variant metal2vulkan::pipeline::PrecisionNote::ExtrapolatedInterpolation ExtrapolatedInterpolation variant metal2vulkan::pipeline::PrecisionNote::F16FmaDoubleRounding F16FmaDoubleRounding variant metal2vulkan::pipeline::PrecisionNote::F16IntConvDoubleRounding F16IntConvDoubleRounding variant metal2vulkan::pipeline::PrecisionNote::FastMathRewrites FastMathRewrites diff --git a/docs/API.md b/docs/API.md index 3b9829f08..2bf50c223 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3790,7 +3790,9 @@ bound. `sample` or `no_perspective`, not `flat`) on a device not measured to interpolate as Metal does (`DriverDeviation::MetalInterpolation`, which MoltenVK takes: Metal interpolates there). Vulkan states no precision for interpolation, and RADV, ANV, lavapipe and NVIDIA's driver each round - most interpolated lanes otherwise than Metal, up to about `1.5e-4` apart (`3e-4` on lavapipe). + most interpolated lanes otherwise than Metal, up to about `1.5e-4` apart (`3e-4` on lavapipe) on + the probes. RADV's read of a perspective input at a sample or an offset is further off, and + records `extrapolated-interpolation`. - `metal2vulkan-degrade-device-interpolation-offset` (precision). `PrecisionNote::DeviceInterpolationOffset`: A fragment function reads an `interpolant` through `interpolate_at_offset`, which Metal evaluates at the offset as given from the pixel's upper-left @@ -3801,6 +3803,17 @@ bound. `subPixelInterpolationOffsetBits` (at least sixteenths): within the range the read lies within half a step of Metal's, past it at the range's nearer end. On MoltenVK Metal reads the offset itself, so within the range (`[-1/16, 15/16]` from the corner on the M3 Max) the read is Metal's. +- `metal2vulkan-degrade-extrapolated-interpolation` (precision). + `PrecisionNote::ExtrapolatedInterpolation`: A fragment function reads a perspective input at a + sample or an offset (`interpolate_at_sample`, `interpolate_at_offset`, or a sample-qualified + varying a function looping over its covered samples reads at each pass's sample) on RADV + (`DriverWorkaround::PerspectiveReadsExtrapolated`), whose driver answers such a read with the + value at the pixel center extrapolated along the quad's coarse derivatives, where Metal + interpolates in perspective at the location itself. The answer is first-order, off by the + value's curvature across the distance, which grows with the triangle's spread of clip `w`: on a + triangle of `w` 1, 2 and 4 over a 6x6 target, up to about 1.0 in a lane whose vertices hand 3, + -2 and 0.5 (the Radeon 780M, Mesa 26.2.6). A no-perspective input is exact there and records + nothing. It is the device's own interpolation, which Vulkan states no precision for. - `metal2vulkan-degrade-quads-split-by-clipping` (precision). `PrecisionNote::QuadsSplitByClipping`: A fragment function runs a quad or simdgroup operation on a device that shades a triangle it clips as several triangles (`DriverWorkaround::ClippedTrianglesSplitPixelFragments`): a quad a seam diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 38e82df04..d602b009d 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -80,7 +80,8 @@ known. The rest of the differences are docs/API.md section 9's precision notes. | A 32-bit float depth outside [0, 1] uploaded into a depth image, on a device without `VK_EXT_depth_range_unrestricted` (ANV on the Iris Xe of RPL-P, which stores it clamped; MoltenVK on the M3 Max, which exposes no such extension, whatever its driver keeps): a blit from a buffer, `replace_region`, a blit from a colour texture, and a heap's depth texture whose shadow copies the heap's bytes into its image: each clamps the value into [0, 1], a NaN to 1.0, before the image takes it (`replace_region` on the CPU, `bind::clamped_depth`; a blit by a dispatch of `bind::depth_clamp_module`; a heap texture's copies in, `TiledLevelMove::clamps_depth`), and a heap texture's copies back then write the clamped value, in texels no command wrote too. | Vulkan takes no such copied value without the extension (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), the device stores one clamped, and a depth image holds a depth by no other means. | `RestrictedDepthUpload` (`restricted-depth-upload`) | | A multisampled 32-bit float depth written by a blit copy from a buffer or a colour texture, or a separate depth texture's copies to and from its pass's scratch image, on a device whose depth/colour copies are missing or wrong (lavapipe, MoltenVK, NVIDIA's GA10x, a device without `VK_KHR_maintenance8`): the values its driver's fragment depth changes (MoltenVK's, NVIDIA's), or on a driver not measured may change (outside [0, 1], denormals, -0), land changed. | Vulkan writes a multisampled depth image's samples by no other means there but a clear; a driver measured to store every fragment depth unchanged (lavapipe's measured releases) is exact. | `DrawnDepthCopy` (`drawn-depth-copy`) | | Signed zeros, infinities and NaNs where the device lacks `SignedZeroInfNanPreserve` at the operation's width. | A device capability. | `DeviceSignedZeroInfNan` (`device-signed-zero-inf-nan`) | -| Every device but MoltenVK interpolates varyings by its own rounding, up to about `1.5e-4` from Metal's (`3e-4` on lavapipe). MoltenVK hands the varyings to Metal. | The exact path needs Metal's interpolation formula, which is not known. | `DeviceInterpolation` (`device-interpolation`) | +| Every device but MoltenVK interpolates varyings by its own rounding, up to about `1.5e-4` from Metal's (`3e-4` on lavapipe) on the probes. MoltenVK hands the varyings to Metal. On RADV a perspective input read at a sample or an offset is further off: the row below. | The exact path needs Metal's interpolation formula, which is not known. | `DeviceInterpolation` (`device-interpolation`) | +| On RADV, a perspective input read at a sample or an offset (`interpolate_at_sample`, `interpolate_at_offset`, and a sample-qualified varying a function looping over its covered samples reads at each pass's sample) is the driver's value at the pixel center extrapolated along the quad's coarse derivatives, a first-order answer, where Metal interpolates in perspective at the location. It is off by the value's curvature across the distance: on the pull-model lane's triangle (clip `w` 1, 2 and 4 over a 6x6 target) up to about 1.0 in a lane whose vertices hand 3, -2 and 0.5, on the Radeon 780M with Mesa 26.2.6. A no-perspective input is exact there. | The device's interpolation is the only form (Vulkan states no precision for it); computing the perspective division in the shader would replace it. | `ExtrapolatedInterpolation` (`extrapolated-interpolation`) | | `interpolate_at_offset` reads at the offset moved to the device's origin and clamped to its `[minInterpolationOffset, maxInterpolationOffset]`, which Vulkan requires, and the device rounds it to its `subPixelInterpolationOffsetBits`; Metal reads at the offset as given, from the pixel's corner, at any distance and on no grid (an Apple M3 Max). Within the range the read lies within half a grid step of Metal's (MoltenVK: Metal's, its range `[-1/16, 15/16]` from the corner); past it, at the range's nearer end. | Vulkan states the range and the grid; no exact form reads past them. | `DeviceInterpolationOffset` (`device-interpolation-offset`) | | Every device but MoltenVK on Apple's GPUs of the Apple M3 Max's macOS 27 identity covers by alpha (`alphaToCoverageEnabled`) by its own algorithm: lavapipe takes a 2x2 ordered dither at one sample too, where Metal covers a pixel there only above an alpha of 1/2, so a whole fragment is stored or dropped between a pixel's threshold and 1/2; at four samples it is Metal's but within an `f32` ulp of a threshold, one sample apart. MoltenVK hands the field to Metal. | The device's coverage is its native answer, and Vulkan specifies no algorithm for it; Metal's dither computed in the shader would emulate the device's own coverage. | `DeviceAlphaCoverage` (`device-alpha-coverage`) | | A fast-math function's `half` color into a blend: within three `half` ulps (16-bit float) or two `float` ulps (32-bit float). A fetched 16-bit float attachment's blend, computed in the pixel interlock, where Metal folds the output's own arithmetic into it or regroups it: within 2 `half` ulps at the operands' magnitude, 16 at the stored value's under cancellation; exact elsewhere. | Metal's compiler regroups the blend per pipeline, following its passes over the whole function: a form the blend state decides is Metal's only where it is measured, and a lane of the output the compiler can fold into the blend has no form at all. Two 16-bit float states are measured, and a fetched attachment's blend takes Metal's forms there; `SourceAlphaSaturated` over `OneMinusSourceAlpha` shows why the rest are not, Metal rounding the destination's product first at one and four channels and the source's at two. A device that enables `storageInputOutput16` receives the output as a 16-bit `half` (`StageIo::half_outputs`): MoltenVK 1.4.2 on the M3 Max then stores Metal's codes at every word of `half-output-blends-*` (a loaded `half4`, 21 blends into 16- and 32-bit float formats). | `HalfOutputFastMathBlend` (`half-output-fast-math-blend`) |