From 4a06ce915da40ed8525a7d4125374fa6c2e3cacb Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 15 Nov 2026 17:26:02 -0800 Subject: [PATCH] SEMANTICS 2129, RUNTIME 2399: Heap storage reads by the formats' own read bits on a device without the feature A compute pipeline that reads a read_write argument-buffer texture was refused Unsupported{ArgumentBufferTextures, needs ShaderStorageImageReadWithoutFormat} on a device without shaderStorageImageReadWithoutFormat (ANV on Gfx12.0, the Iris Xe), so the guest's work waited on a nil pipeline. Vulkan 1.3 and VK_KHR_format_feature_flags2 enable the SPIR-V capability StorageImageReadWithoutFormat, and a read of a view without a format is then valid wherever the view's format has STORAGE_READ_WITHOUT_FORMAT_BIT (spec 19.9.3, VUID-vkCmdDispatch-OpTypeImage-07028). The slot path already took that route; the heap path checked the feature alone. - declare_heap takes a storage (and storage texel buffer) read by the feature or by the formats' bits (DeviceProfile::storage_reads_by_format_bits), and on such a profile needs the read bit of the class's neutral, which a null handle reads. - The binder keeps each storage view as before (writes unchanged). On such a profile, a member whose view's format lacks the read bit is held for its writes and flagged (new entry flag FLAG_STORAGE_UNREADABLE, bit 28: the texel-class field narrows to the 12 bits its indices use), and a storage read through its handle reads the null element, as a nil texture's read does. A member of one of Metal's read-write tier formats, whose read Metal's contract defines, is refused without the bit instead. - handle_entry_flags takes the profile (the flag is the device's). On the committed Iris profile every Metal read-write tier format has the read bit; RGB10A2, BGR10A2, RG11B10Float, BGRA8 and the 16-bit packed formats do not (Mesa's isl: no Gfx12.0 typed reads). A read-write tier format whose view lacks the bit is not refused at the member (binding runs for every shader-writable texture of the runtime's device-wide heap, so a refusal there dropped the texture's writes on a profile such as roadmap-2022, job m3-max-34236): lower::texture::slot:: declare_heap refuses the function that reads a heap storage class where any tier format would be held in that class through a view without the bit, naming each view's bit; the member is held for its writes, flagged. Docs: API.md accepted difference, FAST-PATHS known gap and device-gap row, REFUSALS.md. Verified in the lane (m3-max-34272): clippy -D warnings for metal2vulkan, metal2vulkan-runtime and metal2vulkan-validation, all targets and features; nextest over the heap, handle, storage, profile, fast_paths, without_format, texel_class and tier tests plus api_signatures, refusal_surface and api_surface: 317 passed. A synthetic Iris profile with RGBA16F's read bit cleared refuses the reading kernel naming that format; the committed Iris compiles it. The lavapipe lane with the feature withheld and the Iris run follow from the lane. --- crates/metal2vulkan-runtime/src/heap_sets.rs | 2 +- .../src/runtime_lane/alpha_in_red.rs | 37 +- .../src/runtime_lane/detach_textures.rs | 22 +- .../metal2vulkan/src/bind/dispatch/tests.rs | 1 + crates/metal2vulkan/src/bind/heap.rs | 205 +++++++- crates/metal2vulkan/src/bind/heap/tests.rs | 8 + crates/metal2vulkan/src/cache/mod.rs | 4 +- crates/metal2vulkan/src/device/metal.rs | 44 +- crates/metal2vulkan/src/device/profile.rs | 10 + crates/metal2vulkan/src/lower/access/mod.rs | 11 +- crates/metal2vulkan/src/lower/texture/emit.rs | 49 +- crates/metal2vulkan/src/lower/texture/mod.rs | 34 +- crates/metal2vulkan/src/lower/texture/slot.rs | 52 +- crates/metal2vulkan/src/memory/handles.rs | 158 ++++-- .../src/tests/engine_heap_binder.rs | 4 + .../src/tests/engine_heap_storage_reads.rs | 488 ++++++++++++++++++ .../src/tests/engine_heap_ycbcr_writes.rs | 2 +- crates/metal2vulkan/src/tests/mod.rs | 1 + crates/metal2vulkan/tests/api_signatures.tsv | 2 +- docs/API.md | 14 +- docs/FAST-PATHS.md | 9 +- 21 files changed, 1036 insertions(+), 121 deletions(-) create mode 100644 crates/metal2vulkan/src/tests/engine_heap_storage_reads.rs diff --git a/crates/metal2vulkan-runtime/src/heap_sets.rs b/crates/metal2vulkan-runtime/src/heap_sets.rs index 71cd2163a..652fa770f 100644 --- a/crates/metal2vulkan-runtime/src/heap_sets.rs +++ b/crates/metal2vulkan-runtime/src/heap_sets.rs @@ -610,7 +610,7 @@ impl DeviceHeaps { return self.clear(device, id); } let facts = texture.facts(); - let flags = handle_entry_flags(&facts); + let flags = handle_entry_flags(device.compile_device().profile(), &facts); let bytes = texture.bytes_key(); // The neutral's entry until every set holds the texture. if let Some(table) = &self.table { diff --git a/crates/metal2vulkan-validation/src/runtime_lane/alpha_in_red.rs b/crates/metal2vulkan-validation/src/runtime_lane/alpha_in_red.rs index 2c643eaf1..e11ca356e 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/alpha_in_red.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/alpha_in_red.rs @@ -1442,7 +1442,11 @@ fn a8_texture_buffer_reads_and_writes_alpha_as_metal() { /// its write of (0.8, 0.6, 0.4, 0.2) stores 51, and a `write` member's write of /// (0.2, 0.4, 0.6, 0.8) stores 204), through the texture's `R8_UNORM` image on the device without /// `A8_UNORM`, and its own where it has the format. A device without -/// `shaderStorageImageReadWithoutFormat` (ANV) refuses the kernel, `ArgumentBufferTextures`. +/// `shaderStorageImageReadWithoutFormat` (ANV) reads by the view format's own +/// `STORAGE_READ_WITHOUT_FORMAT` bit under `VK_KHR_format_feature_flags2`: the `read_write` member +/// reads zero where its view lacks the bit (`A8Unorm` is outside Metal's read-write tiers, +/// docs/API.md), and its writes store as Metal's. Without the extension too it refuses the kernel, +/// `ArgumentBufferTextures`. #[test] fn a8_argument_buffer_storage_reads_and_writes_alpha_as_metal() { let messages = Messages::default(); @@ -1457,11 +1461,27 @@ fn a8_argument_buffer_storage_reads_and_writes_alpha_as_metal() { continue; } let form = if withheld { "R8_UNORM" } else { "A8_UNORM" }; - // A heap's storage reads are declared without a format and need the device's feature - // (its formats' own bits do not serve a heap, docs/FAST-PATHS.md): refused without it. + // A heap's storage reads are declared without a format: they need the device's feature, + // or, without it, read by the view format's own bit under `VK_KHR_format_feature_flags2`, + // reading zero where the view lacks the bit. Refused without either. let profile = lane.device.compile_device().profile(); let feature = VkFeature::ShaderStorageImageReadWithoutFormat; - if !profile.enabled().features.contains(&feature) { + let enabled = profile.enabled(); + let has_feature = enabled.features.contains(&feature); + let by_bits = !has_feature + && enabled + .extensions + .contains(&VkExtension::KhrFormatFeatureFlags2); + let view = match lane.in_red() { + true => metal2vulkan::vk::Format::R8_UNORM, + false => metal2vulkan::vk::Format::A8_UNORM, + }; + let readable = !by_bits + || profile.supports_format( + view, + metal2vulkan::device::FormatUsage::StorageImageReadWithoutFormat, + ); + if !has_feature && !by_bits { let function = lane .buffers .new_function_with_name("a8r_held") @@ -1499,10 +1519,13 @@ fn a8_argument_buffer_storage_reads_and_writes_alpha_as_metal() { None, Some((&held, &[&rw, &w])), ); - let alpha = [0.0, 0.0, 0.0, 153.0 / 255.0]; + let alpha = match readable { + true => [0.0, 0.0, 0.0, 153.0 / 255.0], + false => [0.0; 4], + }; assert!( got.iter().all(|&v| v == alpha), - "{name} {form}: the read_write member read {got:?}" + "{name} {form}: the read_write member read {got:?} (by bits {by_bits}, readable {readable})" ); every( &format!("{name} {form}: the read_write member"), @@ -1514,7 +1537,7 @@ fn a8_argument_buffer_storage_reads_and_writes_alpha_as_metal() { &lane.bytes(&w), STORED, ); - println!("A8-HELD {name} {form}: as Metal's"); + println!("A8-HELD {name} {form}: read {alpha:?}, writes as Metal's (by bits {by_bits}, view readable {readable})"); drop(lane); layer_reported_nothing_at_all(&messages); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/detach_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/detach_textures.rs index f834d2f7b..6603aa72e 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/detach_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/detach_textures.rs @@ -42,7 +42,7 @@ use super::{ at_plan, bound_buffers, encode_case, pipeline_state, public_case, CaseResources, PublicCase, }; use super::{buffer_with, texture_descriptor, WAIT}; -use metal2vulkan::device::VkFeature; +use metal2vulkan::device::{VkExtension, VkFeature}; use metal2vulkan::error::{Capability, Feature, Needs}; use metal2vulkan::metal::{PixelFormat, ResourceUsage, TextureUsage}; use metal2vulkan_devtools::llvm_assemble_text; @@ -795,9 +795,11 @@ attributes #8 = { nounwind willreturn memory(argmem: readwrite) } /// and its size is its own. `DetachedStorageKeepsWrites` is announced once for the texture, with /// its ID, in the first commit; `StaleDetachedReach` is not. /// -/// A device without `shaderStorageImageReadWithoutFormat` (Intel's ANV) refuses the kernel: -/// a storage texture reached by ID has no format its module could declare, so its read needs -/// that feature (`Unsupported(ArgumentBufferTextures)` naming it). +/// A storage texture reached by ID has no format its module could declare, so its read needs +/// `shaderStorageImageReadWithoutFormat` or, without it (Intel's ANV), the formats' own read bits +/// under `VK_KHR_format_feature_flags2` (the case's `RGBA32Float` is a read-write tier format, so +/// the kernel compiles there only where its view has the bit); a device with neither refuses the +/// kernel (`Unsupported(ArgumentBufferTextures)` naming the feature). #[test] fn a_storage_read_after_an_unnamed_storage_write_reads_the_sink_and_is_announced_once() { on_device_noticed_with(at_plan, |device, messages| { @@ -812,13 +814,11 @@ fn a_storage_read_after_an_unnamed_storage_write_reads_the_sink_and_is_announced bytes.detach(); let made = made_pipeline_of(device, &llvm_assemble_text(READ_WRITE).unwrap(), "k"); let feature = VkFeature::ShaderStorageImageReadWithoutFormat; - let state = if device - .compile_device() - .profile() - .enabled() - .features - .contains(&feature) - { + let enabled = device.compile_device().profile().enabled(); + let by_bits = enabled + .extensions + .contains(&VkExtension::KhrFormatFeatureFlags2); + let state = if enabled.features.contains(&feature) || by_bits { made.unwrap() } else { let Err(Error::Unsupported(refused)) = made else { diff --git a/crates/metal2vulkan/src/bind/dispatch/tests.rs b/crates/metal2vulkan/src/bind/dispatch/tests.rs index 511d6e939..56995592d 100644 --- a/crates/metal2vulkan/src/bind/dispatch/tests.rs +++ b/crates/metal2vulkan/src/bind/dispatch/tests.rs @@ -1218,6 +1218,7 @@ fn dispatch_reads_names_the_slot_values_the_commands_read() { source: HeapSource::Bound(slot(SlotClass::Texture, 2)), shape: facts(1).shape(), stages: vec![Stage::Kernel], + unreadable: false, }); t.resources.handle_tables.push(PlannedHandleTable { set: 0, diff --git a/crates/metal2vulkan/src/bind/heap.rs b/crates/metal2vulkan/src/bind/heap.rs index 0f92001bc..9bdb57a39 100644 --- a/crates/metal2vulkan/src/bind/heap.rs +++ b/crates/metal2vulkan/src/bind/heap.rs @@ -32,9 +32,15 @@ //! `AlphaInRed`) without an alias, or such an alias, and the view's format serves those accesses //! without a format //! (`metal::format::without_format_gaps`: the device's features and the format's own -//! `VkFormatFeatureFlags2` bits). A fitting member the heap cannot view (another storage choice, -//! a format the profile cannot sample or store) is `Unsupported`, as for a slot: a handle may -//! name it. A storage class holds a texture whose writes Metal drops +//! `VkFormatFeatureFlags2` bits). On a device that reads storage without a format by the +//! formats' own bits alone (`DeviceProfile::storage_reads_by_format_bits`: ANV before Gfx12.5), +//! the device lets a heap write alone, and a storage view whose format lacks the read bit +//! holds its member for its writes, flagged [`FLAG_STORAGE_UNREADABLE`] ([`storage_unreadable`]), +//! whose storage read reads the null element. Metal's contract defines a `read_write` read of its +//! read-write tier formats, so a function that reads a storage class through a handle is +//! refused where one of them would be so held ([`tier_read_gaps`]). A fitting member the heap cannot view (another storage choice, a format the profile cannot +//! sample or store) is `Unsupported`, as for a slot: a handle may name it. A storage class +//! holds a texture whose writes Metal drops //! (`metal::format::writes_dropped`: the 4:2:2 formats, the subsampled and packed two-plane //! YCbCr ones) as its neutral ([`Fit::Dropped`]), which the writes leave as Metal leaves the //! texture, and a 4:4:4 two-plane YCbCr texture whose writes Metal stores into its planes @@ -80,8 +86,10 @@ //! [`FLAG_BORDER_TEXELS`] (`metal::sampler::border_texels` of its pixel format and swizzle, a //! placeholder format's those of the neutral it reads), which a read through a sampler hands //! back at a border; [`FLAG_YCBCR_WRITES`] where it is a 4:4:4 two-plane YCbCr texture whose -//! writes Metal stores (`metal::format::ycbcr_writes_stored`); and its texel class in -//! [`FLAG_TEXEL_CLASS`]. Every other bit is 0. +//! writes Metal stores (`metal::format::ycbcr_writes_stored`); its texel class in +//! [`FLAG_TEXEL_CLASS`]; and [`FLAG_STORAGE_UNREADABLE`] where the plan's profile cannot read its +//! storage view without a format ([`storage_unreadable`], `HeapMember::unreadable`). Every other +//! bit is 0. //! - **Heap samplers**. A heap image is sampled through a separate sampler binding //! (`BindingSource::HeapSampler`) in set 0: a constexpr sampler is the layout's immutable sampler //! and takes no write; a runtime `[[sampler(n)]]` is written with the sampler bound at slot `n` @@ -161,8 +169,8 @@ use crate::device::DeviceProfile; use crate::error::{BindError, Feature, Unsupported}; use crate::memory::handles::{ lookup_host, ENTRY_ELEMENT, ENTRY_FLAGS, ENTRY_ID_HI, ENTRY_ID_LO, FLAG_BORDER_TEXELS, - FLAG_OUT_OF_BOUNDS_ALPHA_ONE, FLAG_RED_BLUE, FLAG_TEXEL_CLASS, FLAG_YCBCR_WRITES, - NEUTRAL_ELEMENT, TABLE_CAPACITY, TABLE_ENTRY_BYTES, + FLAG_OUT_OF_BOUNDS_ALPHA_ONE, FLAG_RED_BLUE, FLAG_STORAGE_UNREADABLE, FLAG_TEXEL_CLASS, + FLAG_YCBCR_WRITES, NEUTRAL_ELEMENT, TABLE_CAPACITY, TABLE_ENTRY_BYTES, }; use crate::metal::format::{ is_depth_stencil, red_blue_exchanged, sampled_type, storage_choice, storage_view_formats, @@ -218,6 +226,9 @@ pub(crate) struct HeapMember { pub shape: TextureShape, /// The stages whose handle tables enter it. pub stages: Vec, + /// Its view in the storage arrays cannot be read without a format on the plan's profile + /// ([`storage_unreadable`]): its entry's flags carry `FLAG_STORAGE_UNREADABLE`. + pub unreadable: bool, } /// One stage's handle table. @@ -575,7 +586,8 @@ fn member_view( .ok_or_else(|| internal("a storage heap member without a format"))?, }; // The declaration names no format, so the member's format must serve those accesses - // without one. + // without one. Where the formats' own bits alone grant a read, a member whose view's + // format lacks the read bit is held for its writes and flagged ([`storage_unreadable`]). let gaps = without_format_gaps(format, use_, profile); if !gaps.is_empty() { return Err(BindError::Unsupported(Unsupported::needs_any_of( @@ -653,7 +665,8 @@ pub fn heap_element( } } -/// The flags word of the handle-table entry of a texture of `facts`, for [`handle_entry`]: bit 1 +/// The flags word of the handle-table entry of a texture of `facts` on `profile`, for +/// [`handle_entry`]: bit 1 /// where its pixel format has no alpha, so a shader-checked read past the texture takes Metal's /// out-of-bounds alpha of 1; bit 2 where its pixel format is blue-first /// (`metal::format::red_blue_exchanged`), so a storage access exchanges red and blue where the @@ -664,14 +677,18 @@ pub fn heap_element( /// emulates Metal's linear filter of the texture's texels, 0 for a swizzled texture; bit 15 where /// it is a 4:4:4 two-plane YCbCr texture whose writes Metal stores into its planes /// (`metal::format::ycbcr_writes_stored`), so a heap write marks its write shadow -/// (`memory::handles::FLAG_YCBCR_WRITES`); every other bit 0. A caller passes the word through -/// as is. -pub fn handle_entry_flags(facts: &TextureFacts) -> u32 { - entry_flags(&facts.shape()) +/// (`memory::handles::FLAG_YCBCR_WRITES`); bit 28 where `profile` reads storage without a format +/// by the formats' own bits alone and cannot read the texture's view in the heap's storage arrays +/// so (`memory::handles::FLAG_STORAGE_UNREADABLE`), whereupon a storage read through its handle +/// reads the null element; every other bit 0. A caller passes the word through as is. +pub fn handle_entry_flags(profile: &DeviceProfile, facts: &TextureFacts) -> u32 { + let shape = facts.shape(); + entry_flags(&shape, storage_unreadable(profile, &shape)) } -/// [`handle_entry_flags`] of a texture of view facts `shape`. -fn entry_flags(shape: &TextureShape) -> u32 { +/// [`handle_entry_flags`] of a texture of view facts `shape`, `unreadable` its +/// [`storage_unreadable`]. +fn entry_flags(shape: &TextureShape, unreadable: bool) -> u32 { let pixel_format = shape.pixel_format(); let swizzle = shape.swizzle(); let alpha = match crate::metal::format::out_of_bounds_alpha_one(pixel_format) { @@ -693,7 +710,145 @@ fn entry_flags(shape: &TextureShape) -> u32 { true => FLAG_YCBCR_WRITES, false => 0, }; - alpha | red_blue | ycbcr | (border & FLAG_BORDER_TEXELS) | (class & FLAG_TEXEL_CLASS) + let unreadable = match unreadable { + true => FLAG_STORAGE_UNREADABLE, + false => 0, + }; + alpha + | red_blue + | ycbcr + | unreadable + | (border & FLAG_BORDER_TEXELS) + | (class & FLAG_TEXEL_CLASS) +} + +/// Whether `profile` reads storage without a format by the formats' own bits alone +/// (`DeviceProfile::storage_reads_by_format_bits`) and the heap's storage arrays hold a texture of +/// view facts `shape` through a view it cannot read so: one whose format lacks +/// `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` ([`storage_read_gaps`]). Such an array +/// holds it for its writes, which the device stores without a format as before; a storage read +/// through its handle reads the null element instead (`memory::handles::FLAG_STORAGE_UNREADABLE`), +/// as a nil texture's read does. A function that reads the array is compiled only where none of +/// Metal's read-write tier formats is so held ([`tier_read_gaps`]). False on every other profile, +/// and for a texture no storage array holds. +pub(crate) fn storage_unreadable(profile: &DeviceProfile, shape: &TextureShape) -> bool { + if !profile.storage_reads_by_format_bits() { + return false; + } + let texture_type = match *shape { + TextureShape::Texture { texture_type, .. } => texture_type, + TextureShape::Buffer { .. } => TextureType::TextureBuffer, + }; + let (pixel_format, swizzle) = (shape.pixel_format(), shape.swizzle()); + let Some(sampled_type) = sampled_type(pixel_format) else { + return false; + }; + // The storage class of the texture's own shape and numeric type, the one array that holds it + // ([`fit`]). + let (dim, arrayed, multisampled) = dims(texture_type); + let class = ImageHandleClass { + dim, + arrayed, + multisampled, + sampled_type, + depth_compare: false, + access: ImageAccess::Storage, + format: crate::pipeline::sym::StorageFormatClass::Unknown, + }; + if fit(shape, &class) != Fit::Holds { + return false; + } + let (format, texel_buffer) = match dim { + ImageDim::Buffer => match member_texel_view(profile, pixel_format, swizzle, &class) { + Ok(format) => (format, true), + Err(_) => return false, + }, + _ => match member_view(profile, shape, &class, vk::ImageLayout::GENERAL) { + Ok(view) => (view.format, false), + Err(_) => return false, + }, + }; + !storage_read_gaps(profile, format, texel_buffer).is_empty() +} + +/// What a storage view of `format` (`texel_buffer`: a texel buffer view) lacks for a read without a +/// format on `profile` where the profile reads storage so by the formats' own bits alone +/// (`DeviceProfile::storage_reads_by_format_bits`); empty on every other profile, whose storage +/// arrays hold only views every access the device's features grant serves ([`heap_storage_use`]). +fn storage_read_gaps( + profile: &DeviceProfile, + format: vk::Format, + texel_buffer: bool, +) -> Vec { + if !profile.storage_reads_by_format_bits() { + return Vec::new(); + } + let use_ = StorageUse { + texel_buffer, + read: true, + write: false, + }; + without_format_gaps(format, use_, profile) +} + +/// What `profile` lacks to read, without a format, the views through which a heap storage array of +/// `class` holds textures of Metal's read-write tier formats on the profile +/// (`device::metal::read_write_tier_formats`), whose `read_write` reads Metal's contract defines: +/// each such view's [`storage_read_gaps`], so empty but where the profile reads storage without a +/// format by the formats' own bits alone. A function that reads the array through a handle needs +/// them (`lower::texture::slot`): without them it would read such a member as +/// [`storage_unreadable`]'s null element. +pub(crate) fn tier_read_gaps( + profile: &DeviceProfile, + class: &ImageHandleClass, +) -> Vec { + use TextureType as T; + let mut gaps = Vec::new(); + if !profile.storage_reads_by_format_bits() || class.access != ImageAccess::Storage { + return gaps; + } + let types = [ + T::Type1D, + T::Type1DArray, + T::Type2D, + T::Type2DArray, + T::Type2DMultisample, + T::Type2DMultisampleArray, + T::Cube, + T::CubeArray, + T::Type3D, + T::TextureBuffer, + ]; + let shape = (class.dim, class.arrayed, class.multisampled); + let Some(texture_type) = types.into_iter().find(|&t| dims(t) == shape) else { + return gaps; + }; + let tiers = crate::device::metal::read_write_tier_formats(profile); + for &pixel_format in tiers.iter().flat_map(|tier| tier.iter()) { + let mut facts = TextureFacts::new(texture_type, pixel_format); + facts.usage = metal::TextureUsage::SHADER_READ | metal::TextureUsage::SHADER_WRITE; + let member = facts.shape(); + if fit(&member, class) != Fit::Holds { + continue; + } + let view = match class.dim { + ImageDim::Buffer => { + member_texel_view(profile, pixel_format, member.swizzle(), class).map(|f| (f, true)) + } + _ => member_view(profile, &member, class, vk::ImageLayout::GENERAL) + .map(|v| (v.format, false)), + }; + // A tier format the array cannot hold at all is not held for its writes either. + let Ok((format, texel_buffer)) = view else { + continue; + }; + for gap in storage_read_gaps(profile, format, texel_buffer) { + if !gaps.contains(&gap) { + gaps.push(gap); + } + } + } + gaps } /// A conversion a storage access through a heap handle makes of the texels of a member its @@ -806,7 +961,8 @@ fn tables(layout: &PipelineLayout, kind: SyntheticBinding) -> Vec<(Stage, u32, u } /// The heap members of `shape` for a pipeline whose handle tables are in `stages` (the module -/// docs); `reach` gives the stages a used resource's render stages reach. +/// docs); `reach` gives the stages a used resource's render stages reach. None is marked +/// unreadable: the planner marks each on its profile ([`storage_unreadable`]). pub(crate) fn members( shape: &BindShape, stages: &[Stage], @@ -830,6 +986,7 @@ pub(crate) fn members( source: HeapSource::Used(token), shape: t, stages: reached, + unreadable: false, }); } } @@ -847,6 +1004,7 @@ pub(crate) fn members( }), shape: *t, stages: vec![stage], + unreadable: false, }); } } @@ -1203,7 +1361,13 @@ impl<'a> HeapPlanner<'a> { Some((a.clone(), entries, admission)) }; let stages: Vec = tables.iter().map(|t| t.0).collect(); - let members = members(shape, &stages, reach); + let members: Vec = members(shape, &stages, reach) + .into_iter() + .map(|m| HeapMember { + unreadable: storage_unreadable(profile, &m.shape), + ..m + }) + .collect(); // A sparse texture a stage's handle tables reach where the stage observes the residency // of its heap accesses, which answer the word of a texture that is not sparse // (`RuntimeFact::HeapResidency`). @@ -2106,7 +2270,10 @@ fn handle_table_bytes( } // A member's flags: Metal's out-of-bounds read of a pixel format without alpha returns // alpha 1, and its texel class. - let flags: Vec = members.iter().map(|m| entry_flags(&m.shape)).collect(); + let flags: Vec = members + .iter() + .map(|m| entry_flags(&m.shape, m.unreadable)) + .collect(); let mut out = Vec::with_capacity(tables.len()); for t in tables { let mut entries: Vec<(u64, u32, u32)> = Vec::new(); diff --git a/crates/metal2vulkan/src/bind/heap/tests.rs b/crates/metal2vulkan/src/bind/heap/tests.rs index c1ce918a8..d732bf6c0 100644 --- a/crates/metal2vulkan/src/bind/heap/tests.rs +++ b/crates/metal2vulkan/src/bind/heap/tests.rs @@ -334,6 +334,7 @@ fn table_bytes_are_sorted_deduplicated_and_padded() { source: HeapSource::Used(token), shape: t2d, stages: vec![Stage::Kernel], + unreadable: false, }); } let planned = PlannedHandleTable { @@ -414,6 +415,7 @@ fn table_bytes_are_sorted_deduplicated_and_padded() { source: HeapSource::Bound(slot), shape: t2d, stages: vec![Stage::Kernel], + unreadable: false, }]; let two = PlannedHandleTable { entries: 2, @@ -448,6 +450,7 @@ fn resource_id_placement_puts_members_and_samplers_at_their_ids() { source: HeapSource::Used(token), shape: t2d, stages: vec![Stage::Kernel], + unreadable: false, }); } for id in [7, 2] { @@ -1278,6 +1281,7 @@ fn a_member_s_level_count_is_not_the_plan_s() { source: HeapSource::Used(7), shape, stages: vec![Stage::Kernel], + unreadable: false, }; let planned = facts.shape().at_one_level(); assert_ne!(planned, facts.shape()); @@ -1391,6 +1395,7 @@ fn a_form_a_heap_reads_is_held_raw_in_the_unsigned_class() { source: HeapSource::Used(1), shape: shape(TextureType::Type2D, pf, 1, READ), stages: vec![Stage::Kernel], + unreadable: false, }], classes, tables: Vec::new(), @@ -1502,6 +1507,7 @@ fn a_heap_member_a_mode_two_write_would_round_is_refused() { source: HeapSource::Used(1), shape: member, stages: vec![Stage::Fragment], + unreadable: false, }], classes: vec![s2d], tables: Vec::new(), @@ -1572,6 +1578,7 @@ fn a_state_in_token_order_finds_its_members_by_search() { source: HeapSource::Used(token), shape: t2d, stages: vec![Stage::Kernel], + unreadable: false, }); } } @@ -1644,6 +1651,7 @@ fn a_state_in_token_order_finds_its_members_searching_forward() { source: HeapSource::Used(token), shape: t2d, stages: vec![Stage::Kernel], + unreadable: false, }); } state.heap_placement = HeapPlacement::ResourceId; diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 6e5f4249a..5bee67394 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 = 2128; +pub const SEMANTICS_VERSION: u32 = 2129; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2398; +pub const RUNTIME_VERSION: u32 = 2399; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/crates/metal2vulkan/src/device/metal.rs b/crates/metal2vulkan/src/device/metal.rs index 5c4dfcf2d..a32ebce75 100644 --- a/crates/metal2vulkan/src/device/metal.rs +++ b/crates/metal2vulkan/src/device/metal.rs @@ -106,6 +106,35 @@ pub const READ_WRITE_TIER2_FORMATS: &[PixelFormat] = &[ PixelFormat::R8Sint, ]; +/// Metal's read-write texture tier on `profile`: a tier holds when each of its formats can be a +/// storage image on the profile, by the same choice lowering and the binder make. +pub(crate) fn read_write_texture_tier(profile: &DeviceProfile) -> ReadWriteTextureTier { + let read_write = |formats: &[PixelFormat]| { + formats + .iter() + .all(|&pf| storage_image_choice(pf, profile).is_ok()) + }; + if !read_write(READ_WRITE_TIER1_FORMATS) { + ReadWriteTextureTier::None + } else if !read_write(READ_WRITE_TIER2_FORMATS) { + ReadWriteTextureTier::Tier1 + } else { + ReadWriteTextureTier::Tier2 + } +} + +/// The formats whose `read_write` texture reads Metal defines on `profile`: those of its +/// read-write texture tier ([`read_write_texture_tier`]) and the tiers below it. +pub(crate) fn read_write_tier_formats( + profile: &DeviceProfile, +) -> &'static [&'static [PixelFormat]] { + match read_write_texture_tier(profile) { + ReadWriteTextureTier::Tier2 => &[READ_WRITE_TIER1_FORMATS, READ_WRITE_TIER2_FORMATS], + ReadWriteTextureTier::Tier1 => &[READ_WRITE_TIER1_FORMATS], + _ => &[], + } +} + /// Which simd usage classes each stage can tier. #[non_exhaustive] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] @@ -151,20 +180,7 @@ impl MetalDeviceProperties { } else { ArgumentBuffersTier::Tier1 }; - // A tier holds when each of its formats can be a storage image on this profile, by the - // same choice lowering and the binder make. - let read_write = |formats: &[PixelFormat]| { - formats - .iter() - .all(|&pf| storage_image_choice(pf, profile).is_ok()) - }; - let read_write_texture_tier = if !read_write(READ_WRITE_TIER1_FORMATS) { - ReadWriteTextureTier::None - } else if !read_write(READ_WRITE_TIER2_FORMATS) { - ReadWriteTextureTier::Tier1 - } else { - ReadWriteTextureTier::Tier2 - }; + let read_write_texture_tier = read_write_texture_tier(profile); let max_buffer_length = match f.buffer_access { BufferAccess::Floor => u64::from(l.max_storage_buffer_range), _ => match allocation.max_buffer_size { diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index ea8880cb9..f7c6f1bf6 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -132,6 +132,16 @@ impl DeviceProfile { .contains(&VkExtension::KhrFormatFeatureFlags2) } + /// Whether the profile reads storage through a declaration without a format by the formats' + /// own bits alone: it lacks `shaderStorageImageReadWithoutFormat`, and Vulkan 1.3 or + /// `VK_KHR_format_feature_flags2` enables the SPIR-V capability `StorageImageReadWithoutFormat` + /// ([`DeviceProfile::without_format_by_format_bits`]), so a read of a view without a format is + /// valid exactly where the view's format has `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` + /// (`VUID-vkCmdDispatch-OpTypeImage-07028`). ANV before Gfx12.5 is such a device. + pub(crate) fn storage_reads_by_format_bits(&self) -> bool { + !self.fields.images.storage_read_without_format && self.without_format_by_format_bits() + } + /// Whether the profile can read (`read`) and write (`write`) storage through a declaration /// without a format at all: by the device's `shaderStorageImage{Read,Write}WithoutFormat`, or /// by the formats' own bits ([`DeviceProfile::without_format_by_format_bits`]). Which formats diff --git a/crates/metal2vulkan/src/lower/access/mod.rs b/crates/metal2vulkan/src/lower/access/mod.rs index 5c4ab86f4..7b68b48dd 100644 --- a/crates/metal2vulkan/src/lower/access/mod.rs +++ b/crates/metal2vulkan/src/lower/access/mod.rs @@ -799,6 +799,11 @@ pub struct AccessPlan { /// `FLAG_YCBCR_WRITES` (`lower::texture::emit`): the handle-table search carries it, under /// the stage's `SpecKey::HeapYCbCrWrites` (`memory::handles::Lookup::Flagged`). pub heap_ycbcr_writes: bool, + /// A heap storage read the function makes on a device that reads storage without a format by + /// the formats' own bits alone reads the null element where the handle carries the entry's + /// `FLAG_STORAGE_UNREADABLE` (`lower::texture::emit`): the handle-table search carries it + /// (`memory::handles::Lookup::Flagged`). + pub heap_unreadable: bool, /// A heap texture's read through a sampler may hand back its border texels /// (`lower::texture::Through`), which its handle-table entry holds /// (`memory::handles::FLAG_BORDER_TEXELS`): the search yields each heap handle's entry index @@ -824,20 +829,22 @@ impl AccessPlan { pub fn lookup(&self) -> crate::memory::handles::Lookup { use crate::memory::handles::Lookup; let (alpha, class, red_blue) = (self.heap_alpha, self.carries_class(), self.heap_red_blue); - let ycbcr = self.heap_ycbcr_writes; + let (ycbcr, unreadable) = (self.heap_ycbcr_writes, self.heap_unreadable); if self.heap_border { Lookup::Indexed { alpha, class, red_blue, ycbcr, + unreadable, } - } else if alpha || class || red_blue || ycbcr { + } else if alpha || class || red_blue || ycbcr || unreadable { Lookup::Flagged { alpha, class, red_blue, ycbcr, + unreadable, } } else { Lookup::Element diff --git a/crates/metal2vulkan/src/lower/texture/emit.rs b/crates/metal2vulkan/src/lower/texture/emit.rs index e5c6a9509..c7d416dc5 100644 --- a/crates/metal2vulkan/src/lower/texture/emit.rs +++ b/crates/metal2vulkan/src/lower/texture/emit.rs @@ -427,23 +427,26 @@ fn image( image: &ImageRef, level: Option, ) -> BResult { - image_in(cx, fb, image, level, None) + image_in(cx, fb, image, level, (None, false)) } /// [`image`], a heap element read in numeric class `class` where given: through the group's -/// array of that class (`HeapPlan::cross`). The level is a level view's ([`level_element`]). +/// array of that class (`HeapPlan::cross`); the null element where `unreadable` and the handle +/// carries `FLAG_STORAGE_UNREADABLE` (`Read::heap_unreadable`). The level is a level view's +/// ([`level_element`]). fn image_in( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, image: &ImageRef, level: Option, - class: Option, + (class, unreadable): (Option, bool), ) -> BResult { let index = match *image { ImageRef::Slot(index) => index, ImageRef::Heap { group, handle } => { let h = match class { Some(k) => heap_cross_element(cx, fb, (group, k), handle)?, + None if unreadable => heap_readable_element(cx, fb, group, handle)?, None => heap_element(cx, fb, (group, false), handle)?, }; return Ok(Loaded { @@ -710,7 +713,24 @@ pub(crate) fn heap_element( let Some(declared) = declared else { return Err(cx.fail(format!("heap group {group} is not declared"))); }; - heap_element_of(cx, fb, declared, handle) + heap_element_of(cx, fb, declared, handle, false) +} + +/// [`heap_element`] of storage heap group `group` for a read on a device that reads storage +/// without a format by the formats' own bits alone (`Read::heap_unreadable`): the null element +/// where the handle carries `FLAG_STORAGE_UNREADABLE`, whose member's view the device cannot read +/// without a format (`VUID-vkCmdDispatch-OpTypeImage-07028`), so the read is a nil texture's. +fn heap_readable_element( + cx: &mut EmitCx<'_>, + fb: &mut FunctionBuilder<'_>, + group: u32, + handle: ValueId, +) -> BResult { + let h = cx.plan.families.texture.heap.get(&group); + let Some(declared) = h.and_then(|h| h.class.zip(h.decl)) else { + return Err(cx.fail(format!("heap group {group} is not declared"))); + }; + heap_element_of(cx, fb, declared, handle, true) } /// [`heap_element`] of heap group `group`'s array of numeric class `class` @@ -727,22 +747,35 @@ fn heap_cross_element( "heap group {group} has no {class:?} class declared" ))); }; - heap_element_of(cx, fb, declared, handle) + heap_element_of(cx, fb, declared, handle, false) } -/// The element of heap handle `handle` in the array of heap class `class`, declared `decl`. +/// The element of heap handle `handle` in the array of heap class `class`, declared `decl`: the +/// null element where `unreadable` and the handle carries `FLAG_STORAGE_UNREADABLE` +/// ([`heap_readable_element`]). fn heap_element_of( cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, (class, decl): (crate::pipeline::sym::ImageHandleClass, ImageDecl), handle: ValueId, + unreadable: bool, ) -> BResult { let Some(g) = cx.decl.families.texture.heap.get(&class).copied() else { return Err(cx.fail(format!("heap class {class:?} is not declared"))); }; let base = fb.module().global_value(g)?; let h = cx.operand(fb, handle)?; - let element = heap_element_index(cx, fb, h)?; + let mut element = heap_element_index(cx, fb, h)?; + if unreadable { + use crate::memory::handles::HANDLE_STORAGE_UNREADABLE; + let flags = heap_flags(cx, fb, h)?; + let bit = u32s(fb, 1, HANDLE_STORAGE_UNREADABLE)?; + let set = fb.binary(BinOp::BitwiseAnd, flags.0, bit)?; + let zero = u32s(fb, 1, 0)?; + let readable = fb.binary(BinOp::IEqual, set, zero)?; + let null = u32s(fb, 1, NEUTRAL_ELEMENT)?; + element = fb.select(readable, element, null)?; + } let flagged = match cx.plan.families.access.heap_alpha { true => Some(heap_flags(cx, fb, h)?), false => None, @@ -2489,7 +2522,7 @@ fn read_texel(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BR live, within, flagged, - } = image_in(cx, fb, &r.image, view, r.heap_class)?; + } = image_in(cx, fb, &r.image, view, (r.heap_class, r.heap_unreadable))?; let plain = match (volume, r.through) { (true, _) => Some(u32s(fb, coord_len(&decl), 0)?), (false, None) => Some(coordinate(cx, fb, &decl, &r.at)?), diff --git a/crates/metal2vulkan/src/lower/texture/mod.rs b/crates/metal2vulkan/src/lower/texture/mod.rs index 16a064735..8d0bd7ac9 100644 --- a/crates/metal2vulkan/src/lower/texture/mod.rs +++ b/crates/metal2vulkan/src/lower/texture/mod.rs @@ -355,6 +355,11 @@ pub struct Read { /// where the handle's class and red-blue order name a member the heap views through its /// storage choice's alias ([`heap_storage_conversions`]). pub heap_conversions: HeapConversions, + /// The read, of a storage heap group on a device that reads storage without a format by the + /// formats' own bits alone ([`heap_unreadable`]), reads the null element where the handle + /// carries `memory::handles::FLAG_STORAGE_UNREADABLE`: its member's view lacks the read bit, + /// so it reads as a nil texture's read does. + pub heap_unreadable: bool, /// The read, of a slot's color texture on a profile whose sparse textures are sparse images /// (it enables `shaderResourceResidency`), sets the lanes Metal reads as constants (a channel /// the format lacks, through the swizzle) after it, from the slot's `ConstantLanes` @@ -379,10 +384,16 @@ pub struct Read { pub heap_cross: Vec, } +/// The estimated words of a storage heap read's unreadable guard ([`Read::heap_unreadable`]): the +/// flag's test and the element's select, with the entry's flags where the handle carries its +/// entry's index (`memory::handles::INDEXED_FLAGS_WORDS`). +pub(crate) const HEAP_UNREADABLE_WORDS: u32 = 24 + crate::memory::handles::INDEXED_FLAGS_WORDS; + /// The estimated words of read `r`: coordinate assembly, the access, the texel conversion, and the /// status composite; the clamps, the in-bounds test, and the out-of-bounds select (with its /// specialized alpha); the level views' count, index clamp, level test, and select; a heap -/// element's access chain, load, and null select or guard; the sparse arm ([`RESIDENCY_WORDS`]) and +/// element's access chain, load, and null select or guard, and a storage one's unreadable guard; +/// the sparse arm ([`RESIDENCY_WORDS`]) and /// the word's select outside the image, with its own in-bounds test where the shader has none; a /// read through a sampler's addressing ([`Through::words`]), and a heap element's border texels /// and the flags its uses then read from its handle-table entry @@ -413,6 +424,11 @@ fn read_words(r: &Read) -> u32 { 0 } + r.heap_conversions.words(true) + + if r.heap_unreadable { + HEAP_UNREADABLE_WORDS + } else { + 0 + } + r.through.map_or(0, Through::words) + match r.through { Some(t) if r.image.heap() && t.sampler.bordered() => { @@ -2553,6 +2569,20 @@ pub(super) fn heap_alpha_in_red( applies } +/// Whether a storage read of `image` reads the null element where its handle carries +/// `memory::handles::FLAG_STORAGE_UNREADABLE` ([`Read::heap_unreadable`]): a heap image on a +/// device that reads storage without a format by the formats' own bits alone +/// (`DeviceProfile::storage_reads_by_format_bits`), whose storage arrays hold a member whose +/// view's format lacks the read bit for its writes alone (`bind::heap`). The handle-table search +/// then carries the flag. +fn heap_unreadable(cx: &mut SelectCx<'_>, image: ImageRef) -> bool { + let applies = image.heap() && cx.profile.storage_reads_by_format_bits(); + if applies { + cx.families.access.heap_unreadable = true; + } + applies +} + /// The conversions a storage access of a `float` or `half` texel through a heap handle makes of /// the members its storage array views through their storage choice's alias /// ([`heap_storage_conversions`]), by each member's key: its texel class index and whether its @@ -3461,6 +3491,7 @@ fn select_read_as( true => heap_storage_conversions(cx, image, shape, texel.conv), false => HeapConversions::default(), }; + let heap_unreadable = storage && heap_unreadable(cx, image); // A member's 8-bit sRGB codes, through its UNORM alias, decoded by the device's transfer, as // a storage slot's are. if !heap_conversions.srgb.is_empty() { @@ -3514,6 +3545,7 @@ fn select_read_as( heap_raw, heap_alpha_red, heap_conversions, + heap_unreadable, constant_lanes, declared, heap_class: as_class, diff --git a/crates/metal2vulkan/src/lower/texture/slot.rs b/crates/metal2vulkan/src/lower/texture/slot.rs index 0f78a114b..3413f9631 100644 --- a/crates/metal2vulkan/src/lower/texture/slot.rs +++ b/crates/metal2vulkan/src/lower/texture/slot.rs @@ -4,7 +4,7 @@ use crate::air::abi::Access as AbiAccess; use crate::air::intrinsics::{ImageDim, ImageShape}; use crate::device::profile::Containment; -use crate::device::requirements::{VkExtension, VkFeature}; +use crate::device::requirements::{FormatUsage, VkExtension, VkFeature}; use crate::error::{Capability, Error, Feature, LowerFamily, RuntimeInput, Unsupported}; use crate::lower::select::{DescriptorCounts, SelectCx}; use crate::memory::contain; @@ -544,10 +544,16 @@ fn declare_heap( ); } // A heap's storage classes are declared without a format, and the binder views its - // members for every access the device's features grant (`bind::heap`): a device's - // formats' own bits do not serve a heap. The features name storage texel buffers too. + // members for every access the device's features grant (`bind::heap`). The features name + // storage texel buffers too. A read needs `shaderStorageImageReadWithoutFormat`, or the + // formats' own bits (`DeviceProfile::storage_reads_by_format_bits`): the binder then + // holds a member whose view's format lacks the read bit for its writes alone, flagged, + // and a read through its handle reads the null element (`Read::heap_unreadable`), where + // no read-write tier format's view lacks it (below). need( - !h.uses.read || images.storage_read_without_format, + !h.uses.read + || images.storage_read_without_format + || cx.profile.storage_reads_by_format_bits(), VkFeature::ShaderStorageImageReadWithoutFormat, ); need( @@ -577,17 +583,7 @@ fn declare_heap( VkFeature::DescriptorBindingSampledImageUpdateAfterBind, ); } - if !missing.is_empty() { - return Err( - Unsupported::needs_any_of(Feature::ArgumentBufferTextures, vec![missing]).into(), - ); - } let texel = h.texel.unwrap_or(TexelClass::Float); - // A heap `ulong` texture would need a heap class of its own (its `RG32` declaration is not - // the formatless class's); not implemented. - if texel == TexelClass::Uint64 { - return Err(refuse()); - } let class = ImageHandleClass { dim: sym, arrayed: shape.array, @@ -601,6 +597,34 @@ fn declare_heap( StorageFormatClass::NotStorage }, }; + // Where the formats' own bits grant the read, the class's neutral, which a null handle and + // a flagged member read, must have its format's read bit too, and so must the view of every + // read-write tier format the class holds, whose read Metal defines. + if storage && h.uses.read && cx.profile.storage_reads_by_format_bits() { + let format = crate::bind::neutral::storage_neutral(texel.sampled_type()); + let usage = match buffer { + true => FormatUsage::StorageTexelBufferReadWithoutFormat, + false => FormatUsage::StorageImageReadWithoutFormat, + }; + if !cx.profile.supports_format(format, usage) { + missing.push(Capability::Format { format, usage }); + } + for gap in crate::bind::heap::tier_read_gaps(cx.profile, &class) { + if !missing.contains(&gap) { + missing.push(gap); + } + } + } + if !missing.is_empty() { + return Err( + Unsupported::needs_any_of(Feature::ArgumentBufferTextures, vec![missing]).into(), + ); + } + // A heap `ulong` texture would need a heap class of its own (its `RG32` declaration is not + // the formatless class's); not implemented. + if texel == TexelClass::Uint64 { + return Err(refuse()); + } let decl = ImageDecl { dim, arrayed: shape.array, diff --git a/crates/metal2vulkan/src/memory/handles.rs b/crates/metal2vulkan/src/memory/handles.rs index 1dac4542d..25cb18ddb 100644 --- a/crates/metal2vulkan/src/memory/handles.rs +++ b/crates/metal2vulkan/src/memory/handles.rs @@ -405,8 +405,8 @@ pub const ENTRY_ELEMENT: u32 = 2; /// Word of an entry holding the flags: for a sampler, its /// [`SamplerWord`](crate::metal::sampler::SamplerWord); for a texture, /// [`FLAG_OUT_OF_BOUNDS_ALPHA_ONE`], [`FLAG_RED_BLUE`], its border texels in -/// [`FLAG_BORDER_TEXELS`], [`FLAG_YCBCR_WRITES`], and the index of its texel class in -/// [`FLAG_TEXEL_CLASS`], every other bit 0. +/// [`FLAG_BORDER_TEXELS`], [`FLAG_YCBCR_WRITES`], the index of its texel class in +/// [`FLAG_TEXEL_CLASS`], and [`FLAG_STORAGE_UNREADABLE`], every other bit 0. pub const ENTRY_FLAGS: u32 = 3; /// The flag of a texture entry whose pixel format has no alpha /// (`metal::format::out_of_bounds_alpha_one`): Metal's out-of-bounds read of such a texture @@ -435,8 +435,20 @@ pub const FLAG_YCBCR_WRITES: u32 = 1 << 15; /// converts or reads the texture's texels where the module reads it (a `half` conversion on Metal's /// own sampler, a fetched gather, a NaN texel's rule, a raw-held form's emulation). A heap handle /// carries it in place, in a module whose search carries it ([`Lookup::Flagged`]'s `class`), so -/// [`HANDLE_TEXEL_CLASS`] is this field. -pub const FLAG_TEXEL_CLASS: u32 = 0x1fff << 16; +/// [`HANDLE_TEXEL_CLASS`] is this field. Its 12 bits hold every index +/// (`metal::texel_format::heap_classes` has fewer than 4096 classes, which a test checks). +pub const FLAG_TEXEL_CLASS: u32 = 0xfff << 16; +/// The flag of a texture entry whose view in the heap's storage arrays (`bind::heap`) a device +/// that reads storage without a format by the formats' own bits alone cannot read so: the view's +/// format lacks `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`, which such a read needs +/// (`VUID-vkCmdDispatch-OpTypeImage-07028`). A storage read through its handle reads the null +/// element instead, as a nil texture's read does ([`Lookup::Flagged`]'s `unreadable`); its writes +/// store as before. Set only on such a device (`bind::heap::handle_entry_flags`). A handle carries +/// it in place, in [`HANDLE_STORAGE_UNREADABLE`]. +pub const FLAG_STORAGE_UNREADABLE: u32 = 1 << 28; +/// The bit of a heap handle that carries its entry's [`FLAG_STORAGE_UNREADABLE`], in place, in a +/// module whose search carries it ([`Lookup::Flagged`]'s `unreadable`). +pub const HANDLE_STORAGE_UNREADABLE: u32 = FLAG_STORAGE_UNREADABLE; /// The field of a heap handle that carries its entry's [`FLAG_TEXEL_CLASS`], in place, in a /// module whose search carries it ([`Lookup::Flagged`]'s `class`). pub const HANDLE_TEXEL_CLASS: u32 = FLAG_TEXEL_CLASS; @@ -480,6 +492,20 @@ const _: () = assert!( == 0 ); const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_ENTRY.trailing_zeros()); +const _: () = assert!( + (HANDLE_TEXEL_CLASS | HANDLE_ALPHA_ONE | HANDLE_RED_BLUE | HANDLE_YCBCR_WRITES) + & HANDLE_STORAGE_UNREADABLE + == 0 +); +const _: () = assert!( + (FLAG_TEXEL_CLASS + | FLAG_OUT_OF_BOUNDS_ALPHA_ONE + | FLAG_RED_BLUE + | FLAG_BORDER_TEXELS + | FLAG_YCBCR_WRITES) + & FLAG_STORAGE_UNREADABLE + == 0 +); const _: () = assert!(TABLE_CAPACITY <= 1 << HANDLE_ENTRY.count_ones()); /// Unrolled steps of the handle-table search. @@ -1383,26 +1409,31 @@ pub enum Lookup { /// storage access converts a member by it (`bind::heap::storage_conversions`); where `ycbcr`, /// its [`FLAG_YCBCR_WRITES`] in [`HANDLE_YCBCR_WRITES`] under the stage's /// `SpecKey::HeapYCbCrWrites` ([`ycbcr_writes_spec`]), the handle of a module with a `float` - /// or `half` write through a heap handle. Every heap access masks them off - /// ([`Lookup::element_mask`]). + /// or `half` write through a heap handle; where `unreadable`, its + /// [`FLAG_STORAGE_UNREADABLE`] in [`HANDLE_STORAGE_UNREADABLE`], the handle of a module that + /// reads a heap storage class on a device that reads storage without a format by the formats' + /// own bits alone. Every heap access masks them off ([`Lookup::element_mask`]). Flagged { alpha: bool, class: bool, red_blue: bool, ycbcr: bool, + unreadable: bool, }, /// The entry's element with the entry's index beside it, in [`HANDLE_ENTRY`] (0 for a miss, /// the null entry's): the handle of a module whose read through a sampler of a heap texture /// may hand back its border texels, which its entry holds ([`FLAG_BORDER_TEXELS`], /// [`border_texels`]). The handle has no room for them beside the flags `Flagged` carries, so - /// it carries none: a use reads the ones its module reads (`alpha`, `class`, `red_blue` and - /// `ycbcr` as `Flagged`'s) from the entry, in the handle `Flagged` would have yielded - /// ([`flagged_handle`]). Every heap access masks the index off ([`Lookup::element_mask`]). + /// it carries none: a use reads the ones its module reads (`alpha`, `class`, `red_blue`, + /// `ycbcr` and `unreadable` as `Flagged`'s) from the entry, in the handle `Flagged` would have + /// yielded ([`flagged_handle`]). Every heap access masks the index off + /// ([`Lookup::element_mask`]). Indexed { alpha: bool, class: bool, red_blue: bool, ycbcr: bool, + unreadable: bool, }, /// The index of the entry found, 0 (the null entry) for a miss: the handle of an argument /// buffer's sampler, whose uses read the entry's element and word ([`entry_field`]). @@ -1419,12 +1450,14 @@ impl Lookup { class, red_blue, ycbcr, + unreadable, } | Lookup::Indexed { alpha, class, red_blue, ycbcr, + unreadable, }) = self else { return Vec::new(); @@ -1442,11 +1475,13 @@ impl Lookup { FLAG_YCBCR_WRITES, HANDLE_YCBCR_WRITES.trailing_zeros() - FLAG_YCBCR_WRITES.trailing_zeros(), )); + let unreadable = unreadable.then_some((FLAG_STORAGE_UNREADABLE, 0)); alpha .into_iter() .chain(class) .chain(red_blue) .chain(ycbcr) + .chain(unreadable) .collect() } @@ -2066,26 +2101,29 @@ mod tests { #[test] fn the_emitted_search_matches_the_host_model() { for int64 in [true, false] { - let flagged = |alpha, class, red_blue, ycbcr| Lookup::Flagged { + let flagged = |alpha, class, red_blue, ycbcr, unreadable| Lookup::Flagged { alpha, class, red_blue, ycbcr, + unreadable, }; for form in [ Lookup::Element, - flagged(true, false, false, false), - flagged(false, true, false, false), - flagged(false, false, true, false), - flagged(false, false, false, true), - flagged(true, true, false, false), - flagged(true, true, true, false), - flagged(true, true, true, true), + flagged(true, false, false, false, false), + flagged(false, true, false, false, false), + flagged(false, false, true, false, false), + flagged(false, false, false, true, false), + flagged(false, false, false, false, true), + flagged(true, true, false, false, false), + flagged(true, true, true, false, false), + flagged(true, true, true, true, true), Lookup::Indexed { alpha: true, class: true, red_blue: false, ycbcr: true, + unreadable: true, }, Lookup::Entry, ] { @@ -2113,6 +2151,7 @@ mod tests { class: false, red_blue: false, ycbcr: true, + unreadable: false, }; let t = table(17); let bytes = table_bytes(&t); @@ -2182,42 +2221,61 @@ mod tests { /// Each flagged form's element mask clears exactly the bits it carries. #[test] fn a_flagged_handle_masks_off_the_bits_it_carries() { - let flagged = |alpha, class, red_blue, ycbcr| { + let flagged = |alpha, class, red_blue, ycbcr, unreadable| { Lookup::Flagged { alpha, class, red_blue, ycbcr, + unreadable, } .element_mask() }; assert_eq!(Lookup::Element.element_mask(), None); assert_eq!(Lookup::Entry.element_mask(), None); - assert_eq!(flagged(false, false, false, false), None); - assert_eq!(flagged(true, false, false, false), Some(!HANDLE_ALPHA_ONE)); - assert_eq!(HANDLE_TEXEL_CLASS, 0x1fff << 16); + assert_eq!(flagged(false, false, false, false, false), None); assert_eq!( - flagged(false, true, false, false), + flagged(true, false, false, false, false), + Some(!HANDLE_ALPHA_ONE) + ); + assert_eq!(HANDLE_TEXEL_CLASS, 0xfff << 16); + assert_eq!( + flagged(false, true, false, false, false), Some(!HANDLE_TEXEL_CLASS) ); - assert_eq!(flagged(false, false, true, false), Some(!HANDLE_RED_BLUE)); assert_eq!( - flagged(false, false, false, true), + flagged(false, false, true, false, false), + Some(!HANDLE_RED_BLUE) + ); + assert_eq!( + flagged(false, false, false, true, false), Some(!HANDLE_YCBCR_WRITES) ); assert_eq!( - flagged(true, true, true, true), - Some(!(HANDLE_ALPHA_ONE | HANDLE_TEXEL_CLASS | HANDLE_RED_BLUE | HANDLE_YCBCR_WRITES)), + flagged(false, false, false, false, true), + Some(!HANDLE_STORAGE_UNREADABLE) + ); + assert_eq!( + flagged(true, true, true, true, true), + Some( + !(HANDLE_ALPHA_ONE + | HANDLE_TEXEL_CLASS + | HANDLE_RED_BLUE + | HANDLE_YCBCR_WRITES + | HANDLE_STORAGE_UNREADABLE) + ), "every carried field is masked off, and the element's 16 bits stay" ); - for (alpha, class, red_blue, ycbcr) in - [(false, false, false, false), (true, true, true, true)] - { + for (alpha, class, red_blue, ycbcr, unreadable) in [ + (false, false, false, false, false), + (true, true, true, true, true), + ] { let indexed = Lookup::Indexed { alpha, class, red_blue, ycbcr, + unreadable, }; assert_eq!( indexed.element_mask(), @@ -2227,9 +2285,26 @@ mod tests { } } + /// Every texel class index fits [`FLAG_TEXEL_CLASS`], so no index reaches + /// [`FLAG_STORAGE_UNREADABLE`] above it. + #[test] + fn every_texel_class_index_fits_its_field() { + let field = FLAG_TEXEL_CLASS >> FLAG_TEXEL_CLASS.trailing_zeros(); + let classes = crate::metal::texel_format::heap_classes().len(); + assert!(classes <= field as usize + 1, "{classes} classes"); + for &pf in crate::metal::PixelFormat::ALL { + let index = crate::metal::texel_format::heap_class_index( + pf, + crate::metal::TextureSwizzleChannels::DEFAULT, + ); + assert_eq!(index & !field, 0, "{pf:?}"); + } + } + /// The flags of the test tables' entry of `element`: none on the null entry, else its low six - /// bits, a class index of it, and [`FLAG_YCBCR_WRITES`] where its bit 4 is set, so each - /// carried flag occurs set and clear, beside bits no form carries. + /// bits, a class index of it, [`FLAG_YCBCR_WRITES`] where its bit 4 is set, and + /// [`FLAG_STORAGE_UNREADABLE`] where its bit 3 is, so each carried flag occurs set and clear, + /// beside bits no form carries. fn flags(element: u32) -> u32 { if element == NEUTRAL_ELEMENT { return 0; @@ -2238,6 +2313,7 @@ mod tests { | ((element.wrapping_mul(2_654_435_761) >> 7) & FLAG_TEXEL_CLASS) | ((element.wrapping_mul(40_503) << 3) & FLAG_BORDER_TEXELS) | ((element & 16) << 11) + | ((element & 8) << 25) } /// The bytes of table `t`, each entry's flags [`flags`] of its element. @@ -2265,20 +2341,23 @@ mod tests { index, }; for int64 in [true, false] { - for (alpha, class, red_blue, ycbcr) in - [(true, true, true, true), (false, true, false, false)] - { + for (alpha, class, red_blue, ycbcr, unreadable) in [ + (true, true, true, true, true), + (false, true, false, false, false), + ] { let indexed = Lookup::Indexed { alpha, class, red_blue, ycbcr, + unreadable, }; let flagged = Lookup::Flagged { alpha, class, red_blue, ycbcr, + unreadable, }; let m = search_module(int64, indexed, |fb, t, h| { Ok(vec![ @@ -2329,6 +2408,11 @@ mod tests { | carried(alpha, FLAG_OUT_OF_BOUNDS_ALPHA_ONE, HANDLE_ALPHA_ONE) | carried(red_blue, FLAG_RED_BLUE, HANDLE_RED_BLUE) | carried(ycbcr, FLAG_YCBCR_WRITES, HANDLE_YCBCR_WRITES) + | carried( + unreadable, + FLAG_STORAGE_UNREADABLE, + HANDLE_STORAGE_UNREADABLE, + ) | match class { true => flags(e) & FLAG_TEXEL_CLASS, false => 0, @@ -2406,10 +2490,16 @@ mod tests { class, red_blue, ycbcr, + unreadable, } => { e | carried(alpha, FLAG_OUT_OF_BOUNDS_ALPHA_ONE, HANDLE_ALPHA_ONE) | carried(red_blue, FLAG_RED_BLUE, HANDLE_RED_BLUE) | carried(ycbcr, FLAG_YCBCR_WRITES, HANDLE_YCBCR_WRITES) + | carried( + unreadable, + FLAG_STORAGE_UNREADABLE, + HANDLE_STORAGE_UNREADABLE, + ) | match class { true => flags(e) & FLAG_TEXEL_CLASS, false => 0, diff --git a/crates/metal2vulkan/src/tests/engine_heap_binder.rs b/crates/metal2vulkan/src/tests/engine_heap_binder.rs index 8a4a3a7fb..f3f8740a0 100644 --- a/crates/metal2vulkan/src/tests/engine_heap_binder.rs +++ b/crates/metal2vulkan/src/tests/engine_heap_binder.rs @@ -601,6 +601,7 @@ fn a_sampled_heap_writes_each_member_and_its_table() { class: false, red_blue: false, ycbcr: false, + unreadable: false, }; assert_eq!(emitted_lookup_in(bytes, &keys, flagged), alpha); // The table's element of an id is the element the plan wrote that texture to. @@ -1158,6 +1159,7 @@ fn table_entries_state_each_members_texel_class() { class: false, red_blue: false, ycbcr: false, + unreadable: false, }; let one = HANDLE_ALPHA_ONE; assert_eq!( @@ -1169,6 +1171,7 @@ fn table_entries_state_each_members_texel_class() { class: true, red_blue: false, ycbcr: false, + unreadable: false, }; assert_eq!( emitted_lookup_in(bytes, &keys, classes), @@ -1179,6 +1182,7 @@ fn table_entries_state_each_members_texel_class() { class: true, red_blue: false, ycbcr: false, + unreadable: false, }; let entry = |k: u32| k << HANDLE_ENTRY.trailing_zeros(); assert_eq!( diff --git a/crates/metal2vulkan/src/tests/engine_heap_storage_reads.rs b/crates/metal2vulkan/src/tests/engine_heap_storage_reads.rs new file mode 100644 index 000000000..2559a278e --- /dev/null +++ b/crates/metal2vulkan/src/tests/engine_heap_storage_reads.rs @@ -0,0 +1,488 @@ +//! A read of an argument buffer's `read_write` texture on a device that reads storage without a +//! format by the formats' own bits alone (`DeviceProfile::storage_reads_by_format_bits`: ANV before +//! Gfx12.5, the Iris Xe of `intel-irisxe-rplp-anv`), whose `shaderStorageImageReadWithoutFormat` +//! is false. +//! +//! Vulkan 1.3 and `VK_KHR_format_feature_flags2` enable the SPIR-V capability +//! `StorageImageReadWithoutFormat`, and a read of a view without a format is valid where the view's +//! format has `STORAGE_READ_WITHOUT_FORMAT_BIT` (`VUID-vkCmdDispatch-OpTypeImage-07028`). The heap's +//! storage class is declared without a format, so its read compiles there (`lower::texture::slot`, +//! `declare_heap`); the binder holds a member whose view lacks the bit for its writes, its entry +//! flagged `FLAG_STORAGE_UNREADABLE`, and a read through its handle reads the null element. Metal +//! defines the read of its read-write tier formats, so a function that reads the class where one +//! of their views lacks the bit is refused instead (`bind::heap::tier_read_gaps`). No GPU is used. + +use std::collections::BTreeMap; +use std::path::Path; + +use crate::bind::heap::tier_read_gaps; +use crate::bind::{ + handle_entry, handle_entry_flags, heap_element, BindState, HeapElement, ResourceClass, + TextureFacts, UsedResource, WriteSource, +}; +use crate::budget::Budget; +use crate::device::metal::read_write_tier_formats; +use crate::device::requirements::{FormatUsage, SpirvCapability, VkFeature}; +use crate::device::{Device, DeviceDescription, DevicePolicy}; +use crate::error::{Capability, Error, Feature, Needs}; +use crate::library::Library; +use crate::memory::handles::{Lookup, FLAG_STORAGE_UNREADABLE}; +use crate::metal::{PixelFormat, TextureType, TextureUsage}; +use crate::pipeline::sym::{ + Axis, HandleClass, ImageAccess, ImageHandleClass, ResourceKind, ResourceSlot, SpecKey, Stage, + SyntheticBinding, +}; +use crate::pipeline::testing::typed_module; +use crate::pipeline::{ + ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, StageSource, +}; +use crate::spirv::interp::{run_with_images, Buffer, Config, Image, Resources}; +use crate::vk; + +use super::engine_binder::assemble_text; + +const HEADER: &str = "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32\"\ntarget triple = \"air64_v28-apple-macosx26.0.0\"\n\n"; + +/// Kernel `heap_rw_read` reads the `texture2d` argument buffer 0 holds at +/// `(gid, 0)` into buffer 1's `float4` at its index. +const KERNEL: &str = r#"%struct.T = type { ptr addrspace(1) } +define void @heap_rw_read(ptr addrspace(2) %r, ptr addrspace(1) %dst, i32 %gid) { + %pt = getelementptr inbounds %struct.T, ptr addrspace(2) %r, i64 0, i32 0 + %t = load ptr addrspace(1), ptr addrspace(2) %pt, align 8 + %p = getelementptr inbounds <4 x float>, ptr addrspace(1) %dst, i32 %gid + %c = insertelement <2 x i32> zeroinitializer, i32 %gid, i64 0 + %smp = call ptr addrspace(2) @air.get_read_sampler() + %x = call { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1) %t, ptr addrspace(2) %smp, <2 x i32> %c, <2 x i32> zeroinitializer, i32 0, i32 3) + %xv = extractvalue { <4 x float>, i8 } %x, 0 + store <4 x float> %xv, ptr addrspace(1) %p, align 16 + ret void +} +declare ptr addrspace(2) @air.get_read_sampler() +declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1), ptr addrspace(2), <2 x i32>, <2 x i32>, i32, i32) +!air.kernel = !{!0} +!air.version = !{!9} +!air.language_version = !{!10} +!0 = !{ptr @heap_rw_read, !1, !2} +!1 = !{} +!2 = !{!3, !7, !8} +!3 = !{i32 0, !"air.indirect_buffer", !"air.buffer_size", i32 8, !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 2, !"air.struct_type_info", !4, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"T", !"air.arg_name", !"r"} +!4 = !{i32 0, i32 8, i32 0, !"texture2d", !"t", !"air.indirect_argument", !5} +!5 = !{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.read_write", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"t"} +!7 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 16, !"air.arg_type_align_size", i32 16, !"air.arg_type_name", !"float4", !"air.arg_name", !"dst"} +!8 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"gid"} +!9 = !{i32 2, i32 8, i32 0} +!10 = !{!"Metal", i32 4, i32 0, i32 0} +"#; + +const ENTRY: &str = "heap_rw_read"; + +/// The committed profile of a device that reads storage without a format by the formats' bits +/// alone: the Iris Xe (Raptor Lake-P) under Mesa 26.2.6. +const IRIS: &str = "intel-irisxe-rplp-anv"; + +/// The resource IDs of the members: a readable texture's, and a flagged one's. +const READABLE_ID: u64 = 0x0000_0001_0000_0010; +const FLAGGED_ID: u64 = 0x0000_0001_0000_0020; + +/// The description of committed profile `stem`. +fn description(stem: &str) -> DeviceDescription { + let path = Path::new(env!("CARGO_MANIFEST_DIR")) + .join(format!("../metal2vulkan-validation/profiles/{stem}.json")); + let text = std::fs::read_to_string(path).expect("profile"); + DeviceDescription::from_khronos_json(&text, None).expect("description") +} + +/// The device of committed profile `stem`. +fn device(stem: &str) -> Device { + Device::new(description(stem), DevicePolicy::default()).expect("device") +} + +/// [`KERNEL`], assembled; `None` where `llvm-as` is missing (the test then skips visibly). +fn kernel() -> Option> { + assemble_text("heap_storage_reads", &format!("{HEADER}{KERNEL}")) +} + +/// [`ENTRY`] of `bc`, compiled on `dev`. +fn pipeline(dev: &Device, bc: &[u8]) -> Result { + let lib = Library::from_air(bc).expect("library"); + let f = lib.function(ENTRY).expect("entry"); + let d = ComputePipelineDescriptor::new(StageSource::Function(FunctionDescriptor::new(f))); + dev.compile_compute_pipeline(&d, &Budget::standard()) +} + +/// The heap's float 2D storage class. +fn storage_class() -> ImageHandleClass { + ImageHandleClass { + dim: crate::pipeline::sym::ImageDim::D2, + arrayed: false, + multisampled: false, + sampled_type: crate::pipeline::sym::SampledType::Float, + depth_compare: false, + access: ImageAccess::Storage, + format: crate::pipeline::sym::StorageFormatClass::Unknown, + } +} + +/// A 2D `read_write` texture of `pf`. +fn read_write(pf: PixelFormat) -> TextureFacts { + let mut f = TextureFacts::new(TextureType::Type2D, pf); + f.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + f +} + +/// A command making the textures of `members` resident, each with its resource ID. +fn state(members: &[(TextureFacts, u64)]) -> BindState { + BindState { + used_resources: (members.iter().zip(1u32..)) + .map(|(&(f, id), token)| { + let mut u = UsedResource::new(ResourceClass::Texture(f), token); + u.resource_id = Some(id); + u + }) + .collect(), + ..Default::default() + } +} + +/// The non-tier formats whose storage view the Iris Xe cannot read without a format (Mesa's isl +/// table: no typed reads of `R10G10B10A2`, `B10G10R10A2`, `R11G11B10_FLOAT` or `B8G8R8A8` below +/// Gfx12.5; `BGR10A2Unorm` through its `A2B10G10R10` twin as well). +const IRIS_UNREADABLE: [PixelFormat; 5] = [ + PixelFormat::RGB10A2Unorm, + PixelFormat::RGB10A2Uint, + PixelFormat::BGR10A2Unorm, + PixelFormat::RG11B10Float, + PixelFormat::BGRA8Unorm, +]; + +/// The heap's storage read compiles where the formats' own bits grant it: on the Iris Xe, without +/// `shaderStorageImageReadWithoutFormat`, the pipeline requires the SPIR-V capability (which +/// Vulkan 1.3 enables) and not the feature, and its handle-table search carries the unreadable +/// flag; on lavapipe, which has the feature, it carries none. The same device as a Vulkan 1.2 +/// context without `VK_KHR_format_feature_flags2` sees, has neither route, and the read is refused +/// naming the feature, as before. +#[test] +fn a_heap_storage_read_compiles_where_the_formats_bits_grant_it() { + let Some(bc) = kernel() else { + return; + }; + let iris = device(IRIS); + assert!(iris.profile().storage_reads_by_format_bits()); + let pipe = pipeline(&iris, &bc).unwrap_or_else(|e| panic!("{IRIS}: {e}")); + let capability = SpirvCapability::of(crate::spv::Capability::StorageImageReadWithoutFormat); + assert!(pipe.requirements.spirv_capabilities.contains(&capability)); + assert!(!pipe + .requirements + .features + .contains(&VkFeature::ShaderStorageImageReadWithoutFormat)); + let (plan, _) = typed_module(&bc, ENTRY, iris.profile()).expect("module"); + assert!(plan.families.access.heap_unreadable); + assert!(matches!( + plan.families.access.lookup(), + Lookup::Flagged { + unreadable: true, + .. + } + )); + + let lavapipe = device("lavapipe"); + assert!(!lavapipe.profile().storage_reads_by_format_bits()); + pipeline(&lavapipe, &bc).expect("lavapipe"); + let (plan, _) = typed_module(&bc, ENTRY, lavapipe.profile()).expect("module"); + assert!(!plan.families.access.heap_unreadable); + + let old = crate::pipeline::testing::description_at_1_2(IRIS, false).expect("description"); + let old = Device::new(old, DevicePolicy::default()).expect("device"); + assert!(!old.profile().storage_reads_by_format_bits()); + match pipeline(&old, &bc) { + Err(Error::Unsupported(u)) => { + assert_eq!(u.feature, Feature::ArgumentBufferTextures); + let Needs::AnyOf(ways) = &u.needs else { + panic!("{:?}", u.needs); + }; + assert!( + ways.iter().any(|way| way.contains(&Capability::Feature( + VkFeature::ShaderStorageImageReadWithoutFormat + ))), + "{ways:?}" + ); + } + other => panic!("a Vulkan 1.2 context: {:?}", other.map(|_| ())), + } +} + +/// Over the CPU interpreter, the Iris Xe's module reads a member through its handle, and reads +/// the null element (zero) through a handle whose entry carries `FLAG_STORAGE_UNREADABLE`, though +/// the element the entry names holds texels: the guard, not the image, answers zero. +#[test] +fn a_flagged_member_reads_the_null_element() { + let Some(bc) = kernel() else { + return; + }; + let iris = device(IRIS); + let (plan, m) = typed_module(&bc, ENTRY, iris.profile()).expect("module"); + let class = (plan.families.texture.heap.values()) + .find_map(|h| h.class) + .expect("a heap class"); + assert_eq!(class, storage_class()); + let slot = ResourceSlot { + stage: Stage::Kernel, + kind: ResourceKind::Heap(HandleClass::Image(class)), + index: 0, + }; + let fl = |v: f32| v.to_bits(); + let texels = |base: f32| -> Vec<[u32; 4]> { + (0..4) + .map(|i| { + let v = base + i as f32; + [fl(v), fl(v + 0.25), fl(v + 0.5), fl(1.0)] + }) + .collect() + }; + let mut images: Vec = [(0, 1), (1, 4), (2, 4)] + .into_iter() + .map(|(e, width)| { + let mut img = Image::new(slot, [width, 1, 1], 1, 1, 1).at_element(e); + img.robust = Some([0, 0, 0, fl(1.0)]); + img + }) + .collect(); + images[1].texels = texels(1.0); + images[2].texels = texels(10.0); + // The table: the null entry, the readable member at element 1, the flagged one at 2. + let table: Vec = [ + handle_entry(0, 0, 0), + handle_entry(READABLE_ID, 1, 0), + handle_entry(FLAGGED_ID, 2, FLAG_STORAGE_UNREADABLE), + ] + .concat(); + let buffer = |kind, index, bytes| Buffer { + slot: Some(ResourceSlot { + stage: Stage::Kernel, + kind, + index, + }), + address: None, + bytes, + }; + for (id, want) in [(READABLE_ID, texels(1.0)), (FLAGGED_ID, vec![[0; 4]; 4])] { + let mut spec = BTreeMap::new(); + for axis in [Axis::X, Axis::Y, Axis::Z] { + spec.insert(SpecKey::LocalSize(axis), 1); + } + spec.insert(SpecKey::FlatLocalSize, 1); + let res = Resources { + buffers: vec![ + buffer(ResourceKind::Buffer, 0, id.to_le_bytes().to_vec()), + buffer(ResourceKind::Buffer, 1, vec![0xab; 64]), + buffer( + ResourceKind::Synthetic(SyntheticBinding::HandleTable), + 0, + table.clone(), + ), + ], + push: vec![0u8; plan.push.push_range.map_or(0, |(_, end)| end as usize)], + spec, + }; + let cfg = Config { + workgroups: [4, 1, 1], + ..Config::default() + }; + let (out, _) = run_with_images(&m, &cfg, res, images.clone()) + .unwrap_or_else(|e| panic!("{id:#x}: {e:?}")); + let got: Vec<[u32; 4]> = out.buffers[1] + .chunks(16) + .map(|t| { + let w = |i: usize| u32::from_le_bytes(t[4 * i..4 * i + 4].try_into().unwrap()); + [w(0), w(1), w(2), w(3)] + }) + .collect(); + assert_eq!(got, want, "{id:#x}"); + } +} + +/// On every committed profile that reads storage without a format by the formats' bits alone, +/// each of Metal's read-write tier formats on the profile is held in its storage class for its +/// writes, and where its view cannot be read so (flagged), a function reading the class is refused +/// for it ([`tier_read_gaps`]): no tier format reads zero. On the Iris Xe none is flagged; the +/// non-tier formats its view cannot read are held for their writes, flagged; on lavapipe, which has +/// the feature, nothing is flagged. +#[test] +fn only_a_view_the_device_cannot_read_is_flagged() { + let layout = vk::ImageLayout::GENERAL; + let mut bits_alone = 0; + for (stem, profile) in crate::spirv::testing::committed_profiles().expect("profiles") { + let profile = &profile; + if !profile.storage_reads_by_format_bits() { + continue; + } + bits_alone += 1; + let tiers = read_write_tier_formats(profile); + for &pf in tiers.iter().flat_map(|tier| tier.iter()) { + let facts = read_write(pf); + let class = ImageHandleClass { + sampled_type: crate::metal::format::sampled_type(pf).expect("type"), + ..storage_class() + }; + match heap_element(profile, &HandleClass::Image(class), &facts, layout) { + Ok(HeapElement::View(_)) => {} + other => panic!("{stem}: {pf:?}: {other:?}"), + } + let flagged = handle_entry_flags(profile, &facts) & FLAG_STORAGE_UNREADABLE != 0; + let gaps = tier_read_gaps(profile, &class); + assert!(!flagged || !gaps.is_empty(), "{stem}: {pf:?} reads zero"); + if stem == IRIS { + assert!(!flagged && gaps.is_empty(), "{stem}: {pf:?}: {gaps:?}"); + } + } + } + assert!( + bits_alone > 0, + "no committed profile reads by the bits alone" + ); + + let iris = device(IRIS); + let lavapipe = device("lavapipe"); + for pf in IRIS_UNREADABLE { + let facts = read_write(pf); + let class = ImageHandleClass { + sampled_type: crate::metal::format::sampled_type(pf).expect("type"), + ..storage_class() + }; + // Held for its writes. + assert!( + matches!( + heap_element(iris.profile(), &HandleClass::Image(class), &facts, layout), + Ok(HeapElement::View(_)) + ), + "{pf:?}" + ); + assert_eq!( + handle_entry_flags(iris.profile(), &facts) & FLAG_STORAGE_UNREADABLE, + FLAG_STORAGE_UNREADABLE, + "{pf:?}" + ); + assert_eq!( + handle_entry_flags(lavapipe.profile(), &facts) & FLAG_STORAGE_UNREADABLE, + 0, + "{pf:?}" + ); + } +} + +/// A plan on the Iris Xe holds an `RGBA16Float` member and an `RG11B10Float` one in the storage +/// class and flags only the second's table entry. +#[test] +fn a_plan_flags_its_unreadable_members() { + let Some(bc) = kernel() else { + return; + }; + let iris = device(IRIS); + let pipe = pipeline(&iris, &bc).expect("pipeline"); + let state = state(&[ + (read_write(PixelFormat::RGBA16Float), READABLE_ID), + (read_write(PixelFormat::RG11B10Float), FLAGGED_ID), + ]); + let bplan = pipe.plan(&iris, &state.shape()).expect("plan"); + let views: Vec<(u32, vk::Format)> = (bplan.descriptors.iter()) + .filter_map(|d| match &d.source { + WriteSource::HeapEntry { element, view, .. } => Some((*element, view.format)), + _ => None, + }) + .collect(); + assert_eq!( + views, + vec![ + (1, vk::Format::R16G16B16A16_SFLOAT), + (2, vk::Format::B10G11R11_UFLOAT_PACK32) + ] + ); + let dispatch = crate::bind::Dispatch::Threadgroups { + groups: [1, 1, 1], + threads_per_group: [1, 1, 1], + }; + let cmds = bplan + .instantiate_dispatch(&state, &dispatch) + .expect("dispatch"); + let (set, binding) = (bplan.descriptors.iter()) + .find_map(|d| { + matches!(d.source, WriteSource::HandleTable { .. }).then_some((d.set, d.binding)) + }) + .expect("a handle table"); + let table = &(cmds.descriptor_bytes.iter()) + .find(|b| (b.set, b.binding) == (set, binding)) + .expect("table bytes") + .bytes; + let flags: Vec<(u64, u32)> = table + .chunks(16) + .map(|e| { + let word = |w: usize| u32::from_le_bytes(e[4 * w..4 * w + 4].try_into().unwrap()); + ( + u64::from(word(0)) | u64::from(word(1)) << 32, + word(3) & FLAG_STORAGE_UNREADABLE, + ) + }) + .filter(|(id, _)| *id != 0) + .collect(); + assert_eq!( + flags, + vec![(READABLE_ID, 0), (FLAGGED_ID, FLAG_STORAGE_UNREADABLE)] + ); +} + +/// A function that reads a storage class one of Metal's read-write tier formats is held in through +/// a view the device cannot read without a format is refused, naming the view's bit, and the member +/// is held for its writes: on the Iris Xe with `R16G16B16A16_SFLOAT`'s `STORAGE_READ_WITHOUT_FORMAT` +/// bit cleared (a synthetic profile), the kernel is `Unsupported` naming that bit alone (the +/// class's neutral, `R32_SFLOAT`, keeps its own), and the device-wide heap's `RGBA16Float` element +/// is its view, flagged. The committed profile compiles the kernel and holds the member unflagged. +#[test] +fn a_tier_format_without_its_read_bit_is_refused() { + let Some(bc) = kernel() else { + return; + }; + let layout = vk::ImageLayout::GENERAL; + let facts = read_write(PixelFormat::RGBA16Float); + let class = HandleClass::Image(storage_class()); + let iris = device(IRIS); + assert!(matches!( + heap_element(iris.profile(), &class, &facts, layout), + Ok(HeapElement::View(_)) + )); + assert_eq!( + handle_entry_flags(iris.profile(), &facts) & FLAG_STORAGE_UNREADABLE, + 0 + ); + pipeline(&iris, &bc).expect("the committed profile"); + let mut desc = description(IRIS); + let format = vk::Format::R16G16B16A16_SFLOAT; + let props = desc.formats.formats.get_mut(&format).expect("RGBA16F"); + props.optimal_tiling = props + .optimal_tiling + .difference(vk::FormatFeatureFlags2::STORAGE_READ_WITHOUT_FORMAT); + let cleared = Device::new(desc, DevicePolicy::default()).expect("device"); + assert!(cleared.profile().storage_reads_by_format_bits()); + let bit = Capability::Format { + format, + usage: FormatUsage::StorageImageReadWithoutFormat, + }; + assert_eq!( + tier_read_gaps(cleared.profile(), &storage_class()), + vec![bit.clone()] + ); + match pipeline(&cleared, &bc) { + Err(Error::Unsupported(u)) => { + assert_eq!(u.feature, Feature::ArgumentBufferTextures); + assert_eq!(u.needs, Needs::AnyOf(vec![vec![bit]])); + } + other => panic!("the kernel: {:?}", other.map(|_| ())), + } + assert!(matches!( + heap_element(cleared.profile(), &class, &facts, layout), + Ok(HeapElement::View(_)) + )); + assert_eq!( + handle_entry_flags(cleared.profile(), &facts) & FLAG_STORAGE_UNREADABLE, + FLAG_STORAGE_UNREADABLE + ); +} diff --git a/crates/metal2vulkan/src/tests/engine_heap_ycbcr_writes.rs b/crates/metal2vulkan/src/tests/engine_heap_ycbcr_writes.rs index f20cf4230..6e26e10ca 100644 --- a/crates/metal2vulkan/src/tests/engine_heap_ycbcr_writes.rs +++ b/crates/metal2vulkan/src/tests/engine_heap_ycbcr_writes.rs @@ -414,7 +414,7 @@ fn a_heap_write_s_ycbcr_constant_is_its_command_s() { (PixelFormat::YCBCR84202P, false), (PixelFormat::RGBA8Unorm, false), ] { - let flags = handle_entry_flags(&facts(pf, WRITE)); + let flags = handle_entry_flags(profile, &facts(pf, WRITE)); assert_eq!(flags & FLAG_YCBCR_WRITES != 0, flagged, "{pf:?}"); } } diff --git a/crates/metal2vulkan/src/tests/mod.rs b/crates/metal2vulkan/src/tests/mod.rs index 4350e68a4..b9aa16623 100644 --- a/crates/metal2vulkan/src/tests/mod.rs +++ b/crates/metal2vulkan/src/tests/mod.rs @@ -77,6 +77,7 @@ mod engine_half_storage_notes; mod engine_handles; mod engine_heap_binder; mod engine_heap_residency; +mod engine_heap_storage_reads; mod engine_heap_texel_buffers; mod engine_heap_ycbcr_writes; mod engine_helper_picks; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index ebba8f593..b2ea8d080 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -5580,7 +5580,7 @@ fn metal2vulkan::bind::fold_object_grid pub fn fold_object_grid(groups: [u32; 3] fn metal2vulkan::bind::geometry_flags pub fn geometry_flags(opaque: bool, allow_duplicate_invocation: bool) -> u32 fn metal2vulkan::bind::geometry_table_offset pub fn geometry_table_offset(offsets: &[u64]) -> Result fn metal2vulkan::bind::handle_entry pub fn handle_entry(id: u64, element: u32, flags: u32) -> [u8; HANDLE_ENTRY_BYTES as usize] -fn metal2vulkan::bind::handle_entry_flags pub fn handle_entry_flags(facts: &TextureFacts) -> u32 +fn metal2vulkan::bind::handle_entry_flags pub fn handle_entry_flags(profile: &DeviceProfile, facts: &TextureFacts) -> u32 fn metal2vulkan::bind::heap_classes pub fn heap_classes(profile: &DeviceProfile) -> Vec fn metal2vulkan::bind::heap_element pub fn heap_element(profile: &DeviceProfile, class: &HandleClass, facts: &TextureFacts, layout: vk::ImageLayout) -> Result fn metal2vulkan::bind::heap_raw_form pub fn heap_raw_form(facts: &TextureFacts) -> Option diff --git a/docs/API.md b/docs/API.md index 9dd47d14a..adfd91134 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1393,7 +1393,8 @@ for dependency in &pipeline.dependencies { element of a texel-buffer class: a uniform texel buffer array where the function only reads it, a storage texel buffer array declared without a format where it writes it, each needing the texel buffer kind's non-uniform indexing and update-after-bind features (a storage one also - `shaderStorageImage{Read,Write}WithoutFormat`). `bind::heap_element` answers + `shaderStorageImageWriteWithoutFormat`, and where it is read `shaderStorageImageReadWithoutFormat` + or, without it, the formats' own read bits, section 10). `bind::heap_element` answers `HeapElement::TexelBuffer` for a texture buffer such a class holds, the format of its texel buffer view; a planned heap's members are textures with images, so only a heap set the consumer keeps for every command (each live texture at its resource ID) holds texture buffers. Push constants carry the values the @@ -5379,6 +5380,17 @@ each item named states the rule in full. - **A gone holder's texture ID reads the neutral texture.** A function reading a texture ID from an argument buffer reaches the texture holding the ID as the command buffer runs; once the holder is gone, the ID reads the neutral texture, where Metal's read is undefined. +- **A `read_write` argument-buffer texture of a format outside Metal's read-write tiers reads zero + where the device cannot read its storage view without a format.** On a device without + `shaderStorageImageReadWithoutFormat` that reads storage without a format by the formats' own + `STORAGE_READ_WITHOUT_FORMAT` bits (Vulkan 1.3 or `VK_KHR_format_feature_flags2`: ANV before + Gfx12.5, the Iris Xe), the heap's storage arrays hold such a texture for its writes, which store + as before, and a read through its handle reads the null element, as a nil texture's read does + (`memory::handles::FLAG_STORAGE_UNREADABLE`). Metal defines a `read_write` texture's read only for + its read-write tier formats (`MTLReadWriteTextureTier`): a function that reads a storage class + one of them is held in through a view the device cannot read so is refused + (`Unsupported{ArgumentBufferTextures}` naming the view format's bit). + Which formats this reaches is in `docs/FAST-PATHS.md`'s device gaps. - **Two live textures with one ID: a function reads the holder**, the texture placed there last. - **An indirect command buffer's ID is Metal's small integer**, from 1, the lowest free, in the indirect command buffers' own space; it stays held while committed work that runs or makes the diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 0fe995ff3..218880973 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -110,6 +110,7 @@ known. The rest of the differences are docs/API.md section 9's precision notes. | On MoltenVK a `Shared` or `Managed` texture whose format packs more than one texel into a block (every block-compressed family) keeps its image out of host-transfer memory, so its CPU copies take submissions where another driver's take none. The stored texels are Metal's either way; what changes is the work, in `WorkCounts::command_buffers_begun_batch_work` and the `command_buffers_begun` and `command_buffers_submitted` that carry it (`bc1-rgba`, four 16 x 16 `BC1_RGBA` levels: `command_buffers_begun` 8 on the bind-time path and 15 off it; `fresh-texture-bc1-rgba-managed`: 3 and 5). A `replaceRegion` of such a texture stages its bytes for the device's next submission and waits for none (`texture/first_move.rs`). Its CPU **reads** come out of a host shadow of the image's texels, made at the first read of the texture by the submission that read waits for either way and read from by every read after it: exact (it holds the image's own bytes, and a CPU write writes both), bounded (`host_shadow::SHADOW_BYTES`, past which a read takes the submission path), and lazy, so a texture nobody reads back holds nothing. It is dropped wherever anything but a CPU write may have written the texels: every commit of the program's, its own Vulkan submissions, another `VkImage`, a detach, or the program taking the image's handle (`texture/host_shadow.rs`; `WorkCounts::texel_shadows_made`, `texel_shadow_reads`, `texel_shadows_dropped`). Measured on an M3 Max: `compressed-moves-bc1-rgba` reads `internal_submissions` 5 where it read 56 and `command_buffers_begun` 30 where it read 81, for 1,168 bytes of shadow over its five textures and 56 reads out of them. | MoltenVK 1.4.2 binds such an image through a `flushToDevice` that `replaceRegion:`s every subresource at one block's bytes a row instead of the row of blocks, tripping AGX's `bytes_per_row >= used_bytes_per_row` assertion (`RuntimeDriverDefect::HostTransferImagesCopiedAtBind`). The copy is the driver's own and no call of the program's asks for it, so the only way not to provoke it is not to ask for the image; every other driver keeps the host-transfer path, as does a device without `VK_EXT_host_image_copy`. A write cannot leave the GPU's copy of the texels unwritten, so only reads come off the host shadow. | None (cost only, and exact) | | On a GPU without unified memory whose types for host-transfer images lie in a heap with no room left, a `Shared` or `Managed` texture made then takes no host-transfer usage: its image lies in device-local memory where that image has room, and its CPU copies take submissions where those of a texture made while the heap had room take none (`memory::host_image_types`, `texture/host_copy.rs`). An RTX 3090 without resizable BAR (NVIDIA 620.70.06) places such images in its 246 MiB BAR heap alone, which every process's devices share, beside a device-local heap of 24 GiB; a color texture there copies on NVIDIA's staging queue where its image has both transfer usages (`texture/staging_copy.rs`), so this reaches its depth and stencil textures and the color textures it does not stage. The texels are Metal's either way. | The heap's size is the device's (resizable BAR is the platform's setting). The other memory with room is system memory, where the GPU would reach the image across the bus for as long as it lives (`device-memory-overflow`) to spare the CPU copies their submissions. | None (cost only, and exact) | | On a driver that does not take a set-0 buffer binding whose entry point uses it through several variables as a **dynamic** descriptor, a draw or dispatch of such a variant that binds it at another offset than its predecessor did allocates and writes a descriptor set of its own, where a dynamic binding would let it bind its predecessor's set again at its own offset. That saving needs the binding's range to stay as its offset moves (`bind::instantiate::descriptor_range`): a slot read to its buffer's end has a range that moves with its offset, so its commands write a set each in either form. Such a binding is a slot reached through its word view and a narrow, `uvec2` or `uvec4` unit view (`memory::views`), as `record_stride_not_a_multiple_of_four`'s `recs` is. The stored values are the same either way; what changes is the set a command allocates and writes (`WorkCounts::set_zero_sets_reused` counts none of them). The device answers for itself, by creating one pipeline of exactly that shape and destroying it (`pipeline::objects::takes_multi_variable_dynamic`, `bind::DynamicViewsModule`, asked once and only where a layout has such a binding), so a driver without the defect pays nothing. A binding the device takes still turns dynamic only while the layout's dynamic-buffer budget lasts (`maxDescriptorSetUniformBuffersDynamic`, `maxDescriptorSetStorageBuffersDynamic`), spent in binding order: on a Radeon 780M (RADV, Mesa 26.2.4, eight dynamic storage buffers) a layout's storage bindings past the eighth get none, so commands that bind them at moving offsets keep a set each wherever set 0 is not pushed. A device whose set 0 is pushed (`VK_KHR_push_descriptor` with an eligible layout) never reaches the choice. | Nothing in Vulkan bounds the variables at a binding, dynamic or not, so there is no exact form to switch to: the driver either compiles the shape or does not. MoltenVK's SPIRV-Cross declares one variable's local alone -- read in 1.4.1's source and measured on 1.4.2 (`driverVersion` 10402) on an Apple M3 Max, where `vkCreateComputePipelines` answers `VK_ERROR_INITIALIZATION_FAILED` for a kernel of three and of four variables at one dynamic binding. The check proves the driver compiles the shape, not that it applies the dynamic offset to every variable at it; no device is measured to get that wrong, and RADV (Mesa 26.2.4, Radeon 780M, at offset 0) and lavapipe (Mesa, arm64, at moving offsets) are measured to get it right, `record_stride_not_a_multiple_of_four` answering Metal's `sizeof` and both its narrow stores with its three-variable binding dynamic. | None (cost only, and exact) | +| On a device without `shaderStorageImageReadWithoutFormat` that reads storage without a format by the formats' own `STORAGE_READ_WITHOUT_FORMAT` bits (Vulkan 1.3 or `VK_KHR_format_feature_flags2`), a read through a `read_write` argument-buffer texture whose storage view lacks the bit reads zero, the null element, as a nil texture's read does; its writes store as before. On ANV before Gfx12.5 (the Iris Xe, Mesa 26.2.6, profile `intel-irisxe-rplp-anv`) those views are `A2B10G10R10` (`RGB10A2Unorm`, `RGB10A2Uint`), `A2R10G10B10` (`BGR10A2Unorm`), `B10G11R11_UFLOAT` (`RG11B10Float`), `B8G8R8A8_UNORM` (`BGRA8Unorm`) and the 16-bit packed formats; every Metal read-write tier format has the bit there. A slot reads them through its declared format. | The heap's storage class is declared without a format, and Gfx12.0 has no typed read of those formats (Mesa's isl format table); Metal defines a `read_write` texture's read only for its read-write tier formats, so a function that reads a storage class one of them is held in through a view without the bit is refused rather than read as zero. | `memory::handles::FLAG_STORAGE_UNREADABLE`, `bind::heap::storage_unreadable`, `bind::heap::tier_read_gaps` | ## Accuracy switches whose default is Metal's @@ -2039,11 +2040,9 @@ driver's. Each is open work. `B10G11R11_UFLOAT_PACK32` lack in the committed ANV profiles: a fetch through the pixel interlock of a 16-bit packed color attachment (`B5G6R5Unorm`, `A1BGR5Unorm`, `ABGR4Unorm`, `BGR5A1Unorm`), which no SPIR-V format names, is refused (`FramebufferFetch`). A read of an argument buffer's - writable texture is refused there whatever its format (`ArgumentBufferTextures`): the heap - views its members for the accesses the device's features grant, for every pipeline alike, and a - check of each member's bit against the pipeline's heap reads is not built. A fetch through a - 16-bit unsigned view that packs the channels in the shader, and heap storage classes typed per - format, are not built either. + writable texture whose view lacks the bit reads zero there (the device-gaps row above). A fetch + through a 16-bit unsigned view that packs the channels in the shader, and heap storage classes + typed per format, are not built. - **The formats from 630 to 645 under macOS 27.0.1.** The macOS 27.0.1 level answers as an Apple M3 Max, which describes none of them (`BGRA10Unorm`, its packed, sRGB, PQ and HLG forms, `R10UintX6`, `RG10UintX12` and the rest): a texture of one is stopped and the linear alignment