c59f48925464d789c94dc40d1c503b139cc65731
[blender-staging.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_compat_cpu.h"
24
25 #ifndef __SPLIT_KERNEL__
26 #  include "kernel_math.h"
27 #  include "kernel_types.h"
28
29 #  include "split/kernel_split_data.h"
30 #  include "kernel_globals.h"
31
32 #  include "kernel_cpu_image.h"
33 #  include "kernel_film.h"
34 #  include "kernel_path.h"
35 #  include "kernel_path_branched.h"
36 #  include "kernel_bake.h"
37 #else
38 #  include "split/kernel_split_common.h"
39
40 #  include "split/kernel_data_init.h"
41 #  include "split/kernel_scene_intersect.h"
42 #  include "split/kernel_lamp_emission.h"
43 #  include "split/kernel_queue_enqueue.h"
44 #  include "split/kernel_background_buffer_update.h"
45 #  include "split/kernel_shader_eval.h"
46 #  include "split/kernel_holdout_emission_blurring_pathtermination_ao.h"
47 #  include "split/kernel_direct_lighting.h"
48 #  include "split/kernel_shadow_blocked.h"
49 #  include "split/kernel_next_iteration_setup.h"
50 #  include "split/kernel_sum_all_radiance.h"
51 #endif
52
53 CCL_NAMESPACE_BEGIN
54
55 #ifndef __SPLIT_KERNEL__
56
57 /* Path Tracing */
58
59 void KERNEL_FUNCTION_FULL_NAME(path_trace)(KernelGlobals *kg,
60                                            float *buffer,
61                                            unsigned int *rng_state,
62                                            int sample,
63                                            int x, int y,
64                                            int offset,
65                                            int stride)
66 {
67 #ifdef __BRANCHED_PATH__
68         if(kernel_data.integrator.branched) {
69                 kernel_branched_path_trace(kg,
70                                            buffer,
71                                            rng_state,
72                                            sample,
73                                            x, y,
74                                            offset,
75                                            stride);
76         }
77         else
78 #endif
79         {
80                 kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
81         }
82 }
83
84 /* Film */
85
86 void KERNEL_FUNCTION_FULL_NAME(convert_to_byte)(KernelGlobals *kg,
87                                                 uchar4 *rgba,
88                                                 float *buffer,
89                                                 float sample_scale,
90                                                 int x, int y,
91                                                 int offset,
92                                                 int stride)
93 {
94         kernel_film_convert_to_byte(kg,
95                                     rgba,
96                                     buffer,
97                                     sample_scale,
98                                     x, y,
99                                     offset,
100                                     stride);
101 }
102
103 void KERNEL_FUNCTION_FULL_NAME(convert_to_half_float)(KernelGlobals *kg,
104                                                       uchar4 *rgba,
105                                                       float *buffer,
106                                                       float sample_scale,
107                                                       int x, int y,
108                                                       int offset,
109                                                       int stride)
110 {
111         kernel_film_convert_to_half_float(kg,
112                                           rgba,
113                                           buffer,
114                                           sample_scale,
115                                           x, y,
116                                           offset,
117                                           stride);
118 }
119
120 /* Shader Evaluate */
121
122 void KERNEL_FUNCTION_FULL_NAME(shader)(KernelGlobals *kg,
123                                        uint4 *input,
124                                        float4 *output,
125                                        float *output_luma,
126                                        int type,
127                                        int filter,
128                                        int i,
129                                        int offset,
130                                        int sample)
131 {
132         if(type >= SHADER_EVAL_BAKE) {
133                 kernel_assert(output_luma == NULL);
134 #ifdef __BAKING__
135                 kernel_bake_evaluate(kg,
136                                      input,
137                                      output,
138                                      (ShaderEvalType)type,
139                                      filter,
140                                      i,
141                                      offset,
142                                      sample);
143 #endif
144         }
145         else {
146                 kernel_shader_evaluate(kg,
147                                        input,
148                                        output,
149                                        output_luma,
150                                        (ShaderEvalType)type,
151                                        i,
152                                        sample);
153         }
154 }
155
156 #else  /* __SPLIT_KERNEL__ */
157
158 /* Split Kernel Path Tracing */
159
160 #define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
161         void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals *kg, KernelData* /*data*/) \
162         { \
163                 kernel_##name(kg); \
164         }
165
166 DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
167 DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
168 DEFINE_SPLIT_KERNEL_FUNCTION(queue_enqueue)
169 DEFINE_SPLIT_KERNEL_FUNCTION(background_buffer_update)
170 DEFINE_SPLIT_KERNEL_FUNCTION(shader_eval)
171 DEFINE_SPLIT_KERNEL_FUNCTION(holdout_emission_blurring_pathtermination_ao)
172 DEFINE_SPLIT_KERNEL_FUNCTION(direct_lighting)
173 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked)
174 DEFINE_SPLIT_KERNEL_FUNCTION(next_iteration_setup)
175 DEFINE_SPLIT_KERNEL_FUNCTION(sum_all_radiance)
176
177 void KERNEL_FUNCTION_FULL_NAME(register_functions)(void(*reg)(const char* name, void* func))
178 {
179 #define REGISTER_NAME_STRING(name) #name
180 #define REGISTER_EVAL_NAME(name) REGISTER_NAME_STRING(name)
181 #define REGISTER(name) reg(REGISTER_EVAL_NAME(KERNEL_FUNCTION_FULL_NAME(name)), (void*)KERNEL_FUNCTION_FULL_NAME(name));
182
183         REGISTER(path_trace);
184         REGISTER(convert_to_byte);
185         REGISTER(convert_to_half_float);
186         REGISTER(shader);
187
188         REGISTER(data_init);
189         REGISTER(scene_intersect);
190         REGISTER(lamp_emission);
191         REGISTER(queue_enqueue);
192         REGISTER(background_buffer_update);
193         REGISTER(shader_eval);
194         REGISTER(holdout_emission_blurring_pathtermination_ao);
195         REGISTER(direct_lighting);
196         REGISTER(shadow_blocked);
197         REGISTER(next_iteration_setup);
198         REGISTER(sum_all_radiance);
199
200 #undef REGISTER
201 #undef REGISTER_EVAL_NAME
202 #undef REGISTER_NAME_STRING
203 }
204
205 #endif  /* __SPLIT_KERNEL__ */
206
207 CCL_NAMESPACE_END