Cycles: Make BVH wider prior to packing
[blender.git] / intern / cycles / bvh / bvh4.h
1 /*
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __BVH4_H__
19 #define __BVH4_H__
20
21 #include "bvh/bvh.h"
22 #include "bvh/bvh_params.h"
23
24 #include "util/util_types.h"
25 #include "util/util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 class BVHNode;
30 struct BVHStackEntry;
31 class BVHParams;
32 class BoundBox;
33 class LeafNode;
34 class Object;
35 class Progress;
36
37 #define BVH_QNODE_SIZE           8
38 #define BVH_QNODE_LEAF_SIZE      1
39 #define BVH_UNALIGNED_QNODE_SIZE 14
40
41 /* BVH4
42  *
43  * Quad BVH, with each node having four children, to use with SIMD instructions.
44  */
45 class BVH4 : public BVH {
46 protected:
47         /* constructor */
48         friend class BVH;
49         BVH4(const BVHParams& params, const vector<Object*>& objects);
50
51         /* Building process. */
52         virtual BVHNode *widen_children_nodes(const BVHNode *root) override;
53
54         /* pack */
55         void pack_nodes(const BVHNode *root);
56
57         void pack_leaf(const BVHStackEntry& e, const LeafNode *leaf);
58         void pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num);
59
60         void pack_aligned_inner(const BVHStackEntry& e,
61                                 const BVHStackEntry *en,
62                                 int num);
63         void pack_aligned_node(int idx,
64                                const BoundBox *bounds,
65                                const int *child,
66                                const uint visibility,
67                                const float time_from,
68                                const float time_to,
69                                const int num);
70
71         void pack_unaligned_inner(const BVHStackEntry& e,
72                                   const BVHStackEntry *en,
73                                   int num);
74         void pack_unaligned_node(int idx,
75                                  const Transform *aligned_space,
76                                  const BoundBox *bounds,
77                                  const int *child,
78                                  const uint visibility,
79                                  const float time_from,
80                                  const float time_to,
81                                  const int num);
82
83         /* refit */
84         void refit_nodes();
85         void refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility);
86 };
87
88 CCL_NAMESPACE_END
89
90 #endif  /* __BVH4_H__ */