diff options
author | Stefan Werner <stefan.werner@tangent-animation.com> | 2020-03-05 14:05:42 +0300 |
---|---|---|
committer | Stefan Werner <stefan.werner@tangent-animation.com> | 2020-03-05 14:21:38 +0300 |
commit | 51e898324de30c0985a80e5bc067358b5ccedbfc (patch) | |
tree | 5efddead1b7ca5655f1d6d2422b59e7da51fe271 /intern/cycles/device/device_optix.cpp | |
parent | 4ccbbd308060f0330472828b317c59e054c9ee7b (diff) |
Adaptive Sampling for Cycles.
This feature takes some inspiration from
"RenderMan: An Advanced Path Tracing Architecture for Movie Rendering" and
"A Hierarchical Automatic Stopping Condition for Monte Carlo Global Illumination"
The basic principle is as follows:
While samples are being added to a pixel, the adaptive sampler writes half
of the samples to a separate buffer. This gives it two separate estimates
of the same pixel, and by comparing their difference it estimates convergence.
Once convergence drops below a given threshold, the pixel is considered done.
When a pixel has not converged yet and needs more samples than the minimum,
its immediate neighbors are also set to take more samples. This is done in order
to more reliably detect sharp features such as caustics. A 3x3 box filter that
is run periodically over the tile buffer is used for that purpose.
After a tile has finished rendering, the values of all passes are scaled as if
they were rendered with the full number of samples. This way, any code operating
on these buffers, for example the denoiser, does not need to be changed for
per-pixel sample counts.
Reviewed By: brecht, #cycles
Differential Revision: https://developer.blender.org/D4686
Diffstat (limited to 'intern/cycles/device/device_optix.cpp')
-rw-r--r-- | intern/cycles/device/device_optix.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp index 61a5c74f69e..30d624fdf7c 100644 --- a/intern/cycles/device/device_optix.cpp +++ b/intern/cycles/device/device_optix.cpp @@ -627,7 +627,11 @@ class OptiXDevice : public CUDADevice { const int end_sample = rtile.start_sample + rtile.num_samples; // Keep this number reasonable to avoid running into TDRs - const int step_samples = (info.display_device ? 8 : 32); + int step_samples = (info.display_device ? 8 : 32); + if (task.adaptive_sampling.use) { + step_samples = task.adaptive_sampling.align_static_samples(step_samples); + } + // Offset into launch params buffer so that streams use separate data device_ptr launch_params_ptr = launch_params.device_pointer + thread_index * launch_params.data_elements; @@ -638,10 +642,9 @@ class OptiXDevice : public CUDADevice { // Copy work tile information to device wtile.num_samples = min(step_samples, end_sample - sample); wtile.start_sample = sample; - check_result_cuda(cuMemcpyHtoDAsync(launch_params_ptr + offsetof(KernelParams, tile), - &wtile, - sizeof(wtile), - cuda_stream[thread_index])); + device_ptr d_wtile_ptr = launch_params_ptr + offsetof(KernelParams, tile); + check_result_cuda( + cuMemcpyHtoDAsync(d_wtile_ptr, &wtile, sizeof(wtile), cuda_stream[thread_index])); OptixShaderBindingTable sbt_params = {}; sbt_params.raygenRecord = sbt_data.device_pointer + PG_RGEN * sizeof(SbtRecord); @@ -666,6 +669,12 @@ class OptiXDevice : public CUDADevice { wtile.h, 1)); + // Run the adaptive sampling kernels at selected samples aligned to step samples. + uint filter_sample = wtile.start_sample + wtile.num_samples - 1; + if (task.adaptive_sampling.use && task.adaptive_sampling.need_filter(filter_sample)) { + adaptive_sampling_filter(filter_sample, &wtile, d_wtile_ptr, cuda_stream[thread_index]); + } + // Wait for launch to finish check_result_cuda(cuStreamSynchronize(cuda_stream[thread_index])); @@ -677,6 +686,14 @@ class OptiXDevice : public CUDADevice { if (task.get_cancel() && !task.need_finish_queue) return; // Cancel rendering } + + // Finalize adaptive sampling + if (task.adaptive_sampling.use) { + device_ptr d_wtile_ptr = launch_params_ptr + offsetof(KernelParams, tile); + adaptive_sampling_post(rtile, &wtile, d_wtile_ptr, cuda_stream[thread_index]); + check_result_cuda(cuStreamSynchronize(cuda_stream[thread_index])); + task.update_progress(&rtile, rtile.w * rtile.h * wtile.num_samples); + } } bool launch_denoise(DeviceTask &task, RenderTile &rtile) |