Cycles: Replace __MAX_CLOSURE__ build option with runtime integrator variable
[blender.git] / intern / cycles / kernel / split / kernel_shader_setup.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 sets up the ShaderData structure from the values computed
20  * by the previous kernels.
21  *
22  * It also identifies the rays of state RAY_TO_REGENERATE and enqueues them
23  * in QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS queue.
24  */
25 ccl_device void kernel_shader_setup(KernelGlobals *kg,
26                                     ccl_local_param unsigned int *local_queue_atomics)
27 {
28         /* Enqeueue RAY_TO_REGENERATE rays into QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS queue. */
29         if(ccl_local_id(0) == 0 && ccl_local_id(1) == 0) {
30                 *local_queue_atomics = 0;
31         }
32         ccl_barrier(CCL_LOCAL_MEM_FENCE);
33
34         int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
35         int queue_index = kernel_split_params.queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS];
36         if(ray_index >= queue_index) {
37                 return;
38         }
39         ray_index = get_ray_index(kg, ray_index,
40                                   QUEUE_ACTIVE_AND_REGENERATED_RAYS,
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         char enqueue_flag = (IS_STATE(kernel_split_state.ray_state, ray_index, RAY_TO_REGENERATE)) ? 1 : 0;
50         enqueue_ray_index_local(ray_index,
51                                 QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
52                                 enqueue_flag,
53                                 kernel_split_params.queue_size,
54                                 local_queue_atomics,
55                                 kernel_split_state.queue_data,
56                                 kernel_split_params.queue_index);
57
58         /* Continue on with shader evaluation. */
59         if(IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE)) {
60                 Intersection isect = kernel_split_state.isect[ray_index];
61                 Ray ray = kernel_split_state.ray[ray_index];
62
63                 shader_setup_from_ray(kg,
64                                       kernel_split_sd(sd, ray_index),
65                                       &isect,
66                                       &ray);
67         }
68 }
69
70 CCL_NAMESPACE_END