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

Prevent using multiple push constant variables in one entry point. #2484

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
19 changes: 19 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,
#[error("Bindings for {0:?} conflict with other resource")]
BindingCollision(Handle<crate::GlobalVariable>),
#[error("Argument {0} varying error")]
Expand Down Expand Up @@ -701,6 +703,23 @@ impl super::Validator {
bg.clear();
}

#[cfg(feature = "validate")]
{
let 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 more than one push constant, and error if so.
// Use a loop for when returning multiple errors is supported.
#[allow(clippy::never_loop)]
for handle in used_push_constants.skip(1) {
andriyDev marked this conversation as resolved.
Show resolved Hide resolved
return Err(EntryPointError::MoreThanOnePushConstantUsed
.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