ClangFormat: apply to source, most of intern
[blender.git] / intern / cycles / kernel / split / kernel_split_common.h
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 #ifndef __KERNEL_SPLIT_H__
18 #define __KERNEL_SPLIT_H__
19
20 #include "kernel/kernel_math.h"
21 #include "kernel/kernel_types.h"
22
23 #include "kernel/split/kernel_split_data.h"
24
25 #include "kernel/kernel_globals.h"
26 #include "kernel/kernel_color.h"
27
28 #ifdef __OSL__
29 #  include "kernel/osl/osl_shader.h"
30 #endif
31
32 #ifdef __KERNEL_OPENCL__
33 #  include "kernel/kernels/opencl/kernel_opencl_image.h"
34 #endif
35 #ifdef __KERNEL_CUDA__
36 #  include "kernel/kernels/cuda/kernel_cuda_image.h"
37 #endif
38 #ifdef __KERNEL_CPU__
39 #  include "kernel/kernels/cpu/kernel_cpu_image.h"
40 #endif
41
42 #include "util/util_atomic.h"
43
44 #include "kernel/kernel_path.h"
45 #ifdef __BRANCHED_PATH__
46 #  include "kernel/kernel_path_branched.h"
47 #endif
48
49 #include "kernel/kernel_queues.h"
50 #include "kernel/kernel_work_stealing.h"
51
52 #ifdef __BRANCHED_PATH__
53 #  include "kernel/split/kernel_branched.h"
54 #endif
55
56 CCL_NAMESPACE_BEGIN
57
58 ccl_device_inline void kernel_split_path_end(KernelGlobals *kg, int ray_index)
59 {
60   ccl_global char *ray_state = kernel_split_state.ray_state;
61
62 #ifdef __BRANCHED_PATH__
63 #  ifdef __SUBSURFACE__
64   ccl_addr_space SubsurfaceIndirectRays *ss_indirect = &kernel_split_state.ss_rays[ray_index];
65
66   if (ss_indirect->num_rays) {
67     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
68   }
69   else
70 #  endif /* __SUBSURFACE__ */
71       if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_INDIRECT_SHARED)) {
72     int orig_ray = kernel_split_state.branched_state[ray_index].original_ray;
73
74     PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
75     PathRadiance *orig_ray_L = &kernel_split_state.path_radiance[orig_ray];
76
77     path_radiance_sum_indirect(L);
78     path_radiance_accum_sample(orig_ray_L, L);
79
80     atomic_fetch_and_dec_uint32(
81         (ccl_global uint *)&kernel_split_state.branched_state[orig_ray].shared_sample_count);
82
83     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_INACTIVE);
84   }
85   else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_LIGHT_INDIRECT)) {
86     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_LIGHT_INDIRECT_NEXT_ITER);
87   }
88   else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_VOLUME_INDIRECT)) {
89     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_VOLUME_INDIRECT_NEXT_ITER);
90   }
91   else if (IS_FLAG(ray_state, ray_index, RAY_BRANCHED_SUBSURFACE_INDIRECT)) {
92     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_SUBSURFACE_INDIRECT_NEXT_ITER);
93   }
94   else {
95     ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
96   }
97 #else
98   ASSIGN_RAY_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER);
99 #endif
100 }
101
102 CCL_NAMESPACE_END
103
104 #endif /* __KERNEL_SPLIT_H__ */