From 7165a06fbfbba9b0b1b2776d8bbb5ee80e9e6d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 14 May 2021 13:49:56 +0100 Subject: [PATCH] [glsl-in] Add glsl-validate and sampling qualifier --- src/front/glsl/ast.rs | 6 +----- src/front/glsl/mod.rs | 2 -- src/front/glsl/parser.rs | 2 ++ src/front/glsl/variables.rs | 5 +++++ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/front/glsl/ast.rs b/src/front/glsl/ast.rs index 017690f6f2..94ef4c173a 100644 --- a/src/front/glsl/ast.rs +++ b/src/front/glsl/ast.rs @@ -163,6 +163,7 @@ impl<'a> Program<'a> { ) } + #[allow(dead_code)] // FIXME: Remove after implementing structs pub fn type_size(&self, ty: Handle) -> Result { Ok(match self.module.types[ty].inner { crate::TypeInner::Scalar { width, .. } => width, @@ -310,11 +311,6 @@ impl<'function> Context<'function> { } } - pub fn clear_scopes(&mut self) { - self.scopes.clear(); - self.scopes.push(FastHashMap::default()); - } - /// Add variable to current scope pub fn add_local_var(&mut self, name: String, expr: Handle) { if let Some(current) = self.scopes.last_mut() { diff --git a/src/front/glsl/mod.rs b/src/front/glsl/mod.rs index d8d0b27f95..e03d611098 100644 --- a/src/front/glsl/mod.rs +++ b/src/front/glsl/mod.rs @@ -5,8 +5,6 @@ use crate::{FastHashMap, Module, ShaderStage}; mod lex; -// TODO: Remove later -#[allow(dead_code)] mod ast; use ast::Program; diff --git a/src/front/glsl/parser.rs b/src/front/glsl/parser.rs index 98a6c8ef38..eabcaaa261 100644 --- a/src/front/glsl/parser.rs +++ b/src/front/glsl/parser.rs @@ -163,6 +163,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> { fn peek_type_qualifier(&mut self) -> bool { self.lexer.peek().map_or(false, |t| match t.value { TokenValue::Interpolation(_) + | TokenValue::Sampling(_) | TokenValue::Const | TokenValue::In | TokenValue::Out @@ -192,6 +193,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> { TokenValue::Uniform => TypeQualifier::StorageQualifier( StorageQualifier::StorageClass(StorageClass::Uniform), ), + TokenValue::Sampling(s) => TypeQualifier::Sampling(s), _ => unreachable!(), }) diff --git a/src/front/glsl/variables.rs b/src/front/glsl/variables.rs index cfbd766e8c..6b629aed38 100644 --- a/src/front/glsl/variables.rs +++ b/src/front/glsl/variables.rs @@ -346,6 +346,11 @@ impl Program<'_> { name: String, init: Option>, ) -> Result, ErrorKind> { + #[cfg(feature = "glsl-validate")] + if ctx.lookup_local_var_current_scope(&name).is_some() { + return Err(ErrorKind::VariableAlreadyDeclared(name)); + } + // FIXME: this should be removed after // fixing the lack of constant qualifier support #[allow(clippy::never_loop)]