[Bf-blender-cvs] [791a085] master: Cycles: Name cleanup and some comments in BVH code

Sergey Sharybin noreply at git.blender.org
Thu Mar 31 13:57:46 CEST 2016


Commit: 791a0852e8d7f17887896245ef62a826b2228648
Author: Sergey Sharybin
Date:   Mon Feb 22 16:33:42 2016 +0100
Branches: master
https://developer.blender.org/rB791a0852e8d7f17887896245ef62a826b2228648

Cycles: Name cleanup and some comments in BVH code

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

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

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

diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index 9f1fb9c..6d785df 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -243,10 +243,10 @@ BVHNode* BVHBuild::run()
 		spatial_storage.resize(1);
 		size_t num_bins = max(root.size(), (int)BVHParams::NUM_SPATIAL_BINS) - 1;
 		foreach(BVHSpatialStorage &storage, spatial_storage) {
-			storage.spatial_right_bounds.clear();
-			storage.spatial_right_bounds.resize(num_bins);
-			storage.spatial_indices.clear();
-			storage.spatial_indices.reserve(num_bins);
+			storage.right_bounds.clear();
+			storage.right_bounds.resize(num_bins);
+			storage.reference_indices.clear();
+			storage.reference_indices.reserve(num_bins);
 		}
 	}
 
diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h
index 2e579ba..022ecbc 100644
--- a/intern/cycles/bvh/bvh_params.h
+++ b/intern/cycles/bvh/bvh_params.h
@@ -183,10 +183,21 @@ struct BVHSpatialBin
  */
 
 struct BVHSpatialStorage {
-	vector<BoundBox> spatial_right_bounds;
-	BVHSpatialBin spatial_bins[3][BVHParams::NUM_SPATIAL_BINS];
-	vector<int> spatial_indices;
-	vector<BVHReference> spatial_new_refs;
+	/* Accumulated bounds when sweeping from right to left.  */
+	vector<BoundBox> right_bounds;
+
+	/* Bins used for histogram when selecting best split plane. */
+	BVHSpatialBin bins[3][BVHParams::NUM_SPATIAL_BINS];
+
+	/* Indices to a reference array used by object splitter to speed up
+	 * sorting process.
+	 */
+	vector<int> reference_indices;
+
+	/* Temporary storage for the new references. Used by spatial split to store
+	 * new references in before they're getting inserted into actual array,
+	 */
+	vector<BVHReference> new_references;
 };
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp
index 5d33238..7ca0767 100644
--- a/intern/cycles/bvh/bvh_split.cpp
+++ b/intern/cycles/bvh/bvh_split.cpp
@@ -42,8 +42,8 @@ BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
 	const BVHReference *ref_ptr = &builder.references[range.start()];
 	float min_sah = FLT_MAX;
 
-	storage->spatial_indices.resize(range.size());
-	int *indices = &storage->spatial_indices[0];
+	storage->reference_indices.resize(range.size());
+	int *indices = &storage->reference_indices[0];
 
 	for(int dim = 0; dim < 3; dim++) {
 		/* Sort references.
@@ -61,7 +61,7 @@ BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
 
 		for(int i = range.size() - 1; i > 0; i--) {
 			right_bounds.grow(ref_ptr[indices[i]].bounds());
-			storage_->spatial_right_bounds[i - 1] = right_bounds;
+			storage_->right_bounds[i - 1] = right_bounds;
 		}
 
 		/* sweep left to right and select lowest SAH. */
@@ -69,7 +69,7 @@ BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
 
 		for(int i = 1; i < range.size(); i++) {
 			left_bounds.grow(ref_ptr[indices[i - 1]].bounds());
-			right_bounds = storage_->spatial_right_bounds[i - 1];
+			right_bounds = storage_->right_bounds[i - 1];
 
 			float sah = nodeSAH +
 				left_bounds.safe_area() * builder.params.primitive_cost(i) +
@@ -117,7 +117,7 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
 
 	for(int dim = 0; dim < 3; dim++) {
 		for(int i = 0; i < BVHParams::NUM_SPATIAL_BINS; i++) {
-			BVHSpatialBin& bin = storage_->spatial_bins[dim][i];
+			BVHSpatialBin& bin = storage_->bins[dim][i];
 
 			bin.bounds = BoundBox::empty;
 			bin.enter = 0;
@@ -143,13 +143,13 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
 				BVHReference leftRef, rightRef;
 
 				split_reference(builder, leftRef, rightRef, currRef, dim, origin[dim] + binSize[dim] * (float)(i + 1));
-				storage_->spatial_bins[dim][i].bounds.grow(leftRef.bounds());
+				storage_->bins[dim][i].bounds.grow(leftRef.bounds());
 				currRef = rightRef;
 			}
 
-			storage_->spatial_bins[dim][lastBin[dim]].bounds.grow(currRef.bounds());
-			storage_->spatial_bins[dim][firstBin[dim]].enter++;
-			storage_->spatial_bins[dim][lastBin[dim]].exit++;
+			storage_->bins[dim][lastBin[dim]].bounds.grow(currRef.bounds());
+			storage_->bins[dim][firstBin[dim]].enter++;
+			storage_->bins[dim][lastBin[dim]].exit++;
 		}
 	}
 
@@ -159,8 +159,8 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
 		BoundBox right_bounds = BoundBox::empty;
 
 		for(int i = BVHParams::NUM_SPATIAL_BINS - 1; i > 0; i--) {
-			right_bounds.grow(storage_->spatial_bins[dim][i].bounds);
-			storage_->spatial_right_bounds[i - 1] = right_bounds;
+			right_bounds.grow(storage_->bins[dim][i].bounds);
+			storage_->right_bounds[i - 1] = right_bounds;
 		}
 
 		/* sweep left to right and select lowest SAH. */
@@ -169,13 +169,13 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
 		int rightNum = range.size();
 
 		for(int i = 1; i < BVHParams::NUM_SPATIAL_BINS; i++) {
-			left_bounds.grow(storage_->spatial_bins[dim][i - 1].bounds);
-			leftNum += storage_->spatial_bins[dim][i - 1].enter;
-			rightNum -= storage_->spatial_bins[dim][i - 1].exit;
+			left_bounds.grow(storage_->bins[dim][i - 1].bounds);
+			leftNum += storage_->bins[dim][i - 1].enter;
+			rightNum -= storage_->bins[dim][i - 1].exit;
 
 			float sah = nodeSAH +
 				left_bounds.safe_area() * builder.params.primitive_cost(leftNum) +
-				storage_->spatial_right_bounds[i - 1].safe_area() * builder.params.primitive_cost(rightNum);
+				storage_->right_bounds[i - 1].safe_area() * builder.params.primitive_cost(rightNum);
 
 			if(sah < this->sah) {
 				this->sah = sah;
@@ -220,7 +220,7 @@ void BVHSpatialSplit::split(BVHBuild *builder, BVHRange& left, BVHRange& right,
 	 * Duplication happens into a temporary pre-allocated vector in order to
 	 * reduce number of memmove() calls happening in vector.insert().
 	 */
-	vector<BVHReference>& new_refs = storage_->spatial_new_refs;
+	vector<BVHReference>& new_refs = storage_->new_references;
 	new_refs.clear();
 	new_refs.reserve(right_start - left_end);
 	while(left_end < right_start) {




More information about the Bf-blender-cvs mailing list