Cycles: Make all #include statements relative to cycles source directory
[blender.git] / intern / cycles / render / session.h
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 "render/buffers.h"
21 #include "device/device.h"
22 #include "render/shader.h"
23 #include "render/tile.h"
24
25 #include "util/util_progress.h"
26 #include "util/util_stats.h"
27 #include "util/util_thread.h"
28 #include "util/util_vector.h"
29
30 CCL_NAMESPACE_BEGIN
31
32 class BufferParams;
33 class Device;
34 class DeviceScene;
35 class DeviceRequestedFeatures;
36 class DisplayBuffer;
37 class Progress;
38 class RenderBuffers;
39 class Scene;
40
41 /* Session Parameters */
42
43 class SessionParams {
44 public:
45         DeviceInfo device;
46         bool background;
47         bool progressive_refine;
48         string output_path;
49
50         bool progressive;
51         bool experimental;
52         int samples;
53         int2 tile_size;
54         TileOrder tile_order;
55         int start_resolution;
56         int threads;
57
58         bool display_buffer_linear;
59
60         double cancel_timeout;
61         double reset_timeout;
62         double text_timeout;
63         double progressive_update_timeout;
64
65         ShadingSystem shadingsystem;
66
67         SessionParams()
68         {
69                 background = false;
70                 progressive_refine = false;
71                 output_path = "";
72
73                 progressive = false;
74                 experimental = false;
75                 samples = INT_MAX;
76                 tile_size = make_int2(64, 64);
77                 start_resolution = INT_MAX;
78                 threads = 0;
79
80                 display_buffer_linear = false;
81
82                 cancel_timeout = 0.1;
83                 reset_timeout = 0.1;
84                 text_timeout = 1.0;
85                 progressive_update_timeout = 1.0;
86
87                 shadingsystem = SHADINGSYSTEM_SVM;
88                 tile_order = TILE_CENTER;
89         }
90
91         bool modified(const SessionParams& params)
92         { return !(device == params.device
93                 && background == params.background
94                 && progressive_refine == params.progressive_refine
95                 && output_path == params.output_path
96                 /* && samples == params.samples */
97                 && progressive == params.progressive
98                 && experimental == params.experimental
99                 && tile_size == params.tile_size
100                 && start_resolution == params.start_resolution
101                 && threads == params.threads
102                 && display_buffer_linear == params.display_buffer_linear
103                 && cancel_timeout == params.cancel_timeout
104                 && reset_timeout == params.reset_timeout
105                 && text_timeout == params.text_timeout
106                 && progressive_update_timeout == params.progressive_update_timeout
107                 && tile_order == params.tile_order
108                 && shadingsystem == params.shadingsystem); }
109
110 };
111
112 /* Session
113  *
114  * This is the class that contains the session thread, running the render
115  * control loop and dispatching tasks. */
116
117 class Session {
118 public:
119         Device *device;
120         Scene *scene;
121         RenderBuffers *buffers;
122         DisplayBuffer *display;
123         Progress progress;
124         SessionParams params;
125         TileManager tile_manager;
126         Stats stats;
127
128         function<void(RenderTile&)> write_render_tile_cb;
129         function<void(RenderTile&)> update_render_tile_cb;
130
131         explicit Session(const SessionParams& params);
132         ~Session();
133
134         void start();
135         bool draw(BufferParams& params, DeviceDrawParams& draw_params);
136         void wait();
137
138         bool ready_to_reset();
139         void reset(BufferParams& params, int samples);
140         void set_samples(int samples);
141         void set_pause(bool pause);
142
143         void update_scene();
144         void load_kernels();
145
146         void device_free();
147
148         /* Returns the rendering progress or 0 if no progress can be determined
149          * (for example, when rendering with unlimited samples). */
150         float get_progress();
151
152 protected:
153         struct DelayedReset {
154                 thread_mutex mutex;
155                 bool do_reset;
156                 BufferParams params;
157                 int samples;
158         } delayed_reset;
159
160         void run();
161
162         void update_status_time(bool show_pause = false, bool show_done = false);
163
164         void tonemap(int sample);
165         void path_trace();
166         void reset_(BufferParams& params, int samples);
167
168         void run_cpu();
169         bool draw_cpu(BufferParams& params, DeviceDrawParams& draw_params);
170         void reset_cpu(BufferParams& params, int samples);
171
172         void run_gpu();
173         bool draw_gpu(BufferParams& params, DeviceDrawParams& draw_params);
174         void reset_gpu(BufferParams& params, int samples);
175
176         bool acquire_tile(Device *tile_device, RenderTile& tile);
177         void update_tile_sample(RenderTile& tile);
178         void release_tile(RenderTile& tile);
179
180         bool device_use_gl;
181
182         thread *session_thread;
183
184         volatile bool display_outdated;
185
186         volatile bool gpu_draw_ready;
187         volatile bool gpu_need_tonemap;
188         thread_condition_variable gpu_need_tonemap_cond;
189
190         bool pause;
191         thread_condition_variable pause_cond;
192         thread_mutex pause_mutex;
193         thread_mutex tile_mutex;
194         thread_mutex buffers_mutex;
195         thread_mutex display_mutex;
196
197         bool kernels_loaded;
198
199         double reset_time;
200
201         /* progressive refine */
202         double last_update_time;
203         bool update_progressive_refine(bool cancel);
204
205         vector<RenderBuffers *> tile_buffers;
206
207         DeviceRequestedFeatures get_requested_device_features();
208
209         /* ** Split kernel routines ** */
210
211         /* Maximumnumber of closure during session lifetime. */
212         int max_closure_global;
213
214         /* Get maximum number of closures to be used in kernel. */
215         int get_max_closure_count();
216 };
217
218 CCL_NAMESPACE_END
219
220 #endif /* __SESSION_H__ */
221