mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Populate ResolveContext with functions
Add support for more math functions
This commit is contained in:
committed by
Dzmitry Malyshau
parent
daf18642d7
commit
c12003f564
@@ -58,12 +58,11 @@ impl Program {
|
||||
&mut self,
|
||||
handle: Handle<crate::Expression>,
|
||||
) -> Result<&crate::TypeInner, ErrorKind> {
|
||||
let functions = Arena::new(); //TODO
|
||||
let resolve_ctx = ResolveContext {
|
||||
constants: &self.module.constants,
|
||||
global_vars: &self.module.global_variables,
|
||||
local_vars: &self.context.local_variables,
|
||||
functions: &functions,
|
||||
functions: &self.module.functions,
|
||||
arguments: &self.context.arguments,
|
||||
};
|
||||
match self.context.typifier.grow(
|
||||
|
||||
@@ -81,7 +81,7 @@ impl Program {
|
||||
Err(ErrorKind::SemanticError("Bad call to texture".into()))
|
||||
}
|
||||
}
|
||||
"ceil" | "round" | "floor" | "fract" | "trunc" => {
|
||||
"ceil" | "round" | "floor" | "fract" | "trunc" | "sin" | "abs" => {
|
||||
if fc.args.len() != 1 {
|
||||
return Err(ErrorKind::WrongNumberArgs(name, 1, fc.args.len()));
|
||||
}
|
||||
@@ -93,6 +93,8 @@ impl Program {
|
||||
"floor" => MathFunction::Floor,
|
||||
"fract" => MathFunction::Fract,
|
||||
"trunc" => MathFunction::Trunc,
|
||||
"sin" => MathFunction::Sin,
|
||||
"abs" => MathFunction::Abs,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
arg: fc.args[0].expression,
|
||||
@@ -103,6 +105,24 @@ impl Program {
|
||||
statements: fc.args.into_iter().flat_map(|a| a.statements).collect(),
|
||||
})
|
||||
}
|
||||
"mix" => {
|
||||
if fc.args.len() != 3 {
|
||||
return Err(ErrorKind::WrongNumberArgs(name, 3, fc.args.len()));
|
||||
}
|
||||
Ok(ExpressionRule {
|
||||
expression: self.context.expressions.append(Expression::Math {
|
||||
fun: match name.as_str() {
|
||||
"mix" => MathFunction::Mix,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
arg: fc.args[0].expression,
|
||||
arg1: Some(fc.args[1].expression),
|
||||
arg2: None,
|
||||
}),
|
||||
sampler: None,
|
||||
statements: fc.args.into_iter().flat_map(|a| a.statements).collect(),
|
||||
})
|
||||
}
|
||||
func_name => {
|
||||
let function = *self.lookup_function.get(func_name).ok_or_else(|| {
|
||||
ErrorKind::SemanticError(
|
||||
|
||||
Reference in New Issue
Block a user