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