e5fad7bce506b8ab6df4cf2c6f8204ac8c351e5c
[blender.git] / intern / cycles / kernel / kernels / opencl / kernel_scene_intersect.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_scene_intersect.h"
18
19 __kernel void kernel_ocl_path_trace_scene_intersect(
20         ccl_global char *globals,
21         ccl_constant KernelData *data,
22         ccl_global uint *rng_coop,
23         ccl_global Ray *Ray_coop,              /* Required for scene_intersect */
24         ccl_global PathState *PathState_coop,  /* Required for scene_intersect */
25         Intersection *Intersection_coop,       /* Required for scene_intersect */
26         ccl_global char *ray_state,            /* Denotes the state of each ray */
27         int sw, int sh,
28         ccl_global int *Queue_data,            /* Memory for queues */
29         ccl_global int *Queue_index,           /* Tracks the number of elements in queues */
30         int queuesize,                         /* Size (capacity) of queues */
31         ccl_global char *use_queues_flag,      /* used to decide if this kernel should use
32                                                 * queues to fetch ray index */
33 #ifdef __KERNEL_DEBUG__
34         DebugData *debugdata_coop,
35 #endif
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         /* Fetch use_queues_flag */
42         ccl_local char local_use_queues_flag;
43         if(get_local_id(0) == 0 && get_local_id(1) == 0) {
44                 local_use_queues_flag = use_queues_flag[0];
45         }
46         barrier(CLK_LOCAL_MEM_FENCE);
47
48         int ray_index;
49         if(local_use_queues_flag) {
50                 int thread_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
51                 ray_index = get_ray_index(thread_index,
52                                           QUEUE_ACTIVE_AND_REGENERATED_RAYS,
53                                           Queue_data,
54                                           queuesize,
55                                           0);
56
57                 if(ray_index == QUEUE_EMPTY_SLOT) {
58                         return;
59                 }
60         } else {
61                 if(x < (sw * parallel_samples) && y < sh){
62                         ray_index = x + y * (sw * parallel_samples);
63                 } else {
64                         return;
65                 }
66         }
67
68         kernel_scene_intersect(globals,
69                                data,
70                                rng_coop,
71                                Ray_coop,
72                                PathState_coop,
73                                Intersection_coop,
74                                ray_state,
75                                sw, sh,
76                                use_queues_flag,
77 #ifdef __KERNEL_DEBUG__
78                                debugdata_coop,
79 #endif
80                                parallel_samples,
81                                ray_index);
82 }