Code cleanup: deduplicate some branched and split kernel code.
[blender-staging.git] / intern / cycles / kernel / split / kernel_lamp_emission.h
1 /*
2  * Copyright 2011-2015 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 operates on QUEUE_ACTIVE_AND_REGENERATED_RAYS.
20  * It processes rays of state RAY_ACTIVE and RAY_HIT_BACKGROUND.
21  * We will empty QUEUE_ACTIVE_AND_REGENERATED_RAYS queue in this kernel.
22  */
23 ccl_device void kernel_lamp_emission(KernelGlobals *kg)
24 {
25 #ifndef __VOLUME__
26         /* We will empty this queue in this kernel. */
27         if(ccl_global_id(0) == 0 && ccl_global_id(1) == 0) {
28                 kernel_split_params.queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS] = 0;
29         }
30 #endif
31         /* Fetch use_queues_flag. */
32         char local_use_queues_flag = *kernel_split_params.use_queues_flag;
33         ccl_barrier(CCL_LOCAL_MEM_FENCE);
34
35         int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
36         if(local_use_queues_flag) {
37                 ray_index = get_ray_index(kg, ray_index,
38                                           QUEUE_ACTIVE_AND_REGENERATED_RAYS,
39                                           kernel_split_state.queue_data,
40                                           kernel_split_params.queue_size,
41 #ifndef __VOLUME__
42                                           1
43 #else
44                                           0
45 #endif
46                                           );
47                 if(ray_index == QUEUE_EMPTY_SLOT) {
48                         return;
49                 }
50         }
51
52         if(IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE) ||
53            IS_STATE(kernel_split_state.ray_state, ray_index, RAY_HIT_BACKGROUND))
54         {
55                 PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
56                 ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
57
58                 float3 throughput = kernel_split_state.throughput[ray_index];
59                 Ray ray = kernel_split_state.ray[ray_index];
60                 ccl_global Intersection *isect = &kernel_split_state.isect[ray_index];
61                 ShaderData *emission_sd = &kernel_split_state.sd_DL_shadow[ray_index];
62
63                 kernel_path_lamp_emission(kg, state, &ray, throughput, isect, emission_sd, L);
64         }
65 }
66
67 CCL_NAMESPACE_END
68