Cycles: OpenCL split kernel cleanup, move casts from .h files to .cl files
[blender.git] / intern / cycles / kernel / kernels / opencl / kernel_shader_eval.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_shader_eval.h"
18
19 __kernel void kernel_ocl_path_trace_shader_eval(
20         ccl_global char *kg,
21         ccl_constant KernelData *data,
22         ccl_global char *sd,                   /* Output ShaderData structure to be filled */
23         ccl_global uint *rng_coop,             /* Required for rbsdf calculation */
24         ccl_global Ray *Ray_coop,              /* Required for setting up shader from ray */
25         ccl_global PathState *PathState_coop,  /* Required for all functions in this kernel */
26         Intersection *Intersection_coop,       /* Required for setting up shader from ray */
27         ccl_global char *ray_state,            /* Denotes the state of each ray */
28         ccl_global int *Queue_data,            /* queue memory */
29         ccl_global int *Queue_index,           /* Tracks the number of elements in each queue */
30         int queuesize)                         /* Size (capacity) of each queue */
31 {
32         /* Enqeueue RAY_TO_REGENERATE rays into QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS 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;
36         }
37         barrier(CLK_LOCAL_MEM_FENCE);
38
39         int ray_index = get_global_id(1) * get_global_size(0) + get_global_id(0);
40         ray_index = get_ray_index(ray_index,
41                                   QUEUE_ACTIVE_AND_REGENERATED_RAYS,
42                                   Queue_data,
43                                   queuesize,
44                                   0);
45
46         if(ray_index == QUEUE_EMPTY_SLOT) {
47                 return;
48         }
49
50         char enqueue_flag = (IS_STATE(ray_state, ray_index, RAY_TO_REGENERATE)) ? 1 : 0;
51         enqueue_ray_index_local(ray_index,
52                                 QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
53                                 enqueue_flag,
54                                 queuesize,
55                                 &local_queue_atomics,
56                                 Queue_data,
57                                 Queue_index);
58
59         /* Continue on with shader evaluation. */
60         kernel_shader_eval((KernelGlobals *)kg,
61                            data,
62                            (ShaderData *)sd,
63                            rng_coop,
64                            Ray_coop,
65                            PathState_coop,
66                            Intersection_coop,
67                            ray_state,
68                            ray_index);
69 }