From 4191b979988d9dc6d6bc770958855d890f4dae23 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Sun, 24 Sep 2023 14:45:32 +0100 Subject: [PATCH 1/7] Added vector extend fns. --- luisa_compute/src/lang/types/vector/impls.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/luisa_compute/src/lang/types/vector/impls.rs b/luisa_compute/src/lang/types/vector/impls.rs index 8765d28..596127b 100644 --- a/luisa_compute/src/lang/types/vector/impls.rs +++ b/luisa_compute/src/lang/types/vector/impls.rs @@ -171,6 +171,24 @@ pub trait VectorExprProxy { })) } } +impl> VectorExprProxy2 { + #[tracked] + pub fn extend(self, z: impl AsExpr) -> Expr> + where + T: VectorAlign<3>, + { + Vec3::expr(self.x, self.y, z) + } +} +impl> VectorExprProxy3 { + #[tracked] + pub fn extend(self, w: impl AsExpr) -> Expr> + where + T: VectorAlign<4>, + { + Vec4::expr(self.x, self.y, self.z, w) + } +} impl SquareMatrix where f32: VectorAlign, From d60bd459d15a40b28c8806a23cd1ea836c9c4def Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Sun, 24 Sep 2023 16:34:59 +0100 Subject: [PATCH 2/7] Add swapchain to prelude. --- luisa_compute/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luisa_compute/src/lib.rs b/luisa_compute/src/lib.rs index 061cf46..f87df30 100644 --- a/luisa_compute/src/lib.rs +++ b/luisa_compute/src/lib.rs @@ -41,7 +41,7 @@ pub mod prelude { pub use crate::runtime::api::StreamTag; pub use crate::runtime::{ Callable, Command, Device, DynCallable, Kernel, KernelBuildOptions, KernelDef, Scope, - Stream, + Stream, Swapchain, }; pub use crate::{cpu_dbg, if_, lc_assert, lc_unreachable, loop_, while_, Context}; From 441672687dc5ff663abfc16eeb84e0742325731a Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 25 Sep 2023 15:46:48 +0100 Subject: [PATCH 3/7] Added debug implementations for Textures and Buffers. --- luisa_compute/src/resource.rs | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index a228d50..09d1d67 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -1,4 +1,5 @@ use std::cell::{Cell, RefCell}; +use std::fmt; use std::ops::RangeBounds; use std::process::abort; use std::sync::Arc; @@ -279,6 +280,32 @@ pub struct Buffer { pub(crate) len: usize, pub(crate) _marker: PhantomData, } +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("..") + } + } + + write!(f, "Buffer<{}>({})", std::any::type_name::(), self.len())?; + if let Some(count) = f.precision() { + if count > self.len() { + f.debug_list().entries(self.copy_to_vec().iter()).finish()?; + } else { + let values = self.view(0..count).copy_to_vec(); + + f.debug_list() + .entries(values.iter()) + .entry(&DebugEllipsis) + .finish()?; + } + } + Ok(()) + } +} + pub(crate) struct BufferHandle { pub(crate) device: Device, pub(crate) handle: api::Buffer, @@ -1060,6 +1087,17 @@ pub struct Tex2d { pub(crate) handle: Arc, pub(crate) marker: PhantomData, } +impl fmt::Debug for Tex2d { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Tex2d<{}>({}, {})", + std::any::type_name::(), + self.width(), + self.height(), + ) + } +} // `T` is the read out type of the texture, which is not necessarily the same as // the storage type In fact, the texture can be stored in any format as long as @@ -1074,6 +1112,19 @@ pub struct Tex3d { pub(crate) handle: Arc, pub(crate) marker: PhantomData, } +impl fmt::Debug for Tex3d { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Tex3d<{}>({}, {}, {})", + std::any::type_name::(), + self.width(), + self.height(), + self.depth(), + ) + } +} + #[derive(Clone, Copy)] pub struct Tex2dView<'a, T: IoTexel> { pub(crate) tex: &'a Tex2d, From 1a894aa6fab25f83f74858aa9bbbd9c4691f01b2 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 25 Sep 2023 15:53:56 +0100 Subject: [PATCH 4/7] Debug patch. --- luisa_compute/src/resource.rs | 7 ++++--- luisa_compute/src/rtx.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index 09d1d67..d632dfd 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -290,8 +290,9 @@ impl fmt::Debug for Buffer { } write!(f, "Buffer<{}>({})", std::any::type_name::(), self.len())?; - if let Some(count) = f.precision() { - if count > self.len() { + if self.len() <= 16 || f.precision().is_some() { + let count = f.precision().unwrap_or(16); + if count >= self.len() { f.debug_list().entries(self.copy_to_vec().iter()).finish()?; } else { let values = self.view(0..count).copy_to_vec(); @@ -876,7 +877,7 @@ unsafe impl Sync for BindlessArray {} pub use api::{PixelFormat, PixelStorage, Sampler, SamplerAddress, SamplerFilter}; use luisa_compute_ir::context::type_hash; use luisa_compute_ir::ir::{ - new_node, Binding, BindlessArrayBinding, BufferBinding, Func, Instruction, Node, TextureBinding, + Binding, BindlessArrayBinding, BufferBinding, Func, Instruction, Node, TextureBinding, }; pub(crate) struct TextureHandle { diff --git a/luisa_compute/src/rtx.rs b/luisa_compute/src/rtx.rs index 50d9295..4159fef 100644 --- a/luisa_compute/src/rtx.rs +++ b/luisa_compute/src/rtx.rs @@ -7,7 +7,7 @@ use crate::internal_prelude::*; use crate::runtime::*; use crate::{ResourceTracker, *}; use luisa_compute_ir::ir::{ - new_node, AccelBinding, Binding, Func, Instruction, IrBuilder, Node, NodeRef, Type, + AccelBinding, Binding, Func, Instruction, IrBuilder, Node, NodeRef, Type, }; use parking_lot::RwLock; use std::ops::Deref; From 8c36496d5b54774201dc6e60fc18eb331eea2424 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Tue, 26 Sep 2023 21:53:34 +0100 Subject: [PATCH 5/7] Fixed copy_from_async fns. --- luisa_compute/examples/path_tracer.rs | 6 +++--- luisa_compute/examples/path_tracer_cutout.rs | 6 +++--- luisa_compute/src/resource.rs | 10 ++++++++-- luisa_compute/src/runtime.rs | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/luisa_compute/examples/path_tracer.rs b/luisa_compute/examples/path_tracer.rs index 8fdd0b0..357b4ce 100644 --- a/luisa_compute/examples/path_tracer.rs +++ b/luisa_compute/examples/path_tracer.rs @@ -250,9 +250,9 @@ fn main() { let path_tracer = Kernel::, Tex2d, Accel, Uint2)>::new_async( &device, &track!(|image: Tex2dVar, - seed_image: Tex2dVar, - accel: AccelVar, - resolution: Expr| { + seed_image: Tex2dVar, + accel: AccelVar, + resolution: Expr| { set_block_size([16u32, 16u32, 1u32]); let cbox_materials = ([ Float3::new(0.725f32, 0.710f32, 0.680f32), // floor diff --git a/luisa_compute/examples/path_tracer_cutout.rs b/luisa_compute/examples/path_tracer_cutout.rs index 4fee5d3..8c697b1 100644 --- a/luisa_compute/examples/path_tracer_cutout.rs +++ b/luisa_compute/examples/path_tracer_cutout.rs @@ -260,9 +260,9 @@ fn main() { let path_tracer = Kernel::, Tex2d, Accel, Uint2)>::new_async( &device, &track!(|image: Tex2dVar, - seed_image: Tex2dVar, - accel: AccelVar, - resolution: Expr| { + seed_image: Tex2dVar, + accel: AccelVar, + resolution: Expr| { set_block_size([16u32, 16u32, 1u32]); let cbox_materials = [ Float3::new(0.725f32, 0.710f32, 0.680f32), // floor diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index d632dfd..467fb21 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -364,7 +364,7 @@ impl<'a, T: Value> BufferView<'a, T> { } } - pub fn copy_from_async<'b>(&'a self, data: &'b [T]) -> Command<'static> { + pub fn copy_from_async<'b>(&'a self, data: &'b [T]) -> Command<'b> { assert_eq!(data.len(), self.len); let mut rt = ResourceTracker::new(); rt.add(self.buffer.handle.clone()); @@ -434,7 +434,7 @@ impl Buffer { self.view(..).copy_from(data); } #[inline] - pub fn copy_from_async<'a>(&self, data: &[T]) -> Command<'_> { + pub fn copy_from_async<'a>(&self, data: &'a [T]) -> Command<'a> { self.view(..).copy_from_async(data) } #[inline] @@ -526,6 +526,12 @@ pub struct BufferHeap { pub(crate) inner: BindlessArray, pub(crate) _marker: PhantomData, } +impl fmt::Debug for BufferHeap { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "BufferHeap<{}>", std::any::type_name::(),) + } +} + pub struct BufferHeapVar { inner: BindlessArrayVar, _marker: PhantomData, diff --git a/luisa_compute/src/runtime.rs b/luisa_compute/src/runtime.rs index 2ad0783..30fa142 100644 --- a/luisa_compute/src/runtime.rs +++ b/luisa_compute/src/runtime.rs @@ -879,6 +879,7 @@ pub fn submit_default_stream_and_sync<'a, I: IntoIterator>>( }) } +#[must_use] pub struct Command<'a> { #[allow(dead_code)] pub(crate) inner: api::Command, From c7640f2fb81195662711cd540bbee8897056a0cf Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Wed, 27 Sep 2023 21:27:27 +0100 Subject: [PATCH 6/7] Make copy_from 'static. --- luisa_compute/src/resource.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index 467fb21..989f470 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -364,7 +364,7 @@ impl<'a, T: Value> BufferView<'a, T> { } } - pub fn copy_from_async<'b>(&'a self, data: &'b [T]) -> Command<'b> { + pub fn copy_from_async<'b>(&'a self, data: &'b [T]) -> Command<'static> { assert_eq!(data.len(), self.len); let mut rt = ResourceTracker::new(); rt.add(self.buffer.handle.clone()); From e81ebf6464cd5bf7b6653ed6c94db2cf7bd968e8 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Fri, 29 Sep 2023 13:52:17 +0100 Subject: [PATCH 7/7] Comment out potentially blocking impl. --- luisa_compute/src/resource.rs | 26 +++++++++++++------------- luisa_compute_sys/LuisaCompute | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/luisa_compute/src/resource.rs b/luisa_compute/src/resource.rs index 989f470..9cfe65f 100644 --- a/luisa_compute/src/resource.rs +++ b/luisa_compute/src/resource.rs @@ -290,19 +290,19 @@ impl fmt::Debug for Buffer { } write!(f, "Buffer<{}>({})", std::any::type_name::(), self.len())?; - if self.len() <= 16 || f.precision().is_some() { - let count = f.precision().unwrap_or(16); - if count >= self.len() { - f.debug_list().entries(self.copy_to_vec().iter()).finish()?; - } else { - let values = self.view(0..count).copy_to_vec(); - - f.debug_list() - .entries(values.iter()) - .entry(&DebugEllipsis) - .finish()?; - } - } + // if self.len() <= 16 || f.precision().is_some() { + // let count = f.precision().unwrap_or(16); + // if count >= self.len() { + // f.debug_list().entries(self.copy_to_vec().iter()).finish()?; + // } else { + // let values = self.view(0..count).copy_to_vec(); + // + // f.debug_list() + // .entries(values.iter()) + // .entry(&DebugEllipsis) + // .finish()?; + // } + // } Ok(()) } } diff --git a/luisa_compute_sys/LuisaCompute b/luisa_compute_sys/LuisaCompute index bcc49cd..fbb048b 160000 --- a/luisa_compute_sys/LuisaCompute +++ b/luisa_compute_sys/LuisaCompute @@ -1 +1 @@ -Subproject commit bcc49cdeb6004b62cd7cfc68010902e47682b5af +Subproject commit fbb048bd662bab74f373935af495f23e655cab48