From 6706d5b97fd6599071615b827d12be7555cffc27 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 3 Dec 2026 11:41:39 -0800 Subject: [PATCH] rt and translator: a sampler of Metal's undeclared filter 2 is made and filters as nearest MTLSamplerMinMagFilter's raw value 2 (SamplerMinMagFilter::Cubic) is declared by no SDK header, Apple page or Metal Shading Language text, and nothing a program asks tells it about the value, so it is undocumented Metal and is not emulated. Metal makes the state on every Mac measured. An Apple M3 Max filters it over a footprint wider than one texel, and a Radeon Pro 5300M and an Intel UHD Graphics 630 read the nearest texel (the conformance case's own inputs: jobs m3-max-85003 and m3-max-85004). The runtime now makes such a state and filters it as nearest on every device: no shader arm, no second pipeline, no query, no note. - rt Device::new_sampler_state no longer refuses a Cubic min or mag filter. Nothing raises Gap::CubicSampler now; the variant stays, documented so, because the consumer names it. - translator: SamplerWord::of sets no bit for a Cubic filter, so its word is the nearest filter's. SamplerWord::CUBIC (bit 30) is deleted (its one reader, the anisotropic word path, is gone on development). SamplerWord::FIELDS is now (1 << 30) - 1. unnormalized_reads compares the two filters as the device's (a Cubic filter's is NEAREST) rather than refusing Cubic. vk_sampler already made NEAREST of Cubic. - SamplerMinMagFilter::Cubic stays, because the consumer converts a guest's raw 2 to it. It is documented through regen_metal_enums.py's PRIVATE_DOCS as Metal's undeclared raw value 2, which the M3 Max filters and the x86 Macs read as nearest, and whose device sampler and word here are the nearest filter's. generated.rs is regenerated against the macOS 27.2 SDK. - docs: the runtime README's sampler line, RESOURCE-ID.md (the word's bit 30 is now 0, and the consumer makes a Cubic state as nearest), resource_words.tsv's three Cubic lines (bit 30 cleared: 0x40000000 -> 0x00000000 twice, 0x58f6ab53 -> 0x18f6ab53), and the comments in select.rs and extended.rs that said the runtime makes no cubic sampler. - reach.tsv's SamplerBicubicFilter row no longer names a runtime cubic sampler as its reach. REFUSALS.md and error/basis.rs regenerated (refusal_surface.py: Gap::CubicSampler has no raise site); api_signatures.tsv blessed (SamplerWord::CUBIC removed, FIELDS changed). - RUNTIME_VERSION: a Cubic state is made where it was refused, so it takes a bump, set at staging (left at development's 2568 here). SEMANTICS_VERSION stays, since no module's words change. runtime-sources.sha256 re-pinned. Consumer search (reims-vgpu development 1913fcbc15 and the steelbrain/* refs from the last day): Gap::CubicSampler, 2 hits (development crates/reims-vgpu-vulkan/src/rt_platform/diag.rs:3071 and :3109, a test that counts the gap's name), kept. SamplerWord::CUBIC, SamplerWord::FIELDS and SamplerMinMagFilter::Cubic by name: 0 hits. The consumer's rt_platform::state::tests::states_on_vulkan, which expects None for min_filter 2, now gets a sampler. --- crates/metal2vulkan-runtime/README.md | 9 +++--- crates/metal2vulkan-runtime/src/error.rs | 13 +++++---- crates/metal2vulkan-runtime/src/sampler.rs | 13 +++++---- .../runtime-sources.sha256 | 2 +- .../src/lower/sampler/extended.rs | 19 +++++++------ .../metal2vulkan/src/lower/sampler/select.rs | 6 ++-- crates/metal2vulkan/src/metal/generated.rs | 5 ++++ crates/metal2vulkan/src/metal/sampler.rs | 28 ++++++------------- crates/metal2vulkan/tests/api_signatures.tsv | 4 +-- crates/metal2vulkan/tests/resource_words.tsv | 6 ++-- docs/REFUSALS.md | 7 ++--- docs/RESOURCE-ID.md | 17 ++++++----- scripts/refusal-surface/reach.tsv | 2 +- .../regen-metal-enums/regen_metal_enums.py | 14 ++++++++-- 14 files changed, 74 insertions(+), 71 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 8b3f281bf..cf0005c8b 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2750,10 +2750,11 @@ made, with no lock, and never rewritten for layouts. - A state's handle holds the device; what a command buffer keeps of it does not (Teardown). Once its last handle and the last command buffer that used it are gone, its elements read the defaults again and its index is free; a device sampler no other state holds goes to the reaper. -- Anisotropy is the device's own filter (`samplerAnisotropy` is in the floor). A cubic filter is - `Gap::CubicSampler`: the runtime makes no cubic sampler, so no live sampler's resource ID carries - the sampler word's cubic bit (30), and a shader does not test an argument buffer's sampler for - it. A descriptor the translator makes no device sampler of is `Error::Translation`. +- Anisotropy is the device's own filter (`samplerAnisotropy` is in the floor). A cubic filter + (`SamplerMinMagFilter::Cubic`, Metal's undeclared raw value 2) is made and filters as nearest, an + x86 Mac's answer, where an Apple-silicon Mac filters it over a wider footprint (`docs/API.md`, + accepted differences): its device samplers and its word are the nearest filter's. A descriptor + the translator makes no device sampler of is `Error::Translation`. - A state bound with LOD clamps (`set_sampler_state_with_lod_clamps`, and the render encoder's `set_vertex_sampler_state_with_lod_clamps` and `set_fragment_sampler_state_with_lod_clamps`: Metal's `lodMinClamp:lodMaxClamp:` forms, whose range forms are loops of them) samples as Metal diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 87957d29a..bf3684bbd 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1431,11 +1431,12 @@ pub enum Gap { /// The texture's pixel format. pixel_format: PixelFormat, }, - /// A sampler state whose minification or magnification filter is cubic - /// ([`Device::new_sampler_state`](crate::Device::new_sampler_state)). + /// A sampler state whose minification or magnification filter is cubic. Not raised: + /// [`Device::new_sampler_state`](crate::Device::new_sampler_state) makes a `Cubic` filter + /// (`MTLSamplerMinMagFilterCubic`, Metal's undeclared raw value 2) and filters it as nearest. + /// The variant stays because a consumer names it. /// - /// Basis: ours (the translator's identity domains do not filter bicubically, and Vulkan's - /// cubic filter is not Metal's). + /// Basis: ours (the runtime's choice of nearest for a value Metal does not document). CubicSampler, /// [`Texture::replace_region`](crate::Texture::replace_region), /// [`Texture::get_bytes`](crate::Texture::get_bytes), a Managed texture's places or a blit @@ -3305,7 +3306,9 @@ impl fmt::Display for Gap { "a grid of {threads_per_grid:?} threads in threadgroups of {threads_per_threadgroup:?} ends in partial threadgroups, which this kernel's variant does not run" ), Gap::MemorylessTexture => f.write_str("Memoryless textures are not built"), - Gap::CubicSampler => f.write_str("cubic sampler filters are not built"), + Gap::CubicSampler => { + f.write_str("a cubic sampler filter, which the runtime makes as nearest") + } Gap::TextureBufferSwizzle { pixel_format } => write!( f, "a swizzled texture buffer of {pixel_format:?} is not built" diff --git a/crates/metal2vulkan-runtime/src/sampler.rs b/crates/metal2vulkan-runtime/src/sampler.rs index bc07c448c..d1575f419 100644 --- a/crates/metal2vulkan-runtime/src/sampler.rs +++ b/crates/metal2vulkan-runtime/src/sampler.rs @@ -25,13 +25,13 @@ use crate::arrays::{Owner, ResourceId}; use crate::counters::Gauge; use crate::device::{lock, Core, Device}; -use crate::error::{Error, Gap, Limit}; +use crate::error::{Error, Limit}; use crate::reaper::Free; use ash::vk; use metal2vulkan::bind::SamplerDescriptor; use metal2vulkan::device::DeviceProfile; use metal2vulkan::metal::sampler::{lod_clamps_read_alike, vk_sampler, SamplerUse, SamplerWord}; -use metal2vulkan::metal::{CompareFunction, SamplerMinMagFilter}; +use metal2vulkan::metal::CompareFunction; use metal2vulkan::pipeline::{CombinedSampler, PrecisionNote}; use metal2vulkan::vk::{BorderColor, SamplerAddressMode, SamplerDesc}; use std::collections::HashMap; @@ -457,8 +457,12 @@ impl Device { /// buffer not yet retired, is taken at once, as a texture's is /// ([`Device::new_texture`](crate::Device::new_texture)): the earlier one's going leaves it. /// + /// A minification or magnification filter of `Cubic` (`MTLSamplerMinMagFilterCubic`, a raw + /// value 2 the SDK headers do not declare) is made and filters as nearest, as an x86 Mac's + /// does, where an Apple-silicon Mac filters it over a wider footprint (`docs/API.md`, accepted + /// differences): its device samplers and its word are the nearest filter's. + /// /// Err: [`Refusal::IndicesNotGranted`](crate::Refusal::IndicesNotGranted); - /// [`Gap::CubicSampler`]; /// [`Error::Translation`] where the translator makes no device sampler of the descriptor; /// [`Limit::DeviceSamplers`] past the device's `maxSamplerAllocationCount`; [`Error::Vulkan`] /// where `vkCreateSampler` fails. @@ -467,9 +471,6 @@ impl Device { descriptor: &SamplerDescriptor, index: u32, ) -> Result { - if [descriptor.min_filter, descriptor.mag_filter].contains(&SamplerMinMagFilter::Cubic) { - return Err(Error::Unsupported(Gap::CubicSampler)); - } let core = self.core(); let uses = uses_of(core, descriptor)?; let samplers = take_samplers(core, &uses)?; diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 74b76fc99..4f9a87f51 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -3ce6013c34fd0d2581049bab81912a9ef3e9fe72a5f0bd79d9af5e48ae183e31 +093c7dc198ccd45d755368e098d7e97b73200b2810831c7f029c5562131d09e2 diff --git a/crates/metal2vulkan/src/lower/sampler/extended.rs b/crates/metal2vulkan/src/lower/sampler/extended.rs index 250c8879b..058a033f0 100644 --- a/crates/metal2vulkan/src/lower/sampler/extended.rs +++ b/crates/metal2vulkan/src/lower/sampler/extended.rs @@ -29,9 +29,10 @@ //! **A runtime sampler** reads its pushed resource ID's word (`PushField::SlotGuestBase`): the //! sample is linear where the word states linear minification and magnification, else nearest; the //! taps follow the word's address modes, border color, and coordinates, and its level the word's -//! mip filter (below). No check refuses a bound word that states anything else but a cubic filter -//! (below): mixed filters sample as nearest, where Metal's sample is not measured. That is an open -//! gap, which no consumer meets while the runtime makes no texture of these formats. +//! mip filter (below). No check refuses a bound word that states anything else: mixed filters +//! sample as nearest, where Metal's sample is not measured, and so does a `Cubic` filter, whose word +//! is the nearest filter's. That is an open gap, which no consumer meets while the runtime makes no +//! texture of these formats. //! //! **Levels and layers.** A sample reads the level Metal's rule reads (`level`, the rule measured //! on the other formats: the level rounded to `half`, clamped into the sampler's clamp and the @@ -96,12 +97,12 @@ //! 2 x 6 and 1 x 1, sampled at each texel's centre and at random coordinates up to 0.15 of the //! texture past its edges, 2,304 per texture, through constexpr bicubic samplers under clamp to //! edge, repeat, mirrored repeat, clamp to zero and the opaque-black and opaque-white borders, with -//! pixel coordinates, and with a constant offset under clamp to edge and repeat, and through a -//! runtime sampler whose filters are `Cubic` (a constexpr sampler of its state, as for the other -//! formats, `bicubic::cubic_state`), with `float` results and, under clamp to edge, `half` ones: -//! 3,317,760 lanes): the footprint, the weights, the addressing, a mirrored axis and a level below -//! four texels are the other formats' (`bicubic`), each tap the decoded texel or the border texel -//! through the format's channels. The sum is the device's arithmetic (`bicubic::routines::Plane`: +//! pixel coordinates, and with a constant offset under clamp to edge and repeat, and on Metal +//! through a runtime sampler whose filters are `Cubic`, with `float` results and, under clamp to +//! edge, `half` ones: 3,317,760 lanes): the footprint, the weights, the addressing, a mirrored axis +//! and a level below four texels are the other formats' (`bicubic`), each tap the decoded texel or +//! the border texel through the format's channels. The sum is the device's arithmetic +//! (`bicubic::routines::Plane`: //! the Catmull-Rom weights computed from the fraction, the decoded taps summed by its multiply and //! add, a level below four texels its `FMix` of the inner taps), clamped into the decoded values of //! the format's codes 0 and 1023 (a color lane's `(0 - 384) / 510` and `(1023 - 384) / 510`, an diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index dfee7a9fa..b813e10c3 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -1177,8 +1177,8 @@ fn select_extended( if volume && (shape.array || gather.is_some() || !measured) { return Err(refused()); } - // Metal's bicubic filter: a constexpr bicubic sampler's. The consumer makes no device sampler - // of a cubic descriptor (`docs/RESOURCE-ID.md`), so a runtime sampler's is never one. + // Metal's bicubic filter: a constexpr bicubic sampler's. A runtime sampler's is never one: a + // `Cubic` descriptor filters as nearest (`docs/RESOURCE-ID.md`). let cubic = match sampler { SamplerArg::Static(SamplerRef::Slot(_), _) => None, SamplerArg::Static(r, _) => super::bicubic::state(r)?, @@ -1452,7 +1452,7 @@ fn select_one( // fetches). let integer = texel(t, 4).is_ok_and(|(_, class)| class != TexelClass::Float); // Metal's bicubic filter: every operation through such a sampler passes its checks. A runtime - // sampler is never one (the consumer makes no device sampler of a cubic descriptor). + // sampler is never one (a `Cubic` descriptor filters as nearest). let bicubic = match stat { Some((SamplerRef::Slot(_), _)) => None, Some((r, _)) => super::bicubic::state(r)?, diff --git a/crates/metal2vulkan/src/metal/generated.rs b/crates/metal2vulkan/src/metal/generated.rs index bcc0766d8..b70c51186 100644 --- a/crates/metal2vulkan/src/metal/generated.rs +++ b/crates/metal2vulkan/src/metal/generated.rs @@ -637,6 +637,11 @@ metal_enum! { SamplerMinMagFilter = "MTLSamplerMinMagFilter" { Nearest = 0, "MTLSamplerMinMagFilterNearest"; Linear = 1, "MTLSamplerMinMagFilterLinear"; + /// + /// Not declared by the SDK headers: the raw value 2 of `minFilter` and `magFilter`. Metal + /// makes a sampler state of it; an Apple M3 Max filters through it bicubically, and a Radeon + /// Pro 5300M and an Intel UHD Graphics 630 as nearest. Its device sampler and sampler word + /// here are the nearest filter's (`docs/API.md`, accepted differences). Cubic = 2, "MTLSamplerMinMagFilterCubic"; } aliases { diff --git a/crates/metal2vulkan/src/metal/sampler.rs b/crates/metal2vulkan/src/metal/sampler.rs index a860a1262..ef2cc13c0 100644 --- a/crates/metal2vulkan/src/metal/sampler.rs +++ b/crates/metal2vulkan/src/metal/sampler.rs @@ -160,8 +160,7 @@ pub(crate) fn unnormalized_reads(desc: &SamplerDescriptor) -> bool { ) }; !desc.normalized_coordinates - && desc.min_filter == desc.mag_filter - && desc.min_filter != SamplerMinMagFilter::Cubic + && filter(desc.min_filter) == filter(desc.mag_filter) && desc.mip_filter == SamplerMipFilter::NotMipmapped && desc.max_anisotropy <= 1 && clamps(desc.s_address_mode) @@ -802,8 +801,9 @@ fn filter(f: SamplerMinMagFilter) -> vk::Filter { match f { SamplerMinMagFilter::Nearest => vk::Filter::NEAREST, SamplerMinMagFilter::Linear => vk::Filter::LINEAR, - // Vulkan's cubic filter is not Metal's bicubic one, so the sampler holds a nearest - // placeholder; a constexpr bicubic sampler's samples are fetches, which read no sampler. + // Metal's undeclared raw value 2 filters as nearest (`docs/API.md`, accepted + // differences). A constexpr bicubic sampler's state is nearest too: its samples are + // fetches, which read no sampler. SamplerMinMagFilter::Cubic => vk::Filter::NEAREST, } } @@ -853,9 +853,9 @@ pub fn compare_op(f: CompareFunction) -> vk::CompareOp { /// | 21 | [`ANISOTROPIC`](Self::ANISOTROPIC): `maxAnisotropy` is above 1 | /// | 22-25 | [`LEVEL_MIN`](Self::LEVEL_MIN): the level a nearest mip filter reads at `lodMinClamp` | /// | 26-29 | [`LEVEL_MAX`](Self::LEVEL_MAX): 15 less the level a nearest mip filter reads at `lodMaxClamp` | -/// | 30 | [`CUBIC`](Self::CUBIC): `minFilter` or `magFilter` is `Cubic` | /// -/// An address mode is `MTLSamplerAddressMode`'s value. Every other bit is 0. The LOD clamps +/// An address mode is `MTLSamplerAddressMode`'s value. A `Cubic` filter (Metal's undeclared raw +/// value 2) sets no bit: it is the nearest filter's word. Every other bit is 0. The LOD clamps /// themselves, `lodAverage`, and the anisotropy's degree are not in the word: the Vulkan sampler /// applies them; the word holds the levels a nearest mip filter reads at the clamps, which a /// nearest sample's snap needs to know the level it reads. @@ -907,13 +907,8 @@ impl SamplerWord { /// 15 less the level a nearest mip filter reads at `lodMaxClamp` (as at /// [`LEVEL_MIN`](Self::LEVEL_MIN)), so that the default clamp, which clamps nothing, is 0. pub const LEVEL_MAX: u32 = 0xf << Self::LEVEL_MAX_SHIFT; - /// The min or the mag filter is `Cubic` (`MTLSamplerMinMagFilterCubic`, raw value 2): a - /// function sampling through an argument buffer's sampler tests it where it reads the sampler's - /// table entry, and fails its command buffer where it reaches one. It is the word's highest - /// bit, so the test is `word >= CUBIC`. - pub const CUBIC: u32 = 1 << 30; /// Every bit a word may set. - pub const FIELDS: u32 = (1 << 31) - 1; + pub const FIELDS: u32 = (1 << 30) - 1; /// The bits of the filter Metal's linear rule answers: the word masked by them is /// [`LINEAR`](Self::LINEAR) exactly for a sampler whose minification and magnification filters /// are linear, without a mip filter, and isotropic. Its reduction does not decide it: a minimum @@ -951,11 +946,6 @@ impl SamplerWord { if desc.mag_filter == SamplerMinMagFilter::Linear { w |= Self::MAG_LINEAR; } - if desc.min_filter == SamplerMinMagFilter::Cubic - || desc.mag_filter == SamplerMinMagFilter::Cubic - { - w |= Self::CUBIC; - } w |= desc.mip_filter.as_raw() << Self::MIP_FILTER_SHIFT; let modes = [ desc.s_address_mode, @@ -2109,7 +2099,6 @@ mod tests { W::ANISOTROPIC, W::LEVEL_MIN, W::LEVEL_MAX, - W::CUBIC, ]; let mut union = 0; for f in fields { @@ -2183,7 +2172,7 @@ mod tests { /// holds for linear minification and magnification filters of one isotropic level, whatever /// the coordinates, addressing, border, comparison and reduction; the state an emulated /// sample reads (`SamplerWord::LINEAR_STATE`) is every field but the comparison, the - /// reduction, the level clamps and the cubic filter. + /// reduction and the level clamps. #[test] fn a_sampler_word_answers_the_linear_predicate() { use SamplerMinMagFilter as F; @@ -2226,7 +2215,6 @@ mod tests { & !SamplerWord::REDUCTION & !SamplerWord::LEVEL_MIN & !SamplerWord::LEVEL_MAX - & !SamplerWord::CUBIC ); } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index d81a069d5..72371ef73 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -100,7 +100,6 @@ assoc-const metal2vulkan::metal::sampler::SamplerWord::BORDER pub const BORDER: assoc-const metal2vulkan::metal::sampler::SamplerWord::BORDER_SHIFT pub const BORDER_SHIFT: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::COMPARE pub const COMPARE: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::COMPARE_SHIFT pub const COMPARE_SHIFT: u32 -assoc-const metal2vulkan::metal::sampler::SamplerWord::CUBIC pub const CUBIC: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::FIELDS pub const FIELDS: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::LEVEL_MAX pub const LEVEL_MAX: u32 assoc-const metal2vulkan::metal::sampler::SamplerWord::LEVEL_MAX_SHIFT pub const LEVEL_MAX_SHIFT: u32 @@ -269,8 +268,7 @@ assoc-const-value metal2vulkan::metal::sampler::SamplerWord::BORDER 0b11 <