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 
22 #include "kernel/kernel_globals.h"
23 
24 CCL_NAMESPACE_BEGIN
25 
split_data_buffer_size(KernelGlobals * kg,size_t num_elements)26 ccl_device_inline uint64_t split_data_buffer_size(KernelGlobals *kg, size_t num_elements)
27 {
28   (void)kg; /* Unused on CPU. */
29 
30   uint64_t size = 0;
31 #define SPLIT_DATA_ENTRY(type, name, num) +align_up(num_elements *num * sizeof(type), 16)
32   size = size SPLIT_DATA_ENTRIES;
33 #undef SPLIT_DATA_ENTRY
34 
35   uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures - 1);
36 
37 #ifdef __BRANCHED_PATH__
38   size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
39 #endif
40 
41   size += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
42 
43   return size;
44 }
45 
split_data_init(KernelGlobals * kg,ccl_global SplitData * split_data,size_t num_elements,ccl_global void * data,ccl_global char * ray_state)46 ccl_device_inline void split_data_init(KernelGlobals *kg,
47                                        ccl_global SplitData *split_data,
48                                        size_t num_elements,
49                                        ccl_global void *data,
50                                        ccl_global char *ray_state)
51 {
52   (void)kg; /* Unused on CPU. */
53 
54   ccl_global char *p = (ccl_global char *)data;
55 
56 #define SPLIT_DATA_ENTRY(type, name, num) \
57   split_data->name = (type *)p; \
58   p += align_up(num_elements * num * sizeof(type), 16);
59   SPLIT_DATA_ENTRIES;
60 #undef SPLIT_DATA_ENTRY
61 
62   uint64_t closure_size = sizeof(ShaderClosure) * (kernel_data.integrator.max_closures - 1);
63 
64 #ifdef __BRANCHED_PATH__
65   split_data->_branched_state_sd = (ShaderData *)p;
66   p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
67 #endif
68 
69   split_data->_sd = (ShaderData *)p;
70   p += align_up(num_elements * (sizeof(ShaderData) + closure_size), 16);
71 
72   split_data->ray_state = ray_state;
73 }
74 
75 CCL_NAMESPACE_END
76 
77 #endif /* __KERNEL_SPLIT_DATA_H__ */
78