1bc7808d834f41a79239f9e15d57ab1bb21a3685
[blender.git] / intern / cycles / kernel / kernels / opencl / kernel_lamp_emission.cl
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 #include "split/kernel_lamp_emission.h"
18
19 __kernel void kernel_ocl_path_trace_lamp_emission(
20         ccl_global char *globals,
21         ccl_constant KernelData *data,
22         ccl_global char *shader_data,          /* Required for lamp emission */
23         ccl_global float3 *throughput_coop,    /* Required for lamp emission */
24         PathRadiance *PathRadiance_coop,       /* Required for lamp emission */
25         ccl_global Ray *Ray_coop,              /* Required for lamp emission */
26         ccl_global PathState *PathState_coop,  /* Required for lamp emission */
27         Intersection *Intersection_coop,       /* Required for lamp emission */
28         ccl_global char *ray_state,            /* Denotes the state of each ray */
29         int sw, int sh,
30         ccl_global int *Queue_data,            /* Memory for queues */
31         ccl_global int *Queue_index,           /* Tracks the number of elements in queues */
32         int queuesize,                         /* Size (capacity) of queues */
33         ccl_global char *use_queues_flag,      /* Used to decide if this kernel should use
34                                                 * queues to fetch ray index
35                                                 */
36         int parallel_samples)                  /* Number of samples to be processed in parallel */
37 {
38         int x = get_global_id(0);
39         int y = get_global_id(1);
40
41         /* We will empty this queue in this kernel. */
42         if(get_global_id(0) == 0 && get_global_id(1) == 0) {
43                 Queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS] = 0;
44         }
45         /* Fetch use_queues_flag. */
46         ccl_local char local_use_queues_flag;
47         if(get_local_id(0) == 0 && get_local_id(1) == 0) {
48                 local_use_queues_flag = use_queues_flag[0];
49         }
50         barrier(CLK_LOCAL_MEM_FENCE);
51
52         int ray_index;
53         if(local_use_queues_flag) {
54                 int thread_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
55                 ray_index = get_ray_index(thread_index,
56                                           QUEUE_ACTIVE_AND_REGENERATED_RAYS,
57                                           Queue_data,
58                                           queuesize,
59                                           1);
60                 if(ray_index == QUEUE_EMPTY_SLOT) {
61                         return;
62                 }
63         } else {
64                 if(x < (sw * parallel_samples) && y < sh){
65                         ray_index = x + y * (sw * parallel_samples);
66                 } else {
67                         return;
68                 }
69         }
70
71         kernel_lamp_emission(globals,
72                              data,
73                              shader_data,
74                              throughput_coop,
75                              PathRadiance_coop,
76                              Ray_coop,
77                              PathState_coop,
78                              Intersection_coop,
79                              ray_state,
80                              sw, sh,
81                              use_queues_flag,
82                              parallel_samples,
83                              ray_index);
84 }