Cycles: Make all #include statements relative to cycles source directory
[blender.git] / intern / cycles / kernel / kernels / cpu / kernel_cpu_impl.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 /* Templated common implementation part of all CPU kernels.
18  *
19  * The idea is that particular .cpp files sets needed optimization flags and
20  * simply includes this file without worry of copying actual implementation over.
21  */
22
23 #include "kernel/kernel_compat_cpu.h"
24
25 #ifndef __SPLIT_KERNEL__
26 #  include "kernel/kernel_math.h"
27 #  include "kernel/kernel_types.h"
28
29 #  include "kernel/split/kernel_split_data.h"
30 #  include "kernel/kernel_globals.h"
31
32 #  include "kernel/kernels/cpu/kernel_cpu_image.h"
33 #  include "kernel/kernel_film.h"
34 #  include "kernel/kernel_path.h"
35 #  include "kernel/kernel_path_branched.h"
36 #  include "kernel/kernel_bake.h"
37 #else
38 #  include "kernel/split/kernel_split_common.h"
39
40 #  include "kernel/split/kernel_data_init.h"
41 #  include "kernel/split/kernel_path_init.h"
42 #  include "kernel/split/kernel_scene_intersect.h"
43 #  include "kernel/split/kernel_lamp_emission.h"
44 #  include "kernel/split/kernel_do_volume.h"
45 #  include "kernel/split/kernel_queue_enqueue.h"
46 #  include "kernel/split/kernel_indirect_background.h"
47 #  include "kernel/split/kernel_shader_eval.h"
48 #  include "kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h"
49 #  include "kernel/split/kernel_subsurface_scatter.h"
50 #  include "kernel/split/kernel_direct_lighting.h"
51 #  include "kernel/split/kernel_shadow_blocked_ao.h"
52 #  include "kernel/split/kernel_shadow_blocked_dl.h"
53 #  include "kernel/split/kernel_next_iteration_setup.h"
54 #  include "kernel/split/kernel_indirect_subsurface.h"
55 #  include "kernel/split/kernel_buffer_update.h"
56 #endif
57
58 CCL_NAMESPACE_BEGIN
59
60 #ifndef __SPLIT_KERNEL__
61
62 /* Path Tracing */
63
64 void KERNEL_FUNCTION_FULL_NAME(path_trace)(KernelGlobals *kg,
65                                            float *buffer,
66                                            unsigned int *rng_state,
67                                            int sample,
68                                            int x, int y,
69                                            int offset,
70                                            int stride)
71 {
72 #ifdef __BRANCHED_PATH__
73         if(kernel_data.integrator.branched) {
74                 kernel_branched_path_trace(kg,
75                                            buffer,
76                                            rng_state,
77                                            sample,
78                                            x, y,
79                                            offset,
80                                            stride);
81         }
82         else
83 #endif
84         {
85                 kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
86         }
87 }
88
89 /* Film */
90
91 void KERNEL_FUNCTION_FULL_NAME(convert_to_byte)(KernelGlobals *kg,
92                                                 uchar4 *rgba,
93                                                 float *buffer,
94                                                 float sample_scale,
95                                                 int x, int y,
96                                                 int offset,
97                                                 int stride)
98 {
99         kernel_film_convert_to_byte(kg,
100                                     rgba,
101                                     buffer,
102                                     sample_scale,
103                                     x, y,
104                                     offset,
105                                     stride);
106 }
107
108 void KERNEL_FUNCTION_FULL_NAME(convert_to_half_float)(KernelGlobals *kg,
109                                                       uchar4 *rgba,
110                                                       float *buffer,
111                                                       float sample_scale,
112                                                       int x, int y,
113                                                       int offset,
114                                                       int stride)
115 {
116         kernel_film_convert_to_half_float(kg,
117                                           rgba,
118                                           buffer,
119                                           sample_scale,
120                                           x, y,
121                                           offset,
122                                           stride);
123 }
124
125 /* Shader Evaluate */
126
127 void KERNEL_FUNCTION_FULL_NAME(shader)(KernelGlobals *kg,
128                                        uint4 *input,
129                                        float4 *output,
130                                        float *output_luma,
131                                        int type,
132                                        int filter,
133                                        int i,
134                                        int offset,
135                                        int sample)
136 {
137         if(type >= SHADER_EVAL_BAKE) {
138                 kernel_assert(output_luma == NULL);
139 #ifdef __BAKING__
140                 kernel_bake_evaluate(kg,
141                                      input,
142                                      output,
143                                      (ShaderEvalType)type,
144                                      filter,
145                                      i,
146                                      offset,
147                                      sample);
148 #endif
149         }
150         else {
151                 kernel_shader_evaluate(kg,
152                                        input,
153                                        output,
154                                        output_luma,
155                                        (ShaderEvalType)type,
156                                        i,
157                                        sample);
158         }
159 }
160
161 #else  /* __SPLIT_KERNEL__ */
162
163 /* Split Kernel Path Tracing */
164
165 #define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
166         void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals *kg, KernelData* /*data*/) \
167         { \
168                 kernel_##name(kg); \
169         }
170
171 #define DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(name, type) \
172         void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals *kg, KernelData* /*data*/) \
173         { \
174                 ccl_local type locals; \
175                 kernel_##name(kg, &locals); \
176         }
177
178 DEFINE_SPLIT_KERNEL_FUNCTION(path_init)
179 DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
180 DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
181 DEFINE_SPLIT_KERNEL_FUNCTION(do_volume)
182 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(queue_enqueue, QueueEnqueueLocals)
183 DEFINE_SPLIT_KERNEL_FUNCTION(indirect_background)
184 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(shader_eval, uint)
185 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(holdout_emission_blurring_pathtermination_ao, BackgroundAOLocals)
186 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(subsurface_scatter, uint)
187 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(direct_lighting, uint)
188 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_ao)
189 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_dl)
190 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(next_iteration_setup, uint)
191 DEFINE_SPLIT_KERNEL_FUNCTION(indirect_subsurface)
192 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(buffer_update, uint)
193
194 void KERNEL_FUNCTION_FULL_NAME(register_functions)(void(*reg)(const char* name, void* func))
195 {
196 #define REGISTER_NAME_STRING(name) #name
197 #define REGISTER_EVAL_NAME(name) REGISTER_NAME_STRING(name)
198 #define REGISTER(name) reg(REGISTER_EVAL_NAME(KERNEL_FUNCTION_FULL_NAME(name)), (void*)KERNEL_FUNCTION_FULL_NAME(name));
199
200         REGISTER(path_trace);
201         REGISTER(convert_to_byte);
202         REGISTER(convert_to_half_float);
203         REGISTER(shader);
204
205         REGISTER(data_init);
206         REGISTER(path_init);
207         REGISTER(scene_intersect);
208         REGISTER(lamp_emission);
209         REGISTER(do_volume);
210         REGISTER(queue_enqueue);
211         REGISTER(indirect_background);
212         REGISTER(shader_eval);
213         REGISTER(holdout_emission_blurring_pathtermination_ao);
214         REGISTER(subsurface_scatter);
215         REGISTER(direct_lighting);
216         REGISTER(shadow_blocked_ao);
217         REGISTER(shadow_blocked_dl);
218         REGISTER(next_iteration_setup);
219         REGISTER(indirect_subsurface);
220         REGISTER(buffer_update);
221
222 #undef REGISTER
223 #undef REGISTER_EVAL_NAME
224 #undef REGISTER_NAME_STRING
225 }
226
227 #endif  /* __SPLIT_KERNEL__ */
228
229 CCL_NAMESPACE_END