Debian Codegraph @

third_party/rust/naga/src/front/spv/null.rs

raw
1 use alloc::vec;
2
3 use super::Error;
4 use crate::arena::{Arena, Handle};
5
6 /// Create a default value for an output built-in.
7 pub fn generate_default_built_in(
8 built_in: Option<crate::BuiltIn>,
9 ty: Handle<crate::Type>,
10 global_expressions: &mut Arena<crate::Expression>,
11 span: crate::Span,
12 ) -> Result<Handle<crate::Expression>, Error> {
13 let expr = match built_in {
14 Some(crate::BuiltIn::Position { .. }) => {
15 let zero = global_expressions
16 .append(crate::Expression::Literal(crate::Literal::F32(0.0)), span);
17 let one = global_expressions
18 .append(crate::Expression::Literal(crate::Literal::F32(1.0)), span);
19 crate::Expression::Compose {
20 ty,
21 components: vec![zero, zero, zero, one],
22 }
23 }
24 Some(crate::BuiltIn::PointSize) => crate::Expression::Literal(crate::Literal::F32(1.0)),
25 Some(crate::BuiltIn::FragDepth) => crate::Expression::Literal(crate::Literal::F32(0.0)),
26 Some(crate::BuiltIn::SampleMask) => {
27 crate::Expression::Literal(crate::Literal::U32(u32::MAX))
28 }
29 // Note: `crate::BuiltIn::ClipDistance` is intentionally left for the default path
30 _ => crate::Expression::ZeroValue(ty),
31 };
32 Ok(global_expressions.append(expr, span))
33 }