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 uint *rng_coop, /* Required for direct lighting */
24 ccl_global PathState *PathState_coop, /* Required for direct lighting */
25 ccl_global int *ISLamp_coop, /* Required for direct lighting */
26 ccl_global Ray *LightRay_coop, /* Required for direct lighting */
27 ccl_global BsdfEval *BSDFEval_coop, /* Required for direct lighting */
28 ccl_global char *ray_state, /* Denotes the state of each ray */
29 ccl_global int *Queue_data, /* Queue memory */
30 ccl_global int *Queue_index, /* Tracks the number of elements in each queue */
31 int queuesize) /* Size (capacity) of each queue */
33 ccl_local unsigned int local_queue_atomics;
34 if(get_local_id(0) == 0 && get_local_id(1) == 0) {
35 local_queue_atomics = 0;
37 barrier(CLK_LOCAL_MEM_FENCE);
39 char enqueue_flag = 0;
40 int ray_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
41 ray_index = get_ray_index(ray_index,
42 QUEUE_ACTIVE_AND_REGENERATED_RAYS,
47 #ifdef __COMPUTE_DEVICE_GPU__
48 /* If we are executing on a GPU device, we exit all threads that are not
51 * If we are executing on a CPU device, then we need to keep all threads
52 * active since we have barrier() calls later in the kernel. CPU devices,
53 * expect all threads to execute barrier statement.
55 if(ray_index == QUEUE_EMPTY_SLOT) {
60 #ifndef __COMPUTE_DEVICE_GPU__
61 if(ray_index != QUEUE_EMPTY_SLOT) {
63 enqueue_flag = kernel_direct_lighting((KernelGlobals *)kg,
73 #ifndef __COMPUTE_DEVICE_GPU__
78 /* Enqueue RAY_SHADOW_RAY_CAST_DL rays. */
79 enqueue_ray_index_local(ray_index,
80 QUEUE_SHADOW_RAY_CAST_DL_RAYS,