diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 7f0d132c2..ee959c456 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2637,9 +2637,11 @@ degradations! { /// Vulkan format holds them): a linear value within one `f32` ulp of Metal's, an encoded /// code within one (`R10Unorm_X6_sRGB`'s and `RGB10A2Unorm_sRGB`'s colour within two /// below `0.0031308`), a `half` result within one `half` ulp. A texture a heap holds - /// by its raw texels alone, which a function's `float` read through an argument buffer - /// decodes so, is announced naming the texture, at the first command that binds a heap - /// set holding it, whether or not its function reads it. + /// by its raw texels alone, which a function's `float` read, sample or gather through an + /// argument buffer decodes so, is announced naming the texture, at the first command that + /// binds a heap set holding it, whether or not its function reads it; and by the stage + /// that decodes it, at a draw or dispatch whose command makes such a texture resident or + /// binds one (`SpecKey::HeapRawTextures`). DevicePackConversion = "device-pack-conversion"; /// A render pipeline whose color attachments the device draws in more than one group: /// each draw runs once per group, each group's variant over its own copy of the pass's @@ -4043,8 +4045,9 @@ impl Device { /// texture's format class, `SpecKey::BoundSamplerWord`) and holds where the draw's plan gives /// the values `bound` gives (`BindingPlan::specialized_value`; /// `StageModule::note_clauses_bound`; and what the command's handles can name, - /// `SpecKey::HeapYCbCrTextures` and `SpecKey::FilteringArgumentSampler`, which the plan gives - /// too: a filter note's heap texture), the class of the format `formats` binds at each + /// `SpecKey::HeapYCbCrTextures`, `SpecKey::HeapRawTextures` and + /// `SpecKey::FilteringArgumentSampler`, which the plan gives too: a filter note's heap + /// texture, a heap decode's raw one), the class of the format `formats` binds at each /// texture slot such a clause also tests (`SpecKey::BoundTexelFormat`: a filter note's /// two-plane YCbCr format under a runtime sampler's filtering word). A clause testing a slot /// bound to nothing does not hold, as [`degrade_bound_formats`](Self::degrade_bound_formats) 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 b83ad2fd9..bd7ff99c8 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs @@ -51,7 +51,7 @@ //! records no `PrecisionNote::NativeHalfConversion`, which it does not where the profile takes //! `DriverDeviation::MetalHalfConversion` ([`heap_half_reads_of_every_code_round_their_float`]). -use super::degrade_notices::on_device; +use super::degrade_notices::{on_device, on_device_with}; use super::half_conversions; use super::host_memory::{not_importable, Mapping, GUEST_PAGE}; use super::Messages; @@ -72,8 +72,9 @@ use metal2vulkan::pipeline::{ use metal2vulkan::Budget; use metal2vulkan_devtools::llvm_assemble_text; use metal2vulkan_runtime::{ - CommandBufferStatus, ComputePipelineState, Degradation, Device, Error, HostMemory, - PipelineOptions, Region, ResourceOptions, SamplerState, Size, Texture, TextureDescriptor, + CommandBufferStatus, ComputePipelineState, Degradation, Device, DeviceOptions, Error, + HostMemory, PipelineOptions, Region, ResourceOptions, SamplerState, Size, Texture, + TextureDescriptor, }; use std::collections::{BTreeMap, BTreeSet}; use std::time::Duration; @@ -840,9 +841,11 @@ fn the_heap_set_holds_the_forms_a_heap_reads_unannounced() { /// A command that binds a heap set holding a texture a heap holds by its raw texels alone /// announces `device-pack-conversion`, naming the texture: its function's `float` read decodes the -/// raw texels by the device's arithmetic, which the stage's notes cannot state, as only the set -/// knows which textures it holds. The same command over an `RGBA8Unorm` texture, with no such -/// texture live, announces no `device-pack-conversion`. +/// raw texels by the device's arithmetic, whichever texture the set holds that the function's +/// handles name. The same command over an `RGBA8Unorm` texture, with no such texture live, +/// announces no `device-pack-conversion`, nor does the pipeline's making: the stage records the +/// note only where its command can name such a texture +/// ([`a_heap_decode_s_stage_note_is_announced_where_its_command_can_name_a_raw_texture`]). #[test] fn a_heap_set_holding_a_raw_texture_announces_its_decode() { on_device(|device, messages| { @@ -875,6 +878,54 @@ fn a_heap_set_holding_a_raw_texture_announces_its_decode() { }); } +/// A heap pipeline whose `float` read decodes a texture a heap holds by its raw texels alone +/// records `PrecisionNote::DevicePackConversion` as a specialized note, holding where its command +/// can name such a texture (`SpecKey::HeapRawTextures`), and the runtime announces it there: on a +/// device whose options ask for `device-pack-conversion` at every occurrence, a dispatch that makes +/// a `BGRA10XR` texture resident announces the stage's note (its object the kernel) beside the +/// heap set's notice naming the texture, while the pipeline's making and a dispatch that makes an +/// `RGBA8Unorm` texture alone resident, with no such texture live, announce neither. +#[test] +fn a_heap_decode_s_stage_note_is_announced_where_its_command_can_name_a_raw_texture() { + let pack = Degradation::DevicePackConversion; + let each = |options: &mut DeviceOptions| { + options.announce_each = [pack].into_iter().collect(); + }; + on_device_with(each, |device, messages| { + let stage = stage_notes(device, true, Texel::Float); + let heap = pipeline(device, true, Texel::Float); + let made_with = notices(messages); + let plain = made(device, PixelFormat::RGBA8Unorm, 4).unwrap(); + dispatch(device, (&heap, true), &plain).unwrap(); + let alone = notices(messages); + let raw = made(device, PixelFormat::BGRA10XR, 8).unwrap(); + dispatch(device, (&heap, true), &raw).unwrap(); + let held = notices(messages); + println!( + "HEAP-RAW-STAGE-NOTE {}: stage notes {stage:?}; making {made_with:?}; RGBA8Unorm alone \ + {alone:?}; BGRA10XR held {held:?}", + device.name() + ); + assert!( + stage.contains(&PrecisionNote::DevicePackConversion), + "{stage:?}" + ); + assert!( + ![&made_with, &alone] + .iter() + .any(|n| n.iter().any(|(k, _)| *k == pack)), + "announced before a raw texture lived" + ); + let kernel = "the kernel of a compute pipeline state".to_owned(); + assert!(held.contains(&(pack, kernel)), "{held:?}"); + let texture = format!( + "BGRA10XR texture at resource ID {}", + raw.gpu_resource_id().0 + ); + assert!(held.contains(&(pack, texture)), "{held:?}"); + }); +} + /// 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/heap.rs b/crates/metal2vulkan/src/bind/heap.rs index 790c87546..8b2c80678 100644 --- a/crates/metal2vulkan/src/bind/heap.rs +++ b/crates/metal2vulkan/src/bind/heap.rs @@ -291,7 +291,7 @@ pub(crate) fn fit(shape: &TextureShape, class: &ImageHandleClass) -> Fit { /// Whether a member of facts `shape` is a texture a heap reads by its raw texels: an unswizzled, /// not sparse texture of one sample, of a form of `ExtendedRange::HEAP_READ`. -fn raw_held(shape: &TextureShape) -> bool { +pub(crate) fn raw_held(shape: &TextureShape) -> bool { match *shape { TextureShape::Texture { pixel_format, diff --git a/crates/metal2vulkan/src/bind/plan/slots.rs b/crates/metal2vulkan/src/bind/plan/slots.rs index 00928a214..7760cde77 100644 --- a/crates/metal2vulkan/src/bind/plan/slots.rs +++ b/crates/metal2vulkan/src/bind/plan/slots.rs @@ -269,9 +269,10 @@ pub(crate) fn record_specialized( /// Record in `resources`' template the value of each key a specialized note of `stages` tests that /// no constant and no push carries but the bound resources decide (`SpecKey::BoundSamplerWord`), -/// or what the command's handles can name (`SpecKey::HeapYCbCrTextures`, through `reach`, the -/// stages a used resource's render stages reach, as for the heap's members; -/// `SpecKey::FilteringArgumentSampler`), which `BindingPlan::specialized_value` gives the runtime at +/// or what the command's handles can name (`SpecKey::HeapYCbCrTextures` and +/// `SpecKey::HeapRawTextures`, through `reach`, the stages a used resource's render stages reach, +/// as for the heap's members; `SpecKey::FilteringArgumentSampler`), which +/// `BindingPlan::specialized_value` gives the runtime at /// each draw or dispatch, where it reads such a note (`StageModule::note_clauses_bound`). Nothing /// pushes it: instantiation writes only the keys its push fields name. pub(crate) fn record_noted<'a>( @@ -291,6 +292,7 @@ pub(crate) fn record_noted<'a>( key, SpecKey::BoundSamplerWord(_) | SpecKey::HeapYCbCrTextures(_) + | SpecKey::HeapRawTextures(_) | SpecKey::FilteringArgumentSampler ) }) @@ -306,6 +308,7 @@ pub(crate) fn record_noted<'a>( } let value = match key { SpecKey::HeapYCbCrTextures(stage) => u64::from(heap_ycbcr(shape, stage, reach)), + SpecKey::HeapRawTextures(stage) => u64::from(heap_raw(shape, stage, reach)), // A sampler state of any listed shape may be the one an argument buffer names. SpecKey::FilteringArgumentSampler => u64::from( (shape.argument_samplers.shapes.iter()) @@ -340,6 +343,19 @@ 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. +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)) +} + /// Whether `shape` binds anything at `slot`. fn present(shape: &BindShape, slot: SlotRef) -> bool { shape diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 87d326d90..6fd1d061d 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -866,7 +866,7 @@ codec_enum! { ConstantLanes(f0), UnmeasuredTexels(f0), BoundTexelFormat(f0), OffsetBaseAxes(f0), SamplerAnisotropy(f0), RangeAtBindOffset(f0), PlainHalfTexels(f0), NearestPixelSampler(f0), BoundSamplerWord(f0), HeapYCbCrTextures(f0), - FilteringArgumentSampler, StageInReach, + FilteringArgumentSampler, StageInReach, HeapRawTextures(f0), } PushField { RootTableAddress, ExecutionStatusAddress, DispatchRegion, BaseVertexInstance, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 0088ca06f..213a1024c 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 = 2009; +pub const SEMANTICS_VERSION: u32 = 2010; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 2009; /// 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 = 497; +pub const ARTIFACT_FORMAT_VERSION: u32 = 498; /// 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/sampler/linear.rs b/crates/metal2vulkan/src/lower/sampler/linear.rs index 8bafd3291..b36d5f938 100644 --- a/crates/metal2vulkan/src/lower/sampler/linear.rs +++ b/crates/metal2vulkan/src/lower/sampler/linear.rs @@ -158,7 +158,7 @@ pub(super) fn metal_filtered_ycbcr(cx: &SelectCx<'_>, image: ImageRef) -> Option ] .map(|p| NoteTest::equal(NoteOn::Bound(index), TexelFormat::PACKED_MASK, p.class().0)), ), - ImageRef::Heap { .. } => any_of([NoteTest::equal(NoteOn::HeapTextures(cx.stage), 1, 1)]), + ImageRef::Heap { .. } => any_of([NoteTest::equal(NoteOn::HeapYCbCr(cx.stage), 1, 1)]), }) } diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index acf24d517..572052815 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -467,7 +467,7 @@ pub fn select_heap_sampling( }; let image = ImageRef::Heap { group, handle }; let mut x = select_one(cx, call, image, s, None, m)?; - x.heap_raw = select_heap_raw(cx, call, (group, handle), s)?; + x.heap_raw = select_heap_raw(cx, call, (group, handle), s, m)?; Ok(TextureStrategy::Sampling(Box::new(x))) } @@ -485,6 +485,7 @@ fn select_heap_raw( call: Call<'_>, (group, handle): (u32, ValueId), sampler: SamplerArg, + m: &mut Meter, ) -> Result, Error> { let shape = call.t.image; let float = match call.t.texel { @@ -500,7 +501,7 @@ fn select_heap_raw( if shape.ms || shape.depth || shape.dim == ImageDim::Buffer || !float { return Ok(None); } - let raw = heap_raw_sample(cx, call, (group, handle), sampler)?; + let raw = heap_raw_sample(cx, call, (group, handle), sampler, m)?; // The neutral wherever such a texture is reached, or where the runtime sampler slot's bound // sampler states what the emulation does not answer. let reads_neutral = match &raw { @@ -529,12 +530,14 @@ fn select_heap_raw( /// word the emulation tests. `None` for every other call, an argument buffer's sampler's /// among them (whose listed states the plan does not check against its textures). It /// plans the group's unsigned integer class (`HeapPlan::reads_raw`), the heap's decode routines, -/// the handle's class index, and the exact routine where it may filter. +/// the handle's class index and the decode's note (`texture::heap_raw::plan`), and the exact +/// routine where it may filter. fn heap_raw_sample( cx: &mut SelectCx<'_>, call: Call<'_>, (group, handle): (u32, ValueId), sampler: SamplerArg, + m: &mut Meter, ) -> Result, Error> { use super::bicubic::TapAddress; use super::heap_raw::{HeapRaw, State}; @@ -639,14 +642,8 @@ fn heap_raw_sample( if moved.iter().enumerate().any(|(a, k)| *k != 0 && wraps(a)) { cx.precision.insert(PrecisionNote::ViewBaseTexelOffset); } - if let Some(h) = cx.families.texture.heap.get_mut(&group) { - h.reads_raw = true; - } - cx.families.texture.heap_raw.insert(false); - if half { - cx.families.texture.heap_raw.insert(true); - } - cx.families.access.heap_class_index = true; + // Every sample takes the `float` routine, a `half` one the `half` routine too. + 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`). if gather.is_none() && !matches!(state, State::Constant { linear: false, .. }) { cx.precision.insert(PrecisionNote::BicubicFilterArithmetic); diff --git a/crates/metal2vulkan/src/lower/select.rs b/crates/metal2vulkan/src/lower/select.rs index ddab22858..6c8e8648c 100644 --- a/crates/metal2vulkan/src/lower/select.rs +++ b/crates/metal2vulkan/src/lower/select.rs @@ -1774,9 +1774,9 @@ fn finish( /// `UnmeasuredTexels` boolean, or the class of the format bound at a texture slot, which no /// constant carries (`SpecKey::BoundTexelFormat`), or the whole word of the sampler bound at a /// sampler slot, which none carries either (`SpecKey::BoundSamplerWord`), or whether a texture a -/// stage's handles can name is two-plane YCbCr (`SpecKey::HeapYCbCrTextures`), or whether a sampler -/// state an argument buffer can name filters (`SpecKey::FilteringArgumentSampler`), which the plan -/// gives. +/// stage's handles can name is two-plane YCbCr (`SpecKey::HeapYCbCrTextures`) or held by its raw +/// texels alone (`SpecKey::HeapRawTextures`), or whether a sampler state an argument buffer can +/// name filters (`SpecKey::FilteringArgumentSampler`), which the plan gives. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub(crate) enum NoteOn { Sampler(u32), @@ -1784,7 +1784,8 @@ pub(crate) enum NoteOn { Unmeasured(u32), Bound(u32), BoundSampler(u32), - HeapTextures(Stage), + HeapYCbCr(Stage), + HeapRaw(Stage), ArgumentSamplers, } @@ -1857,7 +1858,8 @@ fn declared(families: &FamilyPlans, t: NoteTest) -> Option { SpecKey::BoundSamplerWord(families.sampler.slots.get(&index)?.slot) } // Given by the plan from what the command's handles can name, never a constant. - NoteOn::HeapTextures(stage) => SpecKey::HeapYCbCrTextures(stage), + NoteOn::HeapYCbCr(stage) => SpecKey::HeapYCbCrTextures(stage), + NoteOn::HeapRaw(stage) => SpecKey::HeapRawTextures(stage), NoteOn::ArgumentSamplers => SpecKey::FilteringArgumentSampler, NoteOn::Sampler(index) => { let r = families.sampler.slots.get(&index)?; diff --git a/crates/metal2vulkan/src/lower/texture/heap_raw.rs b/crates/metal2vulkan/src/lower/texture/heap_raw.rs index 4ae109be5..96fd4a652 100644 --- a/crates/metal2vulkan/src/lower/texture/heap_raw.rs +++ b/crates/metal2vulkan/src/lower/texture/heap_raw.rs @@ -13,8 +13,19 @@ //! module's routine, which decodes it as a slot's read does (`extended_range::decode`, its `half` //! rounding included) and selects Metal's out-of-bounds texel outside the texture: zero, alpha 1 //! for a form without alpha. +//! +//! That decode is the device's arithmetic, as a slot's is (`ArithPlan::converts`), so a function +//! that plans it ([`plan`]) records `PrecisionNote::DevicePackConversion`, specialized on a +//! texture the stage's handles can name being held by its raw texels alone +//! (`SpecKey::HeapRawTextures`, which a plan gives from the command's heap members): the note is +//! in the module's notes, and a runtime announces it at a draw or dispatch whose command can name +//! such a texture. +use crate::budget::Meter; +use crate::error::Error; +use crate::lower::select::{any_of, NoteOn, NoteTest, SelectCx}; use crate::metal::format::ExtendedRange; +use crate::pipeline::artifact::PrecisionNote; use crate::spirv::builder::ModuleBuilder; use crate::spirv::error::BResult; use crate::spirv::ids::FuncId; @@ -37,6 +48,27 @@ pub const READ_WORDS: u32 = 256; /// element's access chain, load and query. pub const QUERY_WORDS: u32 = 128; +/// 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`). +pub(crate) fn plan( + cx: &mut SelectCx<'_>, + group: u32, + halves: &[bool], + m: &mut Meter, +) -> Result<(), Error> { + if let Some(h) = cx.families.texture.heap.get_mut(&group) { + h.reads_raw = true; + } + 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); + cx.note_when(PrecisionNote::DevicePackConversion, any_of([raw]), m) +} + /// Define the routine decoding raw texel `raw` (a `uvec4`, the raw format's lanes) of the form at /// index `form` (a `u32`) of `ExtendedRange::HEAP_READ`, inside the texture where `inb` (a /// `bool`) holds, else Metal's out-of-bounds texel, as a `vec4` of `f32` (a `half` result's lanes diff --git a/crates/metal2vulkan/src/lower/texture/mod.rs b/crates/metal2vulkan/src/lower/texture/mod.rs index e98c2d0ee..ef7888df6 100644 --- a/crates/metal2vulkan/src/lower/texture/mod.rs +++ b/crates/metal2vulkan/src/lower/texture/mod.rs @@ -3156,14 +3156,7 @@ fn select_read_as( && texel.lanes == 4 && matches!(texel.conv, TexelConv::F32 | TexelConv::F16) => { - if let Some(h) = cx.families.texture.heap.get_mut(&group) { - h.reads_raw = true; - } - cx.families - .texture - .heap_raw - .insert(texel.conv == TexelConv::F16); - cx.families.access.heap_class_index = true; + heap_raw::plan(cx, group, &[texel.conv == TexelConv::F16], m)?; true } _ => false, diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 5ad8e5b15..dc1959a85 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -457,7 +457,8 @@ impl SpecClause { /// (`BindingPlan::specialized_value`): one the function reads as data /// (`SpecKey::read_as_data`), the word of the sampler bound at a slot /// (`SpecKey::BoundSamplerWord`), or what the stage's handles can name - /// (`SpecKey::HeapYCbCrTextures`, `SpecKey::FilteringArgumentSampler`). A runtime reads such + /// (`SpecKey::HeapYCbCrTextures`, `SpecKey::HeapRawTextures`, + /// `SpecKey::FilteringArgumentSampler`). A runtime reads such /// a clause at each draw or dispatch, from the values its plan gives /// ([`StageModule::note_clauses_bound`]). pub fn tests_bound_values(&self) -> bool { @@ -467,6 +468,7 @@ impl SpecClause { t.key, SpecKey::BoundSamplerWord(_) | SpecKey::HeapYCbCrTextures(_) + | SpecKey::HeapRawTextures(_) | SpecKey::FilteringArgumentSampler ) }) @@ -2040,7 +2042,12 @@ pub enum PrecisionNote { /// `2^-13` before its table, a step there spanning 1.6 codes), an sRGB twin's decoded value /// within half a `2^-13` step of Metal's table (`R10Unorm_X6_sRGB`'s and /// `RGB10A2Unorm_sRGB`'s colour within 1.64 steps) beyond the `Pow`'s bound, a `half` result - /// within one `half` ulp. Validation derives no tolerance from it. + /// within one `half` ulp. A `float` or `half` read, sample or gather through an argument + /// buffer that decodes a texture the heap holds by its raw texels alone + /// (`lower::texture::heap_raw`) records it as a specialized note: it holds where a texture + /// the stage's handles can name is one (`SpecKey::HeapRawTextures`, which a plan gives), + /// unless the stage records it outright for another conversion. Validation derives no + /// tolerance from it. DevicePackConversion, /// A render pipeline whose color attachments the device draws in more than one group /// (`GraphicsState::color_group`, the module docs of `pipeline::compile::color_group`): a diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 36bc72d25..c1e790e6d 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -843,6 +843,14 @@ 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. + 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 /// shape in `BindShape`) has a linear minification, magnification or mip filter, anisotropy, diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs b/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs index e68500e44..40c8d6fa7 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/heap.rs @@ -16,6 +16,10 @@ //! runtime sampler's sample declare them and state the fact; a mip-filtered sampler's sample //! states it alone. The same lane compares such samples and gathers through an argument buffer //! with the slot's, and checks the bind refusal of the others. +//! - Each such decode records `PrecisionNote::DevicePackConversion` under one clause, a texture the +//! stage's handles can name held raw (`SpecKey::HeapRawTextures`), which a plan gives from the +//! textures its command makes resident; a query, a `uint` read and a sample the function does +//! not emulate record none. use super::*; use crate::error::{Error, Unsupported}; @@ -377,13 +381,22 @@ fn heap_samples_reach_a_raw_member_through_the_unsigned_twin() { /// A heap access that decodes a texture the heap holds by its raw texels alone /// (`texture::heap_raw`: a `float` or `half` read, and a sample or gather the function emulates, /// `sampler::heap_raw`) records `PrecisionNote::DevicePackConversion`, as a slot's decode of the -/// same texel does, on every committed profile with a sampled heap. A heap access that reaches no -/// such texture records none: a width query alone, a `uint` read, and a sample through a -/// mip-filtered sampler, which the function does not emulate (`RuntimeFact::HeapRawSamples`). +/// same texel does, on every committed profile with a sampled heap: specialized on a texture the +/// stage's handles can name being such a texture (`SpecKey::HeapRawTextures`), its one clause. A +/// heap access that reaches no such texture records none: a width query alone, a `uint` read, and +/// a sample through a mip-filtered sampler, which the function does not emulate +/// (`RuntimeFact::HeapRawSamples`). #[test] fn heap_decodes_record_the_device_pack_conversion() { - use crate::pipeline::PrecisionNote; + use crate::pipeline::{PrecisionNote, SpecClause, SpecTest}; let note = PrecisionNote::DevicePackConversion; + let raw = SpecClause { + all: vec![SpecTest::equal( + SpecKey::HeapRawTextures(Stage::Kernel), + 1, + 1, + )], + }; let consts = FunctionConstantValues::defaults(); let entry = EntryRef::Name("k"); let inputs = LowerInputs::new(); @@ -438,6 +451,15 @@ fn heap_decodes_record_the_device_pack_conversion() { "{what}: {:?}", a.precision ); + let when: Vec<&SpecClause> = (a.specialized.iter()) + .filter(|s| s.note == note) + .flat_map(|s| &s.when) + .collect(); + let want: Vec<&SpecClause> = match decodes { + true => vec![&raw], + false => Vec::new(), + }; + assert_eq!(when, want, "{what}"); compiled += 1; } assert!( @@ -447,6 +469,80 @@ fn heap_decodes_record_the_device_pack_conversion() { } } +/// 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 +/// 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 +/// known value (a reading of the module alone). +#[test] +fn a_heap_decode_s_note_holds_where_its_command_can_name_a_raw_texture() { + use crate::bind::{ResourceClass, UsedResource}; + use crate::cache::SpecializationKey; + use crate::pipeline::PrecisionNote; + let note = PrecisionNote::DevicePackConversion; + let key = SpecKey::HeapRawTextures(Stage::Kernel); + let Some(bc) = assemble("heap_note_plan", &kernel(Use::Float)) 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() + }; + let cases: [(&[PixelFormat], bool); 6] = [ + (&[PixelFormat::BGRA10XR], true), + (&[PixelFormat::RGBA16Bfloat], true), + (&[PixelFormat::RGBA8Unorm, PixelFormat::BGRA10XR], true), + (&[], false), + (&[PixelFormat::RGBA8Unorm], false), + (&[PixelFormat::RGBA16Float], 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}"), + }; + assert!( + (p.stage) + .precision_notes_under(&SpecializationKey::new()) + .contains(¬e), + "{stem}: {:?}", + p.stage.precision_notes + ); + for (formats, raw) 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}"); + let held = (p.stage) + .precision_notes_bound(&plan.specialization, &|k| plan.specialized_value(k)) + .contains(¬e); + assert_eq!(held, raw, "{what}"); + planned += 1; + } + } + assert!(planned > 0, "no committed profile has the sampled heap"); +} + /// A `half` read, nearest sample or gather of a texture an argument buffer holds rounds its texel /// through the device's conversion of the texel's `f32` value (`narrow::round_texel`): the /// fetched texel's, merged with the decode routine's texel of a form a heap reads. On diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 12105a80c..4b4e1737c 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -14507,6 +14507,7 @@ variant metal2vulkan::pipeline::SpecKey::BoundTexelFormat BoundTexelFormat(SlotR variant metal2vulkan::pipeline::SpecKey::ConstantLanes ConstantLanes(SlotRef) variant metal2vulkan::pipeline::SpecKey::FilteringArgumentSampler FilteringArgumentSampler variant metal2vulkan::pipeline::SpecKey::FlatLocalSize FlatLocalSize +variant metal2vulkan::pipeline::SpecKey::HeapRawTextures HeapRawTextures(Stage) variant metal2vulkan::pipeline::SpecKey::HeapYCbCrTextures HeapYCbCrTextures(Stage) variant metal2vulkan::pipeline::SpecKey::ImageblockHeight ImageblockHeight variant metal2vulkan::pipeline::SpecKey::ImageblockWidth ImageblockWidth diff --git a/docs/API.md b/docs/API.md index 6295d2d62..f7946ac79 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4234,10 +4234,13 @@ bound. `half` result within one `half` ulp. A texture a heap holds by its raw texels alone (`BGR10_XR`, `BGRA10_XR`, `R10Unorm_X6`, `RG10Unorm_X12` and the bfloat formats: `bind::heap_raw_form`), whose `float` read, sample or gather through an argument buffer the - function decodes the same way, is announced by the runtime instead of by the stage, naming the - texture, at the first command that binds a heap set holding it (whether or not its function - reads it) or as it is placed in a set a command buffer that bound the set and has not completed - may read through. + function decodes the same way: such a stage records the note as a specialized note, holding + where a texture its handles can name is one (`SpecKey::HeapRawTextures`, which the binding plan + gives from the textures the command makes resident or binds), so a reading of the module alone + holds it and a draw or dispatch whose command can name one announces it. The runtime also + announces it naming the texture, at the first command that binds a heap set holding it (whether + or not its function reads it) or as it is placed in a set a command buffer that bound the set + and has not completed may read through. - `metal2vulkan-degrade-color-attachment-groups` (precision). `PrecisionNote::ColorAttachmentGroups`: A render pipeline whose color attachments the device draws in more than one group (more than the lesser of its `maxColorAttachments` and