[wgsl] early depth test attribute

This commit is contained in:
Dzmitry Malyshau
2021-02-13 00:14:46 -05:00
committed by Dzmitry Malyshau
parent de39e7f4d1
commit 94bd97c0fb
2 changed files with 24 additions and 1 deletions

View File

@@ -184,3 +184,13 @@ pub fn map_standard_fun(word: &str) -> Option<crate::MathFunction> {
_ => return None,
})
}
pub fn map_conservative_depth(word: &str) -> Result<crate::ConservativeDepth, Error<'_>> {
use crate::ConservativeDepth as Cd;
match word {
"greater_equal" => Ok(Cd::GreaterEqual),
"less_equal" => Ok(Cd::LessEqual),
"unchanged" => Ok(Cd::Unchanged),
_ => Err(Error::UnknownConservativeDepth(word)),
}
}

View File

@@ -86,6 +86,8 @@ pub enum Error<'a> {
UnknownFunction(&'a str),
#[error("unknown storage format: `{0}`")]
UnknownStorageFormat(&'a str),
#[error("unknown conservative depth: `{0}`")]
UnknownConservativeDepth(&'a str),
#[error("array stride must not be 0")]
ZeroStride,
#[error("not a composite type: {0:?}")]
@@ -1932,6 +1934,7 @@ impl Parser {
let mut stage = None;
let mut is_block = false;
let mut workgroup_size = [0u32; 3];
let mut early_depth_test = None;
if lexer.skip(Token::DoubleParen('[')) {
let (mut bind_index, mut bind_group) = (None, None);
@@ -1994,6 +1997,16 @@ impl Parser {
}
}
}
"early_depth_test" => {
let conservative = if lexer.skip(Token::Paren('(')) {
let value = conv::map_conservative_depth(lexer.next_ident()?)?;
lexer.expect(Token::Paren(')'))?;
Some(value)
} else {
None
};
early_depth_test = Some(crate::EarlyDepthTest { conservative });
}
word => return Err(Error::UnknownDecoration(word)),
}
match lexer.next() {
@@ -2103,7 +2116,7 @@ impl Parser {
.insert(
(stage, name.to_string()),
crate::EntryPoint {
early_depth_test: None,
early_depth_test,
workgroup_size,
function,
},