diff --git a/src/back/wgsl/writer.rs b/src/back/wgsl/writer.rs index 74c0bf3e88..e91024c2e0 100644 --- a/src/back/wgsl/writer.rs +++ b/src/back/wgsl/writer.rs @@ -1529,13 +1529,9 @@ impl Writer { use crate::MathFunction as Mf; enum Function { - Asincosh { is_sin: bool }, - Atanh, Regular(&'static str), } - // NOTE: If https://github.com/gpuweb/gpuweb/issues/1622 ever is - // accepted, replace this with the builtin functions let function = match fun { Mf::Abs => Function::Regular("abs"), Mf::Min => Function::Regular("min"), @@ -1553,9 +1549,9 @@ impl Writer { Mf::Asin => Function::Regular("asin"), Mf::Atan => Function::Regular("atan"), Mf::Atan2 => Function::Regular("atan2"), - Mf::Asinh => Function::Asincosh { is_sin: true }, - Mf::Acosh => Function::Asincosh { is_sin: false }, - Mf::Atanh => Function::Atanh, + Mf::Asinh => Function::Regular("asinh"), + Mf::Acosh => Function::Regular("acosh"), + Mf::Atanh => Function::Regular("atanh"), Mf::Radians => Function::Regular("radians"), Mf::Degrees => Function::Regular("degrees"), // decomposition @@ -1618,25 +1614,6 @@ impl Writer { }; match function { - Function::Asincosh { is_sin } => { - write!(self.out, "log(")?; - self.write_expr(module, arg, func_ctx)?; - write!(self.out, " + sqrt(")?; - self.write_expr(module, arg, func_ctx)?; - write!(self.out, " * ")?; - self.write_expr(module, arg, func_ctx)?; - match is_sin { - true => write!(self.out, " + 1.0))")?, - false => write!(self.out, " - 1.0))")?, - } - } - Function::Atanh => { - write!(self.out, "0.5 * log((1.0 + ")?; - self.write_expr(module, arg, func_ctx)?; - write!(self.out, ") / (1.0 - ")?; - self.write_expr(module, arg, func_ctx)?; - write!(self.out, "))")?; - } Function::Regular(fun_name) => { write!(self.out, "{}(", fun_name)?; self.write_expr(module, arg, func_ctx)?; diff --git a/src/front/wgsl/conv.rs b/src/front/wgsl/conv.rs index e4c29f7939..7aa4cbc07d 100644 --- a/src/front/wgsl/conv.rs +++ b/src/front/wgsl/conv.rs @@ -149,8 +149,11 @@ pub fn map_standard_fun(word: &str) -> Option { "tan" => Mf::Tan, "tanh" => Mf::Tanh, "acos" => Mf::Acos, + "acosh" => Mf::Acosh, "asin" => Mf::Asin, + "asinh" => Mf::Asinh, "atan" => Mf::Atan, + "atanh" => Mf::Atanh, "atan2" => Mf::Atan2, "radians" => Mf::Radians, "degrees" => Mf::Degrees, diff --git a/tests/out/wgsl/inv-hyperbolic-trig-functions.wgsl b/tests/out/wgsl/inv-hyperbolic-trig-functions.wgsl index e7bee8d858..2ac357020a 100644 --- a/tests/out/wgsl/inv-hyperbolic-trig-functions.wgsl +++ b/tests/out/wgsl/inv-hyperbolic-trig-functions.wgsl @@ -6,11 +6,11 @@ fn main_1() { var d: f32; let _e8 = a; - b = log(_e8 + sqrt(_e8 * _e8 + 1.0)); + b = asinh(_e8); let _e10 = a; - c = log(_e10 + sqrt(_e10 * _e10 - 1.0)); + c = acosh(_e10); let _e12 = a; - d = 0.5 * log((1.0 + _e12) / (1.0 - _e12)); + d = atanh(_e12); return; }