Blender V4.3
denoiser.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7/* TODO(sergey): The integrator folder might not be the best. Is easy to move files around if the
8 * better place is figured out. */
9
10#include "device/denoise.h"
11#include "device/device.h"
12#include "util/function.h"
13#include "util/unique_ptr.h"
14
16
17class BufferParams;
18class Device;
19class RenderBuffers;
20class Progress;
21
22bool use_optix_denoiser(Device *denoiser_device, const DenoiseParams &params);
23
24bool use_gpu_oidn_denoiser(Device *denoiser_device, const DenoiseParams &params);
25
27 Device *cpu_fallback_device,
28 const DenoiseParams &params,
29 Device *&single_denoiser_device);
30
31/* Implementation of a specific denoising algorithm.
32 *
33 * This class takes care of breaking down denoising algorithm into a series of device calls or to
34 * calls of an external API to denoise given input.
35 *
36 * TODO(sergey): Are we better with device or a queue here? */
37class Denoiser {
38 public:
39 /* Create denoiser for the given path trace device.
40 *
41 * Notes:
42 * - The denoiser must be configured. This means that `params.use` must be true.
43 * This is checked in debug builds.
44 * - The device might be MultiDevice.
45 * - If Denoiser from params is not supported by provided denoise device, then Blender will
46 * fallback on the OIDN CPU denoising and use provided cpu_fallback_device. */
47 static unique_ptr<Denoiser> create(Device *denoise_device,
48 Device *cpu_fallback_device,
49 const DenoiseParams &params);
50
51 virtual ~Denoiser() = default;
52
53 void set_params(const DenoiseParams &params);
54 const DenoiseParams &get_params() const;
55
56 /* Recommended type for viewport denoising. */
57 static DenoiserType automatic_viewport_denoiser_type(const DeviceInfo &denoise_device_info);
58
59 /* Create devices and load kernels needed for denoising.
60 * The progress is used to communicate state when kernels actually needs to be loaded.
61 *
62 * NOTE: The `progress` is an optional argument, can be nullptr. */
63 virtual bool load_kernels(Progress *progress);
64
65 /* Denoise the entire buffer.
66 *
67 * Buffer parameters denotes an effective parameters used during rendering. It could be
68 * a lower resolution render into a bigger allocated buffer, which is used in viewport during
69 * navigation and non-unit pixel size. Use that instead of render_buffers->params.
70 *
71 * The buffer might be coming from a "foreign" device from what this denoise is created for.
72 * This means that in general case the denoiser will make sure the input data is available on
73 * the denoiser device, perform denoising, and put data back to the device where the buffer
74 * came from.
75 *
76 * The `num_samples` corresponds to the number of samples in the render buffers. It is used
77 * to scale buffers down to the "final" value in algorithms which don't do automatic exposure,
78 * or which needs "final" value for data passes.
79 *
80 * The `allow_inplace_modification` means that the denoiser is allowed to do in-place
81 * modification of the input passes (scaling them down i.e.). This will lower the memory
82 * footprint of the denoiser but will make input passes "invalid" (from path tracer) point of
83 * view.
84 *
85 * Returns true when all passes are denoised. Will return false if there is a denoiser error (for
86 * example, caused by misconfigured denoiser) or when user requested to cancel rendering. */
87 virtual bool denoise_buffer(const BufferParams &buffer_params,
88 RenderBuffers *render_buffers,
89 const int num_samples,
90 bool allow_inplace_modification) = 0;
91
92 /* Get a device which is used to perform actual denoising.
93 *
94 * Notes:
95 *
96 * - The device can be different from the path tracing device. This happens, for example, when
97 * using OptiX denoiser and rendering on CPU.
98 *
99 * - No threading safety is ensured in this call. This means, that it is up to caller to ensure
100 * that there is no threading-conflict between denoising task lazily initializing the device
101 * and access to this device happen. */
103
104 function<bool(void)> is_cancelled_cb;
105
106 bool is_cancelled() const
107 {
108 if (!is_cancelled_cb) {
109 return false;
110 }
111 return is_cancelled_cb();
112 }
113
114 void set_error(const string &error)
115 {
117 }
118
119 protected:
120 Denoiser(Device *denoiser_device, const DenoiseParams &params);
121
122 /* Get device type mask which is used to filter available devices when new device needs to be
123 * created. */
124 virtual uint get_device_type_mask() const = 0;
125
129};
130
unsigned int uint
function< bool(void)> is_cancelled_cb
Definition denoiser.h:104
void set_error(const string &error)
Definition denoiser.h:114
virtual bool denoise_buffer(const BufferParams &buffer_params, RenderBuffers *render_buffers, const int num_samples, bool allow_inplace_modification)=0
void set_params(const DenoiseParams &params)
Definition denoiser.cpp:206
static DenoiserType automatic_viewport_denoiser_type(const DeviceInfo &denoise_device_info)
Definition denoiser.cpp:172
DenoiseParams params_
Definition denoiser.h:128
Denoiser(Device *denoiser_device, const DenoiseParams &params)
Definition denoiser.cpp:199
virtual bool load_kernels(Progress *progress)
Definition denoiser.cpp:223
bool denoise_kernels_are_loaded_
Definition denoiser.h:127
bool is_cancelled() const
Definition denoiser.h:106
virtual uint get_device_type_mask() const =0
Device * get_denoiser_device() const
Definition denoiser.cpp:256
static unique_ptr< Denoiser > create(Device *denoise_device, Device *cpu_fallback_device, const DenoiseParams &params)
Definition denoiser.cpp:141
Device * denoiser_device_
Definition denoiser.h:126
const DenoiseParams & get_params() const
Definition denoiser.cpp:218
virtual ~Denoiser()=default
virtual void set_error(const string &error)
DenoiserType
Definition denoise.h:13
bool use_gpu_oidn_denoiser(Device *denoiser_device, const DenoiseParams &params)
Definition denoiser.cpp:87
DenoiseParams get_effective_denoise_params(Device *denoiser_device, Device *cpu_fallback_device, const DenoiseParams &params, Device *&single_denoiser_device)
Definition denoiser.cpp:99
bool use_optix_denoiser(Device *denoiser_device, const DenoiseParams &params)
Definition denoiser.cpp:75
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void error(const char *str)