Cycles: Replace __MAX_CLOSURE__ build option with runtime integrator variable
[blender.git] / intern / cycles / kernel / split / kernel_split_data.h
1 /*
2  * Copyright 2011-2016 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_DATA_H__
18 #define __KERNEL_SPLIT_DATA_H__
19
20 #include "kernel/split/kernel_split_data_types.h"
21 #include "kernel/kernel_globals.h"
22
23 CCL_NAMESPACE_BEGIN
24
25 ccl_device_inline uint64_t split_data_buffer_size(KernelGlobals *kg, size_t num_elements)
26 {
27         (void)kg;  /* Unused on CPU. */
28
29         uint64_t size = 0;
30 #define SPLIT_DATA_ENTRY(type, name, num) + align_up(num_elements * num * sizeof(type), 16)
31         size = size SPLIT_DATA_ENTRIES;
32 #undef SPLIT_DATA_ENTRY
33
34         uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures-1);
35
36 #ifdef __BRANCHED_PATH__
37         size += align_up(closure_size * num_elements, 16);
38 #endif
39
40         size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
41
42         return size;
43 }
44
45 ccl_device_inline void split_data_init(KernelGlobals *kg,
46                                        ccl_global SplitData *split_data,
47                                        size_t num_elements,
48                                        ccl_global void *data,
49                                        ccl_global char *ray_state)
50 {
51         (void)kg;  /* Unused on CPU. */
52
53         ccl_global char *p = (ccl_global char*)data;
54
55 #define SPLIT_DATA_ENTRY(type, name, num) \
56         split_data->name = (type*)p; p += align_up(num_elements * num * sizeof(type), 16);
57         SPLIT_DATA_ENTRIES;
58 #undef SPLIT_DATA_ENTRY
59
60         uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures-1);
61
62 #ifdef __BRANCHED_PATH__
63         p += align_up(closure_size * num_elements, 16);
64 #endif
65
66         split_data->_sd = (ShaderData*)p;
67         p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
68
69         split_data->ray_state = ray_state;
70 }
71
72 CCL_NAMESPACE_END
73
74 #endif  /* __KERNEL_SPLIT_DATA_H__ */