Blender V5.3
path_trace_work.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#include "scene/pass.h"
9#include "session/buffers.h"
10#include "util/unique_ptr.h"
11
13
14class BufferParams;
15class Device;
16class DeviceScene;
17class Film;
19class RenderBuffers;
20
22 public:
24 float occupancy = 1.0f;
25 };
26
27 /* Create path trace work which fits best the device.
28 *
29 * The cancel request flag is used for a cheap check whether cancel is to be performed as soon as
30 * possible. This could be, for example, request to cancel rendering on camera navigation in
31 * viewport. */
33 Film *film,
34 DeviceScene *device_scene,
35 const bool *cancel_requested_flag);
36
37 virtual ~PathTraceWork();
38
39 /* Access the render buffers.
40 *
41 * Is only supposed to be used by the PathTrace to update buffer allocation and slicing to
42 * correspond to the big tile size and relative device performance. */
44
45 /* Set effective parameters of the big tile and the work itself. */
46 void set_effective_buffer_params(const BufferParams &effective_big_tile_params,
47 const BufferParams &effective_buffer_params,
48 const BufferParams &effective_denoised_big_tile_params,
49 const BufferParams &effective_denoised_buffer_params);
50
51 /* Check whether the big tile is being worked on by multiple path trace works. */
52 bool has_multiple_works() const;
53
54 /* Allocate working memory for execution. Must be called before init_execution(). */
55 virtual void alloc_work_memory() {};
56
57 /* Initialize execution of kernels.
58 * Will ensure that all device queues are initialized for execution.
59 *
60 * This method is to be called after any change in the scene. It is not needed to call it prior
61 * to an every call of the `render_samples()`. */
62 virtual void init_execution() = 0;
63
64 /* Release resources acquired by init_execution(). */
65 virtual void deinit_execution() {}
66
67 /* Render given number of samples as a synchronous blocking call.
68 * The samples are added to the render buffer associated with this work. */
69 virtual void render_samples(RenderStatistics &statistics,
70 const int start_sample,
71 const int samples_num,
72 const int sample_offset) = 0;
73
74 /* Copy render result from this work to the corresponding place of the GPU display.
75 *
76 * The `pass_mode` indicates whether to access denoised or noisy version of the display pass. The
77 * noisy pass mode will be passed here when it is known that the buffer does not have denoised
78 * passes yet (because denoiser did not run). If the denoised pass is requested and denoiser is
79 * not used then this function will fall-back to the noisy pass instead. */
80 virtual void copy_to_display(PathTraceDisplay *display,
81 PassMode pass_mode,
82 const int num_samples) = 0;
83
84 virtual void destroy_gpu_resources(PathTraceDisplay *display) = 0;
85
86 /* Copy data from/to given render buffers.
87 * Will copy pixels from a corresponding place (from multi-device point of view) of the render
88 * buffers, and copy work's render buffers to the corresponding place of the destination. */
89
90 /* Notes:
91 * - Copies work's render buffer from the device.
92 * - Copies CPU-side buffer of the given buffer
93 * - Does not copy the buffer to its device. */
94 void copy_to_render_buffers(RenderBuffers *render_buffers);
95
96 /* Notes:
97 * - Does not copy given render buffers from the device.
98 * - Copies work's render buffer to its device. */
99 void copy_from_render_buffers(const RenderBuffers *render_buffers);
100
101 /* Special version of the `copy_from_render_buffers()` which only copies denoised passes from the
102 * given render buffers, leaving rest of the passes.
103 *
104 * Same notes about device copying applies to this call as well. */
105 void copy_from_denoised_render_buffers(const RenderBuffers *render_buffers);
106
107 /* Copy render buffers to/from device using an appropriate device queue when needed so that
108 * things are executed in order with the `render_samples()`. */
111
112 /* Zero render buffers to/from device using an appropriate device queue when needed so that
113 * things are executed in order with the `render_samples()`. */
114 virtual bool zero_render_buffers() = 0;
115
116 /* Access pixels rendered by this work and copy them to the corresponding location in the
117 * destination.
118 *
119 * NOTE: Does not perform copy of buffers from the device. Use `copy_render_tile_from_device()`
120 * to update host-side data. */
121 bool get_render_tile_pixels(const PassAccessor &pass_accessor,
122 const PassAccessor::Destination &destination);
123
124 /* Set pass data for baking. */
125 bool set_render_tile_pixels(PassAccessor &pass_accessor, const PassAccessor::Source &source);
126
127 /* Perform convergence test on the render buffer, and filter the convergence mask.
128 * Returns number of active pixels (the ones which did not converge yet). */
129 virtual int adaptive_sampling_converge_filter_count_active(const float threshold,
130 bool reset) = 0;
131
132 /* Denoise Volume Scattering Probability Guiding buffers. */
134
135 /* Run cryptomatte pass post-processing kernels. */
136 virtual void cryptomatte_postproces() = 0;
137
138 /* Cheap-ish request to see whether rendering is requested and is to be stopped as soon as
139 * possible, without waiting for any samples to be finished. */
141 {
142 /* NOTE: Rely on the fact that on x86 CPU reading scalar can happen without atomic even in
143 * threaded environment. */
145 }
146
147 /* Access to the device which is used to path trace this work on. */
149 {
150 return device_;
151 }
152
153#if defined(WITH_PATH_GUIDING)
154 /* Initializes the per-thread guiding kernel data. */
155 virtual void guiding_init_kernel_globals(void * /*unused*/,
156 void * /*unused*/,
157 const bool /*unused*/)
158 {
159 }
160#endif
161
162 protected:
163 PathTraceWork(Device *device,
164 Film *film,
165 DeviceScene *device_scene,
166 const bool *cancel_requested_flag);
167
168 PassAccessor::PassAccessInfo get_display_pass_access_info(PassMode pass_mode) const;
169
170 /* Get destination which offset and stride are configured so that writing to it will write to a
171 * proper location of GPU display texture, taking current tile and device slice into account. */
172 PassAccessor::Destination get_display_destination_template(const PathTraceDisplay *display,
173 const PassMode mode) const;
174
175 /* Device which will be used for path tracing.
176 * Note that it is an actual render device (and never is a multi-device). */
178
179 /* Film is used to access display pass configuration for GPU display update.
180 * Note that only fields which are not a part of kernel data can be accessed via the Film. */
182
183 /* Device side scene storage, that may be used for integrator logic. */
185
186 /* Render buffers where sampling is being accumulated into, allocated for a fraction of the big
187 * tile which is being rendered by this work.
188 * It also defines possible subset of a big tile in the case of multi-device rendering. */
190
191 /* Effective parameters of the big tile, and current work render buffer.
192 * The latter might be different from `buffers_->params` when there is a resolution divider
193 * involved. */
198
199 const bool *cancel_requested_flag_ = nullptr;
200};
201
void reset()
Definition film.h:29
virtual bool zero_render_buffers()=0
virtual void cryptomatte_postproces()=0
BufferParams effective_denoised_buffer_params_
virtual void deinit_execution()
void copy_from_denoised_render_buffers(const RenderBuffers *render_buffers)
PassAccessor::Destination get_display_destination_template(const PathTraceDisplay *display, const PassMode mode) const
RenderBuffers * get_render_buffers()
virtual int adaptive_sampling_converge_filter_count_active(const float threshold, bool reset)=0
unique_ptr< RenderBuffers > buffers_
virtual bool copy_render_buffers_from_device()=0
static unique_ptr< PathTraceWork > create(Device *device, Film *film, DeviceScene *device_scene, const bool *cancel_requested_flag)
PassAccessor::PassAccessInfo get_display_pass_access_info(PassMode pass_mode) const
BufferParams effective_big_tile_params_
bool get_render_tile_pixels(const PassAccessor &pass_accessor, const PassAccessor::Destination &destination)
virtual void denoise_volume_guiding_buffers()=0
virtual bool copy_render_buffers_to_device()=0
bool has_multiple_works() const
void copy_to_render_buffers(RenderBuffers *render_buffers)
BufferParams effective_denoised_big_tile_params_
virtual void destroy_gpu_resources(PathTraceDisplay *display)=0
virtual void copy_to_display(PathTraceDisplay *display, PassMode pass_mode, const int num_samples)=0
void copy_from_render_buffers(const RenderBuffers *render_buffers)
BufferParams effective_buffer_params_
virtual void render_samples(RenderStatistics &statistics, const int start_sample, const int samples_num, const int sample_offset)=0
DeviceScene * device_scene_
virtual void init_execution()=0
PathTraceWork(Device *device, Film *film, DeviceScene *device_scene, const bool *cancel_requested_flag)
Device * get_device() const
bool is_cancel_requested() const
const bool * cancel_requested_flag_
virtual ~PathTraceWork()
bool set_render_tile_pixels(PassAccessor &pass_accessor, const PassAccessor::Source &source)
virtual void alloc_work_memory()
void set_effective_buffer_params(const BufferParams &effective_big_tile_params, const BufferParams &effective_buffer_params, const BufferParams &effective_denoised_big_tile_params, const BufferParams &effective_denoised_buffer_params)
#define CCL_NAMESPACE_END
PassMode
Definition pass.h:20