diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 014cc34b44..9ca75e19a6 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -2445,6 +2445,8 @@ impl<'a, W: Write> Writer<'a, W> { Mf::Asinh => "asinh", Mf::Acosh => "acosh", Mf::Atanh => "atanh", + Mf::Radians => "radians", + Mf::Degrees => "degrees", // glsl doesn't have atan2 function // use two-argument variation of the atan function Mf::Atan2 => "atan", diff --git a/src/back/hlsl/writer.rs b/src/back/hlsl/writer.rs index 0280b50585..dd682d9cb0 100644 --- a/src/back/hlsl/writer.rs +++ b/src/back/hlsl/writer.rs @@ -1835,6 +1835,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Mf::Asinh => Function::Asincosh { is_sin: true }, Mf::Acosh => Function::Asincosh { is_sin: false }, Mf::Atanh => Function::Atanh, + Mf::Radians => Function::Regular("radians"), + Mf::Degrees => Function::Regular("degrees"), // decomposition Mf::Ceil => Function::Regular("ceil"), Mf::Floor => Function::Regular("floor"), diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 664b7ea2ff..dfb85c8d58 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -1135,6 +1135,8 @@ impl Writer { Mf::Asinh => "asinh", Mf::Acosh => "acosh", Mf::Atanh => "atanh", + Mf::Radians => "", + Mf::Degrees => "", // decomposition Mf::Ceil => "ceil", Mf::Floor => "floor", @@ -1223,6 +1225,14 @@ impl Writer { write!(self.out, "as_type(half2(")?; self.put_expression(arg, context, false)?; write!(self.out, "))")?; + } else if fun == Mf::Radians { + write!(self.out, "((")?; + self.put_expression(arg, context, false)?; + write!(self.out, ") * 0.017453292519943295474)")?; + } else if fun == Mf::Degrees { + write!(self.out, "((")?; + self.put_expression(arg, context, false)?; + write!(self.out, ") * 57.295779513082322865)")?; } else { write!(self.out, "{}::{}", NAMESPACE, fun_name)?; self.put_call_parameters( diff --git a/src/back/spv/block.rs b/src/back/spv/block.rs index aba92b9b87..64eaadcc9c 100644 --- a/src/back/spv/block.rs +++ b/src/back/spv/block.rs @@ -540,6 +540,8 @@ impl<'w> BlockContext<'w> { Mf::Asinh => MathOp::Ext(spirv::GLOp::Asinh), Mf::Acosh => MathOp::Ext(spirv::GLOp::Acosh), Mf::Atanh => MathOp::Ext(spirv::GLOp::Atanh), + Mf::Radians => MathOp::Ext(spirv::GLOp::Radians), + Mf::Degrees => MathOp::Ext(spirv::GLOp::Degrees), // decomposition Mf::Ceil => MathOp::Ext(spirv::GLOp::Ceil), Mf::Round => MathOp::Ext(spirv::GLOp::RoundEven), diff --git a/src/back/wgsl/writer.rs b/src/back/wgsl/writer.rs index dbff2db3c3..59c7048c33 100644 --- a/src/back/wgsl/writer.rs +++ b/src/back/wgsl/writer.rs @@ -1527,6 +1527,8 @@ impl Writer { Mf::Asinh => Function::Asincosh { is_sin: true }, Mf::Acosh => Function::Asincosh { is_sin: false }, Mf::Atanh => Function::Atanh, + Mf::Radians => Function::Regular("radians"), + Mf::Degrees => Function::Regular("degrees"), // decomposition Mf::Ceil => Function::Regular("ceil"), Mf::Floor => Function::Regular("floor"), diff --git a/src/front/glsl/builtins.rs b/src/front/glsl/builtins.rs index 1a114a57b2..c2c3e29026 100644 --- a/src/front/glsl/builtins.rs +++ b/src/front/glsl/builtins.rs @@ -4,9 +4,9 @@ use super::{ Error, ErrorKind, Parser, Result, }; use crate::{ - BinaryOperator, Block, Constant, ConstantInner, DerivativeAxis, Expression, Handle, ImageClass, + BinaryOperator, Block, Constant, DerivativeAxis, Expression, Handle, ImageClass, ImageDimension, ImageQuery, MathFunction, Module, RelationalFunction, SampleLevel, - ScalarKind as Sk, ScalarValue, Span, Type, TypeInner, VectorSize, + ScalarKind as Sk, Span, Type, TypeInner, VectorSize, }; impl Module { @@ -535,8 +535,8 @@ pub fn inject_builtin(declaration: &mut FunctionDeclaration, module: &mut Module "asinh" => MacroCall::MathFunction(MathFunction::Asinh), "acosh" => MacroCall::MathFunction(MathFunction::Acosh), "atanh" => MacroCall::MathFunction(MathFunction::Atanh), - "radians" => MacroCall::ConstMultiply(std::f64::consts::PI / 180.0), - "degrees" => MacroCall::ConstMultiply(180.0 / std::f64::consts::PI), + "radians" => MacroCall::MathFunction(MathFunction::Radians), + "degrees" => MacroCall::MathFunction(MathFunction::Degrees), "floatBitsToInt" => MacroCall::BitCast(Sk::Sint), "floatBitsToUint" => MacroCall::BitCast(Sk::Uint), "dFdx" | "dFdxFine" | "dFdxCoarse" => { @@ -1551,7 +1551,6 @@ pub enum MacroCall { Splatted(MathFunction, Option, usize), MixBoolean, Clamp(Option), - ConstMultiply(f64), BitCast(Sk), Derivate(DerivativeAxis), } @@ -1868,30 +1867,6 @@ impl MacroCall { body, )) } - MacroCall::ConstMultiply(value) => { - let constant = parser.module.constants.fetch_or_append( - Constant { - name: None, - specialization: None, - inner: ConstantInner::Scalar { - width: 4, - value: ScalarValue::Float(value), - }, - }, - Span::default(), - ); - let right = - ctx.add_expression(Expression::Constant(constant), Span::default(), body); - Ok(ctx.add_expression( - Expression::Binary { - op: BinaryOperator::Multiply, - left: args[0], - right, - }, - Span::default(), - body, - )) - } MacroCall::BitCast(kind) => Ok(ctx.add_expression( Expression::As { expr: args[0], diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index dc578374b5..d950b280ca 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -2531,162 +2531,115 @@ impl> Parser { let inst_id = self.next()?; let gl_op = Glo::from_u32(inst_id).ok_or(Error::UnsupportedExtInst(inst_id))?; - if gl_op == Glo::Radians || gl_op == Glo::Degrees { - inst.expect(base_wc + 1)?; - let arg = { - let arg_id = self.next()?; - let lexp = self.lookup_expression.lookup(arg_id)?; - get_expr_handle!(arg_id, lexp) - }; - - // constant expressions need to be excluded from the emitter - block.extend(emitter.finish(ctx.expressions)); - let const_value = match gl_op { - Glo::Radians => std::f64::consts::PI / 180.0, - Glo::Degrees => 180.0 / std::f64::consts::PI, - _ => unreachable!(), - }; - let const_handle = ctx.const_arena.fetch_or_append( - crate::Constant { - name: None, - specialization: None, - inner: crate::ConstantInner::Scalar { - width: 4, - value: crate::ScalarValue::Float(const_value), - }, - }, - crate::Span::default(), - ); - let expr_handle = ctx.expressions.append( - crate::Expression::Constant(const_handle), - crate::Span::default(), - ); - emitter.start(ctx.expressions); + let fun = match gl_op { + Glo::Round => Mf::Round, + Glo::RoundEven => Mf::Round, + Glo::Trunc => Mf::Trunc, + Glo::FAbs | Glo::SAbs => Mf::Abs, + Glo::FSign | Glo::SSign => Mf::Sign, + Glo::Floor => Mf::Floor, + Glo::Ceil => Mf::Ceil, + Glo::Fract => Mf::Fract, + Glo::Sin => Mf::Sin, + Glo::Cos => Mf::Cos, + Glo::Tan => Mf::Tan, + Glo::Asin => Mf::Asin, + Glo::Acos => Mf::Acos, + Glo::Atan => Mf::Atan, + Glo::Sinh => Mf::Sinh, + Glo::Cosh => Mf::Cosh, + Glo::Tanh => Mf::Tanh, + Glo::Atan2 => Mf::Atan2, + Glo::Asinh => Mf::Asinh, + Glo::Acosh => Mf::Acosh, + Glo::Atanh => Mf::Atanh, + Glo::Radians => Mf::Radians, + Glo::Degrees => Mf::Degrees, + Glo::Pow => Mf::Pow, + Glo::Exp => Mf::Exp, + Glo::Log => Mf::Log, + Glo::Exp2 => Mf::Exp2, + Glo::Log2 => Mf::Log2, + Glo::Sqrt => Mf::Sqrt, + Glo::InverseSqrt => Mf::InverseSqrt, + Glo::MatrixInverse => Mf::Inverse, + Glo::Determinant => Mf::Determinant, + Glo::Modf => Mf::Modf, + Glo::FMin | Glo::UMin | Glo::SMin | Glo::NMin => Mf::Min, + Glo::FMax | Glo::UMax | Glo::SMax | Glo::NMax => Mf::Max, + Glo::FClamp | Glo::UClamp | Glo::SClamp | Glo::NClamp => Mf::Clamp, + Glo::FMix => Mf::Mix, + Glo::Step => Mf::Step, + Glo::SmoothStep => Mf::SmoothStep, + Glo::Fma => Mf::Fma, + Glo::Frexp => Mf::Frexp, //TODO: FrexpStruct? + Glo::Ldexp => Mf::Ldexp, + Glo::Length => Mf::Length, + Glo::Distance => Mf::Distance, + Glo::Cross => Mf::Cross, + Glo::Normalize => Mf::Normalize, + Glo::FaceForward => Mf::FaceForward, + Glo::Reflect => Mf::Reflect, + Glo::Refract => Mf::Refract, + Glo::PackUnorm4x8 => Mf::Pack4x8unorm, + Glo::PackSnorm4x8 => Mf::Pack4x8snorm, + Glo::PackHalf2x16 => Mf::Pack2x16float, + Glo::PackUnorm2x16 => Mf::Pack2x16unorm, + Glo::PackSnorm2x16 => Mf::Pack2x16snorm, + Glo::UnpackUnorm4x8 => Mf::Unpack4x8unorm, + Glo::UnpackSnorm4x8 => Mf::Unpack4x8snorm, + Glo::UnpackHalf2x16 => Mf::Unpack2x16float, + Glo::UnpackUnorm2x16 => Mf::Unpack2x16unorm, + Glo::UnpackSnorm2x16 => Mf::Unpack2x16snorm, + Glo::FindILsb => Mf::FindLsb, + Glo::FindUMsb | Glo::FindSMsb => Mf::FindMsb, + _ => return Err(Error::UnsupportedExtInst(inst_id)), + }; - self.lookup_expression.insert( - result_id, - LookupExpression { - handle: ctx.expressions.append( - crate::Expression::Binary { - op: crate::BinaryOperator::Multiply, - left: arg, - right: expr_handle, - }, - span, - ), - type_id: result_type_id, - block_id, - }, - ); + let arg_count = fun.argument_count(); + inst.expect(base_wc + arg_count as u16)?; + let arg = { + let arg_id = self.next()?; + let lexp = self.lookup_expression.lookup(arg_id)?; + get_expr_handle!(arg_id, lexp) + }; + let arg1 = if arg_count > 1 { + let arg_id = self.next()?; + let lexp = self.lookup_expression.lookup(arg_id)?; + Some(get_expr_handle!(arg_id, lexp)) } else { - let fun = match gl_op { - Glo::Round => Mf::Round, - Glo::RoundEven => Mf::Round, - Glo::Trunc => Mf::Trunc, - Glo::FAbs | Glo::SAbs => Mf::Abs, - Glo::FSign | Glo::SSign => Mf::Sign, - Glo::Floor => Mf::Floor, - Glo::Ceil => Mf::Ceil, - Glo::Fract => Mf::Fract, - Glo::Sin => Mf::Sin, - Glo::Cos => Mf::Cos, - Glo::Tan => Mf::Tan, - Glo::Asin => Mf::Asin, - Glo::Acos => Mf::Acos, - Glo::Atan => Mf::Atan, - Glo::Sinh => Mf::Sinh, - Glo::Cosh => Mf::Cosh, - Glo::Tanh => Mf::Tanh, - Glo::Atan2 => Mf::Atan2, - Glo::Asinh => Mf::Asinh, - Glo::Acosh => Mf::Acosh, - Glo::Atanh => Mf::Atanh, - Glo::Pow => Mf::Pow, - Glo::Exp => Mf::Exp, - Glo::Log => Mf::Log, - Glo::Exp2 => Mf::Exp2, - Glo::Log2 => Mf::Log2, - Glo::Sqrt => Mf::Sqrt, - Glo::InverseSqrt => Mf::InverseSqrt, - Glo::MatrixInverse => Mf::Inverse, - Glo::Determinant => Mf::Determinant, - Glo::Modf => Mf::Modf, - Glo::FMin | Glo::UMin | Glo::SMin | Glo::NMin => Mf::Min, - Glo::FMax | Glo::UMax | Glo::SMax | Glo::NMax => Mf::Max, - Glo::FClamp | Glo::UClamp | Glo::SClamp | Glo::NClamp => Mf::Clamp, - Glo::FMix => Mf::Mix, - Glo::Step => Mf::Step, - Glo::SmoothStep => Mf::SmoothStep, - Glo::Fma => Mf::Fma, - Glo::Frexp => Mf::Frexp, //TODO: FrexpStruct? - Glo::Ldexp => Mf::Ldexp, - Glo::Length => Mf::Length, - Glo::Distance => Mf::Distance, - Glo::Cross => Mf::Cross, - Glo::Normalize => Mf::Normalize, - Glo::FaceForward => Mf::FaceForward, - Glo::Reflect => Mf::Reflect, - Glo::Refract => Mf::Refract, - Glo::PackUnorm4x8 => Mf::Pack4x8unorm, - Glo::PackSnorm4x8 => Mf::Pack4x8snorm, - Glo::PackHalf2x16 => Mf::Pack2x16float, - Glo::PackUnorm2x16 => Mf::Pack2x16unorm, - Glo::PackSnorm2x16 => Mf::Pack2x16snorm, - Glo::UnpackUnorm4x8 => Mf::Unpack4x8unorm, - Glo::UnpackSnorm4x8 => Mf::Unpack4x8snorm, - Glo::UnpackHalf2x16 => Mf::Unpack2x16float, - Glo::UnpackUnorm2x16 => Mf::Unpack2x16unorm, - Glo::UnpackSnorm2x16 => Mf::Unpack2x16snorm, - Glo::FindILsb => Mf::FindLsb, - Glo::FindUMsb | Glo::FindSMsb => Mf::FindMsb, - _ => return Err(Error::UnsupportedExtInst(inst_id)), - }; - - let arg_count = fun.argument_count(); - inst.expect(base_wc + arg_count as u16)?; - let arg = { - let arg_id = self.next()?; - let lexp = self.lookup_expression.lookup(arg_id)?; - get_expr_handle!(arg_id, lexp) - }; - let arg1 = if arg_count > 1 { - let arg_id = self.next()?; - let lexp = self.lookup_expression.lookup(arg_id)?; - Some(get_expr_handle!(arg_id, lexp)) - } else { - None - }; - let arg2 = if arg_count > 2 { - let arg_id = self.next()?; - let lexp = self.lookup_expression.lookup(arg_id)?; - Some(get_expr_handle!(arg_id, lexp)) - } else { - None - }; - let arg3 = if arg_count > 3 { - let arg_id = self.next()?; - let lexp = self.lookup_expression.lookup(arg_id)?; - Some(get_expr_handle!(arg_id, lexp)) - } else { - None - }; + None + }; + let arg2 = if arg_count > 2 { + let arg_id = self.next()?; + let lexp = self.lookup_expression.lookup(arg_id)?; + Some(get_expr_handle!(arg_id, lexp)) + } else { + None + }; + let arg3 = if arg_count > 3 { + let arg_id = self.next()?; + let lexp = self.lookup_expression.lookup(arg_id)?; + Some(get_expr_handle!(arg_id, lexp)) + } else { + None + }; - let expr = crate::Expression::Math { - fun, - arg, - arg1, - arg2, - arg3, - }; - self.lookup_expression.insert( - result_id, - LookupExpression { - handle: ctx.expressions.append(expr, span), - type_id: result_type_id, - block_id, - }, - ); - } + let expr = crate::Expression::Math { + fun, + arg, + arg1, + arg2, + arg3, + }; + self.lookup_expression.insert( + result_id, + LookupExpression { + handle: ctx.expressions.append(expr, span), + type_id: result_type_id, + block_id, + }, + ); } // Relational and Logical Instructions Op::LogicalNot => { diff --git a/src/front/wgsl/conv.rs b/src/front/wgsl/conv.rs index b93869071e..840dc2b056 100644 --- a/src/front/wgsl/conv.rs +++ b/src/front/wgsl/conv.rs @@ -160,6 +160,8 @@ pub fn map_standard_fun(word: &str) -> Option { "asin" => Mf::Asin, "atan" => Mf::Atan, "atan2" => Mf::Atan2, + "radians" => Mf::Radians, + "degrees" => Mf::Degrees, // decomposition "ceil" => Mf::Ceil, "floor" => Mf::Floor, diff --git a/src/lib.rs b/src/lib.rs index 349ae21f96..6e7083082f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -885,6 +885,8 @@ pub enum MathFunction { Asinh, Acosh, Atanh, + Radians, + Degrees, // decomposition Ceil, Floor, diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 04ae4a594c..13883df909 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -221,6 +221,8 @@ impl super::MathFunction { Self::Asinh => 1, Self::Acosh => 1, Self::Atanh => 1, + Self::Radians => 1, + Self::Degrees => 1, // decomposition Self::Ceil => 1, Self::Floor => 1, diff --git a/src/proc/typifier.rs b/src/proc/typifier.rs index 270276243b..7a1d7a46e0 100644 --- a/src/proc/typifier.rs +++ b/src/proc/typifier.rs @@ -701,6 +701,8 @@ impl<'a> ResolveContext<'a> { Mf::Asinh | Mf::Acosh | Mf::Atanh | + Mf::Radians | + Mf::Degrees | // decomposition Mf::Ceil | Mf::Floor | diff --git a/src/valid/expression.rs b/src/valid/expression.rs index 29409a1bcd..4e59a9ef4b 100644 --- a/src/valid/expression.rs +++ b/src/valid/expression.rs @@ -987,6 +987,8 @@ impl super::Validator { | Mf::Asinh | Mf::Acosh | Mf::Atanh + | Mf::Radians + | Mf::Degrees | Mf::Ceil | Mf::Floor | Mf::Round diff --git a/tests/in/glsl/math-functions.vert b/tests/in/glsl/math-functions.vert index ff1851a69e..dd8ab7cda1 100644 --- a/tests/in/glsl/math-functions.vert +++ b/tests/in/glsl/math-functions.vert @@ -6,33 +6,33 @@ void main() { mat4 m = mat4(a, b, a, b); int i = 5; - vec4 ceilOut = ceil(a); - vec4 roundOut = round(a); - vec4 floorOut = floor(a); - vec4 fractOut = fract(a); - vec4 truncOut = trunc(a); - vec4 sinOut = sin(a); - vec4 absOut = abs(a); + vec4 ceilOut = ceil(a); + vec4 roundOut = round(a); + vec4 floorOut = floor(a); + vec4 fractOut = fract(a); + vec4 truncOut = trunc(a); + vec4 sinOut = sin(a); + vec4 absOut = abs(a); vec4 sqrtOut = sqrt(a); - vec4 inversesqrtOut = inversesqrt(a); - vec4 expOut = exp(a); - vec4 exp2Out = exp2(a); - vec4 signOut = sign(a); - mat4 transposeOut = transpose(m); + vec4 inversesqrtOut = inversesqrt(a); + vec4 expOut = exp(a); + vec4 exp2Out = exp2(a); + vec4 signOut = sign(a); + mat4 transposeOut = transpose(m); // TODO: support inverse function in wgsl output // mat4 inverseOut = inverse(m); - vec4 normalizeOut = normalize(a); - vec4 sinhOut = sinh(a); - vec4 cosOut = cos(a); - vec4 coshOut = cosh(a); - vec4 tanOut = tan(a); - vec4 tanhOut = tanh(a); - vec4 acosOut = acos(a); + vec4 normalizeOut = normalize(a); + vec4 sinhOut = sinh(a); + vec4 cosOut = cos(a); + vec4 coshOut = cosh(a); + vec4 tanOut = tan(a); + vec4 tanhOut = tanh(a); + vec4 acosOut = acos(a); vec4 asinOut = asin(a); - vec4 logOut = log(a); - vec4 log2Out = log2(a); - float lengthOut = length(a); - float determinantOut = determinant(m); + vec4 logOut = log(a); + vec4 log2Out = log2(a); + float lengthOut = length(a); + float determinantOut = determinant(m); int bitCountOut = bitCount(i); int bitfieldReverseOut = bitfieldReverse(i); float atanOut = atan(a.x); @@ -51,5 +51,6 @@ void main() { // vec4 modfOut = modf(a, b); // vec4 frexpOut = frexp(a, b); // float ldexpOut = ldexp(a.x, i); - -} \ No newline at end of file + vec4 rad = radians(a); + float deg = degrees(a.x); +} diff --git a/tests/in/math-functions.param.ron b/tests/in/math-functions.param.ron new file mode 100644 index 0000000000..72873dd667 --- /dev/null +++ b/tests/in/math-functions.param.ron @@ -0,0 +1,2 @@ +( +) diff --git a/tests/in/math-functions.wgsl b/tests/in/math-functions.wgsl new file mode 100644 index 0000000000..90e5720c4c --- /dev/null +++ b/tests/in/math-functions.wgsl @@ -0,0 +1,9 @@ +[[stage(vertex)]] +fn main() { + let f = 1.0; + let v = vec4(0.0); + let a = degrees(f); + let b = radians(f); + let c = degrees(v); + let d = radians(v); +} diff --git a/tests/out/glsl/math-functions.main.Vertex.glsl b/tests/out/glsl/math-functions.main.Vertex.glsl new file mode 100644 index 0000000000..b69069b382 --- /dev/null +++ b/tests/out/glsl/math-functions.main.Vertex.glsl @@ -0,0 +1,14 @@ +#version 310 es + +precision highp float; +precision highp int; + + +void main() { + vec4 v = vec4(0.0); + float a = degrees(1.0); + float b = radians(1.0); + vec4 c = degrees(v); + vec4 d = radians(v); +} + diff --git a/tests/out/hlsl/math-functions.hlsl b/tests/out/hlsl/math-functions.hlsl new file mode 100644 index 0000000000..5d869f7c94 --- /dev/null +++ b/tests/out/hlsl/math-functions.hlsl @@ -0,0 +1,9 @@ + +void main() +{ + float4 v = float4(0.0.xxxx); + float a = degrees(1.0); + float b = radians(1.0); + float4 c = degrees(v); + float4 d = radians(v); +} diff --git a/tests/out/hlsl/math-functions.hlsl.config b/tests/out/hlsl/math-functions.hlsl.config new file mode 100644 index 0000000000..f72fafd91f --- /dev/null +++ b/tests/out/hlsl/math-functions.hlsl.config @@ -0,0 +1,3 @@ +vertex=(main:vs_5_1 ) +fragment=() +compute=() diff --git a/tests/out/msl/math-functions.msl b/tests/out/msl/math-functions.msl new file mode 100644 index 0000000000..42f8be358f --- /dev/null +++ b/tests/out/msl/math-functions.msl @@ -0,0 +1,13 @@ +// language: metal1.1 +#include +#include + + +vertex void main_( +) { + metal::float4 v = metal::float4(0.0); + float a = ((1.0) * 57.295779513082322865); + float b = ((1.0) * 0.017453292519943295474); + metal::float4 c = ((v) * 57.295779513082322865); + metal::float4 d = ((v) * 0.017453292519943295474); +} diff --git a/tests/out/spv/math-functions.spvasm b/tests/out/spv/math-functions.spvasm new file mode 100644 index 0000000000..738ac6a728 --- /dev/null +++ b/tests/out/spv/math-functions.spvasm @@ -0,0 +1,25 @@ +; SPIR-V +; Version: 1.1 +; Generator: rspirv +; Bound: 16 +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %7 "main" +%2 = OpTypeVoid +%4 = OpTypeFloat 32 +%3 = OpConstant %4 1.0 +%5 = OpConstant %4 0.0 +%8 = OpTypeFunction %2 +%10 = OpTypeVector %4 4 +%7 = OpFunction %2 None %8 +%6 = OpLabel +OpBranch %9 +%9 = OpLabel +%11 = OpCompositeConstruct %10 %5 %5 %5 %5 +%12 = OpExtInst %4 %1 Degrees %3 +%13 = OpExtInst %4 %1 Radians %3 +%14 = OpExtInst %10 %1 Degrees %11 +%15 = OpExtInst %10 %1 Radians %11 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/math-functions-vert.wgsl b/tests/out/wgsl/math-functions-vert.wgsl index b96147e74d..ee04f886d9 100644 --- a/tests/out/wgsl/math-functions-vert.wgsl +++ b/tests/out/wgsl/math-functions-vert.wgsl @@ -42,6 +42,8 @@ fn main_1() { var outerProductOut: mat4x4; var distanceOut: f32; var stepOut: vec4; + var rad: vec4; + var deg: f32; let _e6 = a; let _e7 = b; @@ -144,6 +146,11 @@ fn main_1() { let _e222 = a; let _e223 = b; stepOut = step(_e222, _e223); + let _e227 = a; + rad = radians(_e227); + let _e230 = a; + let _e232 = a; + deg = degrees(_e232.x); return; } diff --git a/tests/out/wgsl/math-functions.wgsl b/tests/out/wgsl/math-functions.wgsl new file mode 100644 index 0000000000..53a293e51f --- /dev/null +++ b/tests/out/wgsl/math-functions.wgsl @@ -0,0 +1,8 @@ +[[stage(vertex)]] +fn main() { + let v = vec4(0.0); + let a = degrees(1.0); + let b = radians(1.0); + let c = degrees(v); + let d = radians(v); +} diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 57179c5d5a..ca007860a3 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -484,6 +484,10 @@ fn convert_wgsl() { Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), ("cubeArrayShadow", Targets::GLSL), + ( + "math-functions", + Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL + ), ]; for &(name, targets) in inputs.iter() {