Blender V4.5
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
54
55 /* Limit in seconds for how long path tracing is allowed to happen.
56 * Zero means no limit is applied. */
57 double time_limit;
58
60
63
65
67
68 /* Session-specific temporary directory to store in-progress EXR files in. */
69 string temp_dir;
70
72 {
73 headless = false;
74 background = false;
75
76 experimental = false;
77 samples = 1024;
78 use_sample_subset = false;
81 pixel_size = 1;
82 threads = 0;
83 time_limit = 0.0;
84
85 use_profiling = false;
86
87 use_auto_tile = true;
88 tile_size = 2048;
89
91
93 }
94
95 bool modified(const SessionParams &params) const
96 {
97 /* Modified means we have to recreate the session, any parameter changes
98 * that can be handled by an existing Session are omitted. */
99 return !(device == params.device && headless == params.headless &&
100 background == params.background && experimental == params.experimental &&
101 pixel_size == params.pixel_size && threads == params.threads &&
102 use_profiling == params.use_profiling && shadingsystem == params.shadingsystem &&
103 use_auto_tile == params.use_auto_tile && tile_size == params.tile_size);
104 }
105};
106
107/* Session
108 *
109 * This is the class that contains the session thread, running the render
110 * control loop and dispatching tasks. */
111
112class Session {
113 public:
115 /* Denoiser device. Could be the same as the path trace device. */
122
123 /* Callback is invoked by tile manager whenever on-dist tiles storage file is closed after
124 * writing. Allows an engine integration to keep track of those files without worry about
125 * transferring the information when it needs to re-create session during rendering. */
126 std::function<void(string_view)> full_buffer_written_cb;
127
128 explicit Session(const SessionParams &params, const SceneParams &scene_params);
129 ~Session();
130
131 void start();
132
133 /* When quick cancel is requested path tracing is cancels as soon as possible, without waiting
134 * for the buffer to be uniformly sampled. */
135 void cancel(bool quick = false);
136
137 void draw();
138 void wait();
139
140 bool ready_to_reset();
141 void reset(const SessionParams &session_params, const BufferParams &buffer_params);
142
143 void set_pause(bool pause);
144
145 void set_samples(const int samples);
146 void set_time_limit(const double time_limit);
147
150
151 double get_estimated_remaining_time() const;
152
153 void device_free();
154
155 /* Returns the rendering progress or 0 if no progress can be determined
156 * (for example, when rendering with unlimited samples). */
158
160
161 /* --------------------------------------------------------------------
162 * Full-frame on-disk storage.
163 */
164
165 /* Read given full-frame file from disk, perform needed processing and write it to the software
166 * via the write callback. */
167 void process_full_buffer_from_disk(string_view filename);
168
169 protected:
176
177 void thread_run();
178 void thread_render();
179
180 /* Check whether the session thread is in `SESSION_THREAD_RENDER` state.
181 * Returns true if it is so. */
183
184 /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu).
185 *
186 * Will take care of the following things:
187 * - Delayed reset
188 * - Scene update
189 * - Tile manager advance
190 * - Render scheduler work request
191 *
192 * The updates are done in a proper order with proper locking around them, which guarantees
193 * that the device side of scene and render buffers are always in a consistent state.
194 *
195 * Returns render work which is to be rendered next. */
197
198 /* Wait for rendering to be unpaused, or for new tiles for render to arrive.
199 * Returns true if new main render loop iteration is required after this function call.
200 *
201 * The `render_work` is the work which was scheduled by the render scheduler right before
202 * checking the pause. */
203 bool run_wait_for_work(const RenderWork &render_work);
204
206
207 bool update_scene(const bool reset_samples);
208
209 void update_status_time(bool show_pause = false, bool show_done = false);
210
213
215
216 /* Get device used for denoising, may be the same as render device. */
218 {
219 return (denoise_device_) ? denoise_device_.get() : device.get();
220 }
221
222 /* Session thread that performs rendering tasks decoupled from the thread
223 * controlling the sessions. The thread is created and destroyed along with
224 * the session. */
228 enum {
233
234 bool pause_ = false;
235 bool new_work_added_ = false;
236
241
244
245 /* Render scheduler is used to get work to be rendered with the current big tile. */
247
248 /* Path tracer object.
249 *
250 * Is a single full-frame path tracer for interactive viewport rendering.
251 * A path tracer for the current big-tile for an offline rendering. */
253};
254
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_
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
@ SESSION_THREAD_RENDER
void cancel(bool quick=false)
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_
enum Session::@250172000154253336325320364055105024363213317312 session_thread_state_
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