Fix incorrect FLT_MIN use
[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 "buffers.h"
21 #include "device.h"
22 #include "shader.h"
23 #include "tile.h"
24
25 #include "util_progress.h"
26 #include "util_stats.h"
27 #include "util_thread.h"
28 #include "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.type == params.device.type
93                 && device.id == params.device.id
94                 && background == params.background
95                 && progressive_refine == params.progressive_refine
96                 && output_path == params.output_path
97                 /* && samples == params.samples */
98                 && progressive == params.progressive
99                 && experimental == params.experimental
100                 && tile_size == params.tile_size
101                 && start_resolution == params.start_resolution
102                 && threads == params.threads
103                 && display_buffer_linear == params.display_buffer_linear
104                 && cancel_timeout == params.cancel_timeout
105                 && reset_timeout == params.reset_timeout
106                 && text_timeout == params.text_timeout
107                 && progressive_update_timeout == params.progressive_update_timeout
108                 && tile_order == params.tile_order
109                 && shadingsystem == params.shadingsystem); }
110
111 };
112
113 /* Session
114  *
115  * This is the class that contains the session thread, running the render
116  * control loop and dispatching tasks. */
117
118 class Session {
119 public:
120         Device *device;
121         Scene *scene;
122         RenderBuffers *buffers;
123         DisplayBuffer *display;
124         Progress progress;
125         SessionParams params;
126         TileManager tile_manager;
127         Stats stats;
128
129         function<void(RenderTile&)> write_render_tile_cb;
130         function<void(RenderTile&)> update_render_tile_cb;
131
132         Session(const SessionParams& params);
133         ~Session();
134
135         void start();
136         bool draw(BufferParams& params, DeviceDrawParams& draw_params);
137         void wait();
138
139         bool ready_to_reset();
140         void reset(BufferParams& params, int samples);
141         void set_samples(int samples);
142         void set_pause(bool pause);
143
144         void update_scene();
145         void load_kernels();
146
147         void device_free();
148
149 protected:
150         struct DelayedReset {
151                 thread_mutex mutex;
152                 bool do_reset;
153                 BufferParams params;
154                 int samples;
155         } delayed_reset;
156
157         void run();
158
159         void update_status_time(bool show_pause = false, bool show_done = false);
160
161         void tonemap(int sample);
162         void path_trace();
163         void reset_(BufferParams& params, int samples);
164
165         void run_cpu();
166         bool draw_cpu(BufferParams& params, DeviceDrawParams& draw_params);
167         void reset_cpu(BufferParams& params, int samples);
168
169         void run_gpu();
170         bool draw_gpu(BufferParams& params, DeviceDrawParams& draw_params);
171         void reset_gpu(BufferParams& params, int samples);
172
173         bool acquire_tile(Device *tile_device, RenderTile& tile);
174         void update_tile_sample(RenderTile& tile);
175         void release_tile(RenderTile& tile);
176
177         void update_progress_sample();
178
179         bool device_use_gl;
180
181         thread *session_thread;
182
183         volatile bool display_outdated;
184
185         volatile bool gpu_draw_ready;
186         volatile bool gpu_need_tonemap;
187         thread_condition_variable gpu_need_tonemap_cond;
188
189         bool pause;
190         thread_condition_variable pause_cond;
191         thread_mutex pause_mutex;
192         thread_mutex tile_mutex;
193         thread_mutex buffers_mutex;
194         thread_mutex display_mutex;
195
196         bool kernels_loaded;
197
198         double start_time;
199         double reset_time;
200         double preview_time;
201         double paused_time;
202
203         /* progressive refine */
204         double last_update_time;
205         bool update_progressive_refine(bool cancel);
206
207         vector<RenderBuffers *> tile_buffers;
208
209         DeviceRequestedFeatures get_requested_device_features();
210
211         /* ** Split kernel routines ** */
212
213         /* Maximumnumber of closure during session lifetime. */
214         int max_closure_global;
215
216         /* Get maximum number of closures to be used in kernel. */
217         int get_max_closure_count();
218 };
219
220 CCL_NAMESPACE_END
221
222 #endif /* __SESSION_H__ */
223