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  */
kernel_lamp_emission(KernelGlobals * kg)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,
38                               ray_index,
39                               QUEUE_ACTIVE_AND_REGENERATED_RAYS,
40                               kernel_split_state.queue_data,
41                               kernel_split_params.queue_size,
42 #ifndef __VOLUME__
43                               1
44 #else
45                               0
46 #endif
47     );
48     if (ray_index == QUEUE_EMPTY_SLOT) {
49       return;
50     }
51   }
52 
53   if (IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE) ||
54       IS_STATE(kernel_split_state.ray_state, ray_index, RAY_HIT_BACKGROUND)) {
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 *sd = kernel_split_sd(sd, ray_index);
62 
63     kernel_path_lamp_emission(kg, state, &ray, throughput, isect, sd, L);
64   }
65 }
66 
67 CCL_NAMESPACE_END
68