diff --git a/luisa_compute/src/lang/math.rs b/luisa_compute/src/lang/math.rs index 6c4e0f4..d3a6b8d 100644 --- a/luisa_compute/src/lang/math.rs +++ b/luisa_compute/src/lang/math.rs @@ -546,6 +546,12 @@ macro_rules! impl_vec_proxy { FromNode::from_node(__extract::<$scalar>(self.node, index)) } } + impl $vec { + #[inline] + pub fn expr($($comp: impl Into>), *) -> $expr_proxy { + $expr_proxy::new($($comp.into()), *) + } + } }; } @@ -646,6 +652,12 @@ macro_rules! impl_mat_proxy { Expr::<$vec>::from_node(__extract::<$vec>(self.node, index)) } } + impl $mat { + #[inline] + pub fn expr($($comp: impl Into>), *) -> $expr_proxy { + $expr_proxy::new($($comp.into()), *) + } + } }; } @@ -663,7 +675,18 @@ impl_vec_proxy!(Float4, Float4Expr, Float4Var, f32, Float32, 4, x, y, z, w); impl_vec_proxy!(Double2, Double2Expr, Double2Var, f64, Float64, 2, x, y); impl_vec_proxy!(Double3, Double3Expr, Double3Var, f64, Float64, 3, x, y, z); -impl_vec_proxy!(Double4, Double4Expr, Double4Var, f64, Float64, 4, x, y, z, w); +impl_vec_proxy!( + Double4, + Double4Expr, + Double4Var, + f64, + Float64, + 4, + x, + y, + z, + w +); impl_vec_proxy!(Ushort2, Ushort2Expr, Ushort2Var, u16, Uint16, 2, x, y); impl_vec_proxy!(Ushort3, Ushort3Expr, Ushort3Var, u16, Uint16, 3, x, y, z); @@ -1668,10 +1691,10 @@ impl Mul for Mat2Expr { } impl Mat2Expr { pub fn fill(e: impl Into> + Copy) -> Self { - Self::new(make_float2(e, e), make_float2(e, e)) + Self::new(Float2::expr(e, e), Float2::expr(e, e)) } pub fn eye(e: Expr) -> Self { - Self::new(make_float2(e.x(), 0.0), make_float2(0.0, e.y())) + Self::new(Float2::expr(e.x(), 0.0), Float2::expr(0.0, e.y())) } pub fn inverse(&self) -> Self { Mat2Expr::from_node(__current_scope(|s| { @@ -1706,16 +1729,16 @@ impl Mul for Mat3Expr { impl Mat3Expr { pub fn fill(e: impl Into> + Copy) -> Self { Self::new( - make_float3(e, e, e), - make_float3(e, e, e), - make_float3(e, e, e), + Float3::expr(e, e, e), + Float3::expr(e, e, e), + Float3::expr(e, e, e), ) } pub fn eye(e: Expr) -> Self { Self::new( - make_float3(e.x(), 0.0, 0.0), - make_float3(0.0, e.y(), 0.0), - make_float3(0.0, 0.0, e.z()), + Float3::expr(e.x(), 0.0, 0.0), + Float3::expr(0.0, e.y(), 0.0), + Float3::expr(0.0, 0.0, e.z()), ) } pub fn inverse(&self) -> Self { @@ -1751,18 +1774,18 @@ impl_arith_binop_for_mat!(Mat3, f32, Mat3Expr); impl Mat4Expr { pub fn fill(e: impl Into> + Copy) -> Self { Self::new( - make_float4(e, e, e, e), - make_float4(e, e, e, e), - make_float4(e, e, e, e), - make_float4(e, e, e, e), + Float4::expr(e, e, e, e), + Float4::expr(e, e, e, e), + Float4::expr(e, e, e, e), + Float4::expr(e, e, e, e), ) } pub fn eye(e: Expr) -> Self { Self::new( - make_float4(e.x(), 0.0, 0.0, 0.0), - make_float4(0.0, e.y(), 0.0, 0.0), - make_float4(0.0, 0.0, e.z(), 0.0), - make_float4(0.0, 0.0, 0.0, e.w()), + Float4::expr(e.x(), 0.0, 0.0, 0.0), + Float4::expr(0.0, e.y(), 0.0, 0.0), + Float4::expr(0.0, 0.0, e.z(), 0.0), + Float4::expr(0.0, 0.0, 0.0, e.w()), ) } pub fn inverse(&self) -> Self { @@ -1783,193 +1806,6 @@ impl Mat4Expr { } impl_arith_binop_for_mat!(Mat4, f32, Mat4Expr); -#[inline] -pub fn make_half2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_half3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_half4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} - -#[inline] -pub fn make_float2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_float3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_float4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} -#[inline] -pub fn make_float2x2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_float3x3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_float4x4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} - -#[inline] -pub fn make_int2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_int3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_int4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} -#[inline] -pub fn make_uint2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_uint3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_uint4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} - -#[inline] -pub fn make_short2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_short3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_short4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} - -#[inline] -pub fn make_ushort2>, Y: Into>>(x: X, y: Y) -> Expr { - Expr::::new(x.into(), y.into()) -} -#[inline] -pub fn make_ushort3>, Y: Into>, Z: Into>>( - x: X, - y: Y, - z: Z, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into()) -} -#[inline] -pub fn make_ushort4< - X: Into>, - Y: Into>, - Z: Into>, - W: Into>, ->( - x: X, - y: Y, - z: Z, - w: W, -) -> Expr { - Expr::::new(x.into(), y.into(), z.into(), w.into()) -} - #[cfg(test)] mod test { #[test] diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index 23ac9e2..23db759 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -912,7 +912,7 @@ impl_io_texel!( f32, Float4, |x: Float4Expr| x.xy(), - |x: Float2Expr| { make_float4(x.x(), x.y(), 0.0, 0.0) } + |x: Float2Expr| { Float4::expr(x.x(), x.y(), 0.0, 0.0) } ); impl_io_texel!(Float4, f32, Float4, |x: Float4Expr| x, |x: Float4Expr| x); @@ -927,10 +927,10 @@ impl_io_texel!(u32, u32, Uint4, |x: Uint4Expr| x.x(), |x| Uint4Expr::splat( )); impl_io_texel!(i32, i32, Int4, |x: Int4Expr| x.x(), |x| Int4Expr::splat(x)); impl_io_texel!(Uint2, u32, Uint4, |x: Uint4Expr| x.xy(), |x: Uint2Expr| { - make_uint4(x.x(), x.y(), 0u32, 0u32) + Uint4::expr(x.x(), x.y(), 0u32, 0u32) }); impl_io_texel!(Int2, i32, Int4, |x: Int4Expr| x.xy(), |x: Int2Expr| { - make_int4(x.x(), x.y(), 0i32, 0i32) + Int4::expr(x.x(), x.y(), 0i32, 0i32) }); impl_io_texel!(Uint4, u32, Uint4, |x: Uint4Expr| x, |x| x); impl_io_texel!(Int4, i32, Int4, |x: Int4Expr| x, |x| x);