2 * Copyright 2011-2015 Blender Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "split/kernel_direct_lighting.h"
19 __kernel void kernel_ocl_path_trace_direct_lighting(
21 ccl_constant KernelData *data,
22 ccl_global char *sd, /* Required for direct lighting */
23 ccl_global char *sd_DL, /* Required for direct lighting */
24 ccl_global uint *rng_coop, /* Required for direct lighting */
25 ccl_global PathState *PathState_coop, /* Required for direct lighting */
26 ccl_global int *ISLamp_coop, /* Required for direct lighting */
27 ccl_global Ray *LightRay_coop, /* Required for direct lighting */
28 ccl_global BsdfEval *BSDFEval_coop, /* Required for direct lighting */
29 ccl_global char *ray_state, /* Denotes the state of each ray */
30 ccl_global int *Queue_data, /* Queue memory */
31 ccl_global int *Queue_index, /* Tracks the number of elements in each queue */
32 int queuesize) /* Size (capacity) of each queue */
34 ccl_local unsigned int local_queue_atomics;
35 if(get_local_id(0) == 0 && get_local_id(1) == 0) {
36 local_queue_atomics = 0;
38 barrier(CLK_LOCAL_MEM_FENCE);
40 char enqueue_flag = 0;
41 int ray_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
42 ray_index = get_ray_index(ray_index,
43 QUEUE_ACTIVE_AND_REGENERATED_RAYS,
48 #ifdef __COMPUTE_DEVICE_GPU__
49 /* If we are executing on a GPU device, we exit all threads that are not
52 * If we are executing on a CPU device, then we need to keep all threads
53 * active since we have barrier() calls later in the kernel. CPU devices,
54 * expect all threads to execute barrier statement.
56 if(ray_index == QUEUE_EMPTY_SLOT) {
61 #ifndef __COMPUTE_DEVICE_GPU__
62 if(ray_index != QUEUE_EMPTY_SLOT) {
64 enqueue_flag = kernel_direct_lighting((KernelGlobals *)kg,
75 #ifndef __COMPUTE_DEVICE_GPU__
80 /* Enqueue RAY_SHADOW_RAY_CAST_DL rays. */
81 enqueue_ray_index_local(ray_index,
82 QUEUE_SHADOW_RAY_CAST_DL_RAYS,