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