From a4e8a7bd99cde4988cb3ab55ec09730359e789e7 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 6 Dec 2022 22:15:57 -0800 Subject: [PATCH] Add ValidationFlags::BINDINGS --- src/lib.rs | 1 + src/valid/interface.rs | 38 +++++++++++++++++++++++------ src/valid/mod.rs | 3 +++ tests/out/analysis/collatz.info.ron | 4 +-- tests/out/analysis/shadow.info.ron | 6 ++--- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e122d1224c..57841a8785 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,6 +192,7 @@ tree. clippy::unneeded_field_pattern, clippy::match_like_matches_macro, clippy::if_same_then_else, + clippy::collapsible_if, clippy::derive_partial_eq_without_eq )] #![warn( diff --git a/src/valid/interface.rs b/src/valid/interface.rs index 072550e9b0..85610b068e 100644 --- a/src/valid/interface.rs +++ b/src/valid/interface.rs @@ -102,6 +102,7 @@ fn storage_usage(access: crate::StorageAccess) -> GlobalUse { struct VaryingContext<'a> { stage: crate::ShaderStage, output: bool, + flags: super::ValidationFlags, types: &'a UniqueArena, type_info: &'a Vec, location_mask: &'a mut BitSet, @@ -284,7 +285,10 @@ impl VaryingContext<'_> { return Err(VaryingError::NotIOShareableType(ty)); } if !self.location_mask.insert(location as usize) { - return Err(VaryingError::BindingCollision { location }); + #[cfg(feature = "validate")] + if self.flags.contains(super::ValidationFlags::BINDINGS) { + return Err(VaryingError::BindingCollision { location }); + } } let needs_interpolation = match self.stage { @@ -335,9 +339,15 @@ impl VaryingContext<'_> { for (index, member) in members.iter().enumerate() { let span_context = self.types.get_span_context(ty); match member.binding { - None => { - return Err(VaryingError::MemberMissingBinding(index as u32) - .with_span_context(span_context)) + None => + { + #[cfg(feature = "validate")] + if self.flags.contains(super::ValidationFlags::BINDINGS) { + return Err(VaryingError::MemberMissingBinding( + index as u32, + ) + .with_span_context(span_context)); + } } // TODO: shouldn't this be validate? Some(ref binding) => self @@ -346,7 +356,13 @@ impl VaryingContext<'_> { } } } - _ => return Err(VaryingError::MissingBinding.with_span()), + _ => + { + #[cfg(feature = "validate")] + if self.flags.contains(super::ValidationFlags::BINDINGS) { + return Err(VaryingError::MissingBinding.with_span()); + } + } } Ok(()) } @@ -441,7 +457,9 @@ impl super::Validator { } if is_resource != var.binding.is_some() { - return Err(GlobalVariableError::InvalidBinding); + if self.flags.contains(super::ValidationFlags::BINDINGS) { + return Err(GlobalVariableError::InvalidBinding); + } } Ok(()) @@ -497,6 +515,7 @@ impl super::Validator { let mut ctx = VaryingContext { stage: ep.stage, output: false, + flags: self.flags, types: &module.types, type_info: &self.types, location_mask: &mut self.location_mask, @@ -513,6 +532,7 @@ impl super::Validator { let mut ctx = VaryingContext { stage: ep.stage, output: true, + flags: self.flags, types: &module.types, type_info: &self.types, location_mask: &mut self.location_mask, @@ -571,8 +591,10 @@ impl super::Validator { self.bind_group_masks.push(BitSet::new()); } if !self.bind_group_masks[bind.group as usize].insert(bind.binding as usize) { - return Err(EntryPointError::BindingCollision(var_handle) - .with_span_handle(var_handle, &module.global_variables)); + if self.flags.contains(super::ValidationFlags::BINDINGS) { + return Err(EntryPointError::BindingCollision(var_handle) + .with_span_handle(var_handle, &module.global_variables)); + } } } } diff --git a/src/valid/mod.rs b/src/valid/mod.rs index be27316299..c8f92bcbc4 100644 --- a/src/valid/mod.rs +++ b/src/valid/mod.rs @@ -66,6 +66,9 @@ bitflags::bitflags! { /// Constants. #[cfg(feature = "validate")] const CONSTANTS = 0x10; + /// Group, binding, and location attributes. + #[cfg(feature = "validate")] + const BINDINGS = 0x20; } } diff --git a/tests/out/analysis/collatz.info.ron b/tests/out/analysis/collatz.info.ron index cba89d5768..3e1805c6f9 100644 --- a/tests/out/analysis/collatz.info.ron +++ b/tests/out/analysis/collatz.info.ron @@ -2,7 +2,7 @@ functions: [ ( flags: ( - bits: 31, + bits: 63, ), available_stages: ( bits: 7, @@ -346,7 +346,7 @@ entry_points: [ ( flags: ( - bits: 31, + bits: 63, ), available_stages: ( bits: 7, diff --git a/tests/out/analysis/shadow.info.ron b/tests/out/analysis/shadow.info.ron index 9f721bce91..01a3c96554 100644 --- a/tests/out/analysis/shadow.info.ron +++ b/tests/out/analysis/shadow.info.ron @@ -2,7 +2,7 @@ functions: [ ( flags: ( - bits: 31, + bits: 63, ), available_stages: ( bits: 7, @@ -1068,7 +1068,7 @@ ), ( flags: ( - bits: 31, + bits: 63, ), available_stages: ( bits: 7, @@ -2871,7 +2871,7 @@ entry_points: [ ( flags: ( - bits: 31, + bits: 63, ), available_stages: ( bits: 7,