diff --git a/crates/metal2vulkan-validation/src/candidate/engine.rs b/crates/metal2vulkan-validation/src/candidate/engine.rs index ffa379ed7..6a941a951 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine.rs @@ -906,6 +906,9 @@ pub(crate) fn draw_out_of_bounds_run( handle_table: pipeline.interface.needs_handle_translation, policy: *device.policy(), strategies: &graphics::vertex_module(pipeline)?.strategies, + // A render stage reaches its buffers at their addresses or through views checked in + // the shader. + robust_views: false, }, &case.out_of_bounds, ) diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime_bounds.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime_bounds.rs index 5b2e02286..29bc5f70d 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime_bounds.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime_bounds.rs @@ -80,6 +80,8 @@ pub(super) fn contained( handle_table: lowered.resolves_handles(), policy: *translator.policy(), strategies: lowered.strategies(), + robust_views: (lowered.requirements().features) + .contains(&metal2vulkan::device::VkFeature::PipelineRobustness), }; let run = out_of_bounds_run(translator.profile(), &module, &case.out_of_bounds); runs.push((variant, run)); diff --git a/crates/metal2vulkan-validation/src/coverage/tier_table.rs b/crates/metal2vulkan-validation/src/coverage/tier_table.rs index 9c2d33afe..37d8560a6 100644 --- a/crates/metal2vulkan-validation/src/coverage/tier_table.rs +++ b/crates/metal2vulkan-validation/src/coverage/tier_table.rs @@ -266,6 +266,8 @@ pub fn compile_module( // Every committed profile's device takes the resident-table domains (`committed_profiles`). policy: DevicePolicy::RESIDENT_TABLES, strategies: function.strategies(), + robust_views: (function.requirements().features) + .contains(&metal2vulkan::device::VkFeature::PipelineRobustness), }; let out_of_bounds = inputs .out_of_bounds 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 35e2db7eb..f08a439d0 100644 --- a/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs +++ b/crates/metal2vulkan-validation/src/executor_contract/out_of_bounds.rs @@ -9,7 +9,9 @@ //! 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, //! 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 +//! every leg, except that a kernel whose buffer arguments are bound as storage buffers of set 0 +//! (`ModuleFacts::robust_views`) leaves its views' loads and stores to its pipeline's +//! `robustBufferAccess2` and checks only their atomics in the shader; 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 @@ -340,6 +342,11 @@ pub struct ModuleFacts<'a> { /// (`Device::policy`). pub policy: DevicePolicy, pub strategies: &'a StrategyCensus, + /// The module's storage views are contained by its pipeline's robust buffer access 2, not by + /// a check in the shader: a kernel whose buffer arguments are bound as storage buffers of set + /// 0, which requires the pipeline-robustness feature (`VkFeature::PipelineRobustness` in its + /// requirements). Its atomics keep their check in the shader. + pub robust_views: bool, } impl ModuleFacts<'_> { @@ -452,7 +459,10 @@ pub fn containment( BufferForm::Descriptor => made( ContainmentForm::StorageBuffer, Medium::DescriptorView, - Check::Shader, + match module.robust_views { + true => Check::Robust2, + false => Check::Shader, + }, written, ), _ => unknown(), 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 d736568ae..f924723f9 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 @@ -778,6 +778,7 @@ fn thread_memory_is_contained_by_the_typed_arrays_check_only() { handle_table: true, policy: DevicePolicy::RESIDENT_TABLES, strategies: &strategies, + robust_views: false, }; let target = OutOfBoundsTarget { resource, @@ -894,6 +895,7 @@ fn the_identity_domains_leave_a_loaded_pointer_unchecked_and_mask_a_resource_id( handle_table: false, policy, strategies: &strategies, + robust_views: false, }; let target = |resource, form| OutOfBoundsTarget { resource, @@ -990,6 +992,7 @@ fn a_draws_targets_are_contained_by_their_fetch() { handle_table: false, policy: DevicePolicy::RESIDENT_TABLES, strategies, + robust_views: false, }; let target = OutOfBoundsTarget { resource, @@ -1098,3 +1101,76 @@ fn a_draws_targets_are_contained_by_their_fetch() { ReadRule::ResidentTexels ); } + +/// A kernel's storage view is contained by its pipeline's robust buffer access 2 where the module +/// binds its buffers as storage buffers of set 0 (`ModuleFacts::robust_views`), and by a check in +/// the shader where it does not; an atomic on the view keeps its check in the shader either way. +/// The read rule is zero in each. +#[test] +fn a_bound_kernel_s_storage_view_is_contained_by_robust_buffer_access_2() { + use metal2vulkan::pipeline::StrategyCensus; + let profiles = crate::coverage::tier_table::committed_profiles().unwrap(); + let profile = &profiles + .iter() + .find(|entry| entry.tier.stem == "intel-irisxe-anv") + .unwrap() + .profile; + let slots = BTreeMap::from([( + SlotRef { + stage: SymStage::Kernel, + class: SlotClass::Buffer, + index: 1, + }, + // A written buffer slot reached through its storage view (the interface has no + // constructor outside the product). + serde_json::from_value::(serde_json::json!({"Buffer": { + "access": {"read": true, "write": true}, + "window": "Whole", + "form": "Descriptor", + "kind": "Buffer", + }})) + .unwrap(), + )]); + let strategies = StrategyCensus::default(); + let attributes = BTreeMap::new(); + let mut identity = DevicePolicy::default(); + identity.pointer_domain = PointerDomain::Identity; + identity.handle_domain = HandleDomain::Identity; + let contained = |robust_views, form| { + let module = ModuleFacts { + stage: SymStage::Kernel, + slots: &slots, + attributes: &attributes, + resident_roots: false, + handle_table: false, + policy: identity, + strategies: &strategies, + robust_views, + }; + let target = OutOfBoundsTarget { + resource: OutOfBoundsResource::Buffer { binding: 1 }, + form, + reach_before: 0, + reach_after: 256, + }; + containment(&target, &module, profile).unwrap() + }; + for (robust_views, form, check) in [ + (true, ContainmentForm::StorageBuffer, Check::Robust2), + (false, ContainmentForm::StorageBuffer, Check::Shader), + (true, ContainmentForm::BufferAtomic, Check::Shader), + (false, ContainmentForm::BufferAtomic, Check::Shader), + ] { + let what = format!("{form:?} with robust views {robust_views}"); + let c = contained(robust_views, form); + assert_eq!(c.form, form, "{what}"); + assert_eq!(c.mechanism.medium, Medium::DescriptorView, "{what}"); + assert_eq!(c.mechanism.check, check, "{what}"); + assert!(c.written, "{what}"); + assert_eq!( + read_rule(c.form, c.mechanism, true), + ReadRule::Zero, + "{what}" + ); + } +} diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 15ecb250d..f3b44a47c 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -3203,6 +3203,14 @@ fn lower_bounded( .properties .insert(crate::device::requirements::VkProperty::DeviceSampling); } + // A kernel that reaches its buffers through storage views of set 0 is contained by its + // pipeline's robust buffer access 2 (`RuntimeFact::RobustStorageBuffers`), which a pipeline + // states only where the device enables the pipeline-robustness feature. + if plan.families.access.robust_views { + requirements + .features + .insert(crate::device::requirements::VkFeature::PipelineRobustness); + } // The set-1 heap's binding flags need their features beside the module's. requirements .features diff --git a/crates/metal2vulkan/src/tests/engine_bound_buffers.rs b/crates/metal2vulkan/src/tests/engine_bound_buffers.rs index 396c92476..c093da1e7 100644 --- a/crates/metal2vulkan/src/tests/engine_bound_buffers.rs +++ b/crates/metal2vulkan/src/tests/engine_bound_buffers.rs @@ -9,8 +9,8 @@ //! no slot pushes its address or its bounds (`PushField::SlotGuestBase`, //! `PushField::SlotBounds`), and no load reads the zero range (`PushField::ZeroAddress`). The //! module states `RuntimeFact::RobustStorageBuffers` and each slot's alignment -//! (`RuntimeFact::AddressAlignment`: 4 for a `uint` buffer, 16 for a `float4` one), and passes -//! L3. +//! (`RuntimeFact::AddressAlignment`: 4 for a `uint` buffer, 16 for a `float4` one), requires the +//! pipeline-robustness feature (`VkFeature::PipelineRobustness`), and passes L3. //! - A slot the dispatch binds at a multiple of 4 below its argument's alignment //! (`LoweringInputs::word_bound_buffers`) keeps its device address, held to 4: a view's `uvec4` //! units take the bind offset to be a multiple of the argument's alignment. @@ -21,6 +21,7 @@ use std::collections::BTreeSet; use super::engine_word_phases::{bound_identity_profiles, device_alignments}; +use crate::device::requirements::VkFeature; use crate::lower::select::LowerInputs; use crate::pipeline::facts::RuntimeFact; use crate::pipeline::sym::{PushField, ResourceKind, SlotClass, SlotRef, Stage}; @@ -113,6 +114,11 @@ fn a_kernel_reaches_its_buffers_through_set_0_views_at_their_bind_offsets() { "{what}: {:?}", a.facts ); + assert!( + (a.requirements.features).contains(&VkFeature::PipelineRobustness), + "{what}: {:?}", + a.requirements.features + ); let stated: Vec = (a.facts.iter()) .filter_map(|f| match f { RuntimeFact::AddressAlignment { align, .. } => Some(*align), @@ -147,5 +153,10 @@ fn a_word_bound_slot_keeps_its_device_address() { "{what}: {:?}", a.facts ); + assert!( + !(a.requirements.features).contains(&VkFeature::PipelineRobustness), + "{what}: {:?}", + a.requirements.features + ); } }