Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ValidationFlags::BINDINGS #2156

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
38 changes: 30 additions & 8 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::Type>,
type_info: &'a Vec<super::r#type::TypeInfo>,
location_mask: &'a mut BitSet,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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(())
}
Expand Down Expand Up @@ -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) {
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
return Err(GlobalVariableError::InvalidBinding);
}
}

Ok(())
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
return Err(EntryPointError::BindingCollision(var_handle)
.with_span_handle(var_handle, &module.global_variables));
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ bitflags::bitflags! {
/// Constants.
#[cfg(feature = "validate")]
const CONSTANTS = 0x10;
/// Group, binding, and location attributes.
#[cfg(feature = "validate")]
const BINDINGS = 0x20;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/out/analysis/collatz.info.ron
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
functions: [
(
flags: (
bits: 31,
bits: 63,
),
available_stages: (
bits: 7,
Expand Down Expand Up @@ -346,7 +346,7 @@
entry_points: [
(
flags: (
bits: 31,
bits: 63,
),
available_stages: (
bits: 7,
Expand Down
6 changes: 3 additions & 3 deletions tests/out/analysis/shadow.info.ron
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
functions: [
(
flags: (
bits: 31,
bits: 63,
),
available_stages: (
bits: 7,
Expand Down Expand Up @@ -1068,7 +1068,7 @@
),
(
flags: (
bits: 31,
bits: 63,
),
available_stages: (
bits: 7,
Expand Down Expand Up @@ -2871,7 +2871,7 @@
entry_points: [
(
flags: (
bits: 31,
bits: 63,
),
available_stages: (
bits: 7,
Expand Down