Skip to content

Commit

Permalink
Merge pull request #26 from iMplode-nZ/main
Browse files Browse the repository at this point in the history
Added buffer length; texture clone; clippy fix.
  • Loading branch information
shiinamiyuki authored Oct 18, 2023
2 parents 794318e + e0e9161 commit 704bb81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
5 changes: 5 additions & 0 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ impl<'a, T: Value> BufferView<'a, T> {
pub fn handle(&self) -> api::Buffer {
self.buffer.handle()
}
pub fn len(&self) -> usize {
self.len
}
pub fn copy_to_async<'b>(&'a self, data: &'b mut [T]) -> Command<'b, 'b> {
assert_eq!(data.len(), self.len);
let mut rt = ResourceTracker::new();
Expand Down Expand Up @@ -1075,6 +1078,7 @@ impl_storage_texel!([f16; 4], Byte4, f32, Float2, Float4, Int2, Int4, Uint2, Uin
// `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
// it can be converted to `T`
#[derive(Clone)]
pub struct Tex2d<T: IoTexel> {
#[allow(dead_code)]
pub(crate) width: u32,
Expand All @@ -1098,6 +1102,7 @@ impl<T: IoTexel + fmt::Debug> fmt::Debug for Tex2d<T> {
// `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
// it can be converted to `T`
#[derive(Clone)]
pub struct Tex3d<T: IoTexel> {
#[allow(dead_code)]
pub(crate) width: u32,
Expand Down
6 changes: 2 additions & 4 deletions luisa_compute_derive_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ impl Compiler {
#vis fn from_comps_expr(ctor: #ctor_proxy_name #ty_generics) -> #lang_path::types::Expr<#name #ty_generics> {
use #lang_path::*;
let node = #lang_path::__compose::<#name #ty_generics>(&[ #( #lang_path::ToNode::node(&ctor.#field_names.as_expr()).get() ),* ]);
let expr = <#lang_path::types::Expr::<#name> as #lang_path::FromNode>::from_node(node.into());
expr
<#lang_path::types::Expr::<#name> as #lang_path::FromNode>::from_node(node.into())
}
}
)
Expand Down Expand Up @@ -454,8 +453,7 @@ impl Compiler {
#vis fn new_expr(#(#field_names: impl #lang_path::types::AsExpr<Value = #field_types>),*) -> #lang_path::types::Expr::<#name> {
use #lang_path::*;
let node = #lang_path::__compose::<#name #ty_generics>(&[ #( #lang_path::ToNode::node(&#field_names.as_expr()).get() ),* ]);
let expr = <#lang_path::types::Expr::<#name> as #lang_path::FromNode>::from_node(node.into());
expr
<#lang_path::types::Expr::<#name> as #lang_path::FromNode>::from_node(node.into())
}
}
}
Expand Down
28 changes: 13 additions & 15 deletions luisa_compute_track/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ impl VisitMut for TraceVisitor {
}
}
}
Stmt::Item(item) => match item {
Item::Const(c) => match c.expr.as_ref() {
Expr::Lit(_) => {}
_ => {
panic!("Please wrap CONST statments with `escape!`");
}
},
_ => {}
Stmt::Item(Item::Const(c)) => match c.expr.as_ref() {
Expr::Lit(_) => {}
_ => {
panic!("Please wrap CONST statments with `escape!`");
}
},
_ => {}
}
Expand Down Expand Up @@ -99,15 +96,15 @@ impl VisitMut for TraceVisitor {
if let Expr::Let(_) = **cond {
} else if let Some((_, else_branch)) = else_branch {
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("if",
#debug_path::with_lineno("if",
file!(),
line!(),
column!(),
|| <_ as #trait_path::SelectMaybeExpr<_>>::if_then_else(#cond, || #then_branch, || #else_branch))
}
} else {
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("if",
#debug_path::with_lineno("if",
file!(),
line!(),
column!(),
Expand All @@ -119,7 +116,7 @@ impl VisitMut for TraceVisitor {
let cond = &expr.cond;
let body = &expr.body;
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("while",
#debug_path::with_lineno("while",
file!(),
line!(),
column!(), ||<_ as #trait_path::LoopMaybeExpr>::while_loop(|| #cond, || #body))
Expand All @@ -128,7 +125,7 @@ impl VisitMut for TraceVisitor {
Expr::Loop(expr) => {
let body = &expr.body;
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("loop",
#debug_path::with_lineno("loop",
file!(),
line!(),
column!(), || #flow_path::loop_(|| #body))
Expand All @@ -144,14 +141,14 @@ impl VisitMut for TraceVisitor {
let unroll = attrs.iter().any(|attr| attr.path().is_ident("unroll"));
if unroll {
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("for range",
#debug_path::with_lineno("for range",
file!(),
line!(),
column!(), || #range.for_each(|#pat| #body))
}
} else {
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("for range",
*node = parse_quote_spanned! {span=>
#debug_path::with_lineno("for range",
file!(),
line!(),
column!(), ||#flow_path::for_range(#range, |#pat| #body))
Expand Down Expand Up @@ -380,6 +377,7 @@ pub fn tracked(
name.strip_suffix("::f").unwrap()
};
::luisa_compute::lang::debug::comment(&format!("begin fn {} at {}:{}:{}", __fn_name, file!(), line!(), column!()));
#[allow(clippy::let_unit_value)]
let __ret: #ret_type = #body;
#[allow(unreachable_code)]
{
Expand Down

0 comments on commit 704bb81

Please sign in to comment.