Blender  V3.3
session/session.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __SESSION_H__
5 #define __SESSION_H__
6 
7 #include "device/device.h"
9 #include "scene/shader.h"
10 #include "scene/stats.h"
11 #include "session/buffers.h"
12 #include "session/tile.h"
13 
14 #include "util/progress.h"
15 #include "util/stats.h"
16 #include "util/thread.h"
17 #include "util/unique_ptr.h"
18 #include "util/vector.h"
19 
21 
22 class BufferParams;
23 class Device;
24 class DeviceScene;
25 class DisplayDriver;
26 class OutputDriver;
27 class PathTrace;
28 class Progress;
29 class RenderBuffers;
30 class Scene;
31 class SceneParams;
32 
33 /* Session Parameters */
34 
36  public:
38 
39  bool headless;
40  bool background;
41 
43  int samples;
46  int threads;
47 
48  /* Limit in seconds for how long path tracing is allowed to happen.
49  * Zero means no limit is applied. */
50  double time_limit;
51 
53 
55  int tile_size;
56 
58 
60 
61  /* Session-specific temporary directory to store in-progress EXR files in. */
62  string temp_dir;
63 
65  {
66  headless = false;
67  background = false;
68 
69  experimental = false;
70  samples = 1024;
71  sample_offset = 0;
72  pixel_size = 1;
73  threads = 0;
74  time_limit = 0.0;
75 
76  use_profiling = false;
77 
78  use_auto_tile = true;
79  tile_size = 2048;
80 
82 
84  }
85 
86  bool modified(const SessionParams &params) const
87  {
88  /* Modified means we have to recreate the session, any parameter changes
89  * that can be handled by an existing Session are omitted. */
90  return !(device == params.device && headless == params.headless &&
91  background == params.background && experimental == params.experimental &&
92  pixel_size == params.pixel_size && threads == params.threads &&
93  use_profiling == params.use_profiling && shadingsystem == params.shadingsystem &&
94  use_auto_tile == params.use_auto_tile && tile_size == params.tile_size);
95  }
96 };
97 
98 /* Session
99  *
100  * This is the class that contains the session thread, running the render
101  * control loop and dispatching tasks. */
102 
103 class Session {
104  public:
111 
112  /* Callback is invoked by tile manager whenever on-dist tiles storage file is closed after
113  * writing. Allows an engine integration to keep track of those files without worry about
114  * transferring the information when it needs to re-create session during rendering. */
115  function<void(string_view)> full_buffer_written_cb;
116 
117  explicit Session(const SessionParams &params, const SceneParams &scene_params);
118  ~Session();
119 
120  void start();
121 
122  /* When quick cancel is requested path tracing is cancels as soon as possible, without waiting
123  * for the buffer to be uniformly sampled. */
124  void cancel(bool quick = false);
125 
126  void draw();
127  void wait();
128 
129  bool ready_to_reset();
130  void reset(const SessionParams &session_params, const BufferParams &buffer_params);
131 
132  void set_pause(bool pause);
133 
134  void set_samples(int samples);
135  void set_time_limit(double time_limit);
136 
137  void set_output_driver(unique_ptr<OutputDriver> driver);
138  void set_display_driver(unique_ptr<DisplayDriver> driver);
139 
140  double get_estimated_remaining_time() const;
141 
142  void device_free();
143 
144  /* Returns the rendering progress or 0 if no progress can be determined
145  * (for example, when rendering with unlimited samples). */
146  float get_progress();
147 
149 
150  /* --------------------------------------------------------------------
151  * Full-frame on-disk storage.
152  */
153 
154  /* Read given full-frame file from disk, perform needed processing and write it to the software
155  * via the write callback. */
156  void process_full_buffer_from_disk(string_view filename);
157 
158  protected:
159  struct DelayedReset {
161  bool do_reset;
165 
166  void thread_run();
167  void thread_render();
168 
169  /* Check whether the session thread is in `SESSION_THREAD_RENDER` state.
170  * Returns true if it is so. */
172 
173  /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu).
174  *
175  * Will take care of the following things:
176  * - Delayed reset
177  * - Scene update
178  * - Tile manager advance
179  * - Render scheduler work request
180  *
181  * The updates are done in a proper order with proper locking around them, which guarantees
182  * that the device side of scene and render buffers are always in a consistent state.
183  *
184  * Returns render work which is to be rendered next. */
186 
187  /* Wait for rendering to be unpaused, or for new tiles for render to arrive.
188  * Returns true if new main render loop iteration is required after this function call.
189  *
190  * The `render_work` is the work which was scheduled by the render scheduler right before
191  * checking the pause. */
192  bool run_wait_for_work(const RenderWork &render_work);
193 
194  void run_main_render_loop();
195 
196  bool update_scene(int width, int height);
197 
198  void update_status_time(bool show_pause = false, bool show_done = false);
199 
200  void do_delayed_reset();
201 
203 
204  /* Session thread that performs rendering tasks decoupled from the thread
205  * controlling the sessions. The thread is created and destroyed along with
206  * the session. */
210  enum {
215 
216  bool pause_ = false;
217  bool new_work_added_ = false;
218 
223 
226 
227  /* Render scheduler is used to get work to be rendered with the current big tile. */
229 
230  /* Path tracer object.
231  *
232  * Is a single full-frame path tracer for interactive viewport rendering.
233  * A path tracer for the current big-tile for an offline rendering. */
234  unique_ptr<PathTrace> path_trace_;
235 };
236 
238 
239 #endif /* __SESSION_H__ */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
bool modified(const SessionParams &params) const
bool use_resolution_divider
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_
enum Session::@1267 session_thread_state_
void start()
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_
BufferParams buffer_params_
RenderWork run_update_for_next_iteration()
void reset(const SessionParams &session_params, const BufferParams &buffer_params)
thread * session_thread_
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_
@ SESSION_THREAD_END
@ SESSION_THREAD_RENDER
@ SESSION_THREAD_WAIT
bool new_work_added_
Definition: thread.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
SyclQueue void void size_t num_bytes void
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ShadingSystem
Definition: scene/shader.h:34
@ SHADINGSYSTEM_SVM
Definition: scene/shader.h:34
SessionParams session_params
BufferParams buffer_params
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: thread.h:27
std::condition_variable thread_condition_variable
Definition: thread.h:29