Blender V5.0
session/session.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
7#include <functional>
8
9#include "device/device.h"
11#include "scene/shader.h"
12#include "scene/stats.h"
13#include "session/buffers.h"
14#include "session/tile.h"
15
16#include "util/progress.h"
17#include "util/stats.h"
18#include "util/thread.h"
19#include "util/unique_ptr.h"
20
22
23class BufferParams;
24class Device;
25class DeviceScene;
26class DisplayDriver;
27class OutputDriver;
28class PathTrace;
29class Progress;
30class RenderBuffers;
31class Scene;
32class SceneParams;
33
34/* Session Parameters */
35
37 public:
38 /* Device, which is chosen based on Blender Cycles preferences, as well as Scene settings and
39 * command line arguments. */
41 /* Device from Cycles preferences for denoising. */
43
46
53
54 /* Limit in seconds for how long path tracing is allowed to happen.
55 * Zero means no limit is applied. */
56 double time_limit;
57
59
62
64
66
67 /* Session-specific temporary directory to store in-progress EXR files in. */
68 string temp_dir;
69
71 {
72 headless = false;
73 background = false;
74
75 samples = 1024;
76 use_sample_subset = false;
79 pixel_size = 1;
80 threads = 0;
81 time_limit = 0.0;
82
83 use_profiling = false;
84
85 use_auto_tile = true;
86 tile_size = 2048;
87
89
91 }
92
93 bool modified(const SessionParams &params) const
94 {
95 /* Modified means we have to recreate the session, any parameter changes
96 * that can be handled by an existing Session are omitted. */
97 return !(device == params.device && headless == params.headless &&
98 background == params.background && pixel_size == params.pixel_size &&
99 threads == params.threads && use_profiling == params.use_profiling &&
100 shadingsystem == params.shadingsystem && use_auto_tile == params.use_auto_tile &&
101 tile_size == params.tile_size);
102 }
103};
104
105/* Session
106 *
107 * This is the class that contains the session thread, running the render
108 * control loop and dispatching tasks. */
109
110class Session {
111 public:
113 /* Denoiser device. Could be the same as the path trace device. */
120
121 /* Callback is invoked by tile manager whenever on-dist tiles storage file is closed after
122 * writing. Allows an engine integration to keep track of those files without worry about
123 * transferring the information when it needs to re-create session during rendering. */
124 std::function<void(string_view)> full_buffer_written_cb;
125
126 explicit Session(const SessionParams &params, const SceneParams &scene_params);
127 ~Session();
128
129 void start();
130
131 /* When quick cancel is requested path tracing is cancels as soon as possible, without waiting
132 * for the buffer to be uniformly sampled. */
133 void cancel(bool quick = false);
134
135 void draw();
136 void wait();
137
138 bool ready_to_reset();
139 void reset(const SessionParams &session_params, const BufferParams &buffer_params);
140
141 void set_pause(bool pause);
142
143 void set_samples(const int samples);
144 void set_time_limit(const double time_limit);
145
148
149 double get_estimated_remaining_time() const;
150
151 void device_free();
152
153 /* Returns the rendering progress or 0 if no progress can be determined
154 * (for example, when rendering with unlimited samples). */
156
158
159 /* --------------------------------------------------------------------
160 * Full-frame on-disk storage.
161 */
162
163 /* Read given full-frame file from disk, perform needed processing and write it to the software
164 * via the write callback. */
165 void process_full_buffer_from_disk(string_view filename);
166
167 protected:
174
175 void thread_run();
176 void thread_render();
177
178 /* Check whether the session thread is in `SESSION_THREAD_RENDER` state.
179 * Returns true if it is so. */
181
182 /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu).
183 *
184 * Will take care of the following things:
185 * - Delayed reset
186 * - Scene update
187 * - Tile manager advance
188 * - Render scheduler work request
189 *
190 * The updates are done in a proper order with proper locking around them, which guarantees
191 * that the device side of scene and render buffers are always in a consistent state.
192 *
193 * Returns render work which is to be rendered next. */
195
196 /* Wait for rendering to be unpaused, or for new tiles for render to arrive.
197 * Returns true if new main render loop iteration is required after this function call.
198 *
199 * The `render_work` is the work which was scheduled by the render scheduler right before
200 * checking the pause. */
201 bool run_wait_for_work(const RenderWork &render_work);
202
204
205 bool update_scene(const bool reset_samples);
206
207 void update_status_time(bool show_pause = false, bool show_done = false);
208
211
213
214 /* Get device used for denoising, may be the same as render device. */
216 {
217 return (denoise_device_) ? denoise_device_.get() : device.get();
218 }
219
220 /* Session thread that performs rendering tasks decoupled from the thread
221 * controlling the sessions. The thread is created and destroyed along with
222 * the session. */
226 enum {
231
232 bool pause_ = false;
233 bool new_work_added_ = false;
234
239
242
243 /* Render scheduler is used to get work to be rendered with the current big tile. */
245
246 /* Path tracer object.
247 *
248 * Is a single full-frame path tracer for interactive viewport rendering.
249 * A path tracer for the current big-tile for an offline rendering. */
251};
252
void reset()
clear internal cached data and reset random seed
bool modified(const SessionParams &params) const
bool use_resolution_divider
DeviceInfo denoise_device
ShadingSystem shadingsystem
DeviceInfo device
void thread_run()
unique_ptr< Scene > scene
float get_progress()
void collect_statistics(RenderStats *stats)
RenderScheduler render_scheduler_
unique_ptr< thread > session_thread_
enum Session::@160214110334236026320245177267173251377254361251 session_thread_state_
void update_status_time(bool show_pause=false, bool show_done=false)
void set_pause(bool pause)
thread_mutex pause_mutex_
Device * denoise_device()
int2 get_effective_tile_size() const
void process_full_buffer_from_disk(string_view filename)
void set_display_driver(unique_ptr< DisplayDriver > driver)
bool ready_to_reset()
std::function< void(string_view)> full_buffer_written_cb
void cancel(bool quick=false)
@ SESSION_THREAD_RENDER
thread_mutex tile_mutex_
thread_condition_variable pause_cond_
bool update_scene(const bool reset_samples)
Progress progress
Profiler profiler
bool run_wait_for_work(const RenderWork &render_work)
double get_estimated_remaining_time() const
SessionParams params
thread_condition_variable session_thread_cond_
Session(const SessionParams &params, const SceneParams &scene_params)
void update_buffers_for_params()
void run_main_render_loop()
void thread_render()
thread_mutex session_thread_mutex_
BufferParams buffer_params_
unique_ptr< Device > denoise_device_
RenderWork run_update_for_next_iteration()
void set_time_limit(const double time_limit)
bool is_session_thread_rendering()
void set_samples(const int samples)
void device_free()
unique_ptr< Device > device
thread_mutex buffers_mutex_
void set_output_driver(unique_ptr< OutputDriver > driver)
struct Session::DelayedReset delayed_reset_
bool delayed_reset_buffer_params()
unique_ptr< PathTrace > path_trace_
TileManager tile_manager_
bool new_work_added_
#define CCL_NAMESPACE_END
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ShadingSystem
@ SHADINGSYSTEM_SVM
SessionParams session_params
std::mutex thread_mutex
Definition thread.h:27
std::condition_variable thread_condition_variable
Definition thread.h:29