Blender V5.0
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);
70 bool denoise_filter_color_flip_y(const DenoiseContext &context, const DenoisePass &pass);
73
74 /* Read guiding passes from the render buffers, preprocess them in a way which is expected by
75 * the GPU denoiser and store in the guiding passes memory within the given context.
76 *
77 * Pre-processing of the guiding passes is to only happen once per context lifetime. DO not
78 * preprocess them for every pass which is being denoised. */
80
81 void denoise_pass(DenoiseContext &context, PassType pass_type);
82
83 /* Returns true if task is fully handled. */
84 virtual bool denoise_buffer(const DenoiseTask &task);
85 virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass) = 0;
86
88
111
113 public:
114 explicit DenoiseContext(Device *device, const DenoiseTask &task);
115
117
120
121 /* Previous output. */
122 struct {
124
126
127 int stride = -1;
128 int pass_stride = -1;
130
131 /* Device-side storage of the guiding passes. */
133
134 struct {
136
137 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
141
142 int stride = -1;
143 int pass_stride = -1;
145
146 /* Number of input passes. Including the color and extra auxiliary passes. */
148 bool use_guiding_passes = false;
149 bool use_pass_albedo = false;
150 bool use_pass_normal = false;
151 bool use_pass_motion = false;
152
153 int num_samples = 0;
154
156
157 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
161
162 /* For passes which don't need albedo channel for denoising we replace the actual albedo with
163 * the (0.5, 0.5, 0.5). This flag indicates that the real albedo pass has been replaced with
164 * the fake values and denoising of passes which do need albedo can no longer happen. */
166 };
167};
168
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:164
DenoiseContext(Device *device, const DenoiseTask &task)
const BufferParams & buffer_params
const DenoiseParams & denoise_params
struct DenoiserGPU::DenoiseContext::@050206006210205270244255127364203000027050045236 guiding_params
device_only_memory< float > guiding_buffer
struct DenoiserGPU::DenoiseContext::@307212312150265072240212162357356346325073224303 prev_output
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_filter_color_flip_y(const DenoiseContext &context, const DenoisePass &pass)
bool denoise_buffer(const BufferParams &buffer_params, RenderBuffers *render_buffers, const int num_samples, bool allow_inplace_modification) override
unique_ptr< DeviceQueue > denoiser_queue_
bool denoise_filter_guiding_flip_y(const DenoiseContext &context)
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:146
#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:39
bool use_denoising_albedo
Definition pass.h:44
int num_components
Definition pass.h:28
uint64_t device_ptr
Definition types_base.h:44