Cycles: Replace __MAX_CLOSURE__ build option with runtime integrator variable
[blender.git] / intern / cycles / kernel / split / kernel_shader_eval.h
1 /*
2  * Copyright 2011-2017 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 CCL_NAMESPACE_BEGIN
18
19 /* This kernel evaluates ShaderData structure from the values computed
20  * by the previous kernels.
21  */
22 ccl_device void kernel_shader_eval(KernelGlobals *kg)
23 {
24
25         int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
26         /* Sorting on cuda split is not implemented */
27 #ifdef __KERNEL_CUDA__
28         int queue_index = kernel_split_params.queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS];
29 #else
30         int queue_index = kernel_split_params.queue_index[QUEUE_SHADER_SORTED_RAYS];
31 #endif
32         if(ray_index >= queue_index) {
33                 return;
34         }
35         ray_index = get_ray_index(kg, ray_index,
36 #ifdef __KERNEL_CUDA__
37                                   QUEUE_ACTIVE_AND_REGENERATED_RAYS,
38 #else
39                                   QUEUE_SHADER_SORTED_RAYS,
40 #endif
41                                   kernel_split_state.queue_data,
42                                   kernel_split_params.queue_size,
43                                   0);
44
45         if(ray_index == QUEUE_EMPTY_SLOT) {
46                 return;
47         }
48
49         ccl_global char *ray_state = kernel_split_state.ray_state;
50         if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) {
51                 ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
52
53                 shader_eval_surface(kg, kernel_split_sd(sd, ray_index), state, state->flag, kernel_data.integrator.max_closures);
54 #ifdef __BRANCHED_PATH__
55                 if(kernel_data.integrator.branched) {
56                         shader_merge_closures(kernel_split_sd(sd, ray_index));
57                 }
58                 else
59 #endif
60                 {
61                         shader_prepare_closures(kernel_split_sd(sd, ray_index), state);
62                 }
63         }
64 }
65
66 CCL_NAMESPACE_END