Blender V4.3
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#ifndef __SESSION_H__
6#define __SESSION_H__
7
8#include "device/device.h"
10#include "scene/shader.h"
11#include "scene/stats.h"
12#include "session/buffers.h"
13#include "session/tile.h"
14
15#include "util/progress.h"
16#include "util/stats.h"
17#include "util/thread.h"
18#include "util/unique_ptr.h"
19#include "util/vector.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
52
53 /* Limit in seconds for how long path tracing is allowed to happen.
54 * Zero means no limit is applied. */
55 double time_limit;
56
58
61
63
65
66 /* Session-specific temporary directory to store in-progress EXR files in. */
67 string temp_dir;
68
70 {
71 headless = false;
72 background = false;
73
74 experimental = false;
75 samples = 1024;
76 sample_offset = 0;
77 pixel_size = 1;
78 threads = 0;
79 time_limit = 0.0;
80
81 use_profiling = false;
82
83 use_auto_tile = true;
84 tile_size = 2048;
85
87
89 }
90
91 bool modified(const SessionParams &params) const
92 {
93 /* Modified means we have to recreate the session, any parameter changes
94 * that can be handled by an existing Session are omitted. */
95 return !(device == params.device && headless == params.headless &&
96 background == params.background && experimental == params.experimental &&
97 pixel_size == params.pixel_size && threads == params.threads &&
98 use_profiling == params.use_profiling && shadingsystem == params.shadingsystem &&
99 use_auto_tile == params.use_auto_tile && tile_size == params.tile_size);
100 }
101};
102
103/* Session
104 *
105 * This is the class that contains the session thread, running the render
106 * control loop and dispatching tasks. */
107
108class Session {
109 public:
111 /* Denoiser device. Could be the same as the path trace device. */
118
119 /* Callback is invoked by tile manager whenever on-dist tiles storage file is closed after
120 * writing. Allows an engine integration to keep track of those files without worry about
121 * transferring the information when it needs to re-create session during rendering. */
122 function<void(string_view)> full_buffer_written_cb;
123
124 explicit Session(const SessionParams &params, const SceneParams &scene_params);
125 ~Session();
126
127 void start();
128
129 /* When quick cancel is requested path tracing is cancels as soon as possible, without waiting
130 * for the buffer to be uniformly sampled. */
131 void cancel(bool quick = false);
132
133 void draw();
134 void wait();
135
136 bool ready_to_reset();
137 void reset(const SessionParams &session_params, const BufferParams &buffer_params);
138
139 void set_pause(bool pause);
140
141 void set_samples(int samples);
142 void set_time_limit(double time_limit);
143
144 void set_output_driver(unique_ptr<OutputDriver> driver);
145 void set_display_driver(unique_ptr<DisplayDriver> driver);
146
147 double get_estimated_remaining_time() const;
148
149 void device_free();
150
151 /* Returns the rendering progress or 0 if no progress can be determined
152 * (for example, when rendering with unlimited samples). */
154
156
157 /* --------------------------------------------------------------------
158 * Full-frame on-disk storage.
159 */
160
161 /* Read given full-frame file from disk, perform needed processing and write it to the software
162 * via the write callback. */
163 void process_full_buffer_from_disk(string_view filename);
164
165 protected:
172
173 void thread_run();
174 void thread_render();
175
176 /* Check whether the session thread is in `SESSION_THREAD_RENDER` state.
177 * Returns true if it is so. */
179
180 /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu).
181 *
182 * Will take care of the following things:
183 * - Delayed reset
184 * - Scene update
185 * - Tile manager advance
186 * - Render scheduler work request
187 *
188 * The updates are done in a proper order with proper locking around them, which guarantees
189 * that the device side of scene and render buffers are always in a consistent state.
190 *
191 * Returns render work which is to be rendered next. */
193
194 /* Wait for rendering to be unpaused, or for new tiles for render to arrive.
195 * Returns true if new main render loop iteration is required after this function call.
196 *
197 * The `render_work` is the work which was scheduled by the render scheduler right before
198 * checking the pause. */
199 bool run_wait_for_work(const RenderWork &render_work);
200
202
203 bool update_scene(int width, int height);
204
205 void update_status_time(bool show_pause = false, bool show_done = false);
206
207 void do_delayed_reset();
208
210
211 /* Session thread that performs rendering tasks decoupled from the thread
212 * controlling the sessions. The thread is created and destroyed along with
213 * the session. */
217 enum {
222
223 bool pause_ = false;
224 bool new_work_added_ = false;
225
230
233
234 /* Render scheduler is used to get work to be rendered with the current big tile. */
236
237 /* Path tracer object.
238 *
239 * Is a single full-frame path tracer for interactive viewport rendering.
240 * A path tracer for the current big-tile for an offline rendering. */
241 unique_ptr<PathTrace> path_trace_;
242};
243
245
246#endif /* __SESSION_H__ */
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()
float get_progress()
void collect_statistics(RenderStats *stats)
RenderScheduler render_scheduler_
Device * device
void update_status_time(bool show_pause=false, bool show_done=false)
void set_pause(bool pause)
thread_mutex pause_mutex_
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()
void set_time_limit(double time_limit)
void cancel(bool quick=false)
void do_delayed_reset()
thread_mutex tile_mutex_
thread_condition_variable pause_cond_
Device * denoise_device
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)
bool update_scene(int width, int height)
function< void(string_view)> full_buffer_written_cb
void run_main_render_loop()
void thread_render()
thread_mutex session_thread_mutex_
@ SESSION_THREAD_RENDER
BufferParams buffer_params_
RenderWork run_update_for_next_iteration()
thread * session_thread_
enum Session::@1464 session_thread_state_
bool is_session_thread_rendering()
void device_free()
thread_mutex buffers_mutex_
Scene * scene
void set_output_driver(unique_ptr< OutputDriver > driver)
struct Session::DelayedReset delayed_reset_
void set_samples(int samples)
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
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29
std::condition_variable thread_condition_variable
Definition thread.h:31