Skip to content

Commit

Permalink
Prevent using multiple push constant variables in one entry point.
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyDev committed Sep 17, 2023
1 parent df8107b commit 38a391d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub enum EntryPointError {
ForbiddenStageOperations,
#[error("Global variable {0:?} is used incorrectly as {1:?}")]
InvalidGlobalUsage(Handle<crate::GlobalVariable>, GlobalUse),
#[error("More than 1 push constant variable is used")]
MoreThanOnePushConstantUsed(Handle<crate::GlobalVariable>),
#[error("Bindings for {0:?} conflict with other resource")]
BindingCollision(Handle<crate::GlobalVariable>),
#[error("Argument {0} varying error")]
Expand Down Expand Up @@ -701,6 +703,28 @@ impl super::Validator {
bg.clear();
}

#[cfg(feature = "validate")]
{
let mut used_push_constants = module
.global_variables
.iter()
.filter(|&(_, var)| var.space == crate::AddressSpace::PushConstant)
.map(|(handle, _)| handle)
.filter(|&handle| !info[handle].is_empty());
// Check if there is one push constant. Some iterators can restart iteration after
// `next` returns None, so don't continue if the iterator returns None.
if used_push_constants.next().is_some() {
// Check if there is a second push constant.
match used_push_constants.next() {
None => {}
Some(handle) => {
return Err(EntryPointError::MoreThanOnePushConstantUsed(handle)
.with_span_handle(handle, &module.global_variables))
}
}
}
}

#[cfg(feature = "validate")]
for (var_handle, var) in module.global_variables.iter() {
let usage = info[var_handle];
Expand Down

0 comments on commit 38a391d

Please sign in to comment.