Blender V4.3
denoiser_gpu.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
8
10
11/* Implementation of Denoiser which uses a device-specific denoising implementation, running on a
12 * GPU device queue. It makes sure the to-be-denoised buffer is available on the denoising device
13 * and invokes denoising kernels via the device queue API. */
14class DenoiserGPU : public Denoiser {
15 public:
16 DenoiserGPU(Device *denoiser_device, const DenoiseParams &params);
18
19 virtual bool denoise_buffer(const BufferParams &buffer_params,
20 RenderBuffers *render_buffers,
21 const int num_samples,
22 bool allow_inplace_modification) override;
23
24 protected:
25 class DenoisePass;
26 class DenoiseContext;
27
28 /* All the parameters needed to perform buffer denoising on a device.
29 * Is not really a task in its canonical terms (as in, is not an asynchronous running task). Is
30 * more like a wrapper for all the arguments and parameters needed to perform denoising. Is a
31 * single place where they are all listed, so that it's not required to modify all device methods
32 * when these parameters do change. */
34 public:
36
38
41
42 /* Allow to do in-place modification of the input passes (scaling them down i.e.). This will
43 * lower the memory footprint of the denoiser but will make input passes "invalid" (from path
44 * tracer) point of view. */
46 };
47
48 /* Make sure the GPU denoiser is created and configured. */
49 virtual bool denoise_ensure(DenoiseContext &context);
50
51 /* Create GPU denoiser descriptor if needed.
52 * Will do nothing if the current GPU descriptor is usable for the given parameters.
53 * If the GPU denoiser descriptor did re-allocate here it is left unconfigured. */
54 virtual bool denoise_create_if_needed(DenoiseContext &context) = 0;
55
56 /* Configure existing GPU denoiser descriptor for the use for the given task. */
57 virtual bool denoise_configure_if_needed(DenoiseContext &context) = 0;
58
59 /* Read input color pass from the render buffer into the memory which corresponds to the noisy
60 * input within the given context. Pixels are scaled to the number of samples, but are not
61 * preprocessed yet. */
62 void denoise_color_read(const DenoiseContext &context, const DenoisePass &pass);
63
64 /* Run corresponding filter kernels, preparing data for the denoiser or copying data from the
65 * denoiser result to the render buffer. */
66 bool denoise_filter_color_preprocess(const DenoiseContext &context, const DenoisePass &pass);
67 bool denoise_filter_color_postprocess(const DenoiseContext &context, const DenoisePass &pass);
69
70 /* Read guiding passes from the render buffers, preprocess them in a way which is expected by
71 * the GPU denoiser and store in the guiding passes memory within the given context.
72 *
73 * Pre-processing of the guiding passes is to only happen once per context lifetime. DO not
74 * preprocess them for every pass which is being denoised. */
76
77 void denoise_pass(DenoiseContext &context, PassType pass_type);
78
79 /* Returns true if task is fully handled. */
80 virtual bool denoise_buffer(const DenoiseTask &task);
81 virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass) = 0;
82
83 unique_ptr<DeviceQueue> denoiser_queue_;
84
86 public:
87 DenoisePass(const PassType type, const BufferParams &buffer_params) : type(type)
88 {
89 noisy_offset = buffer_params.get_pass_offset(type, PassMode::NOISY);
91
92 const PassInfo pass_info = Pass::get_info(type);
96 }
97
99
102
106 };
107
109 public:
110 explicit DenoiseContext(Device *device, const DenoiseTask &task);
111
113
116
117 /* Previous output. */
118 struct {
120
121 int offset = PASS_UNUSED;
122
123 int stride = -1;
124 int pass_stride = -1;
126
127 /* Device-side storage of the guiding passes. */
129
130 struct {
132
133 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
137
138 int stride = -1;
139 int pass_stride = -1;
141
142 /* Number of input passes. Including the color and extra auxiliary passes. */
144 bool use_guiding_passes = false;
145 bool use_pass_albedo = false;
146 bool use_pass_normal = false;
147 bool use_pass_motion = false;
148
149 int num_samples = 0;
150
152
153 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
157
158 /* For passes which don't need albedo channel for denoising we replace the actual albedo with
159 * the (0.5, 0.5, 0.5). This flag indicates that the real albedo pass has been replaced with
160 * the fake values and denoising of passes which do need albedo can no longer happen. */
162 };
163};
164
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:167
DenoiseContext(Device *device, const DenoiseTask &task)
const BufferParams & buffer_params
const DenoiseParams & denoise_params
struct DenoiserGPU::DenoiseContext::@1421 guiding_params
struct DenoiserGPU::DenoiseContext::@1420 prev_output
device_only_memory< float > guiding_buffer
RenderBuffers * render_buffers
DenoisePass(const PassType type, const BufferParams &buffer_params)
RenderBuffers * render_buffers
bool denoise_filter_guiding_set_fake_albedo(const DenoiseContext &context)
virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass)=0
DenoiserGPU(Device *denoiser_device, const DenoiseParams &params)
virtual bool denoise_ensure(DenoiseContext &context)
bool denoise_filter_color_postprocess(const DenoiseContext &context, const DenoisePass &pass)
bool denoise_filter_color_preprocess(const DenoiseContext &context, const DenoisePass &pass)
bool denoise_filter_guiding_preprocess(const DenoiseContext &context)
virtual bool denoise_create_if_needed(DenoiseContext &context)=0
virtual bool denoise_buffer(const BufferParams &buffer_params, RenderBuffers *render_buffers, const int num_samples, bool allow_inplace_modification) override
unique_ptr< DeviceQueue > denoiser_queue_
void denoise_pass(DenoiseContext &context, PassType pass_type)
void denoise_color_read(const DenoiseContext &context, const DenoisePass &pass)
virtual bool denoise_configure_if_needed(DenoiseContext &context)=0
PassInfo get_info() const
Definition pass.cpp:141
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define PASS_UNUSED
PassType
bool use_compositing
Definition pass.h:38
bool use_denoising_albedo
Definition pass.h:43
int num_components
Definition pass.h:28
uint64_t device_ptr
Definition util/types.h:45