diff --git a/crates/metal2vulkan-conformance/src/cases/pixel_samplers.rs b/crates/metal2vulkan-conformance/src/cases/pixel_samplers.rs index b1c249ff0..cb1255d26 100644 --- a/crates/metal2vulkan-conformance/src/cases/pixel_samplers.rs +++ b/crates/metal2vulkan-conformance/src/cases/pixel_samplers.rs @@ -23,14 +23,17 @@ //! `the_recorded_digests_are_the_m4_answers` hold the recorded M3 answers against the digests an //! Apple M4 answered: same question, two chips. //! -//! **What may differ, and what justifies it.** A `const` site hands the device's unnormalized -//! sampler the coordinate itself, and a nearest `slot` or `arg` site hands the device's normalized -//! sampler its texel's centre over the size, where the device reads exactly Metal's texel. A linear -//! `slot` or `arg` site hands it the coordinate divided by the size, which the device's sampler -//! reads in its own arithmetic: at a sub-texel step it may read the neighbouring step, which the -//! runtime announces on every device (`pixel-sampler-scaling`, and -//! `argument-pixel-sampler-scaling` for `arg`). The `slot` site announces it under a nearest -//! state too, as the function does not know the bound state. +//! **What may differ, and what justifies it.** A nearest site hands the device's normalized +//! sampler its texel's centre over the size, where the device reads exactly Metal's texel (a +//! nearest `const` site clamped to the edge fetches the texel). A linear `const` or `arg` site +//! hands it the coordinate divided by the size, which the device's sampler reads in its own +//! arithmetic: at a sub-texel step it may read the neighbouring step, which the runtime announces +//! on every device (`pixel-sampler-scaling`, and `argument-pixel-sampler-scaling` for `arg`). A +//! linear `slot` site hands the coordinate itself to the bound state's unnormalized twin at the +//! texture's level-0 element, so the device's own filter reads Metal's coordinate +//! (`device-sampling`, a native note): its weights may still be another sub-texel step than +//! Metal's, by the device's own precision. The `slot` site announces `pixel-sampler-scaling` +//! under every state, as the function does not know the bound state. //! Each notice is declared at the notices site alone, so a texel that differs still fails the case //! where it differs, and is a `known-gaps-rt.tsv` row naming the note. //! @@ -40,8 +43,9 @@ //! sign, or `-2^-126` beside them (`subnormal_grid`). A nearest `slot` or `arg` site hands the //! device its texel's centre `floor(x) + 0.5`, whose `floor` reads a subnormal by the device's //! float controls (`device-denormals`, a native note): where a negative subnormal is a texel apart -//! from zero to Metal's sampler, an address mode that reads texel -1 as texel 0 (clamp to edge, -//! mirror clamp to edge) answers alike, and clamp to zero and to the border read the border. +//! from zero to Metal's sampler (the recorded answers read texel -1 there, and texel 0 at a +//! positive subnormal), an address mode that reads texel -1 as texel 0 (clamp to edge, mirror +//! clamp to edge) answers alike, and clamp to zero and to the border read the border. //! //! Nothing here can fault a GPU: one small texture, three or four compute passes a case, no loop. //! The coordinates do reach outside the texture, which is what the address modes are for. diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 5e2d2bef8..76eed37ff 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1803,8 +1803,8 @@ once, as it is made, with no lock, and never rewritten for layouts. count, these and those of a function that asks `get_num_mip_levels` of a storage texture. - Binding 0's elements 131,072 to 196,607 are level-0 elements, and binding 2's elements 8,000 to 15,999 unnormalized twins. A sample or gather through a sampler slot whose state reads pixel - coordinates (`SamplerWord::reads_unnormalized`: nearest or linear filters alike for min and - mag, no mip filter, no anisotropy, and s and t clamped to the edge, to zero or to the border) + coordinates (`SamplerWord::reads_unnormalized`: linear filters for min and mag, no mip + filter, no anisotropy, and s and t clamped to the edge, to zero or to the border) of a 1D or 2D texture slot, with no compare (`TextureSlot::level_zero_samplers`), samples at the coordinate Metal gives, at level 0, through the state's twin at element `s + 8,000`, the same sampler with Vulkan's unnormalized coordinates, and the texture's level-0 element at diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 7a93f89ab..f26cb9cd6 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -fd0bc690352769791ffb9cdd1459945b6e28444b6429dc68c66b4f0b6ca7b100 +dfca0dd814c3e885907f41caa3a8b9d0b1d3bf267426c5c7d238d02a4c5bbefb diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index b84f7b502..cb23f4c22 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 = 2375; +pub const SEMANTICS_VERSION: u32 = 2376; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 610; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2574; +pub const RUNTIME_VERSION: u32 = 2575; /// Writes a digest as lowercase hex. pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result { diff --git a/crates/metal2vulkan/src/lower/sampler/emit.rs b/crates/metal2vulkan/src/lower/sampler/emit.rs index d95957298..3bbcf3aab 100644 --- a/crates/metal2vulkan/src/lower/sampler/emit.rs +++ b/crates/metal2vulkan/src/lower/sampler/emit.rs @@ -893,11 +893,8 @@ fn level_zero_test( let word = sampler_word(cx, fb, Pixel::Spec(n))?; let mask = k(fb, SamplerWord::UNNORMALIZED_FILTERS)?; let filters = fb.binary(BinOp::BitwiseAnd, word, mask)?; - let nearest = k(fb, SamplerWord::UNNORMALIZED_NEAREST)?; let linear = k(fb, SamplerWord::UNNORMALIZED_LINEAR)?; - let is_nearest = fb.binary(BinOp::IEqual, filters, nearest)?; - let is_linear = fb.binary(BinOp::IEqual, filters, linear)?; - let mut at = fb.binary(BinOp::LogicalOr, is_nearest, is_linear)?; + let mut at = fb.binary(BinOp::IEqual, filters, linear)?; // The `s` and `t` axes' address fields. let axes = SamplerWord::ADDRESS .into_iter() diff --git a/crates/metal2vulkan/src/lower/sampler/mod.rs b/crates/metal2vulkan/src/lower/sampler/mod.rs index 41305e971..993be3979 100644 --- a/crates/metal2vulkan/src/lower/sampler/mod.rs +++ b/crates/metal2vulkan/src/lower/sampler/mod.rs @@ -84,7 +84,14 @@ //! - Every other access is handed `x / N`, from which the device reads its texels and weights in //! its own arithmetic ([`PixelPosition::Scaled`], `PrecisionNote::PixelSamplerScaling`, //! `PrecisionNote::ArgumentPixelSamplerScaling`): a linear filter's sample or a gather through -//! any pixel sampler; a comparison's linear filter; and a level query. +//! any pixel sampler; a comparison's linear filter; and a level query. The exception is a +//! sample or gather through a runtime sampler slot of a float 1D or 2D texture that is no array +//! ([`Sampling::level_zero`]): where the bound state's word reads unnormalized (pixel +//! coordinates and linear filters, `SamplerWord::reads_unnormalized`) it hands `x` itself to +//! the state's unnormalized twin at the texture's level-0 element, and the device's own filter +//! reads Metal's coordinate (`PrecisionNote::DeviceSampling`). A nearest word keeps its texel's +//! centre above, which reads Metal's texel at a texel's edge and at a subnormal coordinate +//! where a device's unnormalized sampler handed `x` may read another. //! //! A constexpr pixel sampler with nearest filtering and clamp-to-edge addressing instead fetches //! its texel, `OpImageFetch(clamp(floor(coord) + offset))` ([`SampleOp::PixelFetch`]), which also diff --git a/crates/metal2vulkan/src/metal/sampler.rs b/crates/metal2vulkan/src/metal/sampler.rs index 720de323f..a6bbab754 100644 --- a/crates/metal2vulkan/src/metal/sampler.rs +++ b/crates/metal2vulkan/src/metal/sampler.rs @@ -981,18 +981,14 @@ impl SamplerWord { mask } - /// The bits of a sampler's filters that decide whether the device's unnormalized sampler reads - /// it ([`reads_unnormalized`](Self::reads_unnormalized)): the word masked by them is - /// [`UNNORMALIZED_NEAREST`](Self::UNNORMALIZED_NEAREST) or - /// [`UNNORMALIZED_LINEAR`](Self::UNNORMALIZED_LINEAR) exactly for one. + /// The bits of a sampler's filters that decide whether a runtime sampler slot reads it through + /// the device's unnormalized sampler ([`reads_unnormalized`](Self::reads_unnormalized)): the + /// word masked by them is [`UNNORMALIZED_LINEAR`](Self::UNNORMALIZED_LINEAR) exactly for one. pub const UNNORMALIZED_FILTERS: u32 = Self::PIXEL_COORDINATES | Self::MIN_LINEAR | Self::MAG_LINEAR | Self::MIP_FILTER | Self::ANISOTROPIC; - /// [`UNNORMALIZED_FILTERS`](Self::UNNORMALIZED_FILTERS) of a pixel sampler of nearest filters, - /// no mip filter, isotropic. - pub const UNNORMALIZED_NEAREST: u32 = Self::PIXEL_COORDINATES; /// [`UNNORMALIZED_FILTERS`](Self::UNNORMALIZED_FILTERS) of a pixel sampler of linear filters, /// no mip filter, isotropic. pub const UNNORMALIZED_LINEAR: u32 = Self::PIXEL_COORDINATES | Self::LINEAR; @@ -1001,21 +997,22 @@ impl SamplerWord { /// device's `CLAMP_TO_EDGE` and `CLAMP_TO_BORDER` are. pub const UNNORMALIZED_MODES: [u32; 3] = [0, 4, 5]; - /// Whether the device's unnormalized sampler (`VkSamplerCreateInfo::unnormalizedCoordinates`) - /// reads the sampler of this word as it is, the word's form of a descriptor's - /// `metal::sampler::unnormalized_reads`: pixel coordinates, one minification and - /// magnification filter (nearest or linear), no mip filter, no anisotropy, and on the `s` and - /// `t` axes one of [`UNNORMALIZED_MODES`](Self::UNNORMALIZED_MODES). A sample or gather + /// Whether a runtime sampler slot reads the sampler of this word through the device's + /// unnormalized sampler (`VkSamplerCreateInfo::unnormalizedCoordinates`): pixel coordinates, + /// linear minification and magnification filters, no mip filter, no anisotropy, and on the `s` + /// and `t` axes one of [`UNNORMALIZED_MODES`](Self::UNNORMALIZED_MODES), the word's form of a + /// descriptor's `metal::sampler::unnormalized_reads` of linear filters. A sample or gather /// through a runtime sampler slot whose word this holds for reads the texture's level-0 /// element through the state's unnormalized twin at the coordinate itself (docs/RESOURCE-ID.md, /// [`TextureSlot::level_zero_samplers`](crate::pipeline::TextureSlot::level_zero_samplers)). + /// A pixel sampler of nearest filters is handed its texel's centre over the size instead, + /// which reads Metal's texel at a texel's edge and at a subnormal coordinate, where a device's + /// unnormalized sampler handed the coordinate itself may read another. pub fn reads_unnormalized(self) -> bool { let filters = self.0 & Self::UNNORMALIZED_FILTERS; let mode = |axis: usize| (self.0 & Self::ADDRESS[axis]) >> Self::ADDRESS_SHIFT[axis]; - matches!( - filters, - Self::UNNORMALIZED_NEAREST | Self::UNNORMALIZED_LINEAR - ) && (0..2).all(|axis| Self::UNNORMALIZED_MODES.contains(&mode(axis))) + filters == Self::UNNORMALIZED_LINEAR + && (0..2).all(|axis| Self::UNNORMALIZED_MODES.contains(&mode(axis))) } } @@ -1048,9 +1045,10 @@ mod tests { } } - /// A word's `reads_unnormalized` is its descriptor's `unnormalized_reads`, over every - /// coordinate kind, pair of filters, mip filter, anisotropy and pair of `s` and `t` address - /// modes, with the `r` axis's mode, the border, the comparison and the reduction moved too. + /// A word's `reads_unnormalized` is its descriptor's `unnormalized_reads` of linear filters, + /// over every coordinate kind, pair of filters, mip filter, anisotropy and pair of `s` and `t` + /// address modes, with the `r` axis's mode, the border, the comparison and the reduction moved + /// too. #[test] fn a_words_unnormalized_reads_are_its_descriptors() { let mut seen = [0usize; 2]; @@ -1075,7 +1073,9 @@ mod tests { reduction_mode: SamplerReductionMode::Minimum, ..metal_default() }; - let reads = unnormalized_reads(&desc); + let reads = unnormalized_reads(&desc) + && min_filter == SamplerMinMagFilter::Linear + && mag_filter == SamplerMinMagFilter::Linear; assert_eq!( SamplerWord::of(&desc).reads_unnormalized(), reads, @@ -1089,10 +1089,8 @@ mod tests { } } } - // Each answer is met: the five pairs of filters that read as one (nearest with nearest or - // Metal's raw value 2, which filters as nearest, in either place, and linear with linear), - // three modes on each axis. - assert_eq!(seen[1], 5 * 3 * 3); + // Each answer is met: linear with linear, three modes on each axis. + assert_eq!(seen[1], 3 * 3); } /// Of the pixel samplers the device's unnormalized sampler reads, a runtime sampler slot reads diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index a9839ccef..c0d7aef1f 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -119,7 +119,6 @@ assoc-const metal2vulkan::metal::sampler::SamplerWord::REDUCTION_SHIFT pub const assoc-const metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_FILTERS pub const UNNORMALIZED_FILTERS: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_LINEAR pub const UNNORMALIZED_LINEAR: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_MODES pub const UNNORMALIZED_MODES: [u32; 3] -assoc-const metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_NEAREST pub const UNNORMALIZED_NEAREST: u32 assoc-const metal2vulkan::pipeline::AccessSet::READ pub const READ: AccessSet assoc-const metal2vulkan::pipeline::AccessSet::READ_WRITE pub const READ_WRITE: AccessSet assoc-const metal2vulkan::pipeline::AccessSet::UNUSED pub const UNUSED: AccessSet @@ -291,7 +290,6 @@ assoc-const-value metal2vulkan::metal::sampler::SamplerWord::REDUCTION_SHIFT 19 assoc-const-value metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_FILTERS Self::PIXEL_COORDINATES | Self::MIN_LINEAR | Self::MAG_LINEAR | Self::MIP_FILTER | Self::ANISOTROPIC assoc-const-value metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_LINEAR Self::PIXEL_COORDINATES | Self::LINEAR assoc-const-value metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_MODES [0, 4, 5] -assoc-const-value metal2vulkan::metal::sampler::SamplerWord::UNNORMALIZED_NEAREST Self::PIXEL_COORDINATES assoc-const-value metal2vulkan::pipeline::AccessSet::READ AccessSet assoc-const-value metal2vulkan::pipeline::AccessSet::READ_WRITE AccessSet assoc-const-value metal2vulkan::pipeline::AccessSet::UNUSED AccessSet diff --git a/docs/RESOURCE-ID.md b/docs/RESOURCE-ID.md index da52930af..bddb12cde 100644 --- a/docs/RESOURCE-ID.md +++ b/docs/RESOURCE-ID.md @@ -119,8 +119,8 @@ sample depends on them (pixel coordinates, a nearest pixel sampler). A runtime sampler slot's sample or gather of a 1D or 2D texture slot, not an array, with no compare, takes Metal's pixel coordinate itself where the bound sampler's word reads unnormalized -(`SamplerWord::reads_unnormalized`: pixel coordinates, nearest or linear filters alike for min and -mag, no mip filter, no anisotropy, and `s` and `t` clamped to the edge, to zero or to the border) +(`SamplerWord::reads_unnormalized`: pixel coordinates, linear filters for min and mag, no mip +filter, no anisotropy, and `s` and `t` clamped to the edge, to zero or to the border) and the texture's index is below 65,536. It samples at that coordinate, moved by its offset, at level 0, through element `s + 8,000` of binding 2 (`pipeline::UNNORMALIZED_TWIN_ELEMENT`), the device sampler of sampler `s`'s descriptor made with `unnormalizedCoordinates`, and element