From 4ede83929c53dba9570f465f159462934b54aee0 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:35:18 +0100 Subject: [PATCH] [valid] make sure overrides are not present after evaluation --- naga/src/back/pipeline_constants.rs | 2 +- naga/src/valid/expression.rs | 2 +- naga/src/valid/mod.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/naga/src/back/pipeline_constants.rs b/naga/src/back/pipeline_constants.rs index a301b4ff3..9679aaecb 100644 --- a/naga/src/back/pipeline_constants.rs +++ b/naga/src/back/pipeline_constants.rs @@ -111,7 +111,7 @@ pub(super) fn process_overrides<'a>( } let mut validator = Validator::new(ValidationFlags::all(), Capabilities::all()); - let module_info = validator.validate(&module)?; + let module_info = validator.validate_no_overrides(&module)?; Ok((Cow::Owned(module), Cow::Owned(module_info))) } diff --git a/naga/src/valid/expression.rs b/naga/src/valid/expression.rs index 055ca6dfd..bf46fd326 100644 --- a/naga/src/valid/expression.rs +++ b/naga/src/valid/expression.rs @@ -213,7 +213,7 @@ impl super::Validator { crate::TypeInner::Scalar { .. } => {} _ => return Err(super::ConstExpressionError::InvalidSplatType(value)), }, - _ if global_expr_kind.is_const(handle) => { + _ if global_expr_kind.is_const(handle) || !self.allow_overrides => { return Err(super::ConstExpressionError::NonFullyEvaluatedConst) } // the constant evaluator will report errors about override-expressions diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index b9730c1f3..f34c0f6f1 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -175,6 +175,7 @@ pub struct Validator { valid_expression_list: Vec>, valid_expression_set: BitSet, override_ids: FastHashSet, + allow_overrides: bool, } #[derive(Clone, Debug, thiserror::Error)] @@ -203,6 +204,8 @@ pub enum OverrideError { NonConstructibleType, #[error("The type is not a scalar")] TypeNotScalar, + #[error("Override declarations are not allowed")] + NotAllowed, } #[derive(Clone, Debug, thiserror::Error)] @@ -322,6 +325,7 @@ impl Validator { valid_expression_list: Vec::new(), valid_expression_set: BitSet::new(), override_ids: FastHashSet::default(), + allow_overrides: true, } } @@ -370,6 +374,10 @@ impl Validator { gctx: crate::proc::GlobalCtx, mod_info: &ModuleInfo, ) -> Result<(), OverrideError> { + if !self.allow_overrides { + return Err(OverrideError::NotAllowed); + } + let o = &gctx.overrides[handle]; if o.name.is_none() && o.id.is_none() { @@ -414,6 +422,25 @@ impl Validator { pub fn validate( &mut self, module: &crate::Module, + ) -> Result> { + self.allow_overrides = true; + self.validate_impl(module) + } + + /// Check the given module to be valid. + /// + /// With the additional restriction that overrides are not present. + pub fn validate_no_overrides( + &mut self, + module: &crate::Module, + ) -> Result> { + self.allow_overrides = false; + self.validate_impl(module) + } + + fn validate_impl( + &mut self, + module: &crate::Module, ) -> Result> { self.reset(); self.reset_types(module.types.len());