mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 10:03:58 +01:00
[glsl-in] support inverse function
This commit is contained in:
1 parent
b642c5b89b
commit
7a124550d4
8 files changed
+32
-2
No files matched your search
@@ -1624,6 +1624,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Mf::SmoothStep => "smoothstep",
|
||||
Mf::Sqrt => "sqrt",
|
||||
Mf::InverseSqrt => "inversesqrt",
|
||||
Mf::Inverse => "inverse",
|
||||
Mf::Transpose => "transpose",
|
||||
Mf::Determinant => "determinant",
|
||||
// bits
|
||||
|
||||
@@ -646,6 +646,7 @@ impl<W: Write> Writer<W> {
|
||||
Mf::SmoothStep => "smoothstep",
|
||||
Mf::Sqrt => "sqrt",
|
||||
Mf::InverseSqrt => "rsqrt",
|
||||
Mf::Inverse => return Err(Error::UnsupportedCall(format!("{:?}", fun))),
|
||||
Mf::Transpose => "transpose",
|
||||
Mf::Determinant => "determinant",
|
||||
// bits
|
||||
|
||||
@@ -1505,6 +1505,7 @@ impl Writer {
|
||||
Mf::SmoothStep => MathOp::Ext(spirv::GLOp::SmoothStep),
|
||||
Mf::Sqrt => MathOp::Ext(spirv::GLOp::Sqrt),
|
||||
Mf::InverseSqrt => MathOp::Ext(spirv::GLOp::InverseSqrt),
|
||||
Mf::Inverse => MathOp::Ext(spirv::GLOp::MatrixInverse),
|
||||
Mf::Transpose => MathOp::Custom(Instruction::unary(
|
||||
spirv::Op::Transpose,
|
||||
result_type_id,
|
||||
|
||||
@@ -125,7 +125,9 @@ impl Program {
|
||||
&resolve_ctx,
|
||||
) {
|
||||
//TODO: better error report
|
||||
Err(_) => Err(ErrorKind::SemanticError("Can't resolve type".into())),
|
||||
Err(error) => Err(ErrorKind::SemanticError(
|
||||
format!("Can't resolve type: {:?}", error).into(),
|
||||
)),
|
||||
Ok(()) => Ok(self.context.typifier.get(handle, &self.module.types)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ impl Program {
|
||||
}
|
||||
}
|
||||
"ceil" | "round" | "floor" | "fract" | "trunc" | "sin" | "abs" | "sqrt"
|
||||
| "exp" | "sign" => {
|
||||
| "inversesqrt" | "exp" | "exp2" | "sign" | "transpose" | "inverse"
|
||||
| "normalize" => {
|
||||
if fc.args.len() != 1 {
|
||||
return Err(ErrorKind::WrongNumberArgs(name, 1, fc.args.len()));
|
||||
}
|
||||
@@ -98,8 +99,13 @@ impl Program {
|
||||
"sin" => MathFunction::Sin,
|
||||
"abs" => MathFunction::Abs,
|
||||
"sqrt" => MathFunction::Sqrt,
|
||||
"inversesqrt" => MathFunction::InverseSqrt,
|
||||
"exp" => MathFunction::Exp,
|
||||
"exp2" => MathFunction::Exp2,
|
||||
"sign" => MathFunction::Sign,
|
||||
"transpose" => MathFunction::Transpose,
|
||||
"inverse" => MathFunction::Inverse,
|
||||
"normalize" => MathFunction::Normalize,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
arg: fc.args[0].expression,
|
||||
|
||||
@@ -605,6 +605,7 @@ pub enum MathFunction {
|
||||
SmoothStep,
|
||||
Sqrt,
|
||||
InverseSqrt,
|
||||
Inverse,
|
||||
Transpose,
|
||||
Determinant,
|
||||
// bits
|
||||
|
||||
@@ -133,6 +133,7 @@ impl super::MathFunction {
|
||||
Self::SmoothStep => 3,
|
||||
Self::Sqrt => 1,
|
||||
Self::InverseSqrt => 1,
|
||||
Self::Inverse => 1,
|
||||
Self::Transpose => 1,
|
||||
Self::Determinant => 1,
|
||||
// bits
|
||||
|
||||
@@ -427,6 +427,23 @@ impl Typifier {
|
||||
})
|
||||
}
|
||||
},
|
||||
Mf::Inverse => match *self.get(arg, types) {
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
width,
|
||||
} if columns == rows => Resolution::Value(crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
width,
|
||||
}),
|
||||
ref other => {
|
||||
return Err(ResolveError::IncompatibleOperand {
|
||||
op: "inverse".to_string(),
|
||||
operand: format!("{:?}", other),
|
||||
})
|
||||
}
|
||||
},
|
||||
Mf::Determinant => match *self.get(arg, types) {
|
||||
crate::TypeInner::Matrix {
|
||||
width,
|
||||
|
||||
Reference in new issue
Block a user