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