From eaf4f429956927eb78758fa964087f3c0f2f9480 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/valid/interface.rs b/src/valid/interface.rs index 2416e89216..2444d29d90 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,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) { + 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];