Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2015-01-10 20:32:44 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-01-12 12:49:59 +0300
commitc707b91ce6b14182a3a579b645cfd832fc1ae658 (patch)
treebffa2e62e92bb5892365380641b6d2347b20a797 /intern/cycles/bvh
parentb56f5900dc776c45d83c99334473d1cb3874feaf (diff)
Cycles: Optimize leaf splitting code by avoid vector allocation
Use variables allocated in the stack and avoid heap allocation which should make leaf splitting code a bit faster.
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r--intern/cycles/bvh/bvh_build.cpp43
-rw-r--r--intern/cycles/bvh/bvh_build.h9
2 files changed, 29 insertions, 23 deletions
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index f4368a84482..d0542f064a3 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -449,16 +449,15 @@ BVHNode *BVHBuild::create_object_leaf_nodes(const BVHReference *ref, int start,
}
}
-BVHNode *BVHBuild::create_primitive_leaf_node(const vector<int>& p_type,
- const vector<int>& p_index,
- const vector<int>& p_object,
+BVHNode *BVHBuild::create_primitive_leaf_node(const int *p_type,
+ const int *p_index,
+ const int *p_object,
const BoundBox& bounds,
uint visibility,
- int start)
+ int start,
+ int num)
{
- assert(p_type.size() == p_index.size());
- assert(p_index.size() == p_object.size());
- for(int i = 0; i < p_type.size(); ++i) {
+ for(int i = 0; i < num; ++i) {
if(start + i == prim_index.size()) {
assert(params.use_spatial_split);
prim_type.push_back(p_type[i]);
@@ -471,30 +470,34 @@ BVHNode *BVHBuild::create_primitive_leaf_node(const vector<int>& p_type,
prim_object[start + i] = p_object[i];
}
}
- return new LeafNode(bounds, visibility, start, start + p_type.size());
+ return new LeafNode(bounds, visibility, start, start + num);
}
BVHNode* BVHBuild::create_leaf_node_split(const BVHRange& range)
{
- /* TODO(sergey): Reserve some elementsin arrays by default. */
- vector<int> p_type[PRIMITIVE_NUM_TOTAL];
- vector<int> p_index[PRIMITIVE_NUM_TOTAL];
- vector<int> p_object[PRIMITIVE_NUM_TOTAL];
+#define MAX_LEAF_SIZE 8
+ int p_num[PRIMITIVE_NUM_TOTAL] = {0};
+ int p_type[PRIMITIVE_NUM_TOTAL][MAX_LEAF_SIZE];
+ int p_index[PRIMITIVE_NUM_TOTAL][MAX_LEAF_SIZE];
+ int p_object[PRIMITIVE_NUM_TOTAL][MAX_LEAF_SIZE];
+ uint visibility[PRIMITIVE_NUM_TOTAL] = {0};
+ /* NOTE: Keep initializtion in sync with actual number of primitives. */
BoundBox bounds[PRIMITIVE_NUM_TOTAL] = {BoundBox::empty,
BoundBox::empty,
BoundBox::empty,
BoundBox::empty};
int ob_num = 0;
- uint visibility[PRIMITIVE_NUM_TOTAL] = {0};
/* Fill in per-type type/index array. */
for(int i = 0; i < range.size(); i++) {
BVHReference& ref = references[range.start() + i];
if(ref.prim_index() != -1) {
int type_index = bitscan(ref.prim_type() & PRIMITIVE_ALL);
- p_type[type_index].push_back(ref.prim_type());
- p_index[type_index].push_back(ref.prim_index());
- p_object[type_index].push_back(ref.prim_object());
+ int idx = p_num[type_index];
+ p_type[type_index][idx] = ref.prim_type();
+ p_index[type_index][idx] = ref.prim_index();
+ p_object[type_index][idx] = ref.prim_object();
+ ++p_num[type_index];
bounds[type_index].grow(ref.bounds());
visibility[type_index] |= objects[ref.prim_object()]->visibility;
@@ -512,15 +515,16 @@ BVHNode* BVHBuild::create_leaf_node_split(const BVHRange& range)
int num_leaves = 0;
int start = range.start();
for(int i = 0; i < PRIMITIVE_NUM_TOTAL; ++i) {
- if(p_type[i].size()) {
+ if(p_num[i] != 0) {
leaves[num_leaves] = create_primitive_leaf_node(p_type[i],
p_index[i],
p_object[i],
bounds[i],
visibility[i],
- start);
+ start,
+ p_num[i]);
++num_leaves;
- start += p_type[i].size();
+ start += p_num[i];
}
}
@@ -557,6 +561,7 @@ BVHNode* BVHBuild::create_leaf_node_split(const BVHRange& range)
BVHNode *inner_b = new InnerNode(inner_bounds_b, leaves[2], leaves[3]);
return new InnerNode(range.bounds(), inner_a, inner_b);
}
+#undef AMX_LEAF_SIZE
}
BVHNode* BVHBuild::create_leaf_node(const BVHRange& range)
diff --git a/intern/cycles/bvh/bvh_build.h b/intern/cycles/bvh/bvh_build.h
index 75c64be6eab..1e629fb5eb2 100644
--- a/intern/cycles/bvh/bvh_build.h
+++ b/intern/cycles/bvh/bvh_build.h
@@ -72,12 +72,13 @@ protected:
/* Leaf node type splitting. */
BVHNode *create_leaf_node_split(const BVHRange& range);
- BVHNode *create_primitive_leaf_node(const vector<int>& p_type,
- const vector<int>& p_index,
- const vector<int>& p_object,
+ BVHNode *create_primitive_leaf_node(const int *p_type,
+ const int *p_index,
+ const int *p_object,
const BoundBox& bounds,
uint visibility,
- int start);
+ int start,
+ int nun);
bool range_within_max_leaf_size(const BVHRange& range);