From 168533bc2f40aef2400e311e9091eb551a5e8a57 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sun, 17 Sep 2023 10:32:37 -0700 Subject: [PATCH] Prevent using multiple push constant variables in one entry point. --- src/valid/interface.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/valid/interface.rs b/src/valid/interface.rs index 2416e89216..e848b80058 100644 --- a/src/valid/interface.rs +++ b/src/valid/interface.rs @@ -90,6 +90,8 @@ pub enum EntryPointError { ForbiddenStageOperations, #[error("Global variable {0:?} is used incorrectly as {1:?}")] InvalidGlobalUsage(Handle, GlobalUse), + #[error("More than 1 push constant variable is used")] + MoreThanOnePushConstantUsed, #[error("Bindings for {0:?} conflict with other resource")] BindingCollision(Handle), #[error("Argument {0} varying error")] @@ -701,6 +703,21 @@ 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. + if let Some(handle) = used_push_constants.skip(1).next() { + 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];