Blender V5.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
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 const BufferParams &denoised_buffer_params,
23 RenderBuffers *render_buffers,
24 int num_samples,
25 bool allow_inplace_modification,
26 float2 pixel_jitter) override;
27
28 protected:
29 class DenoisePass;
30 class DenoiseContext;
31
32 /* Make sure the GPU denoiser is created and configured. */
33 virtual bool denoise_ensure(DenoiseContext &context);
34
35 /* Create GPU denoiser descriptor if needed.
36 * Will do nothing if the current GPU descriptor is usable for the given parameters.
37 * If the GPU denoiser descriptor did re-allocate here it is left unconfigured. */
38 virtual bool denoise_create_if_needed(DenoiseContext &context) = 0;
39
40 /* Configure existing GPU denoiser descriptor for the use for the given task. */
41 virtual bool denoise_configure_if_needed(DenoiseContext &context) = 0;
42
43 /* Read input color pass from the render buffer into the memory which corresponds to the noisy
44 * input within the given context. Pixels are scaled to the number of samples, but are not
45 * preprocessed yet. */
46 void denoise_color_read(const DenoiseContext &context, const DenoisePass &pass);
47
48 /* Run corresponding filter kernels, preparing data for the denoiser or copying data from the
49 * denoiser result to the render buffer. */
50 virtual bool denoise_filter_color_preprocess(const DenoiseContext &context,
51 const DenoisePass &pass);
52 virtual bool denoise_filter_color_postprocess(const DenoiseContext &context,
53 const DenoisePass &pass);
55 const BufferParams &buffer_params,
56 const DenoisePass &pass);
59
60 /* Read guiding passes from the render buffers, preprocess them in a way which is expected by
61 * the GPU denoiser and store in the guiding passes memory within the given context.
62 *
63 * Pre-processing of the guiding passes is to only happen once per context lifetime. DO not
64 * preprocess them for every pass which is being denoised. */
66
67 bool denoise_pass(DenoiseContext &context, PassType pass_type);
68
69 /* Returns true if task is fully handled. */
70 virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass) = 0;
71
73
75 public:
76 DenoisePass(const PassType type, const BufferParams &buffer_params) : type(type)
77 {
80
81 const PassInfo pass_info = Pass::get_info(type);
84 }
85
87
90
93 };
94
96 public:
97 explicit DenoiseContext(Device *device,
98 const DenoiseParams &params,
102 int num_samples,
103 bool allow_inplace_modification,
105
107
111
112 /* Previous output. */
113 struct {
115
116 int offset = PASS_UNUSED;
117
118 int stride = -1;
119 int pass_stride = -1;
121
122 /* Device-side storage of the guiding passes. */
124
125 struct {
127
128 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
132
133 int stride = -1;
134 int pass_stride = -1;
136
137 const bool use_guiding_passes = false;
138
139 int num_samples = 0;
140
142
143 /* NOTE: Are only initialized when the corresponding guiding pass is enabled. */
147
148 /* For passes which don't need albedo channel for denoising we replace the actual albedo with
149 * the (0.5, 0.5, 0.5). This flag indicates that the real albedo pass has been replaced with
150 * the fake values and denoising of passes which do need albedo can no longer happen. */
152
153 /* Sub-pixel jitter offset of the current frame. This can be used for upscaling. */
155 };
156};
157
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
Definition buffers.cpp:164
struct DenoiserGPU::DenoiseContext::@266163214042137003147233165315237216072160255244 prev_output
const BufferParams & buffer_params
DenoiseContext(Device *device, const DenoiseParams &params, const BufferParams &buffer_params, const BufferParams &denoised_buffer_params, RenderBuffers *render_buffers, int num_samples, bool allow_inplace_modification, float2 pixel_jitter)
struct DenoiserGPU::DenoiseContext::@054256012063023057250165003331300343343046235202 guiding_params
const DenoiseParams & denoise_params
const BufferParams & denoised_buffer_params
device_only_memory< float > guiding_buffer
RenderBuffers * render_buffers
DenoisePass(const PassType type, const BufferParams &buffer_params)
virtual bool denoise_run(const DenoiseContext &context, const DenoisePass &pass)=0
DenoiserGPU(Device *denoiser_device, const DenoiseParams &params)
bool denoise_filter_guiding_set_fake_albedo(DenoiseContext &context)
virtual bool denoise_filter_guiding_preprocess(DenoiseContext &context)
virtual bool denoise_ensure(DenoiseContext &context)
bool denoise_buffer(const BufferParams &buffer_params, const BufferParams &denoised_buffer_params, RenderBuffers *render_buffers, int num_samples, bool allow_inplace_modification, float2 pixel_jitter) override
bool denoise_filter_color_flip_y(const DenoiseContext &context, const BufferParams &buffer_params, const DenoisePass &pass)
virtual bool denoise_filter_color_postprocess(const DenoiseContext &context, const DenoisePass &pass)
virtual bool denoise_filter_color_preprocess(const DenoiseContext &context, const DenoisePass &pass)
virtual bool denoise_create_if_needed(DenoiseContext &context)=0
unique_ptr< DeviceQueue > denoiser_queue_
bool denoise_filter_guiding_flip_y(const DenoiseContext &context)
bool 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:252
PassInfo get_info() const
Definition pass.cpp:150
#define PASS_UNUSED
#define CCL_NAMESPACE_END
PassType
@ DENOISED
Definition pass.h:22
@ NOISY
Definition pass.h:21
bool use_denoising_albedo
Definition pass.h:44
int num_components
Definition pass.h:28
uint64_t device_ptr
Definition types_base.h:44