Skip to content

Commit

Permalink
working on oidn for dx
Browse files Browse the repository at this point in the history
shiinamiyuki committed Nov 6, 2023
1 parent ef73fa2 commit 05b6875
Showing 4 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions luisa_compute/examples/denoiser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use image::Rgb;
use luisa::runtime::extension::Denoiser;
use luisa::runtime::extension::DenoiserInput;
use luisa::runtime::DeviceExtensions;
use luisa_compute_api_types::denoiser_ext::{ImageColorSpace, ImageFormat, PrefilterMode};
use luisa_compute_api_types::StreamTag;
@@ -494,21 +494,21 @@ fn run_pt(device: Device) {
.unwrap_or_else(|| panic!("denoiser not available on current device"));
let mut denoiser = ext.create(&device.default_stream());
{
let mut inputs = Denoiser::input_builder(img_w, img_h);
inputs.push_image(
let mut inputs = DenoiserInput::new(img_w, img_h);
inputs.push_noisy_image(
&color_buf.view(..),
&output_buf.view(..),
ImageFormat::Float3,
ImageColorSpace::Hdr,
None,
);
inputs.set_feature_image(
inputs.push_feature_image(
"albedo",
&albedo_buf.view(..),
ImageFormat::Float3,
ImageColorSpace::Hdr,
);
inputs.set_feature_image(
inputs.push_feature_image(
"normal",
&normal_buf.view(..),
ImageFormat::Float3,
3 changes: 3 additions & 0 deletions luisa_compute/src/resource.rs
Original file line number Diff line number Diff line change
@@ -342,6 +342,7 @@ pub struct BufferView<T: Value> {
pub(crate) offset: usize,
/// length in #elements
pub(crate) len: usize,
pub(crate) total_size_bytes: usize,
pub(crate) _marker: PhantomData<fn() -> T>,
}
impl<T: Value> BufferView<T> {
@@ -357,6 +358,7 @@ impl<T: Value> BufferView<T> {
handle: self.handle.clone(),
offset: self.offset,
len: self.len * std::mem::size_of::<T>() / std::mem::size_of::<U>(),
total_size_bytes: self.total_size_bytes,
_marker: PhantomData,
}
}
@@ -482,6 +484,7 @@ impl<T: Value> BufferView<T> {
handle: self.handle.clone(),
offset: lower,
len: upper - lower,
total_size_bytes: self.total_size_bytes,
_marker: PhantomData,
}
}
20 changes: 9 additions & 11 deletions luisa_compute/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -101,20 +101,20 @@ impl Drop for DeviceHandle {
}
pub mod extension {
use super::*;
use api::denoiser_ext::{DenoiserInput, Feature, Image};
use api::denoiser_ext::{Feature, Image};
pub use api::denoiser_ext::{ImageColorSpace, ImageFormat, PrefilterMode};
pub struct DenosierInputBuilder {
inner: DenoiserInput,
pub struct DenoiserInput {
inner: api::denoiser_ext::DenoiserInput,
inputs: Vec<Image>,
features: Vec<Feature>,
outputs: Vec<Image>,
rt: ResourceTracker,
names: Vec<CString>,
}
impl DenosierInputBuilder {
impl DenoiserInput {
pub fn new(width: u32, height: u32) -> Self {
Self {
inner: DenoiserInput {
inner: api::denoiser_ext::DenoiserInput {
inputs: std::ptr::null_mut(),
inputs_count: 0,
outputs: std::ptr::null_mut(),
@@ -161,7 +161,7 @@ pub mod extension {
}
/// Add an (input, output) image pair to the denoiser input.
/// The denoiser holds a weak reference to the buffers.
pub fn push_image<T: Value, U: Value>(
pub fn push_noisy_image<T: Value, U: Value>(
&mut self,
input: &BufferView<T>,
output: &BufferView<U>,
@@ -177,7 +177,7 @@ pub mod extension {
}
/// Add a feature image to the denoiser input.
/// The denoiser holds a weak reference to the buffer.
pub fn set_feature_image<S: AsRef<str>, T: Value>(
pub fn push_feature_image<S: AsRef<str>, T: Value>(
&mut self,
name: S,
image: &BufferView<T>,
@@ -231,12 +231,9 @@ pub mod extension {
}
}
impl Denoiser {
pub fn input_builder(width: u32, height: u32) -> DenosierInputBuilder {
DenosierInputBuilder::new(width, height)
}
/// Initialize the denoiser with the given input.
/// Blocks if the denoiser is still running.
pub fn init(&mut self, mut input: DenosierInputBuilder) {
pub fn init(&mut self, mut input: DenoiserInput) {
unsafe {
let inner = &mut input.inner;
inner.inputs = input.inputs.as_ptr();
@@ -440,6 +437,7 @@ impl Device {
handle: Arc::downgrade(&handle),
offset: 0,
len: count,
total_size_bytes: buffer.total_size_bytes,
_marker: PhantomData,
},
};

0 comments on commit 05b6875

Please sign in to comment.