[Bf-blender-cvs] [34f4c31] master: Cycles: Move vector re-allocation out of loops

Sergey Sharybin noreply at git.blender.org
Mon Apr 25 12:25:42 CEST 2016


Commit: 34f4c31692fc35b45fc15b9973bf147079d7e35d
Author: Sergey Sharybin
Date:   Mon Apr 25 12:25:30 2016 +0200
Branches: master
https://developer.blender.org/rB34f4c31692fc35b45fc15b9973bf147079d7e35d

Cycles: Move vector re-allocation out of loops

===================================================================

M	intern/cycles/bvh/bvh_build.cpp
M	intern/cycles/bvh/bvh_split.cpp

===================================================================

diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index a0b09c7..bba89a8 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -617,7 +617,7 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
 	                                        BoundBox::empty,
 	                                        BoundBox::empty};
 	int ob_num = 0;
-
+	int num_new_prims = 0;
 	/* Fill in per-type type/index array. */
 	for(int i = 0; i < range.size(); i++) {
 		const BVHReference& ref = references[range.start() + i];
@@ -629,10 +629,11 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
 
 			bounds[type_index].grow(ref.bounds());
 			visibility[type_index] |= objects[ref.prim_object()]->visibility;
+			++num_new_prims;
 		}
 		else {
 			object_references.push_back(ref);
-			ob_num++;
+			++ob_num;
 		}
 	}
 
@@ -651,11 +652,11 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
 	vector<int, LeafStackAllocator> local_prim_type,
 	                                local_prim_index,
 	                                local_prim_object;
+	local_prim_type.resize(num_new_prims);
+	local_prim_index.resize(num_new_prims);
+	local_prim_object.resize(num_new_prims);
 	for(int i = 0; i < PRIMITIVE_NUM_TOTAL; ++i) {
 		int num = (int)p_type[i].size();
-		local_prim_type.resize(start_index + num);
-		local_prim_index.resize(start_index + num);
-		local_prim_object.resize(start_index + num);
 		if(num != 0) {
 			assert(p_type[i].size() == p_index[i].size());
 			assert(p_type[i].size() == p_object[i].size());
diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp
index 9185bd9..8084975 100644
--- a/intern/cycles/bvh/bvh_split.cpp
+++ b/intern/cycles/bvh/bvh_split.cpp
@@ -44,6 +44,8 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
 	const BVHReference *ref_ptr = &references_->at(range.start());
 	float min_sah = FLT_MAX;
 
+	storage_->right_bounds.resize(range.size());
+
 	for(int dim = 0; dim < 3; dim++) {
 		/* Sort references. */
 		bvh_reference_sort(range.start(),
@@ -53,8 +55,6 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
 
 		/* sweep right to left and determine bounds. */
 		BoundBox right_bounds = BoundBox::empty;
-
-		storage_->right_bounds.resize(range.size());
 		for(int i = range.size() - 1; i > 0; i--) {
 			right_bounds.grow(ref_ptr[i].bounds());
 			storage_->right_bounds[i - 1] = right_bounds;
@@ -157,11 +157,10 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
 	}
 
 	/* select best split plane. */
+	storage_->right_bounds.resize(BVHParams::NUM_SPATIAL_BINS);
 	for(int dim = 0; dim < 3; dim++) {
 		/* sweep right to left and determine bounds. */
 		BoundBox right_bounds = BoundBox::empty;
-
-		storage_->right_bounds.resize(BVHParams::NUM_SPATIAL_BINS);
 		for(int i = BVHParams::NUM_SPATIAL_BINS - 1; i > 0; i--) {
 			right_bounds.grow(storage_->bins[dim][i].bounds);
 			storage_->right_bounds[i - 1] = right_bounds;




More information about the Bf-blender-cvs mailing list