Blender V4.3
build.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Adapted code from NVIDIA Corporation. */
7
8#ifndef __BVH_BUILD_H__
9#define __BVH_BUILD_H__
10
11#include <float.h>
12
13#include "bvh/params.h"
14#include "bvh/unaligned.h"
15
16#include "util/array.h"
17#include "util/task.h"
18#include "util/vector.h"
19
21
22class Boundbox;
23class BVHBuildTask;
24class BVHNode;
25class BVHSpatialSplitBuildTask;
26class BVHParams;
27class InnerNode;
28class Geometry;
29class Hair;
30class Mesh;
31class Object;
32class PointCloud;
33class Progress;
34
35/* BVH Builder */
36
37class BVHBuild {
38 public:
39 /* Constructor/Destructor */
40 BVHBuild(const vector<Object *> &objects,
45 const BVHParams &params,
47 ~BVHBuild();
48
49 BVHNode *run();
50
51 protected:
52 friend class BVHMixedSplit;
53 friend class BVHObjectSplit;
54 friend class BVHSpatialSplit;
55 friend class BVHBuildTask;
57 friend class BVHObjectBinning;
58
59 /* Adding references. */
60 void add_reference_triangles(BoundBox &root, BoundBox &center, Mesh *mesh, int i);
61 void add_reference_curves(BoundBox &root, BoundBox &center, Hair *hair, int i);
62 void add_reference_points(BoundBox &root, BoundBox &center, PointCloud *pointcloud, int i);
63 void add_reference_geometry(BoundBox &root, BoundBox &center, Geometry *geom, int i);
64 void add_reference_object(BoundBox &root, BoundBox &center, Object *ob, int i);
65 void add_references(BVHRange &root);
66
67 /* Building. */
68 BVHNode *build_node(const BVHRange &range,
70 int level,
71 BVHSpatialStorage *storage);
72 BVHNode *build_node(const BVHObjectBinning &range, int level);
74 BVHNode *create_object_leaf_nodes(const BVHReference *ref, int start, int num);
75
76 bool range_within_max_leaf_size(const BVHRange &range,
77 const vector<BVHReference> &references) const;
78
79 /* Threads. */
80 enum { THREAD_TASK_SIZE = 4096 };
81 void thread_build_node(InnerNode *node, int child, const BVHObjectBinning &range, int level);
83 int child,
84 const BVHRange &range,
86 int level);
88
89 /* Progress. */
90 void progress_update();
91
92 /* Tree rotations. */
93 void rotate(BVHNode *node, int max_depth);
94 void rotate(BVHNode *node, int max_depth, int iterations);
95
96 /* Objects and primitive references. */
100
101 /* Output primitive indexes and objects. */
106
108
109 /* Build parameters. */
111
112 /* Progress reporting. */
118
119 /* Spatial splitting. */
121 enumerable_thread_specific<BVHSpatialStorage> spatial_storage;
124
125 /* Threads. */
127
128 /* Unaligned building. */
130};
131
133
134#endif /* __BVH_BUILD_H__ */
BVHNode * create_object_leaf_nodes(const BVHReference *ref, int start, int num)
Definition build.cpp:899
BVHNode * create_leaf_node(const BVHRange &range, const vector< BVHReference > &references)
Definition build.cpp:936
void thread_build_spatial_split_node(InnerNode *node, int child, const BVHRange &range, vector< BVHReference > &references, int level)
Definition build.cpp:616
size_t progress_count
Definition build.h:115
BVHBuild(const vector< Object * > &objects, array< int > &prim_type, array< int > &prim_index, array< int > &prim_object, array< float2 > &prim_time, const BVHParams &params, Progress &progress)
Definition build.cpp:35
bool range_within_max_leaf_size(const BVHRange &range, const vector< BVHReference > &references) const
Definition build.cpp:636
thread_spin_lock spatial_spin_lock
Definition build.h:123
thread_mutex build_mutex
Definition build.h:87
void add_references(BVHRange &root)
Definition build.cpp:411
void add_reference_object(BoundBox &root, BoundBox &center, Object *ob, int i)
Definition build.cpp:375
BVHNode * build_node(const BVHRange &range, vector< BVHReference > &references, int level, BVHSpatialStorage *storage)
Definition build.cpp:778
void add_reference_curves(BoundBox &root, BoundBox &center, Hair *hair, int i)
Definition build.cpp:149
friend class BVHBuildTask
Definition build.h:55
bool need_prim_time
Definition build.h:107
size_t spatial_free_index
Definition build.h:122
BVHUnaligned unaligned_heuristic
Definition build.h:129
BVHNode * run()
Definition build.cpp:473
TaskPool task_pool
Definition build.h:126
void add_reference_geometry(BoundBox &root, BoundBox &center, Geometry *geom, int i)
Definition build.cpp:356
Progress & progress
Definition build.h:113
array< float2 > & prim_time
Definition build.h:105
vector< Object * > objects
Definition build.h:97
array< int > & prim_index
Definition build.h:103
void rotate(BVHNode *node, int max_depth)
Definition build.cpp:1194
enumerable_thread_specific< BVHSpatialStorage > spatial_storage
Definition build.h:121
size_t progress_total
Definition build.h:116
friend class BVHSpatialSplitBuildTask
Definition build.h:56
size_t progress_original_total
Definition build.h:117
BVHParams params
Definition build.h:110
void thread_build_node(InnerNode *node, int child, const BVHObjectBinning &range, int level)
Definition build.cpp:590
float spatial_min_overlap
Definition build.h:120
int num_original_references
Definition build.h:99
array< int > & prim_type
Definition build.h:102
@ THREAD_TASK_SIZE
Definition build.h:80
double progress_start_time
Definition build.h:114
array< int > & prim_object
Definition build.h:104
void add_reference_points(BoundBox &root, BoundBox &center, PointCloud *pointcloud, int i)
Definition build.cpp:261
void progress_update()
Definition build.cpp:574
~BVHBuild()
Definition build.cpp:55
vector< BVHReference > references
Definition build.h:98
void add_reference_triangles(BoundBox &root, BoundBox &center, Mesh *mesh, int i)
Definition build.cpp:59
Definition hair.h:14
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex
Definition thread.h:29
tbb::spin_mutex thread_spin_lock
Definition thread.h:55