Skip to content

Commit

Permalink
added address() method for interop with external code
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Dec 4, 2023
1 parent 9ed12f0 commit 96049ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions luisa_compute/src/lang/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ impl<T: Value> Expr<T> {
pub fn _type_tag(&self) -> TypeTag<T> {
TypeTag(PhantomData)
}
/// Address of this `Expr`, only available in some backends.
pub fn address(&self) -> Expr<u64> {
let self_node = self.node().get();
let node = __current_scope(|b| b.call(Func::AddressOf, &[self_node], u64::type_()));
Expr::<u64>::from_node(node.into())
}
}

impl<T: Value> Var<T> {
Expand Down Expand Up @@ -344,6 +350,12 @@ impl<T: Value> Var<T> {
pub fn store(&self, value: impl AsExpr<Value = T>) {
crate::lang::_store(self, &value.as_expr());
}
/// Address of this `Var`, only available in some backends.
pub fn address(&self) -> Expr<u64> {
let self_node = self.node().get();
let node = __current_scope(|b| b.call(Func::AddressOf, &[self_node], u64::type_()));
Expr::<u64>::from_node(node.into())
}
}
impl<T: Value> AtomicRef<T> {
pub fn _ref<'a>(self) -> &'a Self {
Expand Down
24 changes: 24 additions & 0 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,14 @@ pub struct BufferVar<T: Value> {
pub(crate) handle: Option<Arc<BufferHandle>>,
pub(crate) node: SafeNodeRef,
}
impl<T: Value> BufferVar<T> {
pub fn device_address(&self) -> Expr<u64> {
let buf = self.node().get();
Expr::from_node(
__current_scope(|b| b.call(Func::BufferAddress, &[buf], u64::type_())).into(),
)
}
}
impl<T: Value> ToNode for BufferVar<T> {
fn node(&self) -> SafeNodeRef {
self.node
Expand All @@ -1423,6 +1431,22 @@ impl<T: Value> ToNode for BindlessBufferVar<T> {
self.array
}
}
impl<T: Value> BindlessBufferVar<T> {
pub fn device_address(&self) -> Expr<u64> {
let array = self.array.get();
let buffer_index = self.buffer_index.node().get();
Expr::from_node(
__current_scope(|b| {
b.call(
Func::BindlessBufferAddress,
&[array, buffer_index],
u64::type_(),
)
})
.into(),
)
}
}

impl<T: Value> IndexRead for BindlessBufferVar<T> {
type Element = T;
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 41 files
+7 −1 bootstrap.py
+1 −2 include/luisa/ast/statement.h
+10 −13 include/luisa/backends/ext/dstorage_ext.hpp
+1 −0 include/luisa/backends/ext/dstorage_ext_interface.h
+9 −1 include/luisa/core/logging.h
+10 −0 include/luisa/core/stl/format.h
+19 −0 include/luisa/core/stl/memory.h
+19 −0 include/luisa/core/stl/optional.h
+5 −0 include/luisa/rust/ir.hpp
+1 −1 scripts/validate_options.cmake
+5 −0 src/ast/statement.cpp
+4 −4 src/backends/common/hlsl/access_chain.cpp
+1 −0 src/backends/common/shader_print_formatter.h
+5 −5 src/backends/cuda/cuda_device.cpp
+1 −1 src/backends/cuda/cuda_error.h
+49 −0 src/backends/cuda/cuda_shader.cpp
+4 −2 src/backends/cuda/cuda_shader.h
+5 −25 src/backends/cuda/cuda_shader_native.cpp
+2 −5 src/backends/cuda/cuda_shader_native.h
+23 −10 src/backends/cuda/cuda_shader_optix.cpp
+2 −4 src/backends/cuda/cuda_shader_optix.h
+71 −9 src/backends/cuda/cuda_stream.cpp
+8 −4 src/backends/dx/DXApi/LCCmdBuffer.cpp
+7 −2 src/backends/dx/DXApi/ext.cpp
+1 −1 src/backends/dx/DXApi/ext.h
+6 −16 src/backends/dx/DXRuntime/CommandQueue.cpp
+1 −2 src/backends/dx/DXRuntime/CommandQueue.h
+32 −28 src/backends/dx/DXRuntime/DStorageCommandQueue.cpp
+2 −3 src/backends/dx/DXRuntime/DStorageCommandQueue.h
+11 −1 src/core/logging.cpp
+1 −1 src/ext/glfw
+2 −3 src/runtime/image.cpp
+4 −0 src/runtime/volume.cpp
+29 −0 src/rust/luisa_compute_backend_impl/src/cpu/codegen/cpp.rs
+17 −0 src/rust/luisa_compute_backend_impl/src/cpu/codegen/cpu_resource.h
+5 −0 src/rust/luisa_compute_ir/src/ir.rs
+55 −50 src/tests/CMakeLists.txt
+9 −9 src/tests/common/config.h
+48 −15 src/tests/test_dstorage.cpp
+4 −3 src/tests/test_swapchain_wx.cpp
+0 −2 src/tests/test_type.cpp

0 comments on commit 96049ef

Please sign in to comment.