diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index bb09194c6..95bc9436d 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -921,6 +921,7 @@ codec_enum! { RegionBox, TexelRows(f0), ArgumentTableAddress, + ConstexprSampler(f0), } Symbol { Binding(f0), DescriptorSet(f0), Location(f0), Component(f0), SpecId(f0) } } diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 1b79e12c7..936102b33 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -61,7 +61,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 = 2160; +pub const SEMANTICS_VERSION: u32 = 2162; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -71,7 +71,7 @@ pub const SEMANTICS_VERSION: u32 = 2160; /// 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 = 530; +pub const ARTIFACT_FORMAT_VERSION: u32 = 531; /// 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/lower/push.rs b/crates/metal2vulkan/src/lower/push.rs index 9a82175e8..048edaa60 100644 --- a/crates/metal2vulkan/src/lower/push.rs +++ b/crates/metal2vulkan/src/lower/push.rs @@ -123,6 +123,8 @@ pub const fn shape(f: PushField) -> FieldShape { PushField::StorageKeptChannels => FieldShape::U32, // A specialization key's value carried as data: every such key is a `u32` or a boolean. PushField::Specialized(_) => FieldShape::U32, + // A constexpr sampler's index in its use's sampler array. + PushField::ConstexprSampler(_) => FieldShape::U32, // An in-place YCbCr texture's size, planes and conversion. PushField::YCbCrInPlace(_) => FieldShape::UVec4Array(2), // A texture's size, rows and first texel in its texel buffer view. diff --git a/crates/metal2vulkan/src/lower/sampler/emit.rs b/crates/metal2vulkan/src/lower/sampler/emit.rs index b42b3a974..be31ffdc9 100644 --- a/crates/metal2vulkan/src/lower/sampler/emit.rs +++ b/crates/metal2vulkan/src/lower/sampler/emit.rs @@ -20,6 +20,7 @@ use crate::air::ir::ValueId; use crate::lower::texture::TexelClass; use crate::memory::handles::{entry_field, EntryField}; use crate::metal::sampler::SamplerWord; +use crate::pipeline::sym::{CombinedSampler, SamplerRef}; use super::{ BiasReach, Binding, CombinedImage, CubeFootprint, Hoist, Lod, MinLevel, Offset, Pixel, @@ -1324,9 +1325,10 @@ fn sampler_id(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, n: u32) -> BRes } /// Under the identity domains, the sampled image of combined binding `key` -/// ([`super::IdentitySampling`]): the texture slot's element of its class's set-1 array and the -/// sampler slot's element of the set-1 sampler array of the use, each at the index its pushed -/// resource ID holds, uniform over the call, joined by `OpSampledImage`. +/// ([`super::IdentitySampling`]): the texture slot's element of its class's set-1 array at the +/// index its pushed resource ID holds, and the element of the set-1 sampler array of the use at +/// the index a runtime sampler slot's pushed resource ID holds, or a constexpr sampler's pushed +/// index (`PushField::ConstexprSampler`), uniform over the call, joined by `OpSampledImage`. fn identity_sampled_image( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, @@ -1335,9 +1337,6 @@ fn identity_sampled_image( let Some(i) = cx.plan.families.sampler.identity.get(&key).copied() else { return Err(cx.fail(format!("combined binding {key:?} has no identity sampling"))); }; - let crate::pipeline::sym::SamplerRef::Slot(n) = key.sampler else { - return Err(cx.fail("an identity sampling of a constexpr sampler")); - }; let slot = cx .plan .families @@ -1355,8 +1354,16 @@ fn identity_sampled_image( let base = fb.module().global_value(images)?; let p = fb.access_chain(base, &[element])?; let img = fb.load(p, MemAccess::default())?; - let id = sampler_id(cx, fb, n)?; - let element = fb.composite_extract(id, &[0])?; + let element = match key.sampler { + SamplerRef::Slot(n) => { + let id = sampler_id(cx, fb, n)?; + fb.composite_extract(id, &[0])? + } + SamplerRef::Constexpr(_) => { + let c = CombinedSampler::new(key.sampler, key.compare, i.use_.integer_texture); + cx.push_field(fb, crate::pipeline::sym::PushField::ConstexprSampler(c))? + } + }; let base = fb.module().global_value(samplers)?; let p = fb.access_chain(base, &[element])?; let sampler = fb.load(p, MemAccess::default())?; @@ -1984,13 +1991,13 @@ pub(super) fn word_pixel(s: &Sampling) -> Option { ( _, Source::Combined(super::BindingKey { - sampler: super::SamplerRef::Slot(n), + sampler: SamplerRef::Slot(n), .. }) | Source::Heap { key: super::HeapKey { - sampler: super::SamplerRef::Slot(n), + sampler: SamplerRef::Slot(n), .. }, .. diff --git a/crates/metal2vulkan/src/lower/sampler/mod.rs b/crates/metal2vulkan/src/lower/sampler/mod.rs index 4bad7c906..6d7ca1c2e 100644 --- a/crates/metal2vulkan/src/lower/sampler/mod.rs +++ b/crates/metal2vulkan/src/lower/sampler/mod.rs @@ -1401,8 +1401,14 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> { }; if crate::lower::access::identity(cx.profile) { let refused = || Unsupported::not_implemented(Feature::IdentityDomains); - if !matches!(key.sampler, SamplerRef::Slot(_)) || key.unnormalized { - return Err(refused().into()); + if key.unnormalized { + return Err(invariant( + "an identity sampling through the device's unnormalized sampler", + )); + } + if let SamplerRef::Constexpr(_) = key.sampler { + cx.push + .insert(crate::pipeline::sym::PushField::ConstexprSampler(sampler)); } let class = crate::lower::texture::identity_class(&image).ok_or_else(refused)?; identity.insert( diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index cbc86cdef..94dff61da 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -2022,8 +2022,10 @@ fn select_one( None => false, }; // A sample the exact fetch takes (its arm comes first) is no unnormalized one; its sampler's - // gather is. + // gather is. Under the identity domains the consumer makes every sampler normalized and the + // shader scales a pixel sampler's coordinates. let native = bicubic.is_none() + && !crate::lower::access::identity(cx.profile) && matches!(image, ImageRef::Slot(_)) && !crate::lower::texture::status_observed(cx, at) && match stat { diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index 3a9beb183..4d3bb3380 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1911,8 +1911,9 @@ fn identity_unsourced(f: &RuntimeFact) -> bool { } /// Under the identity domains, the plans lowered so far: a kernel that reaches memory only -/// through its buffer slots' device addresses and its textures' and runtime samplers' resource -/// IDs, with no descriptor and no state of a bound texture or sampler but its resource ID's +/// through its buffer slots' device addresses, its textures' and runtime samplers' resource IDs +/// and its constexpr samplers' pushed indices, with no descriptor and no state of a bound texture +/// or sampler but its resource ID's /// (`SlotPlan::identity_lowered`, [`identity_unsourced`]). Its fields past the push window are a /// parameter block, whose address the window holds. fn identity_admits(plan: &Plan) -> Result<(), Error> { @@ -1923,6 +1924,7 @@ fn identity_admits(plan: &Plan) -> Result<(), Error> { PushField::SlotGuestBase(_) | PushField::DispatchRegion | PushField::TextureIntegerChannels(_) + | PushField::ConstexprSampler(_) ), }); let addressed = plan @@ -1956,9 +1958,10 @@ fn identity_admits(plan: &Plan) -> Result<(), Error> { && t.heap_raw.is_empty() && !t.heap_half && t.slots.values().all(|s| s.identity_lowered()); - // Samples only of a texture slot through a runtime sampler slot (`sampler::IdentitySampling`), - // every one's word read from the sampler's resource ID: no constexpr sampler, argument - // buffer's sampler, bicubic filter or specialization of a slot's state. + // Samples only of a texture slot through a runtime sampler slot or a constexpr sampler + // (`sampler::IdentitySampling`), a runtime sampler's word read from its resource ID: no + // argument buffer's sampler, array of samplers, bicubic filter or specialization of a slot's + // state. let sampled = &plan.families.sampler; let sampling = sampled .combined diff --git a/crates/metal2vulkan/src/lower/texture/mod.rs b/crates/metal2vulkan/src/lower/texture/mod.rs index 0438afed5..40f5a214a 100644 --- a/crates/metal2vulkan/src/lower/texture/mod.rs +++ b/crates/metal2vulkan/src/lower/texture/mod.rs @@ -1851,11 +1851,16 @@ pub(crate) fn device_texels(cx: &SelectCx<'_>) -> bool { /// of the texture the slot's variant binds there (`LoweringInputs::address_maps`), `None` for /// the identity. The slot records `RuntimeFact::ConstexprSampled` with the sampler's modes, /// which puts it in the variant where the binder binds a texture whose map changes one of them. +/// Under the identity domains no binder picks a variant: `None`, with no fact, so the sampler +/// samples with its own modes. pub(crate) fn constexpr_address_map( cx: &mut SelectCx<'_>, index: u32, words: [u64; 2], ) -> Result, Error> { + if crate::lower::access::identity(cx.profile) { + return Ok(None); + } let slot = slot_of(cx, index)?.slot; let modes = crate::lower::sampler::address_modes(words) .ok_or_else(|| invariant("a constexpr sampler symbol with undecodable words"))?; diff --git a/crates/metal2vulkan/src/pipeline/link.rs b/crates/metal2vulkan/src/pipeline/link.rs index 8bf7c1531..7b538c8b6 100644 --- a/crates/metal2vulkan/src/pipeline/link.rs +++ b/crates/metal2vulkan/src/pipeline/link.rs @@ -918,12 +918,7 @@ fn immutable_sampler( } _ => return Ok(None), }; - match c.sampler { - crate::pipeline::sym::SamplerRef::Constexpr(words) => Ok(Some( - crate::lower::sampler::constexpr_desc(words, c.sampler_use(), p)?, - )), - _ => Ok(None), - } + c.constexpr_sampler(p) } /// Set each binding's `variables` (`DescriptorBinding::variables`): the most variables one of diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 73df16cd1..712c20ad7 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -567,6 +567,24 @@ impl CombinedSampler { crate::metal::sampler::SamplerUse::new(self.compare, self.integer) .with_unnormalized(self.unnormalized) } + + /// The device's sampler of a constexpr sampler in this use: the immutable sampler link bakes + /// into the binding's layout, and under the identity domains the sampler the consumer makes + /// for `PushField::ConstexprSampler`. Metal compiles a constexpr sampler into the function; + /// this is the `MTLSamplerDescriptor` of the same state through `metal::sampler::vk_sampler`, + /// with the sampler's own LOD bias as its `mipLodBias`. `None` for a runtime sampler's slot. + /// It refuses only what translation for the same profile refused first. + pub fn constexpr_sampler( + &self, + profile: &crate::device::DeviceProfile, + ) -> Result, crate::error::Error> { + match self.sampler { + SamplerRef::Constexpr(words) => { + crate::lower::sampler::constexpr_desc(words, self.sampler_use(), profile).map(Some) + } + SamplerRef::Slot(_) => Ok(None), + } + } } /// The low bits of a separate texture symbol's index that hold its texture slot; the use's rank is @@ -1070,8 +1088,8 @@ pub enum PushField { /// modulo 2^32. SlotBindOffset(SlotRef), /// Guest base address of a static-root slot. Under the identity domains, a `u64`: a buffer - /// slot's device address (its `gpuAddress` plus the bind offset), and a texture slot's - /// `gpuResourceID` (`docs/RESOURCE-ID.md`), 0 for nil. + /// slot's device address (its `gpuAddress` plus the bind offset), and a texture or sampler + /// slot's `gpuResourceID` (`docs/RESOURCE-ID.md`), 0 for nil. SlotGuestBase(SlotRef), /// Stride of a pulled vertex buffer layout. VertexBufferStride(u32), @@ -1224,6 +1242,15 @@ pub enum PushField { /// width and height, its rows in texels and its first texel in the view /// (`bind::TexelRows::words`), from the bound texture's facts (`TextureFacts::texel_rows`). TexelRows(SlotRef), + /// Under the identity domains, the sampler a sample takes through a constexpr sampler + /// (`SamplerRef::Constexpr`), used as the field's [`CombinedSampler`] states: one `u32`, the + /// index (1 to 3,999, `docs/RESOURCE-ID.md`) of the element of the set-1 sampler array of the + /// use (plain, compare, or integer texture) that holds the device's sampler + /// [`CombinedSampler::constexpr_sampler`] describes, as a runtime sampler's resource ID names + /// its element. Metal compiles a constexpr sampler into the function; the consumer makes it + /// a device sampler of its own. The use's coordinates are normalized: the function scales a + /// pixel sampler's coordinates itself. + ConstexprSampler(CombinedSampler), /// The value a draw or dispatch binds for specialization key `key`, carried as data rather /// than specialized: one `u32` holding exactly the value the binder computes for the key's /// specialization constant from the bound textures and samplers (a boolean key as 1 or 0; a diff --git a/crates/metal2vulkan/src/tests/engine_identity.rs b/crates/metal2vulkan/src/tests/engine_identity.rs index 8fec37252..b90510d1d 100644 --- a/crates/metal2vulkan/src/tests/engine_identity.rs +++ b/crates/metal2vulkan/src/tests/engine_identity.rs @@ -34,12 +34,16 @@ //! `sample_down`) takes the texture and the sampler from set 1's arrays at the indices their //! pushed resource IDs hold, the sampler from the plain array, with no descriptor, no //! specialization constant and no fact of the bound sampler; it passes L3. +//! - A kernel sampling through a constexpr sampler (the harness's `sample_up`, and the same +//! kernel through a pixel sampler) takes the sampler from the plain array at the index the +//! consumer pushes for it (`PushField::ConstexprSampler`), whose device sampler is normalized; +//! it passes L3. //! - A kernel writing integer texels to a storage slot without a format (`ic`, generated) //! saturates each lane to the channel widths the consumer pushes //! (`PushField::TextureIntegerChannels`), with no fact, on the CPU interpreter. -//! - A kernel that samples through a constexpr sampler (`engine/a2_dynamic_texel_offset`) is still -//! refused as -//! `Unsupported{IdentityDomains}`, not implemented, where the default domains compile it. +//! - A kernel that samples through a bicubic constexpr sampler (`engine/a2_bicubic_weights`) is +//! still refused as `Unsupported{IdentityDomains}`, not implemented, where the default domains +//! compile it. //! - A kernel's emulated-simdgroup variant (`engine/gsm2_simd_products`'s `simd_float_products`) //! opens every barrier of its exchanges under a branch on `1 < N`, which the default domains do //! not; on the CPU interpreter a threadgroup of one thread passes no barrier, and threadgroups of @@ -339,6 +343,141 @@ fn a_runtime_sampler_is_the_set_1_element_its_resource_id_names() { } } +/// The words of `sample_up`'s constexpr sampler (`fixtures/public/harness/workloads.ll`). +const SAMPLE_UP_WORDS: [u64; 2] = [34_901_797_601_020_489, 0]; + +/// A kernel sampling a texture slot through a constexpr sampler (`sample_up`, a 2D `float` sample +/// of normalized coordinates, and the same kernel through a pixel sampler that the default domains +/// hand the device's unnormalized sampler) takes the texture from set 1's sampled-image array at +/// the index its pushed resource ID holds and the sampler from the plain sampler array at the +/// index the consumer pushes for it (`PushField::ConstexprSampler`, a `u32`), with no descriptor +/// and no specialization constant. The field's sampler is the constexpr one in normalized +/// coordinates, whose device sampler (`CombinedSampler::constexpr_sampler`) is normalized: the +/// shader scales the linear pixel sampler's coordinate and records +/// `PrecisionNote::PixelSamplerScaling`, which the default domains do not. It passes L3 on each +/// profile. +#[test] +fn a_constexpr_sampler_is_the_set_1_element_its_pushed_index_names() { + use crate::air::abi::{AddressMode, Coordinates, Filter, MipFilter, SamplerState}; + use crate::pipeline::artifact::PrecisionNote; + use crate::pipeline::sym::{CombinedSampler, SamplerRef}; + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../metal2vulkan-validation/fixtures/public/harness/workloads.ll"); + let text = std::fs::read_to_string(path).expect("workloads.ll"); + let state = |w: [u64; 2]| format!("[2 x i64] [i64 {}, i64 {}]", w[0], w[1]); + assert_eq!(text.matches(&state(SAMPLE_UP_WORDS)).count(), 1); + let s = crate::lower::sampler::state_of(SAMPLE_UP_WORDS).expect("state"); + let pixel = crate::lower::sampler::state_words(&SamplerState { + coordinates: Coordinates::Pixel, + min_filter: Filter::Linear, + mag_filter: Filter::Linear, + mip_filter: MipFilter::None, + max_anisotropy: 1, + address_s: AddressMode::ClampToEdge, + address_t: AddressMode::ClampToEdge, + ..s + }); + let pixel_text = text.replace(&state(SAMPLE_UP_WORDS), &state(pixel)); + let (Some(normalized), Some(pixel_bc)) = ( + assemble_text("sample_up", &text), + assemble_text("sample_up_pixel", &pixel_text), + ) else { + return; + }; + let mut profiles: Vec<(String, DeviceProfile)> = PROFILES + .iter() + .map(|stem| { + let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}")); + (stem.to_string(), p) + }) + .collect(); + profiles.push(( + "moltenvk-m3 without robustImageAccess2".to_string(), + identity_without("moltenvk-m3", &[VkFeature::RobustImageAccess2]), + )); + for (bc, words) in [(&normalized, SAMPLE_UP_WORDS), (&pixel_bc, pixel)] { + for stem in PROFILES { + // The default domains read the linear pixel sampler's coordinate through the + // device's unnormalized sampler, with no note, so the identity form below scales it + // in its place. + let default = profile(stem, DevicePolicy::default()).unwrap_or_else(|e| panic!("{e}")); + let (a, plan, _) = compile_kept(bc, "sample_up", &default) + .unwrap_or_else(|e| panic!("{stem}: default domains: {e}")); + let unnormalized: Vec = (plan.families.sampler.decls.values()) + .map(|d| d.sampler.unnormalized) + .collect(); + assert_eq!(unnormalized, [words == pixel], "{stem}: default domains"); + assert!( + !a.precision.contains(&PrecisionNote::PixelSamplerScaling), + "{stem}: default domains" + ); + } + for (stem, p) in &profiles { + let (a, plan, _) = + compile_kept(bc, "sample_up", p).unwrap_or_else(|e| panic!("{stem}: {e}")); + link_and_validate(&a, p).unwrap_or_else(|e| panic!("{stem}: L3: {e}")); + assert!( + (a.interface.spec.iter()).all(|c| matches!(c.key, SpecKey::LocalSize(_))), + "{stem}: {:?}", + a.interface.spec + ); + // The sampler's own address modes: no texture's map, so no variant fact. + assert!( + !(plan.facts.iter()).any(|f| matches!(f, RuntimeFact::ConstexprSampled { .. })), + "{stem}: {:?}", + plan.facts + ); + let c = CombinedSampler::new(SamplerRef::Constexpr(words), false, false); + let mut fields: Vec<_> = (plan.push.fields.iter()) + .map(|f| f.field) + .filter(|f| *f != PushField::DispatchRegion) + .collect(); + fields.sort(); + assert_eq!( + fields, + [ + PushField::SlotGuestBase(SlotRef { + stage: Stage::Kernel, + class: SlotClass::Texture, + index: 0 + }), + PushField::SlotGuestBase(SlotRef { + stage: Stage::Kernel, + class: SlotClass::Texture, + index: 1 + }), + PushField::ConstexprSampler(c), + ], + "{stem}" + ); + let desc = (c.constexpr_sampler(p)) + .unwrap_or_else(|e| panic!("{stem}: {e}")) + .expect("a constexpr sampler"); + assert!(!desc.unnormalized, "{stem}"); + // The scaled coordinate's static note. + assert_eq!( + a.precision.contains(&PrecisionNote::PixelSamplerScaling), + words == pixel, + "{stem}" + ); + let linked = + link(&[&a], &LinkInputs::standalone(), p).unwrap_or_else(|e| panic!("{e}")); + assert!( + (linked.layout.sets.iter()) + .flat_map(|s| &s.bindings) + .all(|b| b.immutable_sampler.is_none() && b.immutable_samplers.is_empty()), + "{stem}" + ); + let mut used: Vec = (linked.table.bindings.values()) + .filter(|(set, _)| *set == 1) + .map(|(_, binding)| *binding) + .collect(); + used.sort(); + assert_eq!(used, [0, 1, 2], "{stem}"); + } + } +} + /// A kernel writing `uint4(300, 70000, 5, 2^31)` to its `texture2d` slot 0 at its /// position, over a `2 × 1` grid. fn channels_kernel() -> String { @@ -432,19 +571,19 @@ fn identity_arrays() -> Vec<(u32, vk::DescriptorType, u32)> { ] } -/// A kernel that samples a texture through a constexpr sampler is not lowered under the identity -/// domains yet. +/// A kernel that samples a texture through a bicubic constexpr sampler is not lowered under the +/// identity domains yet. #[test] -fn a_sampling_kernel_is_refused_under_the_identity_domains() { - let Some(bc) = assemble("a2_dynamic_texel_offset") else { +fn a_bicubic_kernel_is_refused_under_the_identity_domains() { + let Some(bc) = assemble("a2_bicubic_weights") else { return; }; for stem in PROFILES { let default = profile(stem, DevicePolicy::default()).unwrap_or_else(|e| panic!("{e}")); - compile(&bc, "a2_dynamic_texel_offset", &default) + compile(&bc, "a2_bicubic_weights", &default) .unwrap_or_else(|e| panic!("{stem}: default domains: {e}")); let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}")); - match compile(&bc, "a2_dynamic_texel_offset", &p) { + match compile(&bc, "a2_bicubic_weights", &p) { Err(Error::Unsupported(u)) => { assert_eq!( (u.feature, u.needs), diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index c18c10f1e..59ee880a6 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -10498,6 +10498,7 @@ method metal2vulkan::pipeline::ColorGroup::groups pub fn groups(&self) -> u32 method metal2vulkan::pipeline::ColorGroup::location pub fn location(&self, color: u32) -> u32 method metal2vulkan::pipeline::ColorGroup::of pub fn of(present: Vec, width: u32, group: u32) -> Option method metal2vulkan::pipeline::ColorGroup::width_on pub fn width_on(profile: &crate::device::DeviceProfile) -> u32 +method metal2vulkan::pipeline::CombinedSampler::constexpr_sampler pub fn constexpr_sampler(&self, profile: &crate::device::DeviceProfile) -> Result, crate::error::Error> method metal2vulkan::pipeline::CombinedSampler::from_heap_index pub fn from_heap_index(sampler: SamplerRef, index: u32) -> CombinedSampler method metal2vulkan::pipeline::CombinedSampler::heap_index pub fn heap_index(&self) -> u32 method metal2vulkan::pipeline::CombinedSampler::new pub fn new(sampler: SamplerRef, compare: bool, integer: bool) -> CombinedSampler @@ -15711,6 +15712,7 @@ variant metal2vulkan::pipeline::PushField::BaseVertexInstance BaseVertexInstance variant metal2vulkan::pipeline::PushField::CaptureIndexAddress CaptureIndexAddress variant metal2vulkan::pipeline::PushField::CaptureLayout CaptureLayout variant metal2vulkan::pipeline::PushField::CommandRecordsAddress CommandRecordsAddress +variant metal2vulkan::pipeline::PushField::ConstexprSampler ConstexprSampler(CombinedSampler) variant metal2vulkan::pipeline::PushField::ControlPointIndexOffset ControlPointIndexOffset variant metal2vulkan::pipeline::PushField::DepthClampRange DepthClampRange variant metal2vulkan::pipeline::PushField::DispatchRegion DispatchRegion diff --git a/docs/API.md b/docs/API.md index 9bcb6a291..e3b2c6a3e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -130,14 +130,17 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: (the consumer refuses a sparse texture). A texture slot sampled through a runtime sampler slot samples set 1's element of the sampler arrays at the index of the sampler's pushed `gpuResourceID`, joined to the texture's element by `OpSampledImage`, and reads the sampler's - word from that ID. An integer write to a storage slot without a format saturates to the channel + word from that ID. One sampled through a constexpr sampler samples the element at the index the + consumer pushes for it (`PushField::ConstexprSampler`), where the consumer places the device + sampler `CombinedSampler::constexpr_sampler` describes, normalized: the shader scales a pixel + sampler's coordinate. An integer write to a storage slot without a format saturates to the channel widths the consumer pushes (`PushField::TextureIntegerChannels`). Every precision note is static there: no constant or binder decides one. So far they lower a kernel that reaches memory through its buffer slots and reads, writes, sizes or tests for nil its texture slots and its - argument buffers' textures, and samples its texture slots through its runtime sampler slots. - Any other function is refused as `Unsupported{IdentityDomains}`: one that samples through a - constexpr or an argument buffer's sampler or samples an argument buffer's texture, emulates a - sampler's anisotropy or bicubic filter, uses a texture buffer, a slot's levels or swizzle, a + argument buffers' textures, and samples its texture slots through its runtime sampler slots + and its constexpr samplers. Any other function is refused as `Unsupported{IdentityDomains}`: + one that samples through an argument buffer's sampler or an array of samplers or samples an + argument buffer's texture, emulates a sampler's anisotropy or bicubic filter, uses a texture buffer, a slot's levels or swizzle, a two-plane, extended-range or sRGB-twin form, reads an argument buffer's texture through another numeric type or as raw texels, or uses any other state of a texture or sampler beyond its ID. - **The model's linear sample of planes read in place** (`YCbCrInPlacePolicy::Model`, the @@ -4604,7 +4607,9 @@ bound. where it is not a nearest one of one isotropic level). Measured: the device's normalized sampler's answer within one `f32` ulp of the quotient on MoltenVK and at the quotient on lavapipe; a linear downscale by 8 within 1/255 of Metal's on MoltenVK and 2/255 on lavapipe. - Nothing is recorded where Metal's texel or footprint follows from the coordinate itself: a + Under the identity domains it is also recorded for a linear sample and a gather through any + constexpr pixel sampler, whose device sampler the consumer makes normalized. Nothing is + recorded where Metal's texel or footprint follows from the coordinate itself: elsewhere a constexpr pixel sampler's sample or gather of a 1D or 2D texture that is no array hands the coordinate, moved by its offset, to the device's unnormalized sampler; a nearest sample elsewhere hands the device its texel's centre, where the device reads exactly Metal's texel; and a nearest diff --git a/docs/RESOURCE-ID.md b/docs/RESOURCE-ID.md index 0365d42a6..1d37ea626 100644 --- a/docs/RESOURCE-ID.md +++ b/docs/RESOURCE-ID.md @@ -51,8 +51,14 @@ filter nearest. The consumer makes each from the descriptor (its reduction mode included); it makes none of a descriptor whose min or mag filter is cubic. A shader takes a runtime sampler slot's ID from the slot's push field, samples through the element its low word indexes, and reads the word's fields where a sample depends on them (pixel coordinates, a nearest -pixel sampler). A constexpr sampler and an argument buffer's sampler are not lowered under these -domains yet. +pixel sampler). + +A constexpr sampler has no ID: the consumer places a device sampler of it (the function's +`PushField::ConstexprSampler` names it and its use, and `CombinedSampler::constexpr_sampler` +describes it) at an index of the use's array and pushes that index as a `u32`. Its coordinates +are normalized; the shader scales a pixel sampler's coordinate itself. It samples with its own +address modes. An argument buffer's +sampler is not lowered under these domains yet. ## The texture word