mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-25 21:33:48 +00:00
[wgsl] support select()
This commit is contained in:
parent
b3d80de9e1
commit
86bb611905
@ -99,6 +99,7 @@ pub fn get_scalar_type(word: &str) -> Option<(crate::ScalarKind, crate::Bytes)>
|
|||||||
"f32" => Some((crate::ScalarKind::Float, 4)),
|
"f32" => Some((crate::ScalarKind::Float, 4)),
|
||||||
"i32" => Some((crate::ScalarKind::Sint, 4)),
|
"i32" => Some((crate::ScalarKind::Sint, 4)),
|
||||||
"u32" => Some((crate::ScalarKind::Uint, 4)),
|
"u32" => Some((crate::ScalarKind::Uint, 4)),
|
||||||
|
"bool" => Some((crate::ScalarKind::Bool, 1)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,6 +443,19 @@ impl Parser {
|
|||||||
arg1,
|
arg1,
|
||||||
arg2,
|
arg2,
|
||||||
})
|
})
|
||||||
|
} else if name == "select" {
|
||||||
|
lexer.expect(Token::Paren('('))?;
|
||||||
|
let accept = self.parse_general_expression(lexer, ctx.reborrow())?;
|
||||||
|
lexer.expect(Token::Separator(','))?;
|
||||||
|
let reject = self.parse_general_expression(lexer, ctx.reborrow())?;
|
||||||
|
lexer.expect(Token::Separator(','))?;
|
||||||
|
let condition = self.parse_general_expression(lexer, ctx.reborrow())?;
|
||||||
|
lexer.expect(Token::Paren(')'))?;
|
||||||
|
Some(crate::Expression::Select {
|
||||||
|
condition,
|
||||||
|
accept,
|
||||||
|
reject,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// texture sampling
|
// texture sampling
|
||||||
match name {
|
match name {
|
||||||
|
@ -197,7 +197,19 @@ fn parse_texture_query() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_postfix() {
|
fn parse_postfix() {
|
||||||
parse_str("fn foo() { const x: f32 = vec4<f32>(1.0, 2.0, 3.0, 4.0).xyz.rgbr.aaaa.wz.g; }")
|
parse_str(
|
||||||
.unwrap();
|
"fn foo() {
|
||||||
parse_str("fn foo() { const x: f32 = fract(vec2<f32>(0.5, 1.0)).x; }").unwrap();
|
const x: f32 = vec4<f32>(1.0, 2.0, 3.0, 4.0).xyz.rgbr.aaaa.wz.g;
|
||||||
|
const y: f32 = fract(vec2<f32>(0.5, x)).x;
|
||||||
|
}",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_expressions() {
|
||||||
|
parse_str("fn foo() {
|
||||||
|
const x: f32 = select(0.0, 1.0, true);
|
||||||
|
const y: vec2<f32> = select(vec2<f32>(1.0, 1.0), vec2<f32>(x, x), vec2<bool>(x < 0.5, x > 0.5));
|
||||||
|
}").unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user