[glsl-in] Add glsl-validate and sampling qualifier

This commit is contained in:
João Capucho
2021-05-14 13:49:56 +01:00
committed by Dzmitry Malyshau
parent 565c27292a
commit 7165a06fbf
4 changed files with 8 additions and 7 deletions

View File

@@ -163,6 +163,7 @@ impl<'a> Program<'a> {
)
}
#[allow(dead_code)] // FIXME: Remove after implementing structs
pub fn type_size(&self, ty: Handle<Type>) -> Result<u8, ErrorKind> {
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<Expression>) {
if let Some(current) = self.scopes.last_mut() {

View File

@@ -5,8 +5,6 @@ use crate::{FastHashMap, Module, ShaderStage};
mod lex;
// TODO: Remove later
#[allow(dead_code)]
mod ast;
use ast::Program;

View File

@@ -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!(),
})

View File

@@ -346,6 +346,11 @@ impl Program<'_> {
name: String,
init: Option<Handle<Constant>>,
) -> Result<Handle<Expression>, 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)]