From ff45556bcce23b1fb88bc2c5f0752569027fdf14 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 10 Nov 2026 03:28:51 -0800 Subject: [PATCH] An argument buffer's sample filter note holds only where its heap can name a filtered raw texture What: a heap sample the function emulates (`sampler::heap_raw`) recorded `PrecisionNote::BicubicFilterArithmetic` whatever the command's heap held: unconditionally through a constexpr linear sampler, and under the bound sampler's word through a runtime slot. A command whose heap holds no raw texture samples through the device's own sampler, and a bfloat form's sample reads the nearest texel, so neither filters by the device's arithmetic. `SpecKey::HeapRawTextures`' value now carries two bits, which the plan gives from the command's heap members (`slots::heap_raw`): `heap_raw::HELD` (1, a raw-held texture: the decode's `DevicePackConversion`, unchanged) and `heap_raw::FILTERED` (2, a raw-held texture of a form the function filters: not a bfloat one). The filter note's clauses each test `FILTERED` (beside the bound word's test through a runtime slot). Runtime: `degrade_bound_values` reads the clause at each draw or dispatch, so a command whose heap holds only RGBA8Unorm or RGBA16Bfloat textures no longer announces bicubic-filter-arithmetic for a linear heap sample; one holding a BGRA10XR texture still does. No runtime code changed (the path is generic). Tests: heap::a_heap_sample_s_filter_note_follows_the_raw_texture_and_the_bound_sampler_word (artifact clauses on every committed profile), heap::a_heap_sample_s_filter_note_holds_where_its_command_can_name_a_filtered_raw_texture (plan values 3/1/0 and the notes bound under them), the decode-note plan test's values (3 for BGRA10XR, 1 for RGBA16Bfloat), engine_sampler's argument-buffer stage check, and the lane heap_extended_reads::a_heap_sample_s_filter_note_is_announced_where_its_command_can_name_a_filtered_raw_texture. Docs: SpecKey::HeapRawTextures, the note's rustdoc, API.md. SEMANTICS_VERSION 2018 (renumbered at landing). (cherry picked from commit dbc8a2781ef6170f797d5b7a7a83b46264c5e4e2) --- .../src/runtime_lane/heap_extended_reads.rs | 75 +++++++++ crates/metal2vulkan/src/bind/plan/slots.rs | 29 +++- crates/metal2vulkan/src/cache/mod.rs | 2 +- .../metal2vulkan/src/lower/sampler/select.rs | 26 ++-- .../src/lower/texture/heap_raw.rs | 13 +- crates/metal2vulkan/src/pipeline/artifact.rs | 5 +- crates/metal2vulkan/src/pipeline/sym.rs | 16 +- .../src/tests/engine_extended_range/heap.rs | 146 ++++++++++++++---- .../metal2vulkan/src/tests/engine_sampler.rs | 14 +- docs/API.md | 4 +- 10 files changed, 265 insertions(+), 65 deletions(-) diff --git a/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs index 4136270f2..2d9bb4276 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs @@ -927,6 +927,81 @@ fn a_heap_decode_s_stage_note_is_announced_where_its_command_can_name_a_raw_text }); } +/// A heap linear sample the function filters (`sampler::heap_raw`) records +/// `PrecisionNote::BicubicFilterArithmetic` as a specialized note, holding where its command can +/// name a texture the heap holds by its raw texels in a form the function filters +/// (`SpecKey::HeapRawTextures`), and through a runtime sampler where the bound word filters too; +/// the runtime announces it there alone: on a device whose options ask for +/// `bicubic-filter-arithmetic` at every occurrence, a constexpr linear sample's dispatch that makes +/// an `RGBA8Unorm` texture alone resident (the device's own sample) or an `RGBA16Bfloat` one (whose +/// sample reads the nearest texel) announces nothing of it, and one that makes a `BGRA10XR` one +/// resident announces it for the kernel; through the runtime sampler over `BGRA10XR`, a bound +/// nearest sampler announces nothing of it, and a bound linear one announces it. +#[test] +fn a_heap_sample_s_filter_note_is_announced_where_its_command_can_name_a_filtered_raw_texture() { + let filter = Degradation::BicubicFilterArithmetic; + let each = |options: &mut DeviceOptions| { + options.announce_each = [filter].into_iter().collect(); + at_plan(options); + }; + on_device_with(each, |device, messages| { + let lanes = sample_lanes(); + let linear = SAMPLERS[1].1; + let constexpr = sample_kernel(true, Through::Constexpr(linear), Op::Sample, false); + let stage = notes_of(device, &constexpr); + let heap = pipeline_of(device, &constexpr); + let slot = pipeline_of( + device, + &sample_kernel(true, Through::Slot, Op::Sample, false), + ); + let made_with = notices(messages); + let sampler = |f| { + let mut d = SamplerDescriptor::new(); + (d.min_filter, d.mag_filter) = (f, f); + d.s_address_mode = SamplerAddressMode::ClampToEdge; + d.t_address_mode = SamplerAddressMode::ClampToEdge; + device.new_sampler_state(&d).unwrap() + }; + let (nearest, linear) = ( + sampler(SamplerMinMagFilter::Nearest), + sampler(SamplerMinMagFilter::Linear), + ); + let plain = made(device, PixelFormat::RGBA8Unorm, 4).unwrap(); + let bfloat = made(device, PixelFormat::RGBA16Bfloat, 8).unwrap(); + let raw = made(device, PixelFormat::BGRA10XR, 8).unwrap(); + let mut seen = Vec::new(); + for (name, pipeline, texture, bound) in [ + ("RGBA8Unorm, constexpr linear", &heap, &plain, None), + ("RGBA16Bfloat, constexpr linear", &heap, &bfloat, None), + ("BGRA10XR, bound nearest", &slot, &raw, Some(&nearest)), + ("BGRA10XR, constexpr linear", &heap, &raw, None), + ("BGRA10XR, bound linear", &slot, &raw, Some(&linear)), + ] { + dispatch_with(device, (pipeline, true), (texture, bound), &lanes).unwrap(); + let announced = notices(messages) + .into_iter() + .filter(|(k, _)| *k == filter) + .map(|(_, object)| object) + .collect::>(); + seen.push((name, announced)); + } + println!( + "HEAP-FILTER-NOTE {}: stage notes {stage:?}; making {made_with:?}; {seen:?}", + device.name() + ); + assert!(stage.contains(&FILTER_ARITHMETIC), "{stage:?}"); + assert!( + !made_with.iter().any(|(k, _)| *k == filter), + "announced as it was made" + ); + let kernel = "the kernel of a compute pipeline state".to_owned(); + for (name, announced) in &seen { + let want = name.starts_with("BGRA10XR") && !name.ends_with("nearest"); + assert_eq!(announced.contains(&kernel), want, "{name}: {announced:?}"); + } + }); +} + /// The kinds among `messages`' notices delivered so far, each with its notice's object. fn notices(messages: &Messages) -> Vec<(Degradation, String)> { messages diff --git a/crates/metal2vulkan/src/bind/plan/slots.rs b/crates/metal2vulkan/src/bind/plan/slots.rs index 9ef1c67f0..27ba266aa 100644 --- a/crates/metal2vulkan/src/bind/plan/slots.rs +++ b/crates/metal2vulkan/src/bind/plan/slots.rs @@ -346,17 +346,32 @@ fn heap_ycbcr( }) } -/// Whether a heap member of `shape` that reaches `stage` (as for [`heap_ycbcr`]) is a texture a -/// heap holds by its raw texels alone (`bind::heap::heap_raw_form`), which the stage's `float` -/// read, sample or gather decodes by the device's arithmetic. +/// The `SpecKey::HeapRawTextures` of `stage` for `shape`: of the heap members of `shape` that reach +/// `stage` (as for [`heap_ycbcr`]), the bit `lower::texture::heap_raw::HELD` where one is a texture +/// a heap holds by its raw texels alone (`bind::heap::heap_raw_form`), which the stage's `float` +/// read, sample or gather decodes by the device's arithmetic, and the bit +/// `lower::texture::heap_raw::FILTERED` where one such is of a form whose sample the function +/// filters (not a bfloat one). fn heap_raw( shape: &BindShape, stage: Stage, reach: &dyn Fn(metal::RenderStages) -> Vec, -) -> bool { - crate::bind::heap::members(shape, &[stage], reach) - .iter() - .any(|m| crate::bind::heap::raw_held(&m.shape)) +) -> u32 { + use crate::lower::texture::heap_raw::{FILTERED, HELD}; + let mut bits = 0; + for m in crate::bind::heap::members(shape, &[stage], reach) { + let TextureShape::Texture { pixel_format, .. } = m.shape else { + continue; + }; + if !crate::bind::heap::raw_held(&m.shape) { + continue; + } + bits |= HELD; + if crate::metal::format::ExtendedRange::of(pixel_format).is_some_and(|f| !f.bfloat()) { + bits |= FILTERED; + } + } + bits } /// Whether `shape` binds anything at `slot`. diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index b5c07fe27..56975bbf4 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 = 2017; +pub const SEMANTICS_VERSION: u32 = 2018; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index 4da8d4e57..650639291 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -646,19 +646,23 @@ fn heap_raw_sample( crate::lower::texture::heap_raw::plan(cx, group, &[false, half], m)?; // A linear filter's sum of the decoded taps is the device's arithmetic (`extended::filtered`): // a constexpr sampler's that filters, and a runtime sampler slot's where the word bound there - // filters (`linear::filtering_word`), as a word that reads one texel takes that texel alone. + // filters (`linear::filtering_word`), as a word that reads one texel takes that texel alone; + // each where a texture the stage's handles can name is held by its raw texels in a form the + // function filters (`SpecKey::HeapRawTextures`' `FILTERED` bit), as a bfloat form's sample + // reads the nearest texel and any other member's is the device's own sample. if gather.is_none() { + use crate::lower::texture::heap_raw::FILTERED; let note = PrecisionNote::BicubicFilterArithmetic; - match state { - State::Constant { linear: false, .. } => {} - State::Constant { .. } => { - cx.precision.insert(note); - } - State::Slot { sampler: n } => { - let when = any_of(super::linear::filtering_word(n)); - cx.note_when(note, when, m)?; - } - } + let raw = NoteTest::equal(NoteOn::HeapRaw(cx.stage), FILTERED, FILTERED); + let when: Vec = match state { + State::Constant { linear: false, .. } => Vec::new(), + State::Constant { .. } => vec![[raw].into()], + State::Slot { sampler: n } => super::linear::filtering_word(n) + .into_iter() + .map(|word| [raw, word].into()) + .collect(), + }; + cx.note_when(note, when, m)?; } Ok(Some(HeapRaw { state, diff --git a/crates/metal2vulkan/src/lower/texture/heap_raw.rs b/crates/metal2vulkan/src/lower/texture/heap_raw.rs index 96fd4a652..b07f73744 100644 --- a/crates/metal2vulkan/src/lower/texture/heap_raw.rs +++ b/crates/metal2vulkan/src/lower/texture/heap_raw.rs @@ -48,12 +48,21 @@ pub const READ_WORDS: u32 = 256; /// element's access chain, load and query. pub const QUERY_WORDS: u32 = 128; +/// The bit of `SpecKey::HeapRawTextures`' value that a texture the stage's handles can name is held +/// by its raw texels alone, whose decode the function's `float` read, sample or gather takes. +pub(crate) const HELD: u32 = 1; + +/// The bit of `SpecKey::HeapRawTextures`' value that such a texture is of a form whose sample the +/// function filters (`sampler::heap_raw`): every form of `ExtendedRange::HEAP_READ` but a bfloat +/// one, whose sample reads the nearest texel under either filter. +pub(crate) const FILTERED: u32 = 2; + /// Plan a `float` or `half` read, sample or gather of heap group `group` that decodes a member of a /// form a heap reads where its handle's class index names one, with the decode routine of each /// result type of `halves` (`false` a `float` one, `true` a `half` one): the group's unsigned /// integer class ([`HeapPlan::reads_raw`](super::slot::HeapPlan)), the routines, the handle's /// class index, and the decode's `PrecisionNote::DevicePackConversion` where a texture the stage's -/// handles can name is held by its raw texels alone (`SpecKey::HeapRawTextures`). +/// handles can name is held by its raw texels alone (`SpecKey::HeapRawTextures`' [`HELD`] bit). pub(crate) fn plan( cx: &mut SelectCx<'_>, group: u32, @@ -65,7 +74,7 @@ pub(crate) fn plan( } cx.families.texture.heap_raw.extend(halves.iter().copied()); cx.families.access.heap_class_index = true; - let raw = NoteTest::equal(NoteOn::HeapRaw(cx.stage), 1, 1); + let raw = NoteTest::equal(NoteOn::HeapRaw(cx.stage), HELD, HELD); cx.note_when(PrecisionNote::DevicePackConversion, any_of([raw]), m) } diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index adde1370a..6b69e2353 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -882,7 +882,10 @@ pub enum PrecisionNote { /// (`SpecKey::BoundSamplerWord`, which the runtime reads at each draw or dispatch): it holds /// where that word filters (a linear minification or magnification filter, anisotropy, a cubic /// filter or a linear mip filter), and a nearest word's sample, the decoded texel at Metal's - /// position, holds none. + /// position, holds none. Through an argument buffer it holds where a texture the stage's + /// handles can name is held by its raw texels in a form whose sample the function filters + /// (`SpecKey::HeapRawTextures`, which a plan gives): a command whose heap holds no such + /// texture samples through the device's own sampler, or reads a bfloat form's nearest texel. /// /// Inferences, taken by family: the signed clamp's lower bound, the treatment of the formats /// no case reads (`RG8UnormSRGB`, `RG8Unorm`, `RG8Snorm`, `RG16Unorm`, `BGRA8Unorm`, diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 0bd3adfa1..572437fd3 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -843,13 +843,15 @@ pub enum SpecKey { /// test holds. A texture the command neither names nor makes resident, which a handle loaded /// from memory may still reach and whose read Metal leaves undefined, is not counted. HeapYCbCrTextures(Stage), - /// Boolean: a texture the stage's handles can name is one a heap holds by its raw texels alone - /// (`bind::heap::heap_raw_form`: an unswizzled, not sparse texture of one sample of a form of - /// `ExtendedRange::HEAP_READ`, whose texels the function's `float` read, sample or gather - /// decodes by the device's arithmetic, `PrecisionNote::DevicePackConversion`): a heap member - /// of the command reaching the stage, as for - /// [`HeapYCbCrTextures`](Self::HeapYCbCrTextures), and read by a specialized note's test alone, - /// given by a plan, as that is. + /// Two bits: 1 where a texture the stage's handles can name is one a heap holds by its raw + /// texels alone (`bind::heap::heap_raw_form`: an unswizzled, not sparse texture of one sample + /// of a form of `ExtendedRange::HEAP_READ`, whose texels the function's `float` read, sample + /// or gather decodes by the device's arithmetic, `PrecisionNote::DevicePackConversion`), and 2 + /// where one such is of a form whose linear sample the function filters by the device's + /// arithmetic (not a bfloat form, whose sample reads the nearest texel under either filter, + /// `PrecisionNote::BicubicFilterArithmetic`): of the heap members of the command reaching the + /// stage, as for [`HeapYCbCrTextures`](Self::HeapYCbCrTextures), and read by a specialized + /// note's test alone, given by a plan, as that is. HeapRawTextures(Stage), /// Boolean: a sampler state an argument buffer's sampler handle can name filters: one of the /// bind state's argument samplers (`BindState::argument_samplers`, every live state, its diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs b/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs index 71d1e99ac..2b3e7cefe 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs @@ -470,13 +470,15 @@ fn heap_decodes_record_the_device_pack_conversion() { } /// A heap sample the function emulates (`sampler::heap_raw`) records the filter's note -/// (`PrecisionNote::BicubicFilterArithmetic`, the device's sum of the decoded taps) as a slot's -/// sample does, on every committed profile with a sampled heap: through a runtime sampler slot -/// only where the word of the sampler bound there filters (`SpecKey::BoundSamplerWord`: its -/// clauses hold for a linear word and not for a nearest one); through a constexpr linear sampler -/// whatever is bound; and through a constexpr nearest sampler, or as a gather, not at all. +/// (`PrecisionNote::BicubicFilterArithmetic`, the device's sum of the decoded taps) as a +/// specialized note, on every committed profile with a sampled heap: each clause holds only where a +/// texture the stage's handles can name is held by its raw texels in a form the function filters +/// (`SpecKey::HeapRawTextures` 2, not a bfloat form's 1 alone, nor 0), and through a runtime +/// sampler slot only where the word of the sampler bound there filters too +/// (`SpecKey::BoundSamplerWord`: a linear word, not a nearest one); through a constexpr linear +/// sampler whatever is bound; through a constexpr nearest sampler, or as a gather, not at all. #[test] -fn a_heap_sample_s_filter_note_follows_the_bound_sampler_word() { +fn a_heap_sample_s_filter_note_follows_the_raw_texture_and_the_bound_sampler_word() { use crate::bind::SamplerDescriptor; use crate::metal::sampler::SamplerWord; use crate::metal::SamplerMinMagFilter as F; @@ -487,15 +489,25 @@ fn a_heap_sample_s_filter_note_follows_the_bound_sampler_word() { class: SlotClass::Sampler, index: 0, }; + let raw = SpecKey::HeapRawTextures(Stage::Kernel); let word = |filter| { let mut d = SamplerDescriptor::new(); (d.min_filter, d.mag_filter) = (filter, filter); SamplerWord::of(&d).0 }; - let holds = |clause: &SpecClause, word: u32| { + // Whether `clause` holds where the key reads `held` and the bound word is `bound`. + let holds = |clause: &SpecClause, held: u32, bound: u32| { + assert!( + clause.all.iter().any(|t| t.key == raw), + "a clause past the raw texture: {clause:?}" + ); clause.all.iter().all(|t| { - assert_eq!(t.key, SpecKey::BoundSamplerWord(sampler), "{clause:?}"); - ((word & t.mask) == t.bits) == t.equal + let v = match t.key { + k if k == raw => held, + SpecKey::BoundSamplerWord(s) if s == sampler => bound, + k => panic!("{k:?} in {clause:?}"), + }; + ((v & t.mask) == t.bits) == t.equal }) }; let consts = FunctionConstantValues::defaults(); @@ -542,16 +554,17 @@ fn a_heap_sample_s_filter_note_follows_the_bound_sampler_word() { .filter(|s| s.note == note) .flat_map(|s| &s.when) .collect(); - assert_eq!(!when.is_empty(), bound, "{what}: {when:?}"); - if bound { + assert_eq!(!when.is_empty(), recorded, "{what}: {when:?}"); + let any = |held, bound| when.iter().any(|c| holds(c, held, bound)); + let (linear, nearest) = (word(F::Linear), word(F::Nearest)); + if recorded { assert!( - when.iter().any(|c| holds(c, word(F::Linear))), - "{what}: a linear word" - ); - assert!( - !when.iter().any(|c| holds(c, word(F::Nearest))), - "{what}: a nearest word" + any(3, linear), + "{what}: a filtered raw texture, a linear word" ); + assert!(!any(1, linear), "{what}: a bfloat raw texture alone"); + assert!(!any(0, linear), "{what}: no raw texture"); + assert_eq!(any(3, nearest), !bound, "{what}: a nearest word"); } compiled += 1; } @@ -564,10 +577,11 @@ fn a_heap_sample_s_filter_note_follows_the_bound_sampler_word() { /// A heap `float` read's `DevicePackConversion` holds where its command can name a texture the heap /// holds by its raw texels alone: on every committed profile with a sampled heap, a plan of its -/// pipeline gives `SpecKey::HeapRawTextures` 1 exactly where a texture the command makes resident -/// is such a texture (`BGRA10_XR`, `RGBA16Bfloat`, beside an `RGBA8Unorm` one too), and 0 where it +/// pipeline gives `SpecKey::HeapRawTextures` bit 1 exactly where a texture the command makes +/// resident is such a texture (`BGRA10_XR`, `RGBA16Bfloat`, beside an `RGBA8Unorm` one too), bit 2 +/// where it is of a form the function filters (`BGRA10_XR`, not `RGBA16Bfloat`), and 0 where it /// makes none or only `RGBA8Unorm` or `RGBA16Float` ones resident; the stage's note holds under the -/// plan's values exactly where the key is 1 (`StageModule::precision_notes_bound`), and under no +/// plan's values exactly where bit 1 is set (`StageModule::precision_notes_bound`), and under no /// known value (a reading of the module alone). #[test] fn a_heap_decode_s_note_holds_where_its_command_can_name_a_raw_texture() { @@ -592,13 +606,14 @@ fn a_heap_decode_s_note_holds_where_its_command_can_name_a_raw_texture() { .collect(), ..Default::default() }; - let cases: [(&[PixelFormat], bool); 6] = [ - (&[PixelFormat::BGRA10XR], true), - (&[PixelFormat::RGBA16Bfloat], true), - (&[PixelFormat::RGBA8Unorm, PixelFormat::BGRA10XR], true), - (&[], false), - (&[PixelFormat::RGBA8Unorm], false), - (&[PixelFormat::RGBA16Float], false), + // The formats, and the key's value: 1 a raw texture, 2 one of a form the function filters. + let cases: [(&[PixelFormat], u64); 6] = [ + (&[PixelFormat::BGRA10XR], 3), + (&[PixelFormat::RGBA16Bfloat], 1), + (&[PixelFormat::RGBA8Unorm, PixelFormat::BGRA10XR], 3), + (&[], 0), + (&[PixelFormat::RGBA8Unorm], 0), + (&[PixelFormat::RGBA16Float], 0), ]; let mut planned = 0; for (stem, dev) in devices() { @@ -620,16 +635,87 @@ fn a_heap_decode_s_note_holds_where_its_command_can_name_a_raw_texture() { "{stem}: {:?}", p.stage.precision_notes ); - for (formats, raw) in cases { + for (formats, value) in cases { let what = format!("{formats:?} on {stem}"); let plan = p .plan(&dev, &state(formats).shape()) .unwrap_or_else(|e| panic!("{what}: {e}")); - assert_eq!(plan.specialized_value(key), Some(u64::from(raw)), "{what}"); + assert_eq!(plan.specialized_value(key), Some(value), "{what}"); let held = (p.stage) .precision_notes_bound(&plan.specialization, &|k| plan.specialized_value(k)) .contains(¬e); - assert_eq!(held, raw, "{what}"); + assert_eq!(held, value & 1 == 1, "{what}"); + planned += 1; + } + } + assert!(planned > 0, "no committed profile has the sampled heap"); +} + +/// A heap linear sample's `BicubicFilterArithmetic` holds where its command can name a texture the +/// heap holds by its raw texels in a form the function filters: on every committed profile with a +/// sampled heap, under the plan's values (`StageModule::precision_notes_bound`) of a constexpr +/// linear sample's pipeline, it holds where the command makes a `BGRA10_XR` texture resident +/// (`SpecKey::HeapRawTextures` 3, beside an `RGBA8Unorm` one too), and not where it makes an +/// `RGBA16Bfloat` one alone resident (1: its sample reads the nearest texel), nor where it makes +/// none or an `RGBA8Unorm` one alone resident (0: the device's own sample); the stage's decode note +/// holds wherever a raw texture is resident. +#[test] +fn a_heap_sample_s_filter_note_holds_where_its_command_can_name_a_filtered_raw_texture() { + use crate::bind::{ResourceClass, UsedResource}; + use crate::pipeline::PrecisionNote; + let filter = PrecisionNote::BicubicFilterArithmetic; + let pack = PrecisionNote::DevicePackConversion; + let key = SpecKey::HeapRawTextures(Stage::Kernel); + let Some(bc) = assemble( + "heap_filter_plan", + &sampling_kernel(Sampling::Sample(words(true, false))), + ) else { + return; + }; + // A command making `formats` resident, at IDs of their own. + let state = |formats: &[PixelFormat]| BindState { + used_resources: (formats.iter().zip(1u32..)) + .map(|(&pf, token)| { + let mut facts = TextureFacts::new(TextureType::Type2D, pf); + facts.usage = metal::TextureUsage::SHADER_READ; + let mut u = UsedResource::new(ResourceClass::Texture(facts), token); + u.resource_id = Some(0x0000_0001_0000_0000 | u64::from(token) << 4); + u + }) + .collect(), + ..Default::default() + }; + // The formats, the key's value, and whether the filter's note holds. + let cases: [(&[PixelFormat], u64, bool); 5] = [ + (&[PixelFormat::BGRA10XR], 3, true), + (&[PixelFormat::RGBA8Unorm, PixelFormat::BGRA10XR], 3, true), + (&[PixelFormat::RGBA16Bfloat], 1, false), + (&[PixelFormat::RGBA8Unorm], 0, false), + (&[], 0, false), + ]; + let mut planned = 0; + for (stem, dev) in devices() { + let lib = Library::from_air(&bc).expect("library"); + let f = lib.function("k").expect("function"); + let d = ComputePipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(f))); + let p = match dev.compile_compute_pipeline(&d, &Budget::standard()) { + Ok(p) => p, + Err(crate::error::Error::Unsupported(Unsupported { + feature: Feature::ArgumentBufferTextures, + .. + })) => continue, + Err(e) => panic!("{stem}: {e}"), + }; + for (formats, value, filtered) in cases { + let what = format!("{formats:?} on {stem}"); + let plan = p + .plan(&dev, &state(formats).shape()) + .unwrap_or_else(|e| panic!("{what}: {e}")); + assert_eq!(plan.specialized_value(key), Some(value), "{what}"); + let notes = (p.stage) + .precision_notes_bound(&plan.specialization, &|k| plan.specialized_value(k)); + assert_eq!(notes.contains(&filter), filtered, "{what}: {notes:?}"); + assert_eq!(notes.contains(&pack), value != 0, "{what}: {notes:?}"); planned += 1; } } diff --git a/crates/metal2vulkan/src/tests/engine_sampler.rs b/crates/metal2vulkan/src/tests/engine_sampler.rs index 9647fa391..9624ed997 100644 --- a/crates/metal2vulkan/src/tests/engine_sampler.rs +++ b/crates/metal2vulkan/src/tests/engine_sampler.rs @@ -500,7 +500,8 @@ fn runtime_pixel_accesses_hand_the_device_the_scaled_coordinate() { /// announces only while a pixel state lives, records its centre's reading. The depth comparison /// records `RestrictedDepthRange`, as MoltenVK exposes no `VK_EXT_depth_range_unrestricted`. An /// argument buffer's raw texture sampled through the runtime slot holds its filter's -/// `BicubicFilterArithmetic` only under the bound sampler's word (`SpecKey::BoundSamplerWord`). +/// `BicubicFilterArithmetic` only under the bound sampler's word (`SpecKey::BoundSamplerWord`) +/// where its handles can name a raw texture (`SpecKey::HeapRawTextures`). #[test] fn normalized_and_cubic_stages_record_no_note_their_states_cannot_run() { use crate::pipeline::sym::SpecKey; @@ -621,16 +622,19 @@ fn normalized_and_cubic_stages_record_no_note_their_states_cannot_run() { "{what}: {n:?}" ); } - // An emulated filter's note through the runtime slot: under the bound sampler's word. + // An emulated filter's note through the runtime slot: under the bound sampler's word and, + // an argument buffer's, a raw texture its handles can name. + let raw = SpecKey::HeapRawTextures(Stage::Kernel); for n in a .specialized .iter() .filter(|n| n.note == N::BicubicFilterArithmetic) { assert!( - n.when - .iter() - .all(|c| c.all.iter().all(|t| t.key == SpecKey::BoundSamplerWord(s))), + n.when.iter().all(|c| { + let keys: BTreeSet = c.all.iter().map(|t| t.key).collect(); + keys == [SpecKey::BoundSamplerWord(s), raw].into() + }), "{what}: {n:?}" ); } diff --git a/docs/API.md b/docs/API.md index 592d4c136..2c9218f56 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3666,7 +3666,9 @@ bound. and by up to `1/64` of the two levels' difference under a linear mip filter. Through a runtime sampler slot it is announced at a draw or dispatch only where the bound sampler filters (a linear minification or magnification filter, anisotropy, a cubic filter or a linear mip filter): a - nearest sampler's sample is the decoded texel at Metal's position. + nearest sampler's sample is the decoded texel at Metal's position. Through an argument buffer it + is announced only at a draw or dispatch whose command can name a texture held by its raw texels in + a form the function filters (`BGR10_XR`, `BGRA10_XR`, the padded forms; not a bfloat one). - `metal2vulkan-degrade-sparse-residency` (precision). `PrecisionNote::SparseResidency`: A stage samples or gathers a texture whose residency it observes (`sparse_color::resident()`) through the slot's sparse form, which the module has where the profile enables `shaderResourceResidency`: