Cycles: Remove few function arguments needed only for the split kernel
[blender.git] / intern / cycles / kernel / kernels / opencl / kernel_background_buffer_update.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_background_buffer_update.h"
18
19 __kernel void kernel_ocl_path_trace_background_buffer_update(
20         ccl_global char *kg,
21         ccl_constant KernelData *data,
22         ccl_global float *per_sample_output_buffers,
23         ccl_global uint *rng_state,
24         ccl_global uint *rng_coop,             /* Required for buffer Update */
25         ccl_global float3 *throughput_coop,    /* Required for background hit processing */
26         PathRadiance *PathRadiance_coop,       /* Required for background hit processing and buffer Update */
27         ccl_global Ray *Ray_coop,              /* Required for background hit processing */
28         ccl_global PathState *PathState_coop,  /* Required for background hit processing */
29         ccl_global float *L_transparent_coop,  /* Required for background hit processing and buffer Update */
30         ccl_global char *ray_state,            /* Stores information on the current state of a ray */
31         int sw, int sh, int sx, int sy, int stride,
32         int rng_state_offset_x,
33         int rng_state_offset_y,
34         int rng_state_stride,
35         ccl_global unsigned int *work_array,   /* Denotes work of each ray */
36         ccl_global int *Queue_data,            /* Queues memory */
37         ccl_global int *Queue_index,           /* Tracks the number of elements in each queue */
38         int queuesize,                         /* Size (capacity) of each queue */
39         int end_sample,
40         int start_sample,
41 #ifdef __WORK_STEALING__
42         ccl_global unsigned int *work_pool_wgs,
43         unsigned int num_samples,
44 #endif
45 #ifdef __KERNEL_DEBUG__
46         DebugData *debugdata_coop,
47 #endif
48         int parallel_samples)                  /* Number of samples to be processed in parallel */
49 {
50         ccl_local unsigned int local_queue_atomics;
51         if(get_local_id(0) == 0 && get_local_id(1) == 0) {
52                 local_queue_atomics = 0;
53         }
54         barrier(CLK_LOCAL_MEM_FENCE);
55
56         int ray_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
57         if(ray_index == 0) {
58                 /* We will empty this queue in this kernel. */
59                 Queue_index[QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS] = 0;
60         }
61         char enqueue_flag = 0;
62         ray_index = get_ray_index(ray_index,
63                                   QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
64                                   Queue_data,
65                                   queuesize,
66                                   1);
67
68 #ifdef __COMPUTE_DEVICE_GPU__
69         /* If we are executing on a GPU device, we exit all threads that are not
70          * required.
71          *
72          * If we are executing on a CPU device, then we need to keep all threads
73          * active since we have barrier() calls later in the kernel. CPU devices,
74          * expect all threads to execute barrier statement.
75          */
76         if(ray_index == QUEUE_EMPTY_SLOT) {
77                 return;
78         }
79 #endif
80
81 #ifndef __COMPUTE_DEVICE_GPU__
82         if(ray_index != QUEUE_EMPTY_SLOT) {
83 #endif
84                 enqueue_flag =
85                         kernel_background_buffer_update((KernelGlobals *)kg,
86                                                         per_sample_output_buffers,
87                                                         rng_state,
88                                                         rng_coop,
89                                                         throughput_coop,
90                                                         PathRadiance_coop,
91                                                         Ray_coop,
92                                                         PathState_coop,
93                                                         L_transparent_coop,
94                                                         ray_state,
95                                                         sw, sh, sx, sy, stride,
96                                                         rng_state_offset_x,
97                                                         rng_state_offset_y,
98                                                         rng_state_stride,
99                                                         work_array,
100                                                         end_sample,
101                                                         start_sample,
102 #ifdef __WORK_STEALING__
103                                                         work_pool_wgs,
104                                                         num_samples,
105 #endif
106 #ifdef __KERNEL_DEBUG__
107                                                         debugdata_coop,
108 #endif
109                                                         parallel_samples,
110                                                         ray_index);
111 #ifndef __COMPUTE_DEVICE_GPU__
112         }
113 #endif
114
115         /* Enqueue RAY_REGENERATED rays into QUEUE_ACTIVE_AND_REGENERATED_RAYS;
116          * These rays will be made active during next SceneIntersectkernel.
117          */
118         enqueue_ray_index_local(ray_index,
119                                 QUEUE_ACTIVE_AND_REGENERATED_RAYS,
120                                 enqueue_flag,
121                                 queuesize,
122                                 &local_queue_atomics,
123                                 Queue_data,
124                                 Queue_index);
125 }