CMake: add WITH_LINKER_LLD option for unix platforms
[blender-staging.git] / intern / cycles / kernel / split / kernel_indirect_subsurface.h
1 /*
2  * Copyright 2011-2017 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 CCL_NAMESPACE_BEGIN
18
19 ccl_device void kernel_indirect_subsurface(KernelGlobals *kg)
20 {
21   int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
22   if (thread_index == 0) {
23     /* We will empty both queues in this kernel. */
24     kernel_split_params.queue_index[QUEUE_ACTIVE_AND_REGENERATED_RAYS] = 0;
25     kernel_split_params.queue_index[QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS] = 0;
26   }
27
28   int ray_index;
29   get_ray_index(kg,
30                 thread_index,
31                 QUEUE_ACTIVE_AND_REGENERATED_RAYS,
32                 kernel_split_state.queue_data,
33                 kernel_split_params.queue_size,
34                 1);
35   ray_index = get_ray_index(kg,
36                             thread_index,
37                             QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
38                             kernel_split_state.queue_data,
39                             kernel_split_params.queue_size,
40                             1);
41
42 #ifdef __SUBSURFACE__
43   if (ray_index == QUEUE_EMPTY_SLOT) {
44     return;
45   }
46
47   ccl_global char *ray_state = kernel_split_state.ray_state;
48   ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
49   PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
50   ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
51   ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
52
53   if (IS_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER)) {
54     ccl_addr_space SubsurfaceIndirectRays *ss_indirect = &kernel_split_state.ss_rays[ray_index];
55
56     /* Trace indirect subsurface rays by restarting the loop. this uses less
57      * stack memory than invoking kernel_path_indirect.
58      */
59     if (ss_indirect->num_rays) {
60       kernel_path_subsurface_setup_indirect(kg, ss_indirect, state, ray, L, throughput);
61       ASSIGN_RAY_STATE(ray_state, ray_index, RAY_REGENERATED);
62     }
63   }
64 #endif /* __SUBSURFACE__ */
65 }
66
67 CCL_NAMESPACE_END