diff --git a/luisa_compute/src/lang.rs b/luisa_compute/src/lang.rs index 47c8a5b..cce944b 100644 --- a/luisa_compute/src/lang.rs +++ b/luisa_compute/src/lang.rs @@ -50,9 +50,6 @@ pub(crate) trait CallFuncTrait { y: Expr, z: Expr, ) -> Expr; - fn call_void(self, x: Expr); - fn call2_void(self, x: Expr, y: Expr); - fn call3_void(self, x: Expr, y: Expr, z: Expr); } impl CallFuncTrait for Func { fn call(self, x: Expr) -> Expr { @@ -82,27 +79,6 @@ impl CallFuncTrait for Func { b.call(self, &[x, y, z], ::type_()) }))) } - fn call_void(self, x: Expr) { - let x = x.node().get(); - __current_scope(|b| { - b.call(self, &[x], Type::void()); - }); - } - fn call2_void(self, x: Expr, y: Expr) { - let x = x.node().get(); - let y = y.node().get(); - __current_scope(|b| { - b.call(self, &[x, y], Type::void()); - }); - } - fn call3_void(self, x: Expr, y: Expr, z: Expr) { - let x = x.node().get(); - let y = y.node().get(); - let z = z.node().get(); - __current_scope(|b| { - b.call(self, &[x, y, z], Type::void()); - }); - } } /** diff --git a/luisa_compute/src/lang/control_flow.rs b/luisa_compute/src/lang/control_flow.rs index 25f0b14..60f8927 100644 --- a/luisa_compute/src/lang/control_flow.rs +++ b/luisa_compute/src/lang/control_flow.rs @@ -1,5 +1,3 @@ -use std::ffi::CString; - use crate::internal_prelude::*; use ir::SwitchCase; diff --git a/luisa_compute/src/lang/types/vector/gen_swizzle.py b/luisa_compute/src/lang/types/vector/gen_swizzle.py index f619f33..3df347c 100644 --- a/luisa_compute/src/lang/types/vector/gen_swizzle.py +++ b/luisa_compute/src/lang/types/vector/gen_swizzle.py @@ -1,8 +1,12 @@ from typing import List from itertools import permutations, product -s = '' + +s = "" + + def swizzle_name(perm: List[int]): - return ''.join('xyzw'[i] for i in perm) + return "".join("xyzw"[i] for i in perm) + swizzles2 = list(product(range(4), repeat=2)) swizzles3 = list(product(range(4), repeat=3)) @@ -15,29 +19,32 @@ def swizzle_name(perm: List[int]): sw_m_to_n = {} for m in range(2, 5): for n in range(2, 5): - comps = 'xyzw'[:m] - sw_m_to_n[(m, n)] = [sw for sw in all_swizzles[n] if len(sw) == n and all([s < m for s in sw])] -for n in range(2,5): - s += 'pub trait Vec{}Swizzle {{\n'.format(n) - s += ' type Vec2;\n' - s += ' type Vec3;\n' - s += ' type Vec4;\n' - s += ' fn permute2(&self, x: u32, y: u32) -> Self::Vec2;\n' - s += ' fn permute3(&self, x: u32, y: u32, z: u32) -> Self::Vec3;\n' - s += ' fn permute4(&self, x: u32, y: u32, z: u32, w: u32) -> Self::Vec4;\n' + sw_m_to_n[(m, n)] = [ + sw for sw in all_swizzles[n] if len(sw) == n and all([s < m for s in sw]) + ] +for n in range(2, 5): + s += "pub trait Vec{}Swizzle {{\n".format(n) + s += " type Vec2;\n" + s += " type Vec3;\n" + s += " type Vec4;\n" + s += " fn permute2(&self, x: u32, y: u32) -> Self::Vec2;\n" + s += " fn permute3(&self, x: u32, y: u32, z: u32) -> Self::Vec3;\n" + s += " fn permute4(&self, x: u32, y: u32, z: u32, w: u32) -> Self::Vec4;\n" for sw in sw_m_to_n[(n, 2)]: - s += ' fn {}(&self) -> Self::Vec2 {{\n'.format(swizzle_name(sw)) - s += ' self.permute2({}, {})\n'.format(sw[0], sw[1]) - s += ' }\n' + s += " fn {}(&self) -> Self::Vec2 {{\n".format(swizzle_name(sw)) + s += " self.permute2({}, {})\n".format(sw[0], sw[1]) + s += " }\n" for sw in sw_m_to_n[(n, 3)]: - s += ' fn {}(&self) -> Self::Vec3 {{\n'.format(swizzle_name(sw)) - s += ' self.permute3({}, {}, {})\n'.format(sw[0], sw[1], sw[2]) - s += ' }\n' + s += " fn {}(&self) -> Self::Vec3 {{\n".format(swizzle_name(sw)) + s += " self.permute3({}, {}, {})\n".format(sw[0], sw[1], sw[2]) + s += " }\n" for sw in sw_m_to_n[(n, 4)]: - s += ' fn {}(&self) -> Self::Vec4 {{\n'.format(swizzle_name(sw)) - s += ' self.permute4({}, {}, {}, {})\n'.format(sw[0], sw[1], sw[2], sw[3]) - s += ' }\n' - s += '}\n' + s += " fn {}(&self) -> Self::Vec4 {{\n".format(swizzle_name(sw)) + s += " self.permute4({}, {}, {}, {})\n".format( + sw[0], sw[1], sw[2], sw[3] + ) + s += " }\n" + s += "}\n" -with open('swizzle.rs', 'w') as f: +with open("swizzle.rs", "w") as f: f.write(s) diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index ab4ed08..445a299 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -292,12 +292,12 @@ impl BufferView { } impl fmt::Debug for Buffer { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - struct DebugEllipsis; - impl fmt::Debug for DebugEllipsis { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("..") - } - } + // struct DebugEllipsis; + // impl fmt::Debug for DebugEllipsis { + // fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // f.write_str("..") + // } + // } write!(f, "Buffer<{}>({})", std::any::type_name::(), self.len())?; // if self.len() <= 16 || f.precision().is_some() { @@ -901,6 +901,37 @@ macro_rules! impl_io_texel { } }; } +impl_io_texel!( + f16, + f32, + Float4, + |a: Expr| a.x.cast_f16(), + |x: Expr| { Float4::splat_expr(x.cast_f32()) } +); +impl_io_texel!( + Half2, + f32, + Float4, + |a: Expr| a.xy().cast_f16(), + |x: Expr| { + let x = x.cast_f32(); + Float4::expr(x.x, x.y, 0.0, 0.0) + } +); +impl_io_texel!( + Half3, + f32, + Float4, + |a: Expr| a.xyz().cast_f16(), + |x: Expr| { x.cast_f32().extend(0.0) } +); +impl_io_texel!( + Half4, + f32, + Float4, + |a: Expr| a.cast_f16(), + |x: Expr| { x.cast_f32() } +); impl_io_texel!( bool, f32, @@ -946,6 +977,14 @@ impl_io_texel!(Uint2, u32, Uint4, |x: Expr| x.xy(), |x: Expr< impl_io_texel!(Int2, i32, Int4, |x: Expr| x.xy(), |x: Expr| { Int4::expr(x.x, x.y, 0i32, 0i32) }); +impl_io_texel!(Uint3, u32, Uint4, |x: Expr| x.xyz(), |x: Expr< + Uint3, +>| { + Uint4::expr(x.x, x.y, x.z, 0u32) +}); +impl_io_texel!(Int3, i32, Int4, |x: Expr| x.xyz(), |x: Expr| { + Int4::expr(x.x, x.y, x.z, 0i32) +}); impl_io_texel!(Uint4, u32, Uint4, |x: Expr| x, |x| x); impl_io_texel!(Int4, i32, Int4, |x: Expr| x, |x| x);