diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index ce48ff149..a3a1e79d3 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1357,10 +1357,12 @@ made, with no lock, and never rewritten for layouts. descriptor's swizzle composed over it; a depth or stencil format's view takes its depth, else its stencil. The storage element is written where the usage has shader write and the device stores the format through a storage image declared without a format; its view maps each - channel to itself. A multisampled texture has no storage element on any device, as Metal's - shaders only read one (the Metal Shading Language: "Multisampled textures only support the - read attribute"). Its image takes no storage usage, so its sample counts are the device's for - its other usages, whether or not the device has `shaderStorageImageMultisample`. + channel to itself. A cube's or a cube array's storage view is the 2D array of its faces, + layer `6 · cube + face`, which a kernel's storage cube writes and reads by face. A multisampled + texture has no storage element on any device, as Metal's shaders only read one (the Metal + Shading Language: "Multisampled textures only support the read attribute"). Its image takes no + storage usage, so its sample counts are the device's for its other usages, whether or not the + device has `shaderStorageImageMultisample`. - A format is made where the translator's format table maps it for the usage on the device (`vk_format`) to the format itself or to one whose view gives Metal's values (a swizzled or rotated view, alpha held in red, an RGBX format, a depth or stencil aspect of a combined @@ -3307,13 +3309,22 @@ cache is answered compile-required on both. `SlotBindOffset`; a texture's level count, `TextureLevels`; the draw's `InstanceCount` or `BaseVertexInstance`; a stage-in stride, `StageInStride`; and the others the translator pushes beside the identity fields): no test yet; + - among those, a storage texture written or read at a level other than the constant 0 (MSL + `write(color, coord, lod)` at a level the kernel computes or reads), whose slot the + translator declares as one storage element per level, which the identity arrays do not hold + ("an encoder value the function reads as TextureLevels(S)"). Metal writes such a level on + Intel Macs as well as on Apple silicon: an owned kernel's writes at levels 1 and 2, read + from a buffer, landed exactly on a Radeon Pro 5300M and on a UHD 630 under macOS 26.7.1, with + Metal's validation off, with its API validation, and with its shader validation. No test yet; - a buffer argument not reached through its device address ("a buffer argument not reached through its device address"): no test yet; - a texture argument of a type the identity arrays hold no element of, or whose bound texture's state beyond its resource ID the function reads ("texture argument S: a type the identity arrays hold no element of, or state of the bound texture beyond its resource ID"), a cube - read by face among them: the golden table (`tests/golden_hashes.tsv`) holds the refusal's - class for `engine/texture_ops`' `cube_faces`, and no test asserts the text yet; + read by face through `access::read` or `access::sample` among them: the golden table + (`tests/golden_hashes.tsv`) holds the refusal's class for `engine/texture_ops`' `cube_faces`, + and no test asserts the text yet. A storage cube written or read by face is lowered: the + translator test `a_storage_cube_written_by_face_is_the_2d_array_element_of_its_faces`; - a texture argument sampled through a sampler the identity sampling does not take ("a texture argument sampled through a sampler the identity sampling does not take"), and a sampler argument whose minimum level or emulated filter the function specializes ("a sampler argument diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 0291e5838..5bda615ae 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -2782,6 +2782,18 @@ pub(crate) fn components( }) } +/// The view type of the storage element of a texture viewed as `view_type`: a cube's or a cube +/// array's is the 2D array of its faces, layer `6 · cube + face`, the image the translator's +/// identity domains declare a storage cube as and read and write by face; any other texture's is +/// its own. Vulkan views every layer of a cube-compatible image as a 2D array, so this is one +/// form on every device. +fn storage_view_type(view_type: vk::ImageViewType) -> vk::ImageViewType { + match view_type { + vk::ImageViewType::CUBE | vk::ImageViewType::CUBE_ARRAY => vk::ImageViewType::TYPE_2D_ARRAY, + other => other, + } +} + /// An image view of `range` of `image`, of `view_type` and `format`, with `components`, and with /// `usage` where its format is another than the image's (`VkImageViewUsageCreateInfo`: the image's /// usage that the format's features hold), else the image's. Timed in @@ -3194,8 +3206,8 @@ impl Made { plan: &Plan, usage: vk::ImageUsageFlags, ) -> Result<(Option, Option), Error> { - let mut view = |components, aspect| { - let (view_type, format) = (shape.view_type, plan.format); + let mut view = |view_type, components, aspect| { + let format = plan.format; // SAFETY: the caller's contract. let range = whole(aspect); let view = @@ -3205,12 +3217,13 @@ impl Made { }; let sampled = match plan.sampled { Some((components, aspect)) if usage.contains(vk::ImageUsageFlags::SAMPLED) => { - Some(view(components, aspect)?) + Some(view(shape.view_type, components, aspect)?) } _ => None, }; let storage = match plan.storage { true => Some(view( + storage_view_type(shape.view_type), vk::ComponentMapping::default(), vk::ImageAspectFlags::COLOR, )?), @@ -3974,7 +3987,11 @@ impl Texture { }; let image = inner.imaged().image; let make = |(components, aspect, role): (_, _, vk::ImageUsageFlags)| { - let (view_type, format) = (shape.view_type, plan.format); + let view_type = match role == vk::ImageUsageFlags::STORAGE { + true => storage_view_type(shape.view_type), + false => shape.view_type, + }; + let format = plan.format; let usage = views_usage.map(|usage| usage & role); // SAFETY: the image is bound, lists the view's format, has the view's usage, and holds // the range: the texture's levels and layers hold the view's. diff --git a/crates/metal2vulkan/src/lower/texture/slot.rs b/crates/metal2vulkan/src/lower/texture/slot.rs index cfea75716..02249fafd 100644 --- a/crates/metal2vulkan/src/lower/texture/slot.rs +++ b/crates/metal2vulkan/src/lower/texture/slot.rs @@ -1093,7 +1093,7 @@ fn declare_slot( } let cube = shape.dim == ImageDim::Cube; // A cube that is read or written, or whose faces are fetched, and every storage cube, is the - // binder's 2D-array view. + // binder's 2D-array view, or under the identity domains a storage cube's element. let cube_as_array = cube && (storage || s.uses.read || s.uses.write || s.uses.faces); if cube && shape.array && !cube_as_array && !images.cube_array { return Err(needs(Feature::CubeArray, VkFeature::ImageCubeArray)); @@ -1141,7 +1141,9 @@ fn declare_slot( .storage_images .get(&s.slot) .is_some_and(|c| c.x_channel); - if cube_as_array { + // Under the identity domains a storage cube's element is already the 2D-array view of its + // faces ([`identity_class`]): no binder chooses its view. + if cube_as_array && !(storage && crate::lower::access::identity(cx.profile)) { facts.push(RuntimeFact::ImageViewShape { slot: s.slot }); } // Under the identity domains the runtime makes no texture buffer past @@ -1537,11 +1539,15 @@ impl SlotPlan { /// element is of that format. A `ulong` slot is an `RG32` unsigned image whose two words the /// shader joins and splits, so its class is the unsigned integer one of its shape. A texture /// buffer's is a texel buffer's, uniform where the slot reads and storage where it writes, the -/// element its resource ID holds in the texel-buffer arrays. `None` for a declaration the identity -/// arrays hold no element of yet: a cube viewed as an array, level views, a texture buffer's parts, -/// an extended-range or RGBX form, or a storage image with another format or a conversion. +/// element its resource ID holds in the texel-buffer arrays. A storage cube or cube array is +/// declared as the 2D array of its faces (layer `6 · cube + face`), which is its storage element: +/// the runtime holds a cube's storage view as that 2D array. `None` for a declaration the identity +/// arrays hold no element of yet: a sampled cube viewed as an array, level views, a texture +/// buffer's parts, an extended-range or RGBX form, or a storage image with another format or a +/// conversion. pub(crate) fn identity_class(decl: &ImageDecl) -> Option { - let plain = !decl.cube_as_array + let storage = decl.usage == ImageUsage::Storage; + let plain = !(decl.cube_as_array && !storage) && decl.level_views.is_none() && decl.extended.is_none() && !decl.x_channel @@ -1555,7 +1561,6 @@ pub(crate) fn identity_class(decl: &ImageDecl) -> Option { Dim::Buffer => SymDim::Buffer, _ => return None, }; - let storage = decl.usage == ImageUsage::Storage; let format = match (storage, decl.format) { (false, _) => StorageFormatClass::NotStorage, (true, crate::spv::ImageFormat::Unknown) => StorageFormatClass::Unknown, diff --git a/docs/API.md b/docs/API.md index ad30ff699..e0248d806 100644 --- a/docs/API.md +++ b/docs/API.md @@ -188,7 +188,10 @@ and so do the command line, the compile worker and every validation tool. It hol the capped `maxComputeWorkGroupInvocations` on every axis. A texture slot's `gpuResourceID` is pushed as its `PushField::SlotGuestBase`, and its texture is the element at the ID's index of set 1's two fixed arrays, the same layout for every pipeline ([RESOURCE-ID.md](RESOURCE-ID.md)); it binds no - descriptor of its own and declares no specialization constant. An argument buffer's texture is + descriptor of its own and declares no specialization constant. A storage cube or cube array slot + is declared as the 2D array of its faces and written and read by face at layer + `6 · cube + face`, so the storage element a consumer holds for a cube texture is that 2D-array + view of its layers. An argument buffer's texture is the element at the index of the `gpuResourceID` its member holds, with no handle table, so a slot and a member of one class index one array. No variant is chosen there: a texture reads through the plain form whatever texture its ID names, its `float` or `half` reads