MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / final_image

Method final_image

examples/cuda/cpu/path_tracer/src/cuda/mod.rs:117–190  ·  view source on GitHub ↗

Run postprocessing on the accumulated buffer, color correct it, and divide it by the total samples to yield a final image that can be displayed. Also returns the denoising time and postprocessing time.

(
        &mut self,
        cur_sample: usize,
        denoise: bool,
    )

Source from the content-addressed store, hash-verified

115 ///
116 /// Also returns the denoising time and postprocessing time.
117 pub fn final_image(
118 &mut self,
119 cur_sample: usize,
120 denoise: bool,
121 ) -> CudaResult<(&[Vec3<u8>], Duration, Duration)> {
122 let module = &self.module;
123 let stream = &self.stream;
124
125 let (blocks, threads) = self.launch_dimensions();
126 let width = self.buffers.viewport.bounds.x as u32;
127 let height = self.buffers.viewport.bounds.y as u32;
128
129 let start = Event::new(EventFlags::DEFAULT)?;
130 let denoising_stop = Event::new(EventFlags::DEFAULT)?;
131 let postprocessing_stop = Event::new(EventFlags::DEFAULT)?;
132
133 start.record(stream)?;
134
135 unsafe {
136 launch!(
137 module.scale_buffer<<<blocks, threads, 0, stream>>>(
138 self.buffers.accumulated_buffer.as_device_ptr(),
139 self.buffers.scaled_buffer.as_device_ptr(),
140 cur_sample,
141 self.buffers.viewport
142 )
143 )?;
144 }
145
146 let input_buf = if denoise {
147 let input_image = Image::new(
148 &self.buffers.scaled_buffer,
149 ImageFormat::Float3,
150 width,
151 height,
152 );
153
154 self.denoiser
155 .invoke(
156 stream,
157 Default::default(),
158 input_image,
159 Default::default(),
160 &mut self.buffers.denoised_buffer,
161 )
162 .unwrap();
163
164 self.buffers.denoised_buffer.as_device_ptr()
165 } else {
166 self.buffers.scaled_buffer.as_device_ptr()
167 };
168
169 denoising_stop.record(stream)?;
170
171 unsafe {
172 launch!(
173 module.postprocess<<<blocks, threads, 0, stream>>>(
174 input_buf,

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
launch_dimensionsMethod · 0.80
recordMethod · 0.80
elapsedMethod · 0.80
invokeMethod · 0.45
as_device_ptrMethod · 0.45
synchronizeMethod · 0.45
copy_toMethod · 0.45

Tested by

no test coverage detected