Blender V5.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#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"
15#include "session/tile.h"
16
17#include "util/progress.h"
18#include "util/stats.h"
19#include "util/thread.h"
20#include "util/unique_ptr.h"
21
23
24class BufferParams;
25class Device;
26class DeviceScene;
27class DisplayDriver;
28class OutputDriver;
29class PathTrace;
30class Progress;
31class RenderBuffers;
32class Scene;
33class SceneParams;
34
35/* Session Parameters */
36
38 public:
39 /* Device, which is chosen based on Blender Cycles preferences, as well as Scene settings and
40 * command line arguments. */
42 /* Device from Cycles preferences for denoising. */
44
47
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 samples = 1024;
77 use_sample_subset = false;
80 pixel_size = 1;
81 threads = 0;
82 time_limit = 0.0;
83
84 use_profiling = false;
85
86 use_auto_tile = true;
87 tile_size = 2048;
88
90
92 }
93
94 bool modified(const SessionParams &params) const
95 {
96 /* Modified means we have to recreate the session, any parameter changes
97 * that can be handled by an existing Session are omitted. */
98 return !(device == params.device && headless == params.headless &&
99 background == params.background && pixel_size == params.pixel_size &&
100 threads == params.threads && use_profiling == params.use_profiling &&
101 use_auto_tile == params.use_auto_tile && tile_size == params.tile_size &&
103 shadingsystem == params.shadingsystem);
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 void set_navigating(bool navigating);
145
146 void set_samples(const int samples);
147 void set_time_limit(const double time_limit);
148
151
152 double get_estimated_remaining_time() const;
153
154 void device_free();
155
156 /* Returns the rendering progress or 0 if no progress can be determined
157 * (for example, when rendering with unlimited samples). */
159
161
162 /* --------------------------------------------------------------------
163 * Full-frame on-disk storage.
164 */
165
166 /* Read given full-frame file from disk, perform needed processing and write it to the software
167 * via the write callback. */
168 void process_full_buffer_from_disk(string_view filename);
169
170 protected:
177
178 void thread_run();
179 void thread_render();
180
181 /* Check whether the session thread is in `SESSION_THREAD_RENDER` state.
182 * Returns true if it is so. */
184
185 /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu).
186 *
187 * Will take care of the following things:
188 * - Delayed reset
189 * - Scene update
190 * - Tile manager advance
191 * - Render scheduler work request
192 *
193 * The updates are done in a proper order with proper locking around them, which guarantees
194 * that the device side of scene and render buffers are always in a consistent state.
195 *
196 * Returns render work which is to be rendered next. */
198
199 /* Wait for rendering to be unpaused, or for new tiles for render to arrive.
200 * Returns true if new main render loop iteration is required after this function call.
201 *
202 * The `render_work` is the work which was scheduled by the render scheduler right before
203 * checking the pause. */
204 bool run_wait_for_work(const RenderWork &render_work);
205
207
208 bool update_scene(const bool reset_samples);
209
210 void update_status_time(bool show_pause = false, bool show_done = false);
211
214
216
217 /* Get device used for denoising, may be the same as render device. */
219 {
220 return (denoise_device_) ? denoise_device_.get() : device.get();
221 }
222
223 /* Session thread that performs rendering tasks decoupled from the thread
224 * controlling the sessions. The thread is created and destroyed along with
225 * the session. */
229 enum {
234
235 bool pause_ = false;
236 bool new_work_added_ = false;
237
242
245
246 /* Manages when image cache eviction happens. */
248
249 /* Render scheduler is used to get work to be rendered with the current big tile. */
251
252 /* Path tracer object.
253 *
254 * Is a single full-frame path tracer for interactive viewport rendering.
255 * A path tracer for the current big-tile for an offline rendering. */
257};
258
Definition scene.h:133
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
void cancel(bool quick=false)
thread_mutex tile_mutex_
thread_condition_variable pause_cond_
bool update_scene(const bool reset_samples)
Progress progress
void set_navigating(bool navigating)
enum Session::@056371222103363167122077335031026143326111101235 session_thread_state_
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()
CacheEvictionManager eviction_manager_
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)
void reset(const SessionParams &session_params, const BufferParams &buffer_params)
bool is_session_thread_rendering()
void set_samples(const int samples)
void device_free()
unique_ptr< Device > device
thread_mutex buffers_mutex_
@ SESSION_THREAD_RENDER
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
ShadingSystem
@ SHADINGSYSTEM_SVM
SessionParams session_params
std::mutex thread_mutex
Definition thread.h:27
std::condition_variable thread_condition_variable
Definition thread.h:29