diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 18dd69da5..a3f7fb395 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -4765,7 +4765,6 @@ enables that the translator names. | Feature | Structure | Without it | |---|---|---| -| `robustBufferAccess` | `VkPhysicalDeviceFeatures` | a buffer is reached by its device address, and an access through a descriptor view is checked in the shader | | `computeDerivativeGroupLinear` | `VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR` | a derivative in a kernel is refused (`ComputeDerivatives`) | | `descriptorBindingStorageBufferUpdateAfterBind` | `VkPhysicalDeviceVulkan12Features` | the translator's function table is a directory and a snapshot, never a heap array of storage buffers; the runtime supplies no function table (Known gaps of pipeline states) | | `shaderStorageBufferArrayNonUniformIndexing` | `VkPhysicalDeviceVulkan12Features` | as `descriptorBindingStorageBufferUpdateAfterBind` | diff --git a/crates/metal2vulkan-validation/src/candidate/platform/enables/tests.rs b/crates/metal2vulkan-validation/src/candidate/platform/enables/tests.rs index 989ca71ac..0e3bdf07e 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/enables/tests.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/enables/tests.rs @@ -401,9 +401,8 @@ fn a_member_is_enabled_only_through_a_listed_extension() { /// On every committed profile (as a context's API-1.2 query reads it), the engine's context /// enables exactly what the runtime enables of it (`engine::runtime_enables`), in the one closed -/// set `with_enabled` accepts and `Device::from_queries` derives from: its opened profile checks -/// buffers reached through descriptor views in the shader (the runtime enables no buffer -/// robustness) and leaves images to the device where the profile states image robustness. No +/// set `with_enabled` accepts and `Device::from_queries` derives from: its opened profile leaves +/// images to the device where the profile states image robustness. No /// member the vocabulary does not name is enabled (`textureCompressionASTC_HDR` among them). #[test] fn the_list_enables_what_the_runtime_enables_of_the_description() { @@ -424,16 +423,9 @@ fn the_list_enables_what_the_runtime_enables_of_the_description() { .profile() .clone(); let states = |feature| description.features.contains(&feature); - let robust = ( - profile.checks_buffers_in_shader(), - profile.images().robust_image_access, - ); assert_eq!( - robust, - ( - true, - states(F::RobustImageAccess) || states(F::RobustImageAccess2) - ), + profile.images().robust_image_access, + states(F::RobustImageAccess) || states(F::RobustImageAccess2), "{stem}" ); assert!(!enables.linked.contains(&Structure::AstcHdr), "{stem}"); diff --git a/crates/metal2vulkan-validation/src/coverage.rs b/crates/metal2vulkan-validation/src/coverage.rs index a69dbc294..0021fbea4 100644 --- a/crates/metal2vulkan-validation/src/coverage.rs +++ b/crates/metal2vulkan-validation/src/coverage.rs @@ -14,9 +14,9 @@ //! A run's census ([`ExecutedCensus`]) is the class of the device it ran on ([`ExecutionClass`]: //! a CPU ICD, or a GPU's driver, [`HostClass`]), the product build that compiled its modules, and //! their censuses. The tier table compiles each committed profile twice where it states a -//! robustness feature ([`Leg`]): as stated, which selects the robust encodings, and with every -//! robustness feature removed ([`robustness_off`]), which selects the in-shader ones, the ones the -//! runtime's floor compiles, as it enables no robustness feature. +//! robustness feature ([`Leg`]): as stated, which selects the robust image encodings where it +//! states image robustness, and with every robustness feature removed ([`robustness_off`]), which +//! selects the in-shader ones. Buffers are checked in the shader on both legs. use crate::candidate::engine::artifact::ExecutedArtifact; use crate::case::Stage; @@ -59,12 +59,11 @@ impl SubgroupShape { } } -/// The device features whose enablement chooses a containment encoding: buffer robustness drops the -/// in-shader check of descriptor views (`DeviceProfile::checks_buffers_in_shader`), image -/// robustness the in-shader clamp and guard of images (`robust_image_access`). A tier-table -/// profile's robustness-off leg removes them ([`Leg::RobustnessOff`]), and the engine executor's -/// own context enables the ones its device's description states that the runtime enables on some -/// device (the image ones), all or none. +/// The robustness features a tier-table profile's robustness-off leg removes +/// ([`Leg::RobustnessOff`]). Image robustness drops the in-shader clamp and guard of images +/// (`robust_image_access`); buffer robustness chooses no encoding, as the shader checks every +/// descriptor view. The engine executor's own context enables the ones its device's description +/// states that the runtime enables on some device (the image ones), all or none. pub const ROBUSTNESS_FEATURES: [VkFeature; 4] = [ VkFeature::RobustBufferAccess, VkFeature::RobustBufferAccess2, @@ -72,22 +71,20 @@ pub const ROBUSTNESS_FEATURES: [VkFeature; 4] = [ VkFeature::RobustImageAccess2, ]; -/// How buffers reached through descriptor views (and texel buffers) are contained. A texel -/// buffer is left to the device only under `robustBufferAccess2`, and is checked in the shader -/// below it (`DeviceProfile::device_reads_texels`): its out-of-bounds targets' mechanism -/// (`executor_contract::out_of_bounds`) states that exactly, where this module-wide label says -/// what the descriptor views take. +/// How buffers reached through descriptor views (and texel buffers) are contained: the shader +/// checks every one, on every profile. Its out-of-bounds targets' mechanism +/// (`executor_contract::out_of_bounds`) states each access's check, where this module-wide label +/// says what the descriptor views take. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum BufferEncoding { /// The module declares no buffer (no variable in the `StorageBuffer` or `Uniform` storage /// class, no texel buffer), so no buffer encoding applies to it, whatever its profile's. Unused, - /// Checked in the shader: no buffer robustness is enabled - /// (`DeviceProfile::checks_buffers_in_shader`). + /// Checked in the shader. Checked, - /// Left to robust descriptors: `robustBufferAccess` or `robustBufferAccess2` is enabled, and - /// the shader emits no check. Both levels select the same shader. + /// Left to robust descriptors, the shader emitting no check: a stored row may state it; no + /// compile does. Robust, } @@ -114,8 +111,7 @@ pub enum ImageEncoding { /// The containment encodings a module compiled under: the leaf encodings of its descriptor /// accesses. They are those of the profile it compiled for, which every lowering that reads them -/// reads (`DeviceProfile::checks_buffers_in_shader`, the access targets' checks, -/// `lower::texture::slot`). +/// reads (the access targets' checks, `lower::texture::slot`). /// /// Census names do not all show the encoding they compiled under, so the report keys its rows by /// this, taken from the compile, not by the names. An access by device address (a `BufferForm::Psb` @@ -158,10 +154,8 @@ impl Containment { Containment { buffers: if !declared.buffers { BufferEncoding::Unused - } else if profile.checks_buffers_in_shader() { - BufferEncoding::Checked } else { - BufferEncoding::Robust + BufferEncoding::Checked }, images: if !declared.images { ImageEncoding::Unused @@ -454,11 +448,11 @@ impl ExecutedCensus { #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum Leg { - /// The profile as committed, with the robustness features it states: the robust encodings - /// where it states them. + /// The profile as committed, with the robustness features it states: the robust image + /// encodings where it states them. Stated, - /// The profile without any of [`ROBUSTNESS_FEATURES`]: the in-shader encodings. A profile has - /// this leg only when it states one of them. + /// The profile without any of [`ROBUSTNESS_FEATURES`]: the in-shader image encodings. A + /// profile has this leg only when it states one of them. RobustnessOff, } diff --git a/crates/metal2vulkan-validation/src/coverage/tests.rs b/crates/metal2vulkan-validation/src/coverage/tests.rs index 947dea9a7..7a0dfa5d7 100644 --- a/crates/metal2vulkan-validation/src/coverage/tests.rs +++ b/crates/metal2vulkan-validation/src/coverage/tests.rs @@ -239,23 +239,16 @@ fn a_tessellation_pipeline_census_is_its_functions() { } /// The tier table holds every committed profile as stated and, where it states a robustness -/// feature, in its robustness-off leg: the stated leg compiles the robust -/// encodings the profile states, the off leg the in-shader ones, on the same device class and -/// subgroup width. Every committed profile states `robustBufferAccess`, so every one has both legs; -/// every one states image robustness too (the floor's Vulkan 1.3 requires `robustImageAccess`), -/// and `moltenvk-m3` states `robustBufferAccess` without `robustBufferAccess2`. +/// feature, in its robustness-off leg: the stated leg compiles the robust image encodings the +/// profile states, the off leg the in-shader ones, on the same device class and subgroup width. +/// Every committed profile states `robustBufferAccess`, so every one has both legs; every one +/// states image robustness too (the floor's Vulkan 1.3 requires `robustImageAccess`). #[test] fn the_tier_table_derives_a_robustness_off_leg_from_each_profile() { - use metal2vulkan::device::Robustness; let table = committed_profiles().unwrap(); let stems = crate::engine::committed_profiles().unwrap(); assert_eq!(table.len(), 2 * stems.len()); - let robust = |profile: &DeviceProfile| { - ( - profile.checks_buffers_in_shader(), - profile.images().robust_image_access, - ) - }; + let robust = |profile: &DeviceProfile| profile.images().robust_image_access; for stem in &stems { let description = crate::engine::load_description(stem).unwrap(); let legs = table @@ -275,8 +268,8 @@ fn the_tier_table_derives_a_robustness_off_leg_from_each_profile() { ); let images = description.has(VkFeature::RobustImageAccess) || description.has(VkFeature::RobustImageAccess2); - assert_eq!(robust(&stated.profile), (false, images), "{stem}"); - assert_eq!(robust(&off.profile), (true, false), "{stem}"); + assert_eq!(robust(&stated.profile), images, "{stem}"); + assert!(!robust(&off.profile), "{stem}"); } let stated = |stem: &str| { table @@ -286,8 +279,6 @@ fn the_tier_table_derives_a_robustness_off_leg_from_each_profile() { }; assert!(stated("runtime-floor").profile.images().robust_image_access); assert!(stated("lavapipe").profile.images().robust_image_access); - assert_eq!(stated("moltenvk-m3").profile.robustness(), Robustness::Rba); - assert_eq!(stated("lavapipe").profile.robustness(), Robustness::Rba2); // A description that states no robustness feature has no second leg. let mut none = crate::engine::load_description("runtime-floor").unwrap(); none.features @@ -296,14 +287,14 @@ fn the_tier_table_derives_a_robustness_off_leg_from_each_profile() { } /// A compile records the containment it compiled under, from its profile and its own module: -/// the robust and the in-shader leg of one copy census the same strategy names (the name hides -/// the encoding) under different encodings; a kernel that declares no image has none; a texture +/// both legs of one copy census the same strategy names under the one buffer encoding, checked +/// (the shader checks every descriptor view); a kernel that declares no image has none; a texture /// write's image encoding follows the leg's image robustness, and a device that writes a storage /// image only through its declared format (`runtime-floor` without /// `shaderStorageImageWriteWithoutFormat`, below the runtime's floor) needs the texture's format /// first; and a kernel that turns an integer into a pointer (a dynamic root) reaches that memory by -/// device address under names of its own, checked in the shader in both legs, while its descriptor -/// accesses take each leg's encoding. +/// device address under names of its own, checked in the shader in both legs, as its descriptor +/// accesses are. #[test] fn a_compile_records_the_containment_it_compiled_under() { use metal2vulkan_devtools::{engine_dir, fixtures_dir, llvm_assemble}; @@ -335,7 +326,7 @@ fn a_compile_records_the_containment_it_compiled_under() { let (stated, off) = (copy(Leg::Stated), copy(Leg::RobustnessOff)); assert!(stated.strategies.contains("access.memcpy.dynamic")); assert!(off.strategies.contains("access.memcpy.dynamic")); - assert_eq!(stated.containment, encoding(B::Robust, I::Unused)); + assert_eq!(stated.containment, encoding(B::Checked, I::Unused)); assert_eq!(off.containment, encoding(B::Checked, I::Unused)); let write = |stem: &str, leg_of| { @@ -394,28 +385,22 @@ fn a_compile_records_the_containment_it_compiled_under() { .collect::>(); (module.containment, accesses) }; - assert_eq!( - round_trip(Leg::Stated), - ( - encoding(B::Robust, I::Unused), - ["access.dynamic.load", "access.load", "access.store"] + for leg_of in [Leg::Stated, Leg::RobustnessOff] { + assert_eq!( + round_trip(leg_of), + ( + encoding(B::Checked, I::Unused), + [ + "access.dynamic.load", + "access.load.checked", + "access.store.checked" + ] .map(String::from) .into() - ) - ); - assert_eq!( - round_trip(Leg::RobustnessOff), - ( - encoding(B::Checked, I::Unused), - [ - "access.dynamic.load", - "access.load.checked", - "access.store.checked" - ] - .map(String::from) - .into() - ) - ); + ), + "{leg_of:?}" + ); + } } /// A kernel that reads, through a `select` of two textures by thread parity (a switch-at-use), @@ -546,10 +531,10 @@ fn an_image_encoding_names_what_its_device_is_left() { /// A vertex case's row compiles under the vertex descriptor its executors draw it with. /// `vertex_varying_triangle` reads two `float2` attributes and binds no buffer. Under its -/// descriptor the stated leg fetches them fixed function and declares no buffer, while the -/// robustness-off leg, whose buffer robustness no longer bounds fixed-function input, pulls them -/// from a storage buffer checked in the shader: the row the executed module belongs to. A fixture -/// entry's default inputs (no descriptor) declare no buffer on either leg. +/// descriptor both legs pull them from a storage buffer checked in the shader, as nothing bounds +/// fixed-function input outside the identity domains (VUID-vkCmdDraw-None-02721): the row the +/// executed module belongs to. A fixture entry's default inputs (no descriptor) declare no buffer +/// on either leg. #[test] fn a_vertex_case_compiles_under_its_vertex_descriptor() { use crate::case::{AttributeFormat, AttributeInput}; @@ -592,17 +577,12 @@ fn a_vertex_case_compiles_under_its_vertex_descriptor() { .buffers }; for stem in ["lavapipe", "moltenvk-m3", "runtime-floor"] { - assert_eq!( - buffers(&inputs, leg(stem, Leg::Stated)), - BufferEncoding::Unused, - "{stem}" - ); - assert_eq!( - buffers(&inputs, leg(stem, Leg::RobustnessOff)), - BufferEncoding::Checked, - "{stem}" - ); for leg_of in [Leg::Stated, Leg::RobustnessOff] { + assert_eq!( + buffers(&inputs, leg(stem, leg_of)), + BufferEncoding::Checked, + "{stem} {leg_of:?}" + ); assert_eq!( buffers(&CaseInputs::defaults(), leg(stem, leg_of)), BufferEncoding::Unused, @@ -699,11 +679,9 @@ fn target(resource: OutOfBoundsResource, form: ContainmentForm) -> OutOfBoundsTa /// The out-of-bounds fixtures (`engine/ob1_*`) compile each target they declare to the form /// and mechanism of the inventory on lavapipe, MoltenVK, and the runtime's floor, in both legs: a -/// descriptor view left to the device's buffer robustness where the leg enables it and checked in -/// the shader where it does not, a device address and the arena checked in the shader on every -/// leg, and an image or texel buffer left to the device's image or buffer robustness where -/// enabled. The form is the compiled structure's: a robustness-off leg views the `constant` -/// buffer as a storage buffer. +/// descriptor view, a texel buffer, a device address and the arena checked in the shader on every +/// leg, and an image left to the device's image robustness where enabled. The form is the +/// compiled structure's: every leg views the `constant` buffer as a storage buffer. #[test] fn the_out_of_bounds_fixtures_contain_each_target_as_declared() { use metal2vulkan_devtools::{engine_dir, llvm_assemble}; @@ -749,25 +727,15 @@ fn the_out_of_bounds_fixtures_contain_each_target_as_declared() { ], ), ]; - // The mechanism label of each fixture's targets per (stem, leg). MoltenVK and the runtime's - // floor state `robustBufferAccess` without `robustBufferAccess2`. - let expected = |fixture: &str, stem: &str, leg: Leg| -> &str { - let off = leg == Leg::RobustnessOff; - let robust1 = ["moltenvk-m3", "runtime-floor"].contains(&stem); + // The mechanism label of each fixture's targets per (stem, leg). + let expected = |fixture: &str, _: &str, leg: Leg| -> &str { match fixture { "ob1_device_address" => "device-address:shader", "ob1_threadgroup" => "arena:shader", - _ if off => match fixture { - "ob1_texture" => "image:shader", - "ob1_texel_buffer" => "texel-buffer:shader", - _ => "descriptor-view:shader", - }, + "ob1_texture" if leg == Leg::RobustnessOff => "image:shader", "ob1_texture" => "image:robust2", - // `robustBufferAccess` alone: the texel buffer is checked in the shader. - "ob1_texel_buffer" if robust1 => "texel-buffer:shader", - "ob1_texel_buffer" => "texel-buffer:robust2", - _ if robust1 => "descriptor-view:robust", - _ => "descriptor-view:robust2", + "ob1_texel_buffer" => "texel-buffer:shader", + _ => "descriptor-view:shader", } }; // The form each target is exercised as: the declared one, but a buffer as its compiled slot @@ -993,21 +961,18 @@ fn ob3_case(fixture: &str) -> AuthoredCase { /// The fixtures of the authorable forms (`engine/ob3_*`) compile, under the inputs their cases /// imply (a vertex descriptor, a stage-input descriptor), each target to its declared form and the -/// mechanism of its fetch on every committed profile, in both legs: a vertex input is -/// fixed-function under the stated buffer robustness and pulled with the check without it; a -/// control point and a stage input are pulled through a descriptor view, left to the stated -/// robustness or checked in the shader; an index buffer is bounded by `robustBufferAccess2` where -/// the leg enables it and clamped by the binder elsewhere; a top-level texture array's index is -/// clamped in the shader. The profiles without `tessellationShader` refuse the control-point draw, +/// mechanism of its fetch on every committed profile, in both legs: a vertex input, a control +/// point and a stage input are pulled through a descriptor view checked in the shader (outside +/// the identity domains nothing bounds fixed-function input); an index buffer is drawn from a +/// zero-padded copy; a top-level texture array's index is clamped in the shader. The profiles without `tessellationShader` refuse the control-point draw, /// a post-tessellation vertex function, and those without vertex stores the vertex draws, which /// write memory, each a typed refusal; a control point compiles on every other profile. #[test] fn the_ob3_fixtures_contain_each_target_by_its_fetch_on_every_profile() { use metal2vulkan_devtools::{engine_dir, llvm_assemble}; let table = committed_profiles().unwrap(); - // What each profile's description states, by stem: whether it has `robustBufferAccess2`, - // vertex stores and `tessellationShader`. The stated description decides both legs; the robustness-off leg reads none - // of the robustness here. + // What each profile's description states, by stem: whether it has vertex stores and + // `tessellationShader`. The stated description decides both legs. let described = table .iter() .map(|entry| entry.tier.stem.as_str()) @@ -1017,7 +982,6 @@ fn the_ob3_fixtures_contain_each_target_by_its_fetch_on_every_profile() { let description = crate::engine::load_description(stem).unwrap(); let has = |feature| description.has(feature); let facts = ( - has(VkFeature::RobustBufferAccess2), has(VkFeature::VertexPipelineStoresAndAtomics), has(VkFeature::TessellationShader), ); @@ -1039,9 +1003,7 @@ fn the_ob3_fixtures_contain_each_target_by_its_fetch_on_every_profile() { for entry in table.iter() { let label = entry.tier.label(); let stem = entry.tier.stem.as_str(); - let off = entry.tier.leg == Leg::RobustnessOff; - let (robust2, vertex_stores, tessellation) = described[stem]; - let robust = if robust2 { "robust2" } else { "robust" }; + let (vertex_stores, tessellation) = described[stem]; let refused = match fixture { "ob3_control_point" if !tessellation => Some("Tessellation"), "ob3_vertex_input" | "ob3_index_buffer" | "ob3_control_point" => { @@ -1050,13 +1012,12 @@ fn the_ob3_fixtures_contain_each_target_by_its_fetch_on_every_profile() { _ => None, }; let expected = match fixture { - "ob3_vertex_input" if off => "descriptor-view:shader".to_string(), - "ob3_vertex_input" => format!("vertex-input:{robust}"), - "ob3_control_point" | "ob3_stage_input" if off => "descriptor-view:shader".into(), - "ob3_control_point" | "ob3_stage_input" => format!("descriptor-view:{robust}"), + "ob3_vertex_input" | "ob3_control_point" | "ob3_stage_input" => { + "descriptor-view:shader" + } // Every device and leg draws from a zero-padded copy. - "ob3_index_buffer" => "index-buffer:padded".into(), - _ => "handle-array:shader".into(), + "ob3_index_buffer" => "index-buffer:padded", + _ => "handle-array:shader", }; match compile_module(&bitcode, fixture, &inputs, &entry.profile) { Ok(compiled) => { diff --git a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs index 10056aa32..6ed7009d1 100644 --- a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs +++ b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs @@ -7,23 +7,21 @@ //! //! - **The form and mechanism** of each target are what its compiled module does with it, never //! only what the case says ([`containment`]): a buffer is a storage buffer through its -//! descriptor, or a device address; a buffer slot the product reaches through a descriptor view is -//! checked in the shader or left to the device's buffer robustness (the two encodings); a slot -//! reached by its device address and the threadgroup arena are checked in the shader in every -//! leg; a texel buffer and an image follow the product's texel containment -//! (`DeviceProfile::device_reads_texels` and `device_drops_texel_writes`): a texel buffer is left -//! to `robustBufferAccess2` and otherwise checked in the shader; an image's reads are left to -//! `robustImageAccess2` and its writes to `robustImageAccess` at either level, each otherwise -//! checked in the shader. A buffer reached through a pointer loaded from an argument buffer is a +//! descriptor, or a device address; a buffer slot the product reaches through a descriptor view, +//! a slot reached by its device address and the threadgroup arena are checked in the shader in +//! every leg; a texel buffer and an image follow the product's texel containment +//! (`DeviceProfile::device_reads_texels` and `device_drops_texel_writes`): a texel buffer is +//! checked in the shader; an image's reads are left to `robustImageAccess2` and its writes to +//! `robustImageAccess` at either level, each otherwise checked in the shader. A buffer reached through a pointer loaded from an argument buffer is a //! device address the resident set resolves, a thread-local array a typed object whose index is //! checked against its length, and an argument buffer's texture array a handle table the loaded //! resource id is looked up in: each checked in the shader in every leg. Under the identity //! domains (`DevicePolicy`) a loaded pointer is the address it holds, which nothing checks, so //! the candidate does not run the case ([`Check::Unchecked`]), and a loaded resource id's index //! is masked onto the descriptor arrays, whose elements no live texture owns are null -//! descriptors. An attribute buffer is fetched by fixed-function vertex input, left to the -//! device's buffer robustness (unchecked without it, [`Check::Unchecked`]), or pulled in the -//! shader through the slot its fetch names, contained as that slot is ([`Fetch`]); a direct +//! descriptors. An attribute buffer is fetched by fixed-function vertex input, which nothing +//! bounds ([`Check::Unchecked`]), or pulled in the shader through the slot its fetch names, +//! contained as that slot is ([`Fetch`]); a direct //! indexed draw's index buffer is bounded by `robustBufferAccess2` or the binder's clamp; and a //! top-level texture array's dynamic index is clamped onto its elements in the shader. //! - **The read rule** ([`read_rule`]) says what an out-of-bounds read of the target may return: @@ -51,7 +49,7 @@ use crate::case::out_of_bounds::{ContainmentForm, OutOfBoundsResource, OutOfBoun use crate::case::{AuthoredCase, OutputSelection}; use crate::observation_contract::{ComparisonClass, ObservationLanes}; use base64::Engine as _; -use metal2vulkan::device::{DevicePolicy, DeviceProfile, HandleDomain, PointerDomain, Robustness}; +use metal2vulkan::device::{DevicePolicy, DeviceProfile, HandleDomain, PointerDomain}; use metal2vulkan::library::CompiledFunction; use metal2vulkan::pipeline::VertexInputState; use metal2vulkan::pipeline::{AttributeFetch, StrategyCensus}; @@ -104,7 +102,8 @@ pub enum Check { /// The shader clamps an image's reads, and the device's `robustImageAccess` without the /// second level discards its writes. ShaderReads, - /// The device's `robustBufferAccess` without the second level. + /// The device's `robustBufferAccess` without the second level. No executor contains a target + /// so now; committed records of earlier runs state it. Robust, /// The device's `robustBufferAccess2` (or `robustImageAccess2`). Robust2, @@ -406,10 +405,9 @@ mod census { pub const HANDLE_ARRAY_LOAD_CLAMPED: &str = "access.handle.array_load.clamped"; } -/// How the compiled `module` contains `target`, compiled for `profile`, whose buffer and image -/// robustness are the leg's (`Robustness::Rba2` for `robustBufferAccess2`; -/// `robust_image_access2` for `robustImageAccess2`), read through the product's own containment -/// predicates (the `DeviceProfile` containment facts). +/// How the compiled `module` contains `target`, compiled for `profile`, whose image robustness is +/// the leg's (`robust_image_access2` for `robustImageAccess2`), read through the product's own +/// containment predicates (the `DeviceProfile` containment facts). /// /// The form is the structure's, never only the case's word: a buffer is a `uniform_buffer` when /// the module views it as a uniform buffer, a `storage_buffer` when it views it as a storage @@ -429,7 +427,6 @@ pub fn containment( profile: &DeviceProfile, ) -> Result { let ModuleFacts { stage, slots, .. } = *module; - let robust = robust_check(profile)?; let slot = |class, index| { slots .get(&SlotRef { @@ -478,13 +475,13 @@ pub fn containment( BufferForm::Descriptor if atomic => made( ContainmentForm::BufferAtomic, Medium::DescriptorView, - robust, + Check::Shader, written, ), BufferForm::Descriptor => made( ContainmentForm::StorageBuffer, Medium::DescriptorView, - robust, + Check::Shader, written, ), _ => unknown(), @@ -568,17 +565,15 @@ pub fn containment( ) } OutOfBoundsResource::AttributeBuffer { location } => { - // Fixed-function vertex input is left to the device's buffer robustness, which a - // device without it leaves unchecked, and a pulled fetch reads its buffer's slot, - // contained as that slot is. + // Nothing bounds fixed-function vertex input (no buffer robustness is enabled), and a + // pulled fetch reads its buffer's slot, contained as that slot is. match module.attributes.get(&location).copied() { None => Err(format!( "the compiled module fetches no attribute {location}" )), - Some(Fetch::FixedFunction) if robust == Check::Shader => { + Some(Fetch::FixedFunction) => { made(target.form, Medium::VertexInput, Check::Unchecked, false) } - Some(Fetch::FixedFunction) => made(target.form, Medium::VertexInput, robust, false), Some(Fetch::Pulled { buffer_index }) => { match slot(SlotClass::Buffer, buffer_index)? { SlotInterface::Buffer(buffer) => match buffer.form { @@ -586,7 +581,7 @@ pub fn containment( made(target.form, Medium::DeviceAddress, Check::Shader, false) } BufferForm::Descriptor => { - made(target.form, Medium::DescriptorView, robust, false) + made(target.form, Medium::DescriptorView, Check::Shader, false) } _ => unknown(), }, @@ -626,22 +621,14 @@ pub fn containment( ) } OutOfBoundsResource::Texture { binding } => match slot(SlotClass::Texture, binding)? { - // The product's texel containment: a texel buffer is left to the device only where both - // its reads and its writes are Metal's there (`robustBufferAccess2`). - SlotInterface::Texture(texture) if target.form == ContainmentForm::TexelBuffer => { - let device = - profile.device_reads_texels(true) && profile.device_drops_texel_writes(true); - made( - ContainmentForm::TexelBuffer, - Medium::TexelBuffer, - if device { - Check::Robust2 - } else { - Check::Shader - }, - texture.access.write, - ) - } + // The product's texel containment: the shader checks every texel buffer access + // (`DeviceProfile::device_reads_texels`). + SlotInterface::Texture(texture) if target.form == ContainmentForm::TexelBuffer => made( + ContainmentForm::TexelBuffer, + Medium::TexelBuffer, + Check::Shader, + texture.access.write, + ), // An image's writes are left to `robustImageAccess` at either level, its reads only // to the second level. SlotInterface::Texture(texture) => { @@ -664,26 +651,6 @@ pub fn containment( } } -/// The check `profile`'s leg gives every access its compiled modules leave to the device's buffer -/// robustness (the two encodings): a descriptor view's loads, stores and atomics and -/// fixed-function vertex input. -/// [`Check::Robust2`] under `robustBufferAccess2`, [`Check::Robust`] under `robustBufferAccess` -/// alone, and [`Check::Shader`] without buffer robustness; `Err` for a robustness validation -/// does not know. The only source of -/// [`Check::Robust`]: every other medium's check is the shader's, the binder's, or -/// `robustBufferAccess2`'s. -pub fn robust_check(profile: &DeviceProfile) -> Result { - match profile.robustness() { - Robustness::Rba2 => Ok(Check::Robust2), - Robustness::Rba | Robustness::None => Ok(if profile.checks_buffers_in_shader() { - Check::Shader - } else { - Check::Robust - }), - _ => Err("a robustness validation does not know".into()), - } -} - /// Whether a candidate observation `candidate` of `case` matches its Metal observation `golden` /// under `class`, with the out-of-bounds facts `run` of the run for a case that declares targets. A /// case without targets compares as every case does. diff --git a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs index eadeffcba..f0a5c47a2 100644 --- a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs +++ b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds/tests.rs @@ -933,9 +933,9 @@ fn the_identity_domains_leave_a_loaded_pointer_unchecked_and_mask_a_resource_id( assert_eq!(run.targets[0].mechanism, masked.mechanism); } -/// A draw's targets: a fixed-function attribute is contained by the device's buffer robustness, and -/// unchecked without it; a direct indexed draw's index buffer by the padded copy of its indices on -/// every device; a top-level texture array by the clamped handle-array load. A pulled attribute is +/// A draw's targets: a fixed-function attribute is unchecked on every device (no buffer +/// robustness bounds it); a direct indexed draw's index buffer is contained by the padded copy of +/// its indices on every device; a top-level texture array by the clamped handle-array load. A pulled attribute is /// contained as the slot its fetch names, which a module that does not bind it does not access. #[test] fn a_draws_targets_are_contained_by_their_fetch() { @@ -970,7 +970,6 @@ fn a_draws_targets_are_contained_by_their_fetch() { let fixed = BTreeMap::from([(0, Fetch::FixedFunction)]); let pulled = BTreeMap::from([(0, Fetch::Pulled { buffer_index: 30 })]); let attribute = OutOfBoundsResource::AttributeBuffer { location: 0 }; - let mut unchecked_seen = false; for committed in &profiles { let profile = &committed.profile; let label = &committed.tier.stem; @@ -984,19 +983,11 @@ fn a_draws_targets_are_contained_by_their_fetch() { strategies, ) }; - let shader = - !matches!(profile.robustness(), Robustness::Rba2) && profile.checks_buffers_in_shader(); let contained = vertex(attribute, ContainmentForm::VertexInput, &fixed, &strategies) .unwrap_or_else(|why| panic!("{label}: {why}")); assert_eq!(contained.mechanism.medium, Medium::VertexInput, "{label}"); - assert_ne!(contained.mechanism.check, Check::Shader, "{label}"); - assert_eq!( - contained.mechanism.check == Check::Unchecked, - shader, - "{label}" - ); + assert_eq!(contained.mechanism.check, Check::Unchecked, "{label}"); assert!(!contained.written, "{label}"); - unchecked_seen |= shader; assert!( vertex( attribute, @@ -1043,8 +1034,6 @@ fn a_draws_targets_are_contained_by_their_fetch() { ) .is_err()); } - // Some committed profile enables no buffer robustness, so the unchecked form is exercised. - assert!(unchecked_seen); // A top-level texture array's target needs its slot and the clamped load. let lavapipe = &profiles .iter() diff --git a/crates/metal2vulkan/src/device/derive.rs b/crates/metal2vulkan/src/device/derive.rs index 493b0b958..adbbcd73e 100644 --- a/crates/metal2vulkan/src/device/derive.rs +++ b/crates/metal2vulkan/src/device/derive.rs @@ -17,7 +17,6 @@ use crate::device::policy::DevicePolicy; use crate::device::profile::{ BufferAccess, DescriptorCaps, DeviceProfile, EnabledCaps, FormatTable, FragmentCaps, FunctionStorage, HandleDomain, ImageCaps, Independence, LeafCaps, PointerDomain, ProfileFields, - Robustness, }; use crate::device::requirements::{ ApiVersion, FloatControl, FloatWidth, FormatUsage, ResolveMode, SubgroupOp, VkExtension, @@ -186,15 +185,6 @@ fn derive_fields(desc: &DeviceDescription, policy: &DevicePolicy) -> ProfileFiel } else { BufferAccess::Floor }; - // The bounds of a descriptor view's access are a leaf choice from the enabled robustness. - let robustness = if has(VkFeature::RobustBufferAccess2) { - Robustness::Rba2 - } else if has(VkFeature::RobustBufferAccess) { - Robustness::Rba - } else { - Robustness::None - }; - let leaf = LeafCaps { int8: has(VkFeature::ShaderInt8), int16: has(VkFeature::ShaderInt16), @@ -283,7 +273,6 @@ fn derive_fields(desc: &DeviceDescription, policy: &DevicePolicy) -> ProfileFiel buffer_access, pointer_domain: policy.pointer_domain, handle_domain: policy.handle_domain, - robustness, leaf, subgroup: subgroup_model(desc), images, diff --git a/crates/metal2vulkan/src/device/mod.rs b/crates/metal2vulkan/src/device/mod.rs index 51f5afd7c..8dac1d6a7 100644 --- a/crates/metal2vulkan/src/device/mod.rs +++ b/crates/metal2vulkan/src/device/mod.rs @@ -71,9 +71,8 @@ pub use profile::{ Independence, Limits, MeshLimits, PointerDomain, }; // The profile's facts a consumer or a validation tool reads: its descriptor capabilities, its -// subgroup model and simdgroup tiers, the buffer robustness that bounds a buffer-slot access, and -// the Function storage a thread holds. -pub use profile::{DescriptorCaps, FunctionStorage, Robustness}; +// subgroup model and simdgroup tiers, and the Function storage a thread holds. +pub use profile::{DescriptorCaps, FunctionStorage}; pub use requirements::{ ApiVersion, FloatControl, FloatWidth, FormatUsage, Requirements, ResolveMode, SpirvCapability, SpirvExtension, StageCreateFlag, SubgroupOp, VkExtension, VkFeature, VkLimit, VkProperty, diff --git a/crates/metal2vulkan/src/device/profile.rs b/crates/metal2vulkan/src/device/profile.rs index 96608298c..ffd59e889 100644 --- a/crates/metal2vulkan/src/device/profile.rs +++ b/crates/metal2vulkan/src/device/profile.rs @@ -11,7 +11,6 @@ use crate::air::container::Hash256; use crate::device::requirements::{ApiVersion, FormatUsage, VkExtension, VkFeature, VkProperty}; use crate::device::subgroup::{SimdClass, SubgroupModel, Tier}; use crate::error::{Capability, Unsupported}; -use crate::memory::contain::Check; use crate::pipeline::sym::Stage; use crate::vk; @@ -181,29 +180,16 @@ impl DeviceProfile { crate::device::subgroup::tier(class, stage, &self.fields.subgroup) } - /// The buffer robustness this profile enables, which bounds a descriptor view's access at a - /// run-time offset where it holds ([`checks_buffers_in_shader`](Self::checks_buffers_in_shader)). - pub fn robustness(&self) -> Robustness { - self.fields.robustness - } - - /// Whether a module compiled for this profile checks a buffer access in the shader: exactly - /// when no buffer robustness is enabled. Elsewhere the descriptor range and the device's - /// robustness bound it. - pub fn checks_buffers_in_shader(&self) -> bool { - crate::memory::contain::encoding(self) == Check::InShader - } - - /// Whether this profile leaves an out-of-bounds read of an image (`texel_buffer`: of a texel - /// buffer) to the device, whose robustness answers Metal's out-of-bounds texel; elsewhere the - /// shader checks the read. + /// Whether this profile leaves an out-of-bounds read of an image to the device, whose + /// `robustImageAccess2` answers Metal's out-of-bounds texel; elsewhere, and for every texel + /// buffer (`texel_buffer`), the shader checks the read. pub fn device_reads_texels(&self, texel_buffer: bool) -> bool { crate::memory::contain::device_reads_texels(self, texel_buffer) } - /// Whether this profile leaves an out-of-bounds write of an image (`texel_buffer`: of a texel - /// buffer) to the device, whose robustness discards it as Metal does; elsewhere the shader - /// guards the write. + /// Whether this profile leaves an out-of-bounds write of an image to the device, whose + /// `robustImageAccess` discards it as Metal does; elsewhere, and for every texel buffer + /// (`texel_buffer`), the shader guards the write. pub fn device_drops_texel_writes(&self, texel_buffer: bool) -> bool { crate::memory::contain::device_drops_texel_writes(self, texel_buffer) } @@ -339,8 +325,6 @@ pub struct ProfileFields { pub buffer_access: BufferAccess, pub pointer_domain: PointerDomain, pub handle_domain: HandleDomain, - /// The buffer robustness the profile enables. - pub robustness: Robustness, pub leaf: LeafCaps, pub subgroup: SubgroupModel, pub images: ImageCaps, @@ -478,20 +462,6 @@ pub enum HandleDomain { Identity, } -/// Which buffer robustness the profile enables: a descriptor view's access at a run-time offset is -/// bounded by it where it holds, and by the normative in-shader check where none is enabled -/// (`memory::contain`). -#[non_exhaustive] -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum Robustness { - /// Neither; descriptor views get in-shader checks. - None, - /// `robustBufferAccess`. - Rba, - /// `robustBufferAccess2`. - Rba2, -} - /// Leaf arithmetic, storage, and atomic capabilities. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct LeafCaps { diff --git a/crates/metal2vulkan/src/device/tests/enables.rs b/crates/metal2vulkan/src/device/tests/enables.rs index 940c83b22..6d785225c 100644 --- a/crates/metal2vulkan/src/device/tests/enables.rs +++ b/crates/metal2vulkan/src/device/tests/enables.rs @@ -188,8 +188,8 @@ fn recommendations_keep_robust_buffer_access_and_vuid_10247() { /// `vkCreateDevice`). Its recommendation keeps the rule, so the /// stated robustness can be created; adding the buffer update-after-bind features to the restricted /// description changes only the profile's update-after-bind facts, which only the set-1 arrays that -/// need them read (the function tables', the texel-buffer classes'): the containment encoding and -/// every other field are the same. +/// need them read (the function tables', the texel-buffer classes'): every other field is the +/// same. #[test] fn a_recommendation_keeps_vuid_10247() { let mut desc = profile("runtime-floor"); @@ -224,7 +224,6 @@ fn a_recommendation_keeps_vuid_10247() { fields.enabled.features.remove(f); } assert_eq!(&fields, stated.profile().fields()); - assert_eq!(fields.robustness, crate::device::profile::Robustness::Rba); // The whole set is the one a conformant SwiftShader refuses. let mut both = rec.clone(); both.features diff --git a/crates/metal2vulkan/src/device/tests/profile.rs b/crates/metal2vulkan/src/device/tests/profile.rs index c0d96fdb2..bc703cfd5 100644 --- a/crates/metal2vulkan/src/device/tests/profile.rs +++ b/crates/metal2vulkan/src/device/tests/profile.rs @@ -1,7 +1,7 @@ //! `Device::from_queries`, profile derivation, the fingerprint, and `requirements ⊆ profile`. use super::*; -use crate::device::profile::{BufferAccess, HandleDomain, Independence, PointerDomain, Robustness}; +use crate::device::profile::{BufferAccess, HandleDomain, Independence, PointerDomain}; use crate::device::requirements::{Requirements, StageCreateFlag, VkLimit, VkProperty}; use crate::error::{Capability, Feature, Needs}; @@ -197,7 +197,6 @@ fn addressed_needs_name_only_the_missing_features() { fn runtime_floor_derives_the_floor_profile() { let dev = device("runtime-floor"); let f = dev.profile().fields(); - assert_eq!(f.robustness, Robustness::Rba); assert_eq!(f.buffer_access, BufferAccess::Addressed); assert!(f.descriptors.uniform_buffer_standard_layout); assert!(f.leaf.vertex_stores_and_atomics); @@ -255,15 +254,10 @@ fn vertex_layer_and_viewport_outputs_follow_the_features_not_the_extension() { assert!(!f.fragment.output_viewport_index); } +/// `moltenvk-m3` derives a dynamic vertex stride and its formats' usages as it reports them. #[test] -fn robustness2_selects_the_rba2_encoding() { - assert_eq!( - device("amd-780m-radv").profile().fields().robustness, - Robustness::Rba2 - ); - // MoltenVK exposes VK_EXT_robustness2 but reports robustBufferAccess2 = false. +fn moltenvk_m3_derives_its_stride_and_format_usages() { let f = device("moltenvk-m3"); - assert_eq!(f.profile().fields().robustness, Robustness::Rba); let m = f.profile().fields(); assert!(m.dynamic_vertex_stride); assert!(f diff --git a/crates/metal2vulkan/src/lower/access/atomic.rs b/crates/metal2vulkan/src/lower/access/atomic.rs index 48790812a..cce1a78de 100644 --- a/crates/metal2vulkan/src/lower/access/atomic.rs +++ b/crates/metal2vulkan/src/lower/access/atomic.rs @@ -72,8 +72,7 @@ //! access, Mesa's RADV and ANV never showed a relaxed one a store that arrived after its first //! read. //! -//! **Containment** is the plain access's (`contain::encoding`): robust descriptors emit no -//! check; an in-shader check +//! **Containment** is the plain access's: an in-shader check //! guards a view's atomic with `if_(inb)` (its result is 0 out of bounds, where Metal's is //! unmeasured); a device-address atomic out of bounds (a static slot's or a wide pointer's, checked //! against the root entry's size) operates on the write-only sink and yields 0; an arena atomic @@ -674,7 +673,7 @@ pub fn select( } } else { let (mut targets, null) = static_roots(cx, r.ptr, m)?; - let check = contain::encoding(cx.profile); + let check = Check::InShader; let fixed = super::fixed_offset(cx, r.ptr); for t in &mut targets { t.check = check; diff --git a/crates/metal2vulkan/src/lower/access/blob.rs b/crates/metal2vulkan/src/lower/access/blob.rs index 0c0783a6f..5ae67bbbd 100644 --- a/crates/metal2vulkan/src/lower/access/blob.rs +++ b/crates/metal2vulkan/src/lower/access/blob.rs @@ -6,10 +6,9 @@ //! offsets with the buffer family's index rule (`access::gep_offset`), and `bitcast`, //! `addrspacecast`, `freeze`, and `select` copy or select the offset. Several blob globals in one //! root set share the representation, since their offsets are all blob offsets. A load is a -//! word-composed leaf from the blob's words (`memory::blob`): a bound blob's storage view, -//! contained by the descriptor encoding (none with robust descriptors, else the normative check -//! against the bound size), or under the identity domains the module's `Private` words, checked -//! against their length on every load. +//! word-composed leaf from the blob's words (`memory::blob`): a bound blob's storage view, under +//! the normative check against the bound size, or under the identity domains the module's +//! `Private` words, checked against their length on every load. //! //! The blob is constant: a store through a blob pointer is refused, as is a root set that mixes //! the blob with a parameter slot or null (not implemented: it needs the blob's root in the @@ -22,7 +21,7 @@ use crate::error::Error; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; use crate::memory::blob::{BlobDecl, BlobHome, BlobUse}; -use crate::memory::contain::{self, Check}; +use crate::memory::contain; use crate::memory::leaf::{self, k32, Leaf, WordMem, WordOps}; use crate::memory::plan::{ConstGlobalForm, MemoryPlan}; use crate::memory::provenance::{Repr, RootSetId}; @@ -42,7 +41,7 @@ use super::{is_ptr_ty, operand, refuse, GepTerms}; pub struct BlobLoad { pub ptr: LocalPtr, pub leaf: Leaf, - /// The in-shader containment check (without robust descriptors). + /// The in-shader containment check. pub checked: bool, } @@ -173,16 +172,6 @@ pub fn use_blob(cx: &mut SelectCx<'_>) -> Result<(), Error> { Ok(()) } -/// The containment check of a load from the blob on `cx`'s profile: the descriptor encoding's for -/// a bound blob; in the shader for the module's words under the identity domains, which no -/// robustness covers. -pub fn check(cx: &SelectCx<'_>) -> Check { - match super::identity(cx.profile) { - true => Check::InShader, - false => contain::encoding(cx.profile), - } -} - /// The operand form of blob pointer `v`: a value, or a global's address as its blob offset. pub fn blob_ptr(cx: &SelectCx<'_>, v: Value) -> Result { let Value::Const(c) = v else { @@ -211,7 +200,7 @@ pub fn load( Ok(BlobLoad { ptr: blob_ptr(cx, ptr)?, leaf, - checked: check(cx) == Check::InShader, + checked: true, }) } diff --git a/crates/metal2vulkan/src/lower/access/copy.rs b/crates/metal2vulkan/src/lower/access/copy.rs index 3fb3f04ad..2cbc22819 100644 --- a/crates/metal2vulkan/src/lower/access/copy.rs +++ b/crates/metal2vulkan/src/lower/access/copy.rs @@ -68,7 +68,6 @@ use crate::lower::arith::{Form, Held}; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; use crate::memory::arena::Arena; -use crate::memory::contain::Check; use crate::memory::leaf::{self, k32, u32_op, Leaf, Path}; use crate::memory::plan::ArenaObject; use crate::pipeline::interface::Window; @@ -387,7 +386,7 @@ pub fn endpoint( blob::use_blob(cx)?; return Ok(Endpoint::Blob { ptr: blob::blob_ptr(cx, v)?, - checked: blob::check(cx) == Check::InShader, + checked: true, }); } match local::home_of(cx, v) { diff --git a/crates/metal2vulkan/src/lower/access/dynamic.rs b/crates/metal2vulkan/src/lower/access/dynamic.rs index 473ddf587..0c072bcba 100644 --- a/crates/metal2vulkan/src/lower/access/dynamic.rs +++ b/crates/metal2vulkan/src/lower/access/dynamic.rs @@ -104,7 +104,7 @@ use crate::error::{Capability, Error, Feature, LowerFamily, Unsupported}; use crate::lower::arith::{Form, Held}; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; -use crate::memory::contain; +use crate::memory::contain::{self, Check}; use crate::memory::leaf::{self, k32, Coherence, Leaf, Path, Units, WordOps}; use crate::memory::provenance::{Repr, RootSetId}; use crate::memory::roots::{self, k64}; @@ -623,7 +623,7 @@ fn static_access( m: &mut Meter, ) -> Result { let (mut targets, null) = static_roots(cx, ptr, m)?; - let check = contain::encoding(cx.profile); + let check = Check::InShader; let fixed = super::fixed_offset(cx, ptr); for t in &mut targets { *t = Target { check, ..*t }; diff --git a/crates/metal2vulkan/src/lower/access/mod.rs b/crates/metal2vulkan/src/lower/access/mod.rs index 4ddad6117..a19d2b73f 100644 --- a/crates/metal2vulkan/src/lower/access/mod.rs +++ b/crates/metal2vulkan/src/lower/access/mod.rs @@ -123,7 +123,7 @@ use crate::error::{Capability, Error, Feature, LowerFamily, Unsupported}; use crate::lower::emit::EmitCx; use crate::lower::select::{DescriptorCounts, FamilyPlans, Plan, SelectCx, SlotChoice}; use crate::lower::strategy::FamilyStrategy; -use crate::memory::contain::{self, Check}; +use crate::memory::contain::Check; use crate::memory::leaf::{self, Coherence, Leaf, Units}; use crate::memory::plan::SlotPlan; use crate::memory::provenance::{Repr, Root}; @@ -2007,7 +2007,7 @@ fn blob_roots( } let blob_check = if in_blob { blob::use_blob(cx)?; - Some(blob::check(cx)) + Some(Check::InShader) } else { None }; @@ -2024,7 +2024,7 @@ fn place_targets( (write, fixed): (bool, bool), reach: u32, ) -> Result<(), Error> { - let check = contain::encoding(cx.profile); + let check = Check::InShader; for t in targets { t.check = check; let plan = cx diff --git a/crates/metal2vulkan/src/lower/stage_io/fetch.rs b/crates/metal2vulkan/src/lower/stage_io/fetch.rs index 1a2ee1f8f..99ef1a0dd 100644 --- a/crates/metal2vulkan/src/lower/stage_io/fetch.rs +++ b/crates/metal2vulkan/src/lower/stage_io/fetch.rs @@ -98,7 +98,7 @@ use crate::lower::arith::{narrow, ops, FloatFmt, Form, Held}; use crate::lower::dispatch; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; -use crate::memory::contain::{self, Check}; +use crate::memory::contain::Check; use crate::memory::leaf::{k32, Leaf, Path}; use crate::metal::{VertexFormat, VertexStepFunction}; use crate::pipeline::facts::RuntimeFact; @@ -632,7 +632,7 @@ pub(super) fn select( step, stride: Stride::Push(PushField::VertexBufferStride(buffer)), form, - check: contain::encoding(cx.profile), + check: Check::InShader, }) } diff --git a/crates/metal2vulkan/src/lower/stage_io/stage_in.rs b/crates/metal2vulkan/src/lower/stage_io/stage_in.rs index 0ed909327..114a6f50f 100644 --- a/crates/metal2vulkan/src/lower/stage_io/stage_in.rs +++ b/crates/metal2vulkan/src/lower/stage_io/stage_in.rs @@ -51,7 +51,7 @@ use crate::lower::arith::Form; use crate::lower::dispatch::Projection; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; -use crate::memory::contain; +use crate::memory::contain::Check; use crate::metal::{AttributeFormat, IndexType, StepFunction, VertexFormat}; use crate::pipeline::facts::RuntimeFact; use crate::pipeline::stage_io::{StageInFetch, StageInInput}; @@ -249,7 +249,7 @@ fn select( step, stride, form, - check: contain::encoding(cx.profile), + check: Check::InShader, }) } diff --git a/crates/metal2vulkan/src/lower/tessellation/mod.rs b/crates/metal2vulkan/src/lower/tessellation/mod.rs index 886b5f88c..47ad12a8b 100644 --- a/crates/metal2vulkan/src/lower/tessellation/mod.rs +++ b/crates/metal2vulkan/src/lower/tessellation/mod.rs @@ -84,7 +84,7 @@ use crate::lower::select::{FamilyPlans, Plan, SelectCx}; use crate::lower::stage_io; use crate::lower::stage_io::fetch::{self, Encoding, PulledRead, Step, Stride}; use crate::lower::strategy::FamilyStrategy; -use crate::memory::contain::{self, Check}; +use crate::memory::contain::Check; use crate::memory::leaf::k32; use crate::metal::VertexStepFunction; use crate::pipeline::facts::RuntimeFact; @@ -579,7 +579,7 @@ fn pulled_read( .pulled .insert(at, PulledInput::new(attribute, ty, fetch)); } - let check = contain::encoding(cx.profile); + let check = Check::InShader; let e = eval(cx)?; match element { Element::Patch => e.patch = true, diff --git a/crates/metal2vulkan/src/memory/contain.rs b/crates/metal2vulkan/src/memory/contain.rs index 252fc489d..8746d776b 100644 --- a/crates/metal2vulkan/src/memory/contain.rs +++ b/crates/metal2vulkan/src/memory/contain.rs @@ -1,25 +1,20 @@ //! The bounds of a buffer-slot access at a run-time offset, and the side-effect guard. //! -//! A descriptor view's access stays inside the range the binder supplied. Its bounds are a leaf -//! encoding chosen from the profile's buffer robustness ([`encoding`]): -//! -//! - **Robust descriptors** (`robustBufferAccess` or `robustBufferAccess2` enabled): no check is -//! emitted. The descriptor range is the containment domain and the hardware keeps accesses -//! inside it. -//! - **In shader**: loads read at `select(inb, off, 0)` and yield `select(inb, v, 0)`; stores and -//! atomics sit in a builder-closed `if_(inb)`. +//! A descriptor view's access stays inside the range the binder supplied, by the in-shader check +//! on every profile: loads read at `select(inb, off, 0)` and yield `select(inb, v, 0)`; stores and +//! atomics sit in a builder-closed `if_(inb)`. No buffer robustness is enabled, so none bounds the +//! access in its place. //! //! An image or texel buffer is contained by the texture family: its reads by //! [`device_reads_texels`], its writes by [`device_drops_texel_writes`], each in the shader where -//! the device's robustness does not give Metal's answer. Validation labels its runs by the same two -//! predicates. +//! the device's image robustness does not give Metal's answer, and a texel buffer's always. +//! Validation labels its runs by the same two predicates. //! //! The bounds check is normative ([`in_bounds`]): `inb = (size >= n) && (off <= size - n)`, //! evaluated in the offset's width, never `off + n <= size`, which wraps. An offset is unsigned and //! relative to the containment domain's base, so a wrapped GEP result is a huge offset and fails //! the check. -use crate::device::profile::Robustness; use crate::device::DeviceProfile; use crate::spirv::builder::FunctionBuilder; use crate::spirv::error::BResult; @@ -29,45 +24,28 @@ use crate::spirv::ir::{BinOp, ConstBits, Constant}; /// How one leaf access is contained. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Check { - /// No in-shader check (robust descriptors). + /// No in-shader check: a device-address access under the identity domains, which nothing + /// bounds (`AccessPlan::psb_contained`). None, /// The normative in-shader check. InShader, } -/// The descriptor-view encoding of `p`: an in-shader check exactly when no buffer robustness is -/// enabled. -pub fn encoding(p: &DeviceProfile) -> Check { - match p.fields().robustness { - Robustness::None => Check::InShader, - Robustness::Rba | Robustness::Rba2 => Check::None, - } -} - /// Whether the device's robustness on `p` returns Metal's out-of-bounds texel for a read of an -/// image (`buffer`: a texel buffer), so the read is left to it: `robustImageAccess2` -/// (`robustBufferAccess2` for a texel buffer). Elsewhere the shader checks the -/// read: `robustImageAccess` alone reads a missing alpha as 0 or 1 and a fetch past the view's -/// levels as undefined, and `robustBufferAccess` alone may read any value of the buffer. +/// image, so the read is left to it: `robustImageAccess2`. Elsewhere, and for a texel buffer +/// (`buffer`), which no enabled buffer robustness bounds, the shader checks the read: +/// `robustImageAccess` alone reads a missing alpha as 0 or 1 and a fetch past the view's levels as +/// undefined. pub fn device_reads_texels(p: &DeviceProfile, buffer: bool) -> bool { - let f = p.fields(); - match buffer { - true => f.robustness == Robustness::Rba2, - false => f.images.robust_image_access2, - } + !buffer && p.fields().images.robust_image_access2 } -/// Whether the device's robustness on `p` discards an out-of-bounds write of an image (`buffer`: -/// a texel buffer), as Metal does, so the write is left to it: `robustImageAccess` at either level -/// (`robustBufferAccess2` for a texel buffer, since under `robustBufferAccess` alone a write past a -/// texel buffer may modify any memory bound to the buffer). Elsewhere the shader guards the write. +/// Whether the device's robustness on `p` discards an out-of-bounds write of an image, as Metal +/// does, so the write is left to it: `robustImageAccess` at either level. Elsewhere, and for a +/// texel buffer (`buffer`), which no enabled buffer robustness bounds, the shader guards the +/// write. pub fn device_drops_texel_writes(p: &DeviceProfile, buffer: bool) -> bool { - let f = p.fields(); - if buffer { - f.robustness == Robustness::Rba2 - } else { - f.images.robust_image_access - } + !buffer && p.fields().images.robust_image_access } /// An integer constant of the type of `like` (a 32- or 64-bit unsigned scalar). diff --git a/crates/metal2vulkan/src/metal/vertex.rs b/crates/metal2vulkan/src/metal/vertex.rs index 3b3623f3b..c5e3979d0 100644 --- a/crates/metal2vulkan/src/metal/vertex.rs +++ b/crates/metal2vulkan/src/metal/vertex.rs @@ -1,9 +1,8 @@ //! Vertex-format and step-function mapping. //! //! A Metal vertex attribute is fetched by fixed-function vertex input when its format and step -//! function have an exact Vulkan equivalent on the profile and the profile bounds fixed-function -//! input (buffer robustness, or containment off), and **pulled** (fetched and decoded in the -//! shader from its buffer) otherwise. There is no third representation: widening a 3-component +//! function have an exact Vulkan equivalent on the profile and containment is off (the identity +//! domains), and **pulled** (fetched and decoded in the shader from its buffer) otherwise. There is no third representation: widening a 3-component //! 8/16-bit format to 4 components reads past the attribute, which at the end of a buffer is //! out of bounds and may replace the whole attribute. //! @@ -14,7 +13,6 @@ use crate::device::requirements::{FormatUsage, VkFeature, VkLimit}; use crate::device::DeviceProfile; use crate::error::{Capability, DescriptorError, Error, Feature, Unsupported}; -use crate::memory::contain::{self, Check}; use crate::metal::{VertexFormat, VertexStepFunction}; use crate::vk; @@ -170,26 +168,12 @@ pub enum AttributeFetch { /// `profile`, read into an attribute of the format's own numeric class (an integer format read into /// a float attribute is fetched in its `USCALED` or `SSCALED` form). /// -/// - `PerVertex`: vertex rate. `PerInstance` with rate 1: instance rate. `PerInstance` with rate -/// `n > 1`: instance rate with divisor `n` when the profile has -/// `vertexAttributeInstanceRateDivisor`, `n ≤ maxVertexAttribDivisor`, and -/// `supportsNonZeroFirstInstance` (a Metal draw may have a nonzero base instance, and without -/// it Vulkan requires `firstInstance == 0` for any divisor other than 1), else pulled. Vulkan -/// fetches at `firstInstance + (instance - firstInstance) / n`, the same element MoltenVK maps -/// Metal's step rate to (expected, not verified on Metal). -/// - `Constant`: under the identity domains the vertex-rate form below, on a binding -/// `pipeline::link::vertex` emits with a **stride of 0**; pulled outside them. -/// - A format the profile cannot fetch as `VERTEX_BUFFER`: pulled. -/// - `FloatRGB9E5` (`E5B9G9R9_UFLOAT_PACK32`): pulled on every profile -/// (`fixed_function_format`). -/// - Every attribute on a profile whose buffer containment is checked in the shader -/// (`contain::encoding` is `Check::InShader`: containment on, neither `robustBufferAccess` -/// nor `robustBufferAccess2` enabled): pulled. Vulkan bounds fixed-function vertex input only -/// under robust buffer access ("Shader Out-of-Bounds Memory Access": the device feature, or -/// `VK_EXT_pipeline_robustness`'s `vertexInputs`, which no profile models); without it a draw -/// must not fetch past a vertex buffer binding (`VUID-vkCmdDraw-None-02721`), and a Metal draw -/// may, so its bounds move the fetch into the shader, where it reads through the normative -/// check. +/// - Every attribute outside the identity domains: pulled. Vulkan bounds fixed-function vertex +/// input only under robust buffer access ("Shader Out-of-Bounds Memory Access": the device +/// feature, or `VK_EXT_pipeline_robustness`'s `vertexInputs`), which no profile enables; without +/// it a draw must not fetch past a vertex buffer binding (`VUID-vkCmdDraw-None-02721`), and a +/// Metal draw may, so its bounds move the fetch into the shader, where it reads through the +/// normative check. /// - `PerPatch`/`PerPatchControlPoint`: tessellation, refused. A `PerInstance` rate of 0 is an /// invalid descriptor. /// @@ -197,7 +181,11 @@ pub enum AttributeFetch { /// fetch reads through a descriptor, which those domains hold none of. Every attribute is fetched /// in fixed function, and the containment rule above does not move it: the device bounds the /// fetch as it bounds any (with no buffer robustness, a fetch outside its buffer reads what the -/// device gives). `Constant` is there a **vertex-rate** binding of stride 0, on every device, +/// device gives). `PerVertex` is vertex rate, `PerInstance` with rate 1 instance rate, and +/// `PerInstance` with rate `n > 1` instance rate with divisor `n` where the profile has +/// `vertexAttributeInstanceRateDivisor` and `n ≤ maxVertexAttribDivisor`: Vulkan fetches at +/// `firstInstance + (instance - firstInstance) / n`, the same element MoltenVK maps Metal's step +/// rate to (expected, not verified on Metal). `Constant` is there a **vertex-rate** binding of stride 0, on every device, /// with no divisor: Vulkan computes a vertex-rate attribute's address as /// `bufferBindingAddress + vertexIndex * stride + attribDesc.offset` ("Vertex Input Address /// Calculation"), so a stride of 0 reads the layout's first element for every vertex and every @@ -249,13 +237,9 @@ pub(crate) fn fetch_as( 1 => (vk::VertexInputRate::INSTANCE, 1), // A Metal draw may have a nonzero base instance, and a divisor other than 1 takes a // nonzero `firstInstance` only where the device reports `supportsNonZeroFirstInstance` - // (VUID-vkCmdDraw-pNext-09461). Elsewhere the step is pulled, or, under the identity - // domains, a divisor still: the consumer refuses each draw through it at a base - // instance other than 0. - n if f.fragment.vertex_attribute_divisor - && n <= f.limits.max_vertex_attrib_divisor - && (identity || f.limits.supports_non_zero_first_instance) => - { + // (VUID-vkCmdDraw-pNext-09461). Where it does not, the divisor still: the consumer + // refuses each draw through it at a base instance other than 0. + n if f.fragment.vertex_attribute_divisor && n <= f.limits.max_vertex_attrib_divisor => { (vk::VertexInputRate::INSTANCE, n) } n => return pulled(divided(profile, n)), @@ -267,16 +251,15 @@ pub(crate) fn fetch_as( // legal on any binding outside the portability subset: its only other rule, // VUID-VkVertexInputBindingDescription-stride-00619, bounds it above, and // VUID-vkCmdBindVertexBuffers2-pStrides-06209 names 0 among the strides a bind may set. - VertexStepFunction::Constant if identity => (vk::VertexInputRate::VERTEX, 1), - VertexStepFunction::Constant => return Ok(AttributeFetch::Pulled), + VertexStepFunction::Constant => (vk::VertexInputRate::VERTEX, 1), VertexStepFunction::PerPatch | VertexStepFunction::PerPatchControlPoint => { return Err(Unsupported::not_implemented(Feature::Tessellation).into()) } }; - // Without buffer robustness nothing bounds fixed-function input (VUID-vkCmdDraw-None-02721). - // Under the identity domains the device's own bounds stand: there is no pulled fetch to move - // the attribute to. - if !identity && contain::encoding(profile) == Check::InShader { + // No buffer robustness is enabled, so nothing bounds fixed-function input + // (VUID-vkCmdDraw-None-02721): outside the identity domains every attribute is pulled. Under + // them the device's own bounds stand: there is no pulled fetch to move the attribute to. + if !identity { return Ok(AttributeFetch::Pulled); } if !fixed_function_format(vk_format) { @@ -301,8 +284,7 @@ pub(crate) fn fetch_as( /// The refusal of Metal's per-instance step at rate `n` above 1 where fixed-function input cannot /// divide the instance index on `profile`. It names what the profile lacks: /// `vertexAttributeInstanceRateDivisor`, else the rate past `maxVertexAttribDivisor`. Only the -/// identity domains read it: elsewhere the step is pulled, as it is where the profile lacks only -/// `supportsNonZeroFirstInstance`, which the identity domains do not refuse. +/// identity domains read it: elsewhere every attribute is pulled. fn divided(profile: &DeviceProfile, n: u32) -> Unsupported { let f = profile.fields(); let needs = match f.fragment.vertex_attribute_divisor { @@ -318,8 +300,8 @@ fn divided(profile: &DeviceProfile, n: u32) -> Unsupported { /// Whether fixed-function input delivers an attribute of `vk_format` where the profile reports /// the format's `VERTEX_BUFFER`: every format but the shared-exponent `E5B9G9R9_UFLOAT_PACK32` -/// (`FloatRGB9E5`), which is pulled on every profile. Vulkan requires no device to fetch that -/// format as vertex input (its mandatory features are a sampled image's, "Mandatory Format +/// (`FloatRGB9E5`), which is never fetched in fixed function. Vulkan requires no device to fetch +/// that format as vertex input (its mandatory features are a sampled image's, "Mandatory Format /// Support: 64-bit/uneven Components"), and its decode has no rounding to leave to the device: /// each component `m · 2^(e - 24)` is an `f32`, and the missing fourth one is 1, Metal's and /// Vulkan's alike. So the module's decode (`lower::stage_io::fetch`) answers what a conformant @@ -489,6 +471,8 @@ mod tests { .1 } + /// Under the identity domains an attribute is fixed function exactly where the profile fetches + /// it as stated, and refused, by what it needs, elsewhere. #[test] fn fetch_is_fixed_function_only_when_exact() { let mut desc = floor(); @@ -502,18 +486,19 @@ mod tests { ); desc.features .remove(&VkFeature::VertexAttributeInstanceRateDivisor); - let plain = Device::from_queries(desc.clone(), DevicePolicy::RESIDENT_TABLES).unwrap(); + let plain = Device::from_queries(desc.clone(), DevicePolicy::default()).unwrap(); desc.features .insert(VkFeature::VertexAttributeInstanceRateDivisor); // Listed with the extension that exposes it below Vulkan 1.4. desc.extensions .insert(VkExtension::KhrVertexAttributeDivisor); desc.limits.max_vertex_attrib_divisor = 4; - // No nonzero first instance with a divisor (VUID-vkCmdDraw-pNext-09461): pulled. + // No nonzero first instance with a divisor (VUID-vkCmdDraw-pNext-09461): the divisor + // still, the consumer refusing a draw through it at a base instance other than 0. desc.limits.supports_non_zero_first_instance = false; - let zero_first = Device::from_queries(desc.clone(), DevicePolicy::RESIDENT_TABLES).unwrap(); + let zero_first = Device::from_queries(desc.clone(), DevicePolicy::default()).unwrap(); desc.limits.supports_non_zero_first_instance = true; - let divisor = Device::from_queries(desc, DevicePolicy::RESIDENT_TABLES).unwrap(); + let divisor = Device::from_queries(desc, DevicePolicy::default()).unwrap(); use VertexStepFunction as S; let fetch = |dev: &Device, f, s, r| attribute_fetch(f, s, r, dev.profile()); let fixed = |rate, divisor| { @@ -534,7 +519,7 @@ mod tests { ); assert_eq!( fetch(&plain, float3, S::PerInstance, 3), - Ok(AttributeFetch::Pulled) + Err(divided(plain.profile(), 3).into()) ); assert_eq!( fetch(&divisor, float3, S::PerInstance, 3), @@ -542,7 +527,7 @@ mod tests { ); assert_eq!( fetch(&zero_first, float3, S::PerInstance, 3), - Ok(AttributeFetch::Pulled) + fixed(vk::VertexInputRate::INSTANCE, 3) ); assert_eq!( fetch(&zero_first, float3, S::PerInstance, 1), @@ -550,17 +535,17 @@ mod tests { ); assert_eq!( fetch(&divisor, float3, S::PerInstance, 5), - Ok(AttributeFetch::Pulled) + Err(divided(divisor.profile(), 5).into()) ); assert_eq!( fetch(&divisor, float3, S::Constant, 0), - Ok(AttributeFetch::Pulled) + fixed(vk::VertexInputRate::VERTEX, 1) ); // Not a vertex-buffer format on this device. - assert_eq!( + assert!(matches!( fetch(&plain, VertexFormat::UChar3, S::PerVertex, 1), - Ok(AttributeFetch::Pulled) - ); + Err(Error::Unsupported(u)) if u.feature == Feature::Format + )); assert!(matches!( fetch(&plain, float3, S::PerInstance, 0), Err(Error::InvalidDescriptor(DescriptorError::VertexStepRate { @@ -573,11 +558,11 @@ mod tests { ); } - /// `FloatRGB9E5` is pulled at every step on a device that reports `E5B9G9R9_UFLOAT_PACK32`'s - /// `VERTEX_BUFFER` (`fixed_function_format`), while `FloatRG11B10`, the other packed float - /// format, stays fixed function there. + /// Under the identity domains `FloatRGB9E5` is refused at every step on a device that reports + /// `E5B9G9R9_UFLOAT_PACK32`'s `VERTEX_BUFFER` (`fixed_function_format`), while `FloatRG11B10`, + /// the other packed float format, is fixed function there. #[test] - fn shared_exponent_attributes_are_pulled_where_the_device_fetches_them() { + fn shared_exponent_attributes_are_not_fixed_function_where_the_device_fetches_them() { let mut desc = floor(); for f in [ vk::Format::E5B9G9R9_UFLOAT_PACK32, @@ -591,7 +576,7 @@ mod tests { }, ); } - let dev = Device::from_queries(desc, DevicePolicy::RESIDENT_TABLES).unwrap(); + let dev = Device::from_queries(desc, DevicePolicy::default()).unwrap(); assert!(dev.profile().supports_format( vk::Format::E5B9G9R9_UFLOAT_PACK32, FormatUsage::VertexBuffer @@ -600,7 +585,7 @@ mod tests { for (step, rate) in [(S::PerVertex, 1), (S::PerInstance, 1)] { assert_eq!( attribute_fetch(VertexFormat::FloatRGB9E5, step, rate, dev.profile()), - Ok(AttributeFetch::Pulled), + Err(Unsupported::not_implemented(Feature::Format).into()), "{step:?}" ); assert!(matches!( @@ -613,13 +598,13 @@ mod tests { } } - /// Without buffer robustness Vulkan does not bound fixed-function vertex input - /// (`VUID-vkCmdDraw-None-02721`), so every attribute is pulled and read through the in-shader - /// check, whatever its format and step; with `robustBufferAccess` or `robustBufferAccess2` it - /// stays fixed function. The descriptor errors and the tessellation refusal come first in - /// every case. + /// Vulkan bounds fixed-function vertex input only under robust buffer access + /// (`VUID-vkCmdDraw-None-02721`), which no profile enables, so outside the identity domains + /// every attribute is pulled and read through the in-shader check, whatever its format and + /// step, and whatever buffer robustness the device describes. The descriptor errors and the + /// tessellation refusal come first in every case. #[test] - fn fixed_function_input_needs_buffer_robustness() { + fn fixed_function_input_is_pulled_outside_the_identity_domains() { use VertexStepFunction as S; let robust = floor(); assert!(robust.features.contains(&VkFeature::RobustBufferAccess)); @@ -628,17 +613,12 @@ mod tests { bare.features.remove(&VkFeature::RobustBufferAccess2); let checked = Device::from_queries(bare, DevicePolicy::RESIDENT_TABLES).unwrap(); let robust = Device::from_queries(robust, DevicePolicy::RESIDENT_TABLES).unwrap(); - assert_eq!(contain::encoding(checked.profile()), Check::InShader); - assert_eq!(contain::encoding(robust.profile()), Check::None); let float4 = VertexFormat::Float4; for (step, rate) in [(S::PerVertex, 1), (S::PerInstance, 1)] { - let fetch = |dev: &Device| attribute_fetch(float4, step, rate, dev.profile()); - assert_eq!(fetch(&checked), Ok(AttributeFetch::Pulled), "{step:?}"); - assert!( - matches!(fetch(&robust), Ok(AttributeFetch::FixedFunction { .. })), - "{step:?}: {:?}", - fetch(&robust) - ); + for dev in [&checked, &robust] { + let fetch = attribute_fetch(float4, step, rate, dev.profile()); + assert_eq!(fetch, Ok(AttributeFetch::Pulled), "{step:?}"); + } } assert!(matches!( attribute_fetch(float4, S::PerInstance, 0, checked.profile()), @@ -652,8 +632,8 @@ mod tests { ); } - /// Vulkan's mandatory vertex-buffer formats are fixed function on every committed profile - /// that reports them. + /// Vulkan's mandatory vertex-buffer formats are fixed function under the identity domains on + /// every committed profile that reports them and opens those domains. #[test] fn mandatory_vertex_formats_are_fixed_function() { for (stem, desc) in committed_descriptions() { @@ -664,7 +644,9 @@ mod tests { { continue; } - let dev = Device::from_queries(desc, DevicePolicy::RESIDENT_TABLES).unwrap(); + let Ok(dev) = Device::from_queries(desc, DevicePolicy::default()) else { + continue; + }; for v in [ VertexFormat::Float, VertexFormat::Float2, diff --git a/crates/metal2vulkan/src/pipeline/compile/stage_bound.rs b/crates/metal2vulkan/src/pipeline/compile/stage_bound.rs index 9df6fc0ea..2da572a88 100644 --- a/crates/metal2vulkan/src/pipeline/compile/stage_bound.rs +++ b/crates/metal2vulkan/src/pipeline/compile/stage_bound.rs @@ -90,7 +90,7 @@ pub(super) fn emit( })?; // A load of a uniform view that every trip of its loop reads alike leaves the loop. m.weighted(crate::pipeline::compile::weights::HOIST, |m| { - crate::spirv::hoist::hoist_uniform_loads(&mut emitted.module, p.robustness(), m) + crate::spirv::hoist::hoist_uniform_loads(&mut emitted.module, m) })?; // A structurizer variable whose value no later trip of a loop reads is ended at each // trip's top, so the driver carries none of it around the loop. diff --git a/crates/metal2vulkan/src/pipeline/link/vertex.rs b/crates/metal2vulkan/src/pipeline/link/vertex.rs index 9a82e8db8..927427d27 100644 --- a/crates/metal2vulkan/src/pipeline/link/vertex.rs +++ b/crates/metal2vulkan/src/pipeline/link/vertex.rs @@ -20,11 +20,10 @@ //! fetch sign-extending each component as Metal's does; //! 2. the per-attribute choice of `metal::vertex::attribute_fetch` (format, step, profile), in //! item 1's Vulkan format. It -//! pulls every attribute when the profile's buffer containment is checked in the shader -//! (`memory::contain::encoding`: containment on and no buffer robustness): Vulkan bounds -//! fixed-function input only under robust buffer access (`VUID-vkCmdDraw-None-02721`), and a +//! pulls every attribute outside the identity domains: Vulkan bounds fixed-function input only +//! under robust buffer access (`VUID-vkCmdDraw-None-02721`), which no profile enables, and a //! Metal draw may fetch past its buffer, so the fetch moves into the shader behind the check. -//! Every later item then finds no fixed-function attribute. +//! Every later item then finds no fixed-function attribute there. //! A layout of Metal's **constant step** is answered there under the identity domains at //! vertex rate (pulled outside them), and this module emits its binding with a **stride of 0** //! ([`binding_stride`]): a vertex-rate binding fetches element `vertexIndex`, Metal's constant diff --git a/crates/metal2vulkan/src/pipeline/testing.rs b/crates/metal2vulkan/src/pipeline/testing.rs index 06062394e..b22f7575a 100644 --- a/crates/metal2vulkan/src/pipeline/testing.rs +++ b/crates/metal2vulkan/src/pipeline/testing.rs @@ -412,7 +412,7 @@ fn typed_module_of( let crate::lower::emit::Emitted { mut module, .. } = crate::lower::emit::emit_module(&spec, &plan, m)?; crate::spirv::roll::roll_entry(&mut module, m)?; - crate::spirv::hoist::hoist_uniform_loads(&mut module, p.robustness(), m)?; + crate::spirv::hoist::hoist_uniform_loads(&mut module, m)?; crate::spirv::carry::end_dead_carries(&mut module, m)?; crate::spirv::verify::verify(&module, p, m)?; Ok((plan, module)) diff --git a/crates/metal2vulkan/src/spirv/hoist/mod.rs b/crates/metal2vulkan/src/spirv/hoist/mod.rs index 6f95112f8..8b38f3026 100644 --- a/crates/metal2vulkan/src/spirv/hoist/mod.rs +++ b/crates/metal2vulkan/src/spirv/hoist/mod.rs @@ -30,12 +30,9 @@ //! write too. A loop in a function the entry calls moves loads only where the module makes no //! such write at all. //! - **Safe to read early.** A load in the loop's header, or in a block the header leads to -//! unconditionally and alone ([`entry_run`]), runs whenever the loop is entered, so it moves on -//! every profile. A load elsewhere in the loop runs on some trips or paths only; it -//! moves only where the profile's bounds rest on the device's robust buffer access -//! ([`Robustness::Rba`] or [`Robustness::Rba2`]), under which a read -//! past the bound range reads defined bytes rather than faulting, and a uniform view carries no -//! in-shader check that moving it could pass by. +//! unconditionally and alone ([`entry_run`]), runs whenever the loop is entered, so it moves. A +//! load elsewhere in the loop runs on some trips or paths only, and stays: no buffer robustness +//! is enabled to make a read the loop would not have made safe. //! //! The loops are taken innermost first, so a load leaves every loop it is the same in. The moved //! values are the same values, computed earlier: nothing a dispatch computes changes. @@ -44,7 +41,6 @@ mod tests; use crate::budget::Meter; -use crate::device::profile::Robustness; use crate::error::Error; use crate::spirv::ids::{BlockId, Value}; use crate::spirv::ir::{ @@ -55,18 +51,12 @@ use crate::spirv::ir::{ /// walk, which no measured address reaches). const MAX_DEPTH: u32 = 64; -/// Move the loads of uniform views that are the same on every trip of their loop out of it, under -/// `containment` (the module docs). Returns the moves made: a load counts once for each loop it -/// leaves. -pub fn hoist_uniform_loads( - m: &mut TypedModule, - robustness: Robustness, - meter: &mut Meter, -) -> Result { +/// Move the loads of uniform views that are the same on every trip of their loop out of it (the +/// module docs). Returns the moves made: a load counts once for each loop it leaves. +pub fn hoist_uniform_loads(m: &mut TypedModule, meter: &mut Meter) -> Result { if m.loops.is_empty() { return Ok(0); } - let speculate = matches!(robustness, Robustness::Rba | Robustness::Rba2); let writers = buffer_writers(m, meter)?; let any_writer = writers.iter().any(|&w| w); let blocks = m.blocks.len(); @@ -87,7 +77,7 @@ pub fn hoist_uniform_loads( for b in 0..blocks { scratch.place(m, BlockId::new(u32::try_from(b).unwrap_or(u32::MAX))); } - let r = hoist_loops(m, (speculate, any_writer), &writers, &mut scratch, meter); + let r = hoist_loops(m, any_writer, &writers, &mut scratch, meter); meter.release(bytes); let moved = r?; if moved > 0 { @@ -145,11 +135,10 @@ impl Scratch { } /// Every loop of `m` whose preheader enters it, innermost first, each moved as the module docs -/// say. `(speculate, any_writer)`: whether a load outside the header may move, and whether the -/// module writes buffer memory anywhere. +/// say. `any_writer`: whether the module writes buffer memory anywhere. fn hoist_loops( m: &mut TypedModule, - (speculate, any_writer): (bool, bool), + any_writer: bool, writers: &[bool], s: &mut Scratch, meter: &mut Meter, @@ -180,7 +169,7 @@ fn hoist_loops( if writes_before(m, &lm, writers, s, meter)? { continue; } - moved = moved.saturating_add(hoist_loop(m, &lm, speculate, s, meter)?); + moved = moved.saturating_add(hoist_loop(m, &lm, s, meter)?); } Ok(moved) } @@ -368,7 +357,6 @@ fn writes_before( fn hoist_loop( m: &mut TypedModule, lm: &LoopMeta, - speculate: bool, s: &mut Scratch, meter: &mut Meter, ) -> Result { @@ -389,7 +377,7 @@ fn hoist_loop( continue; }; meter.tick(u32::try_from(block.insts.len()).unwrap_or(u32::MAX))?; - let early = speculate || run.contains(&b); + let early = run.contains(&b); for (i, node) in block.insts.iter().enumerate() { let (Some(v), Inst::Load { .. } | Inst::ImageFetch { .. }) = (node.result, &node.inst) else { diff --git a/crates/metal2vulkan/src/spirv/hoist/tests.rs b/crates/metal2vulkan/src/spirv/hoist/tests.rs index 19d6ebf76..a8383bfbf 100644 --- a/crates/metal2vulkan/src/spirv/hoist/tests.rs +++ b/crates/metal2vulkan/src/spirv/hoist/tests.rs @@ -1,5 +1,5 @@ -//! A uniform view's load that every trip of its loop reads alike leaves the loop where it may be -//! read early, and every other load stays; the kernel computes the same either way. +//! A uniform view's load that every trip of its loop reads alike, at the top of every trip, leaves +//! the loop, and every other load stays; the kernel computes the same either way. use super::*; use crate::budget::Budget; @@ -16,8 +16,6 @@ use crate::spirv::ir::{ }; use crate::spirv::testing::{assert_valid, committed_profiles}; -const ROBUST: Robustness = Robustness::Rba2; - fn meter() -> Meter { Meter::new(&Budget::default()) } @@ -66,13 +64,13 @@ enum Shape { Guarded, /// `p[1]` at the top of every trip, before the trip test. AtTop, - /// `p[i & 7]`: a word that changes from trip to trip. + /// `p[i & 7]` at the top of every trip: a word that changes from trip to trip. ByTrip, - /// [`Shape::Guarded`], with `out[i + 1] = i` stored on every trip. + /// [`Shape::AtTop`], with `out[i + 1] = i` stored on every trip. StoresInLoop, - /// [`Shape::Guarded`], with `out[1] = n` stored before the loop. + /// [`Shape::AtTop`], with `out[1] = n` stored before the loop. StoresBefore, - /// `in[k + 2]` on odd trips, from the storage buffer. + /// `in[k + 2]` at the top of every trip, from the storage buffer. FromStorage, } @@ -133,11 +131,21 @@ fn kernel(shape: Shape) -> TypedModule { let t = f.load(ip, MemAccess::default())?; let a = f.load(ap, MemAccess::default())?; let top = match shape { - Shape::AtTop => { + Shape::AtTop | Shape::StoresInLoop | Shape::StoresBefore => { let one = c32(f, 1); Some(read_word(f, p, one)?) } - _ => None, + Shape::ByTrip => { + let seven = c32(f, 7); + let at = f.binary(BinOp::BitwiseAnd, t, seven)?; + Some(read_word(f, p, at)?) + } + Shape::FromStorage => { + let two = c32(f, 2); + let at = f.binary(BinOp::IAdd, k, two)?; + Some(word(f, input, at)?) + } + Shape::Guarded => None, }; let done = f.binary(BinOp::UGreaterThanEqual, t, n)?; f.if_( @@ -149,29 +157,19 @@ fn kernel(shape: Shape) -> TypedModule { }), None, )?; - let add = match (shape, top) { - (_, Some(w)) => w, - (Shape::ByTrip, _) => { - let seven = c32(f, 7); - let at = f.binary(BinOp::BitwiseAnd, t, seven)?; - read_word(f, p, at)? - } - _ => { + let add = match top { + Some(w) => w, + None => { let one = c32(f, 1); let odd = f.binary(BinOp::BitwiseAnd, t, one)?; let odd = f.binary(BinOp::INotEqual, odd, zero)?; - let storage = shape == Shape::FromStorage; let merged = f.if_( &mut (), odd, Box::new(move |f, _| { let two = c32(f, 2); let at = f.binary(BinOp::IAdd, k, two)?; - let read = match storage { - true => word(f, input, at)?, - false => read_word(f, p, at)?, - }; - Ok(ArmEnd::FallThrough(vec![read])) + Ok(ArmEnd::FallThrough(vec![read_word(f, p, at)?])) }), Some(Box::new(move |f, _| { let three = c32(f, 3); @@ -275,45 +273,25 @@ fn out_word(m: &TypedModule, input: &[u32], p: &[u32]) -> u32 { u32::from_le_bytes([b[0], b[1], b[2], b[3]]) } -/// Hoist `shape`'s kernel under `robustness`; returns the moves, the kernel before and after. -fn hoisted(shape: Shape, robustness: Robustness) -> (u32, TypedModule, TypedModule) { +/// Hoist `shape`'s kernel; returns the moves, the kernel before and after. +fn hoisted(shape: Shape) -> (u32, TypedModule, TypedModule) { let before = kernel(shape); let mut after = before.clone(); - let moved = hoist_uniform_loads(&mut after, robustness, &mut meter()).expect("hoist"); + let moved = hoist_uniform_loads(&mut after, &mut meter()).expect("hoist"); assert_valid(after.clone(), &lavapipe()); (moved, before, after) } -/// The guarded loads at a trip-invariant word leave the loop for its preheader under robust -/// buffer access, and the kernel sums the same words. +/// A guarded load, which runs on some trips only, stays; a load at the top of every trip leaves, +/// and the kernel sums the same words. #[test] -fn a_guarded_uniform_load_at_a_fixed_word_leaves_its_loop() { - let (moved, before, after) = hoisted(Shape::Guarded, ROBUST); - assert_eq!(moved, 2); - let pre = after.loops()[0].preheader; - assert_eq!(uniform_loads(&after), [(pre, 2)]); - assert!(!uniform_loads(&before).iter().any(|&(b, _)| b == pre)); - let p = [10, 20, 30, 40, 50, 60, 70, 80]; - for (n, k) in [(0, 0), (1, 0), (5, 1), (6, 4)] { - let input = [n, k]; - let want = (0..n) - .map(|t| if t & 1 == 1 { p[k as usize + 2] } else { p[3] }) - .sum::(); - assert_eq!(out_word(&before, &input, &p), want, "before, n {n} k {k}"); - assert_eq!(out_word(&after, &input, &p), want, "after, n {n} k {k}"); - } -} - -/// Without robust buffer access, a guarded load stays, and a load at the top of every trip still -/// leaves. -#[test] -fn without_robust_access_only_a_load_every_entry_runs_leaves() { - let (moved, _, after) = hoisted(Shape::Guarded, Robustness::None); +fn only_a_load_every_entry_runs_leaves() { + let (moved, _, after) = hoisted(Shape::Guarded); assert_eq!(moved, 0); assert!(!uniform_loads(&after) .iter() .any(|&(b, _)| b == after.loops()[0].preheader)); - let (moved, before, after) = hoisted(Shape::AtTop, Robustness::None); + let (moved, before, after) = hoisted(Shape::AtTop); assert_eq!(moved, 1); let p = [0, 7, 0, 0, 0, 0, 0, 0]; for n in [0, 1, 3] { @@ -322,12 +300,18 @@ fn without_robust_access_only_a_load_every_entry_runs_leaves() { } } -/// A load whose word changes from trip to trip, a loop that stores to a buffer, a store to a buffer -/// before the loop, and a load of a storage buffer all stay. +/// At the top of every trip, a load whose word changes from trip to trip, a load in a loop that +/// stores to a buffer, one after a store to a buffer before the loop, and a load of a storage +/// buffer all stay. #[test] fn loads_a_trip_or_a_buffer_write_may_change_stay() { - for shape in [Shape::ByTrip, Shape::StoresInLoop, Shape::StoresBefore] { - let (moved, _, after) = hoisted(shape, ROBUST); + for shape in [ + Shape::ByTrip, + Shape::StoresInLoop, + Shape::StoresBefore, + Shape::FromStorage, + ] { + let (moved, _, after) = hoisted(shape); assert_eq!(moved, 0, "{shape:?}"); assert!( !uniform_loads(&after) @@ -336,9 +320,6 @@ fn loads_a_trip_or_a_buffer_write_may_change_stay() { "{shape:?}" ); } - // The even trips' uniform load leaves; the odd trips' storage load stays. - let (moved, _, _) = hoisted(Shape::FromStorage, ROBUST); - assert_eq!(moved, 1); } /// No module holds a `Uniform` resource that is not a `Block` (what `BufferBlock` decorates in diff --git a/crates/metal2vulkan/src/tests/engine_graphics_binder.rs b/crates/metal2vulkan/src/tests/engine_graphics_binder.rs index a1dfed115..924c424ec 100644 --- a/crates/metal2vulkan/src/tests/engine_graphics_binder.rs +++ b/crates/metal2vulkan/src/tests/engine_graphics_binder.rs @@ -33,7 +33,6 @@ use crate::bind::{ TextureFacts, UseTarget, WriteSource, }; use crate::budget::Budget; -use crate::device::profile::Robustness; use crate::device::{Device, DeviceDescription, DevicePolicy}; use crate::error::{BindError, DescriptorError, Error, Feature}; use crate::library::Library; @@ -2207,8 +2206,8 @@ fn spec_value(plan: &BindingPlan, id: u32) -> u8 { /// A read the shader checks whose alpha the function observes takes its out-of-bounds alpha from /// `OutOfBoundsAlpha`, which the plan sets from the bound pixel format: 1 for a format without /// alpha, 0 for one with it, and 0 for an unbound slot or one bound to a placeholder format (the -/// slot reads its neutral, which reads zero). A compute texel buffer declares it where -/// `robustBufferAccess2` is absent, a fragment texture where `robustImageAccess2` is. +/// slot reads its neutral, which reads zero). A compute texel buffer always declares it (the shader +/// checks every texel buffer read), a fragment texture where `robustImageAccess2` is. #[test] fn out_of_bounds_alpha_follows_the_bound_format() { let (Some(ops), Some(io), Some(tail)) = ( @@ -2254,8 +2253,7 @@ fn out_of_bounds_alpha_follows_the_bound_format() { .constants .iter() .find(|c| c.key == SpecKey::OutOfBoundsAlpha(src)); - let checked = f.robustness != Robustness::Rba2; - assert_eq!(c.is_some(), checked, "{stem}"); + assert!(c.is_some(), "{stem}"); if let Some(c) = c { // Vulkan 1.2 requires `R32_SFLOAT` and `R32G32B32A32_SFLOAT` uniform texel buffers. for (pf, want) in [(PixelFormat::RGBA32Float, 0), (PixelFormat::R32Float, 1)] { diff --git a/crates/metal2vulkan/src/tests/engine_texture_interp.rs b/crates/metal2vulkan/src/tests/engine_texture_interp.rs index 0ced7f5fd..31ddebd20 100644 --- a/crates/metal2vulkan/src/tests/engine_texture_interp.rs +++ b/crates/metal2vulkan/src/tests/engine_texture_interp.rs @@ -13,16 +13,16 @@ //! - a depth read and a multisampled integer read. //! //! Containment: the interpreter traps any access outside an image, so a dispatch that overruns -//! its image on a profile without robust image access (for a texel buffer, without -//! `robustBufferAccess2`) completes only because the shader checks its reads and guards its -//! writes, and the in-range texels are exact. `engine_texture_oob` checks the out-of-bounds +//! its image on a profile without robust image access (for a texel buffer, on every profile) +//! completes only because the shader checks its reads and guards its writes, and the in-range +//! texels are exact. `engine_texture_oob` checks the out-of-bounds //! values themselves. //! //! `llvm-as` assembles the fixture; without it the tests skip visibly. use std::collections::BTreeMap; -use crate::device::profile::{DeviceProfile, Robustness}; +use crate::device::profile::DeviceProfile; use crate::device::requirements::VkFeature; use crate::device::{Device, DeviceDescription}; use crate::error::Error; @@ -95,12 +95,6 @@ fn contains_images(p: &DeviceProfile) -> bool { !f.images.robust_image_access } -/// Reads are checked and writes guarded for texel buffers on `p`: `robustBufferAccess` may write -/// past a texel buffer anywhere in its buffer. -fn contains_texel_buffers(p: &DeviceProfile) -> bool { - matches!(p.fields().robustness, Robustness::None | Robustness::Rba) -} - /// The module of `entry` on `p`, or `None` when `p` needs a runtime input for it (a storage /// texture format without a formatless load/store). fn module(bc: &[u8], entry: &str, stem: &str, p: &DeviceProfile) -> Option<(Plan, TypedModule)> { @@ -191,8 +185,8 @@ fn words(bytes: &[u8]) -> Vec { .collect() } -/// `dst[i] = src[i] * 2` over a texel buffer of `N` texels; on a profile that contains texel -/// buffers, a grid of `N + 3` threads checks its reads and drops its writes past the end. +/// `dst[i] = src[i] * 2` over a texel buffer of `N` texels: on every profile a grid of `N + 3` +/// threads checks its reads and drops its writes past the end. #[test] fn texel_buffers_double_their_input() { const N: u32 = 5; @@ -200,7 +194,6 @@ fn texel_buffers_double_their_input() { return; }; let mut ran = 0; - let mut overran = 0; for (stem, p) in profiles() { let Some((plan, m)) = module(&bc, "texel_buffers", &stem, &p) else { continue; @@ -211,14 +204,8 @@ fn texel_buffers_double_their_input() { *t = [fl(x), fl(-x), fl(0.5 + x), fl(1.0)]; } let dst = Image::new(texture(1), [N, 1, 1], 1, 1, 1); - let threads = if contains_texel_buffers(&p) { - overran += 1; - N + 3 - } else { - N - }; let res = resources(&plan, &[]); - let (_, imgs) = run_both(&m, &res, &[src, dst], [threads, 1, 1]) + let (_, imgs) = run_both(&m, &res, &[src, dst], [N + 3, 1, 1]) .unwrap_or_else(|e| panic!("{stem}: {e:?}")); for (i, t) in imgs[1].texels.iter().enumerate() { let x = i as f32; @@ -230,7 +217,7 @@ fn texel_buffers_double_their_input() { } ran += 1; } - assert!(ran > 0 && overran > 0, "ran {ran}, overran {overran}"); + assert!(ran > 0, "ran {ran}"); } /// A texture buffer's reads take the bound swizzle: `texel_buffers` states @@ -316,9 +303,9 @@ fn a_texel_buffer_read_takes_the_bound_swizzle() { /// A swizzled texture buffer's read past its texels reads Metal's out-of-bounds texel swizzled, /// its alpha the bound format's (1 where it has none) wherever the swizzle carries it, also where /// the function reads only the red lane (the MoltenVK lane read 0 there): `ob1_texel_buffer` writes -/// `src.read(idx[t]).x`, so on a profile whose shader checks its texel-buffer reads it states -/// `OutOfBoundsAlpha` for the slot it reads, and under a swizzle taking red from alpha reads each -/// texel's alpha in bounds and the specialized alpha past them. +/// `src.read(idx[t]).x`, so it states `OutOfBoundsAlpha` for the slot it reads (the shader checks +/// every texel-buffer read), and under a swizzle taking red from alpha reads each texel's alpha in +/// bounds and the specialized alpha past them. #[test] fn a_swizzled_texel_buffer_reads_metals_out_of_bounds_alpha_in_any_lane() { use crate::metal::{TextureSwizzle as S, TextureSwizzleChannels as C}; @@ -348,9 +335,6 @@ fn a_swizzled_texel_buffer_reads_metals_out_of_bounds_alpha_in_any_lane() { let red_from_alpha = C::new(S::Alpha, S::Green, S::Blue, S::Alpha); let mut ran = 0; for (stem, p) in profiles() { - if !contains_texel_buffers(&p) { - continue; - } let Some((plan, m)) = module(&bc, "ob1_texel_buffer", &stem, &p) else { continue; }; @@ -402,9 +386,9 @@ fn limited(stem: &str, limit: u32, drop: &[VkFeature]) -> DeviceProfile { /// (`bind::texel_parts`, `LoweringInputs::texel_buffer_parts`), on lavapipe's profile with views /// of 1024 texels: `ob1_texel_buffer` reads texels on both sides of each part's end, each its own, /// and writes texels on both sides of each part's end, each in its own place and nowhere else. -/// Without robustness the shader checks the reads and guards the writes against the whole width: -/// a read past the last texel is Metal's zero and a write there is dropped. The interpreter traps -/// any access outside an image, so no access leaves its part. +/// With or without the device's robustness, the shader checks the reads and guards the writes +/// against the whole width: a read past the last texel is Metal's zero and a write there is +/// dropped. The interpreter traps any access outside an image, so no access leaves its part. #[test] fn a_texture_buffer_s_parts_hold_every_texel() { use crate::lower::select::LowerInputs; @@ -446,8 +430,6 @@ fn a_texture_buffer_s_parts_hold_every_texel() { crate::bind::part_texels(&p.fields().limits), u64::from(PART) ); - let contained = contains_texel_buffers(&p); - assert_eq!(contained, stem.ends_with("unrobust"), "{stem}"); let (plan, m) = typed_module_with(&bc, "ob1_texel_buffer", &p, &inputs) .unwrap_or_else(|e| panic!("{stem}: {e}")); for at in [read, write] { @@ -471,25 +453,15 @@ fn a_texture_buffer_s_parts_hold_every_texel() { part(1, 1, PART, PART, false), part(1, 2, 2 * PART, dst_n - 2 * PART, false), ]; - // Past the last texel only where the shader checks the access; the device's robustness - // answers such an access elsewhere, which the interpreter traps. - let (past, far) = match contained { - true => (src_n, u32::MAX), - false => (1, 2), - }; - let reads = [0, PART - 1, PART, src_n - 1, past, far, 5, PART + 3]; - let (past, far) = match contained { - true => (dst_n, u32::MAX), - false => (7, 8), - }; + let reads = [0, PART - 1, PART, src_n - 1, src_n, u32::MAX, 5, PART + 3]; let writes = [ PART - 1, PART, 2 * PART - 1, 2 * PART, dst_n - 1, - past, - far, + dst_n, + u32::MAX, 3, ]; let idx: Vec = reads diff --git a/crates/metal2vulkan/src/tests/engine_texture_oob.rs b/crates/metal2vulkan/src/tests/engine_texture_oob.rs index 0658d85b9..0e0c970b0 100644 --- a/crates/metal2vulkan/src/tests/engine_texture_oob.rs +++ b/crates/metal2vulkan/src/tests/engine_texture_oob.rs @@ -15,12 +15,13 @@ //! Each kernel reads (or writes) `p[i]` per thread and must compute Metal's result in both //! scheduling orders on every profile class: //! -//! - `robustImageAccess2` (or `robustBufferAccess2` for a texel buffer): the device reads Metal's -//! texel and discards the write; the interpreter's image models that ([`Image::robust`]). -//! - `robustImageAccess` alone: the shader checks its reads (the device's out-of-bounds texel is -//! not Metal's; the interpreter's poisons it) and the device discards writes. -//! - no robustness for the resource (`robustBufferAccess` alone for a texel buffer): the shader -//! checks reads and guards writes; the interpreter traps any access outside the image. +//! - `robustImageAccess2`, for an image: the device reads Metal's texel and discards the write; +//! the interpreter's image models that ([`Image::robust`]). +//! - `robustImageAccess` alone, for an image: the shader checks its reads (the device's +//! out-of-bounds texel is not Metal's; the interpreter's poisons it) and the device discards +//! writes. +//! - no image robustness, and every texel buffer: the shader checks reads and guards writes; the +//! interpreter traps any access outside the image. //! //! Where the shader checks a read whose alpha it observes, the alpha comes from the //! `OutOfBoundsAlpha` specialization, run with both values. @@ -32,7 +33,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use crate::bind::{BindState, Dispatch, ResourceClass, TextureFacts, UsedResource, WriteSource}; use crate::budget::Budget; -use crate::device::profile::{DeviceProfile, Robustness}; +use crate::device::profile::DeviceProfile; use crate::device::requirements::VkFeature; use crate::device::{Device, DeviceDescription, DevicePolicy}; use crate::error::{Capability, Error, Feature, LowerFamily, Unsupported}; @@ -1167,12 +1168,14 @@ enum Class { fn class(p: &DeviceProfile, buffer: bool) -> Class { let f = p.fields(); - match (buffer, f.robustness) { - (true, Robustness::Rba2) => Class::Device, - (true, _) => Class::Shader, - (false, _) if f.images.robust_image_access2 => Class::Device, - (false, _) if f.images.robust_image_access => Class::ShaderReads, - (false, _) => Class::Shader, + if buffer { + Class::Shader + } else if f.images.robust_image_access2 { + Class::Device + } else if f.images.robust_image_access { + Class::ShaderReads + } else { + Class::Shader } } @@ -1772,8 +1775,8 @@ fn sample_storage_depth_and_half_reads_out_of_bounds_are_zero() { } } -/// A texel buffer read is out of bounds past its last texel, also where `robustBufferAccess` -/// (whose out-of-bounds texel may be any value of the buffer) is the only robustness. +/// A texel buffer read is out of bounds past its last texel: the shader checks it on every +/// profile. #[test] fn texel_buffer_reads_out_of_bounds_are_zero() { let Some(bc) = assemble() else { @@ -1792,13 +1795,7 @@ fn texel_buffer_reads_out_of_bounds_are_zero() { ], }; let ran = case.check(&bc); - assert_eq!(ran, [Class::Device, Class::Shader]); - // `robustBufferAccess` alone is the shader's check. - let vk12 = profiles() - .into_iter() - .find(|(s, _)| s == "runtime-floor") - .expect("runtime-floor"); - assert_eq!(class(&vk12.1, true), Class::Shader); + assert_eq!(ran, [Class::Shader]); } /// Run a write kernel over `rows` on every profile: the texture's texels other than `written` @@ -1864,8 +1861,7 @@ fn cube_array_writes_out_of_bounds_are_dropped() { assert!(ran.contains(&Class::Device), "{ran:?}"); } -/// A texel buffer write past its last texel writes nothing, also where `robustBufferAccess` -/// (which may write the value anywhere in the buffer) is the only robustness. +/// A texel buffer write past its last texel writes nothing: the shader guards it on every profile. #[test] fn texel_buffer_writes_out_of_bounds_are_dropped() { let Some(bc) = assemble() else { @@ -1880,7 +1876,7 @@ fn texel_buffer_writes_out_of_bounds_are_dropped() { &rows, (0, 0, 0, [4, 0, 0]), ); - assert_eq!(ran, [Class::Device, Class::Shader]); + assert_eq!(ran, [Class::Shader]); } /// A thread that writes a texel out of bounds and then reads that location reads Metal's zero @@ -1962,11 +1958,7 @@ fn a_read_where_its_thread_wrote_out_of_bounds_is_zero() { } ran.sort(); ran.dedup(); - let want: &[Class] = if buffer { - &[Class::Device, Class::Shader] - } else { - &ALL - }; + let want: &[Class] = if buffer { &[Class::Shader] } else { &ALL }; assert_eq!(ran, want, "{entry}"); } } diff --git a/crates/metal2vulkan/src/tests/engine_texture_ulong.rs b/crates/metal2vulkan/src/tests/engine_texture_ulong.rs index 2ac99018d..66463b073 100644 --- a/crates/metal2vulkan/src/tests/engine_texture_ulong.rs +++ b/crates/metal2vulkan/src/tests/engine_texture_ulong.rs @@ -30,7 +30,7 @@ use std::collections::BTreeMap; use crate::bind::{BindState, BoundBuffer, BoundTexture, StageTable, TextureFacts}; use crate::budget::Budget; -use crate::device::profile::{DeviceProfile, Robustness}; +use crate::device::profile::DeviceProfile; use crate::device::requirements::VkFeature; use crate::device::{Device, DeviceDescription, DevicePolicy}; use crate::error::{Error, Feature, Needs, Unsupported}; @@ -112,17 +112,19 @@ fn profiles() -> Vec<(String, DeviceProfile)> { } /// What the interpreter's image does outside itself on `p`: the device's texel for an `RG32` view, -/// `(0, 0, 0, 1)`, and its discarded write where the device's robustness covers the access; a -/// poisoned texel where the device discards writes but the shader checks reads; a trap where the -/// shader contains both. +/// `(0, 0, 0, 1)`, and its discarded write where the device's image robustness covers the access; +/// a poisoned texel where the device discards writes but the shader checks reads; a trap where the +/// shader contains both, as it does for every texel buffer (`buffer`). fn robust(p: &DeviceProfile, buffer: bool) -> Option<[u32; 4]> { let f = p.fields(); - match (buffer, f.robustness) { - (true, Robustness::Rba2) => Some([0, 0, 0, 1]), - (true, _) => None, - (false, _) if f.images.robust_image_access2 => Some([0, 0, 0, 1]), - (false, _) if f.images.robust_image_access => Some([0xDEAD_BEEF; 4]), - (false, _) => None, + if buffer { + None + } else if f.images.robust_image_access2 { + Some([0, 0, 0, 1]) + } else if f.images.robust_image_access { + Some([0xDEAD_BEEF; 4]) + } else { + None } } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index b268aa034..5d76fa580 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -865,7 +865,6 @@ enum metal2vulkan::device::HandleDomain #[cfg_attr(feature = "serde", derive(ser enum metal2vulkan::device::Independence #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum Independence enum metal2vulkan::device::PointerDomain #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum PointerDomain enum metal2vulkan::device::ResolveMode #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum ResolveMode -enum metal2vulkan::device::Robustness #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum Robustness enum metal2vulkan::device::SimdClass #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum SimdClass enum metal2vulkan::device::SpirvExtension #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum SpirvExtension enum metal2vulkan::device::StageCreateFlag #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum StageCreateFlag @@ -7035,7 +7034,6 @@ method metal2vulkan::device::DeviceDescription::required_enables pub fn required method metal2vulkan::device::DeviceDescription::with_enabled pub fn with_enabled(mut self, enabled: &EnableSet) -> Result method metal2vulkan::device::DeviceProfile::addressed_needs pub fn addressed_needs(&self) -> Vec method metal2vulkan::device::DeviceProfile::check pub fn check(&self, req: &Requirements) -> Result<(), Capability> -method metal2vulkan::device::DeviceProfile::checks_buffers_in_shader pub fn checks_buffers_in_shader(&self) -> bool method metal2vulkan::device::DeviceProfile::compile_entry pub fn compile_entry(&self, d: &EntryDescriptor<'_>, inputs: &LoweringInputs, budget: &Budget) -> (Result, CompileReport) method metal2vulkan::device::DeviceProfile::descriptors pub fn descriptors(&self) -> &DescriptorCaps method metal2vulkan::device::DeviceProfile::device_drops_texel_writes pub fn device_drops_texel_writes(&self, texel_buffer: bool) -> bool @@ -7049,7 +7047,6 @@ method metal2vulkan::device::DeviceProfile::interpolation_function_needs pub fn method metal2vulkan::device::DeviceProfile::limits pub fn limits(&self) -> &Limits method metal2vulkan::device::DeviceProfile::link_standalone pub fn link_standalone(&self, f: &CompiledFunction) -> Result method metal2vulkan::device::DeviceProfile::plan_entry pub fn plan_entry(&self, d: &EntryDescriptor<'_>, inputs: &LoweringInputs, budget: &Budget) -> (Result, CompileReport) -method metal2vulkan::device::DeviceProfile::robustness pub fn robustness(&self) -> Robustness method metal2vulkan::device::DeviceProfile::simd_tier pub fn simd_tier(&self, class: &SimdClass, stage: Stage) -> Result method metal2vulkan::device::DeviceProfile::specialized_entry pub fn specialized_entry(&self, d: &EntryDescriptor<'_>, inputs: &LoweringInputs, budget: &Budget) -> Result method metal2vulkan::device::DeviceProfile::spirv_validation pub fn spirv_validation(&self) -> SpirvValidation @@ -9897,9 +9894,6 @@ variant metal2vulkan::device::ResolveMode::Average Average variant metal2vulkan::device::ResolveMode::Max Max variant metal2vulkan::device::ResolveMode::Min Min variant metal2vulkan::device::ResolveMode::SampleZero SampleZero -variant metal2vulkan::device::Robustness::None None -variant metal2vulkan::device::Robustness::Rba Rba -variant metal2vulkan::device::Robustness::Rba2 Rba2 variant metal2vulkan::device::SimdClass::CrossLane CrossLane(OpBits) variant metal2vulkan::device::SimdClass::LaneArithmetic LaneArithmetic variant metal2vulkan::device::SimdClass::Matrix Matrix diff --git a/crates/metal2vulkan/tests/api_surface.rs b/crates/metal2vulkan/tests/api_surface.rs index 87604e277..329da2a80 100644 --- a/crates/metal2vulkan/tests/api_surface.rs +++ b/crates/metal2vulkan/tests/api_surface.rs @@ -238,7 +238,6 @@ surface! { enum PointerDomain N; struct DescriptorCaps N; enum FunctionStorage N; - enum Robustness N; enum SimdClass N; struct StageSubgroup N; struct SubgroupModel N; diff --git a/docs/API.md b/docs/API.md index 0642cce9e..dbe06c012 100644 --- a/docs/API.md +++ b/docs/API.md @@ -100,9 +100,8 @@ compile does. `DevicePolicy::default()` is the one constructor: the runtime comp and so do the command line, the compile worker and every validation tool. It holds: - **Bounds on a buffer-slot access at a run-time offset.** Such an access stays inside the range - the binder supplied: where the device enables `robustBufferAccess`, buffer accesses and vertex - input are left to it, and elsewhere the shader checks them. (MoltenVK advertises the feature - without implementing it; there such accesses are not bounded, as on native Metal.) + the binder supplied: the shader checks it on every device, whatever buffer robustness the device + enables. - **The device's arithmetic.** The device's own maths library, divisions, fused multiply-adds, `float` denormals, rounding order of `dot`/`mix`/`fast::sqrt`, the grouping and fusion of fast-math sums and products (each operation in the AIR's order, its own fast-math flags its @@ -307,8 +306,7 @@ println!(" Metal properties: {:?}", device.metal_properties()); - `profile().spirv_validation()`: the `spirv-val` environments and relaxations every module for the device is valid under. The command line runs exactly these. - The profile's facts: `enabled()`, `limits()`, `images()`, `fragment()`, `descriptors()`, - its `subgroups()` model and `simd_tier(...)`, the buffer robustness that bounds a buffer-slot - access (`robustness()`, `checks_buffers_in_shader()`), and the Function + its `subgroups()` model and `simd_tier(...)`, and the Function storage a thread holds (`function_storage()`: `FunctionStorage::Measured` bytes for a measured device, or `FunctionStorage::Assumed` with the 16 KiB floor, past which a vertex or fragment function runs with `FunctionStorageAssumed` up to 192 KiB and any other stage is refused). @@ -797,13 +795,11 @@ A `RenderPipeline` holds: - `stages`: vertex, then fragment when rasterization is enabled; - `layout`: one pipeline layout for every stage; -- `vertex_input`: Vulkan bindings and attributes. An attribute Vulkan cannot fetch as described is - pulled in the shader instead, and so is every attribute on a device without - `robustBufferAccess`. A `FloatRGB9E5` attribute is pulled on every - device: no device must fetch the shared-exponent format as vertex input, and its decode is - exact, so the shader's is the answer a conformant fetch gives. Under the identity domains - nothing is pulled, as the pulled fetch reads through a - descriptor: every attribute is fetched in fixed function, with or without buffer robustness +- `vertex_input`: Vulkan bindings and attributes. Outside the identity domains every attribute is + pulled in the shader through a checked descriptor view: nothing bounds fixed-function input + without buffer robustness (VUID-vkCmdDraw-None-02721), which the translator never leaves an + access to. Under the identity domains nothing is pulled, as the pulled fetch reads through a + descriptor: every attribute is fetched in fixed function (a fetch outside its buffer reads what the device gives), an unnormalized signed-integer format into a variable declared `int`, the constant step at vertex rate on a binding of stride 0 (no divisor); an attribute fixed-function input cannot take is refused,