Blender  V2.93
session.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __SESSION_H__
18 #define __SESSION_H__
19 
20 #include "device/device.h"
21 #include "render/buffers.h"
22 #include "render/shader.h"
23 #include "render/stats.h"
24 #include "render/tile.h"
25 
26 #include "util/util_progress.h"
27 #include "util/util_stats.h"
28 #include "util/util_thread.h"
29 #include "util/util_vector.h"
30 
32 
33 class BufferParams;
34 class Device;
35 class DeviceScene;
37 class DisplayBuffer;
38 class Progress;
39 class RenderBuffers;
40 class Scene;
41 
42 /* Session Parameters */
43 
45  public:
47  bool background;
49 
52  int samples;
58  int threads;
60 
62 
64 
66 
68  double reset_timeout;
69  double text_timeout;
71 
73 
74  function<bool(const uchar *pixels, int width, int height, int channels)> write_render_cb;
75 
77  {
78  background = false;
79  progressive_refine = false;
80 
81  progressive = false;
82  experimental = false;
83  samples = 1024;
84  tile_size = make_int2(64, 64);
85  start_resolution = INT_MAX;
87  pixel_size = 1;
88  threads = 0;
89  adaptive_sampling = false;
90 
91  use_profiling = false;
92 
93  display_buffer_linear = false;
94 
95  cancel_timeout = 0.1;
96  reset_timeout = 0.1;
97  text_timeout = 1.0;
99 
102  }
103 
105  {
106  /* Modified means we have to recreate the session, any parameter changes
107  * that can be handled by an existing Session are omitted. */
108  return !(device == params.device && background == params.background &&
109  progressive_refine == params.progressive_refine &&
110  progressive == params.progressive && experimental == params.experimental &&
111  tile_size == params.tile_size && start_resolution == params.start_resolution &&
112  pixel_size == params.pixel_size && threads == params.threads &&
113  adaptive_sampling == params.adaptive_sampling &&
114  use_profiling == params.use_profiling &&
115  display_buffer_linear == params.display_buffer_linear &&
116  cancel_timeout == params.cancel_timeout && reset_timeout == params.reset_timeout &&
117  text_timeout == params.text_timeout &&
118  progressive_update_timeout == params.progressive_update_timeout &&
119  tile_order == params.tile_order && shadingsystem == params.shadingsystem &&
120  denoising.type == params.denoising.type &&
121  (denoising.use == params.denoising.use || (device.denoisers & denoising.type)));
122  }
123 };
124 
125 /* Session
126  *
127  * This is the class that contains the session thread, running the render
128  * control loop and dispatching tasks. */
129 
130 class Session {
131  public:
141 
142  function<void(RenderTile &)> write_render_tile_cb;
143  function<void(RenderTile &, bool)> update_render_tile_cb;
144  function<void(RenderTile &)> read_bake_tile_cb;
145 
146  explicit Session(const SessionParams &params);
147  ~Session();
148 
149  void start();
150  void cancel();
151  bool draw(BufferParams &params, DeviceDrawParams &draw_params);
152  void wait();
153 
154  bool ready_to_reset();
155  void reset(BufferParams &params, int samples);
156  void set_pause(bool pause);
157  void set_samples(int samples);
158  void set_denoising(const DenoiseParams &denoising);
160 
161  bool update_scene();
162 
163  void device_free();
164 
165  /* Returns the rendering progress or 0 if no progress can be determined
166  * (for example, when rendering with unlimited samples). */
167  float get_progress();
168 
170 
171  protected:
172  struct DelayedReset {
174  bool do_reset;
176  int samples;
178 
179  void run();
180 
181  void update_status_time(bool show_pause = false, bool show_done = false);
182 
183  void render(bool use_denoise);
184  void copy_to_display_buffer(int sample);
185 
186  void reset_(BufferParams &params, int samples);
187 
188  void run_cpu();
189  bool draw_cpu(BufferParams &params, DeviceDrawParams &draw_params);
190  void reset_cpu(BufferParams &params, int samples);
191 
192  void run_gpu();
193  bool draw_gpu(BufferParams &params, DeviceDrawParams &draw_params);
194  void reset_gpu(BufferParams &params, int samples);
195 
196  bool render_need_denoise(bool &delayed);
197 
198  bool steal_tile(RenderTile &tile, Device *tile_device, thread_scoped_lock &tile_lock);
199  bool get_tile_stolen();
200  bool acquire_tile(RenderTile &tile, Device *tile_device, uint tile_types);
201  void update_tile_sample(RenderTile &tile);
202  void release_tile(RenderTile &tile, const bool need_denoise);
203 
204  void map_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device);
205  void unmap_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device);
206 
208 
210 
211  volatile bool display_outdated;
212 
213  volatile bool gpu_draw_ready;
216 
217  bool pause;
225 
226  double reset_time;
229 
231  typedef enum {
232  NOT_STEALING, /* There currently is no tile stealing in progress. */
233  WAITING_FOR_TILE, /* A device is waiting for another device to release a tile. */
234  RELEASING_TILE, /* A device has releasing a stealable tile. */
235  GOT_TILE /* A device has released a stealable tile, which is now stored in stolen_tile. */
237  std::atomic<TileStealingState> tile_stealing_state;
239 
240  /* progressive refine */
242 };
243 
245 
246 #endif /* __SESSION_H__ */
unsigned char uchar
Definition: BLI_sys_types.h:86
unsigned int uint
Definition: BLI_sys_types.h:83
_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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
DenoiserType type
Definition: device_task.h:63
DenoiserTypeMask denoisers
Definition: device.h:88
Definition: device.h:293
double text_timeout
Definition: session.h:69
bool progressive
Definition: session.h:50
int denoising_start_sample
Definition: session.h:56
int samples
Definition: session.h:52
bool progressive_refine
Definition: session.h:48
double reset_timeout
Definition: session.h:68
DenoiseParams denoising
Definition: session.h:65
ShadingSystem shadingsystem
Definition: session.h:72
TileOrder tile_order
Definition: session.h:54
int pixel_size
Definition: session.h:57
bool display_buffer_linear
Definition: session.h:63
int threads
Definition: session.h:58
bool use_profiling
Definition: session.h:61
DeviceInfo device
Definition: session.h:46
double progressive_update_timeout
Definition: session.h:70
bool adaptive_sampling
Definition: session.h:59
function< bool(const uchar *pixels, int width, int height, int channels)> write_render_cb
Definition: session.h:74
bool experimental
Definition: session.h:51
bool modified(const SessionParams &params)
Definition: session.h:104
int start_resolution
Definition: session.h:55
double cancel_timeout
Definition: session.h:67
SessionParams()
Definition: session.h:76
int2 tile_size
Definition: session.h:53
bool background
Definition: session.h:47
float get_progress()
bool acquire_tile(RenderTile &tile, Device *tile_device, uint tile_types)
Definition: session.cpp:441
void reset_cpu(BufferParams &params, int samples)
Definition: session.cpp:347
void set_denoising_start_sample(int sample)
Definition: session.cpp:994
void collect_statistics(RenderStats *stats)
Definition: session.cpp:1301
bool pause
Definition: session.h:217
bool draw_cpu(BufferParams &params, DeviceDrawParams &draw_params)
Definition: session.cpp:363
function< void(RenderTile &, bool)> update_render_tile_cb
Definition: session.h:143
void run_cpu()
Definition: session.cpp:725
thread_condition_variable pause_cond
Definition: session.h:218
thread_mutex tile_mutex
Definition: session.h:220
volatile bool display_outdated
Definition: session.h:211
std::atomic< TileStealingState > tile_stealing_state
Definition: session.h:237
RenderBuffers * buffers
Definition: session.h:134
bool steal_tile(RenderTile &tile, Device *tile_device, thread_scoped_lock &tile_lock)
Definition: session.cpp:385
thread_condition_variable denoising_cond
Definition: session.h:223
void wait()
Definition: session.cpp:1003
Device * device
Definition: session.h:132
void update_status_time(bool show_pause=false, bool show_done=false)
Definition: session.cpp:1046
bool draw(BufferParams &params, DeviceDrawParams &draw_params)
Definition: session.cpp:897
thread_condition_variable tile_steal_cond
Definition: session.h:224
void set_pause(bool pause)
Definition: session.cpp:946
bool ready_to_reset()
Definition: session.cpp:154
void run()
Definition: session.cpp:868
double last_update_time
Definition: session.h:227
thread_condition_variable gpu_need_display_buffer_update_cond
Definition: session.h:215
TileStealingState
Definition: session.h:231
@ WAITING_FOR_TILE
Definition: session.h:233
@ RELEASING_TILE
Definition: session.h:234
@ NOT_STEALING
Definition: session.h:232
@ GOT_TILE
Definition: session.h:235
double reset_time
Definition: session.h:226
bool draw_gpu(BufferParams &params, DeviceDrawParams &draw_params)
Definition: session.cpp:187
void render(bool use_denoise)
Definition: session.cpp:1147
TileManager tile_manager
Definition: session.h:138
bool update_progressive_refine(bool cancel)
Definition: session.cpp:1247
void start()
Definition: session.cpp:128
bool render_need_denoise(bool &delayed)
Definition: session.cpp:1103
Progress progress
Definition: session.h:136
void set_denoising(const DenoiseParams &denoising)
Definition: session.cpp:969
void reset_gpu(BufferParams &params, int samples)
Definition: session.cpp:166
DisplayBuffer * display
Definition: session.h:135
Profiler profiler
Definition: session.h:140
SessionParams params
Definition: session.h:137
void release_tile(RenderTile &tile, const bool need_denoise)
Definition: session.cpp:590
thread * session_thread
Definition: session.h:209
void reset_(BufferParams &params, int samples)
Definition: session.cpp:905
bool get_tile_stolen()
Definition: session.cpp:433
volatile bool gpu_draw_ready
Definition: session.h:213
~Session()
Definition: session.cpp:99
function< void(RenderTile &)> write_render_tile_cb
Definition: session.h:142
volatile bool gpu_need_display_buffer_update
Definition: session.h:214
double last_display_time
Definition: session.h:228
bool update_scene()
Definition: session.cpp:1013
void copy_to_display_buffer(int sample)
Definition: session.cpp:1219
void cancel()
Definition: session.cpp:135
Session(const SessionParams &params)
Definition: session.cpp:46
void map_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device)
Definition: session.cpp:642
thread_mutex display_mutex
Definition: session.h:222
void device_free()
Definition: session.cpp:1290
void reset(BufferParams &params, int samples)
Definition: session.cpp:928
Scene * scene
Definition: session.h:133
void run_gpu()
Definition: session.cpp:219
bool device_use_gl
Definition: session.h:207
thread_mutex pause_mutex
Definition: session.h:219
void unmap_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device)
Definition: session.cpp:719
Stats stats
Definition: session.h:139
RenderTile stolen_tile
Definition: session.h:230
thread_mutex buffers_mutex
Definition: session.h:221
void update_tile_sample(RenderTile &tile)
Definition: session.cpp:575
void set_samples(int samples)
Definition: session.cpp:936
int stealable_tiles
Definition: session.h:238
struct Session::DelayedReset delayed_reset
function< void(RenderTile &)> read_bake_tile_cb
Definition: session.h:144
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define CCL_NAMESPACE_END
#define make_int2(x, y)
static void sample(SocketReader *reader, int x, int y, float color[4])
ShadingSystem
Definition: shader.h:48
@ SHADINGSYSTEM_SVM
Definition: shader.h:48
BufferParams params
Definition: session.h:175
thread_mutex mutex
Definition: session.h:173
TileOrder
Definition: tile.h:56
@ TILE_CENTER
Definition: tile.h:57
std::unique_lock< std::mutex > thread_scoped_lock
Definition: util_thread.h:41
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition: util_thread.h:40
std::condition_variable thread_condition_variable
Definition: util_thread.h:42