Skip to content

Commit

Permalink
added BufferHeap<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Aug 30, 2023
1 parent e1e9b08 commit e3c9b92
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
58 changes: 56 additions & 2 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use std::process::abort;

use std::sync::Arc;
pub struct ByteBuffer {
inner:Buffer<u32>,
inner: Buffer<u32>,
}
pub struct ByteBufferVar {
inner:BufferVar<u32>,
inner: BufferVar<u32>,
}
pub struct Buffer<T: Value> {
pub(crate) device: Device,
Expand Down Expand Up @@ -239,6 +239,60 @@ pub(crate) struct BindlessArraySlot {
pub(crate) tex2d: Option<Arc<TextureHandle>>,
pub(crate) tex3d: Option<Arc<TextureHandle>>,
}
pub struct BufferHeap<T: Value> {
pub(crate) inner: BindlessArray,
pub(crate) _marker: std::marker::PhantomData<T>,
}
pub struct BufferHeapVar<T: Value> {
inner: BindlessArrayVar,
_marker: std::marker::PhantomData<T>,
}
impl<T: Value> BufferHeap<T> {
#[inline]
pub fn var(&self) -> BufferHeapVar<T> {
BufferHeapVar {
inner: self.inner.var(),
_marker: std::marker::PhantomData,
}
}
#[inline]
pub fn handle(&self) -> api::BindlessArray {
self.inner.handle()
}
#[inline]
pub fn native_handle(&self) -> *mut std::ffi::c_void {
self.inner.native_handle()
}
pub fn emplace_buffer_async(&self, index: usize, buffer: &Buffer<T>) {
self.inner.emplace_buffer_async(index, buffer);
}
pub fn emplace_buffer_view_async<'a>(&self, index: usize, bufferview: &BufferView<'a, T>) {
self.inner.emplace_bufferview_async(index, bufferview);
}
pub fn remove_buffer_async(&self, index: usize) {
self.inner.remove_buffer_async(index);
}
#[inline]
pub fn emplace_buffer(&self, index: usize, buffer: &Buffer<T>) {
self.inner.emplace_buffer(index, buffer);
}
#[inline]
pub fn emplace_buffer_view<'a>(&self, index: usize, bufferview: &BufferView<'a, T>) {
self.inner.emplace_bufferview_async(index, bufferview);
}
#[inline]
pub fn remove_buffer(&self, index: usize) {
self.inner.remove_buffer(index);
}
#[inline]
pub fn update(&self) {
self.inner.update();
}
#[inline]
pub fn buffer(&self, index: impl Into<Expr<u32>>) -> BindlessBufferVar<T> {
self.inner.buffer(index)
}
}
pub struct BindlessArray {
pub(crate) device: Device,
pub(crate) handle: Arc<BindlessArrayHandle>,
Expand Down
7 changes: 7 additions & 0 deletions luisa_compute/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ impl Device {
buffer.view(..).fill_fn(f);
buffer
}
pub fn create_buffer_heap<T: Value>(&self, slots: usize) -> BufferHeap<T> {
let array = self.create_bindless_array(slots);
BufferHeap {
inner: array,
_marker: std::marker::PhantomData {},
}
}
pub fn create_bindless_array(&self, slots: usize) -> BindlessArray {
let array = self.inner.create_bindless_array(slots);
BindlessArray {
Expand Down
2 changes: 1 addition & 1 deletion luisa_compute_sys/LuisaCompute
Submodule LuisaCompute updated 44 files
+12 −5 include/luisa/ast/op.h
+18 −0 include/luisa/backends/ext/registry.h
+10 −0 include/luisa/core/magic_enum.h
+138 −6 include/luisa/ir/ir.h
+5 −3 include/luisa/rust/ir.hpp
+2 −2 scripts/setup_compilation.cmake
+3 −1 src/backends/cuda/cuda_builtin/cuda_device_resource.h
+1,030 −1,020 src/backends/cuda/cuda_builtin_embedded.cpp
+1 −1 src/backends/cuda/cuda_builtin_embedded.h
+25 −1 src/backends/cuda/cuda_codegen_ast.cpp
+2 −0 src/backends/cuda/cuda_codegen_ast.h
+2 −2 src/backends/dx/Shader/ComputeShader.cpp
+1 −1 src/backends/dx/Shader/RasterShader.cpp
+4 −1 src/backends/dx/Shader/Shader.cpp
+3 −3 src/backends/dx/Shader/Shader.h
+327 −13 src/backends/metal/metal_builtin/metal_device_lib.metal
+3,204 −2,485 src/backends/metal/metal_builtin_embedded.cpp
+1 −1 src/backends/metal/metal_builtin_embedded.h
+29 −24 src/backends/metal/metal_codegen_ast.cpp
+36 −41 src/ir/ast2ir.cpp
+31 −0 src/ir/ir2ast.cpp
+7 −2 src/rust/CMakeLists.txt
+5 −5 src/rust/luisa_compute_backend/src/lib.rs
+1 −2 src/rust/luisa_compute_backend/src/proxy.rs
+0 −8 src/rust/luisa_compute_backend_impl/Cargo.toml
+3 −6 src/rust/luisa_compute_backend_impl/src/cpu/codegen/cpp.rs
+46 −15 src/rust/luisa_compute_backend_impl/src/cpu/llvm.rs
+2 −2 src/rust/luisa_compute_backend_impl/src/cpu/mod.rs
+1 −2 src/rust/luisa_compute_backend_impl/src/cpu/resource.rs
+1 −2 src/rust/luisa_compute_backend_impl/src/cpu/shader.rs
+4 −8 src/rust/luisa_compute_backend_impl/src/cpu/stream.rs
+16 −9 src/rust/luisa_compute_backend_impl/src/cpu/texture.rs
+3 −3 src/rust/luisa_compute_backend_impl/src/lib.rs
+0 −1 src/rust/luisa_compute_ir/src/display.rs
+1 −1 src/rust/luisa_compute_ir/src/ffi.rs
+6 −8 src/rust/luisa_compute_ir/src/ir.rs
+27 −4 src/rust/luisa_compute_ir/src/serialize/convert.rs
+58 −19 src/rust/luisa_compute_ir/src/serialize/mod.rs
+0 −1 src/rust/luisa_compute_ir/src/transform/autodiff.rs
+1 −1 src/rust/luisa_compute_ir/src/transform/canonicalize_control_flow.rs
+2 −2 src/rust/luisa_compute_ir/src/transform/eval.rs
+13 −14 src/rust/luisa_compute_ir/src/transform/reg2mem.rs
+1 −1 src/rust/luisa_compute_ir/src/transform/ssa.rs
+2 −2 src/rust/luisa_compute_ir/src/usage_detect.rs

0 comments on commit e3c9b92

Please sign in to comment.