[Bf-blender-cvs] [0f6f921] master: Cycles: Temporarily revert index sort commit for spatial split

Sergey Sharybin noreply at git.blender.org
Fri Apr 1 17:47:11 CEST 2016


Commit: 0f6f9218985957aace8ae2135ac91133fb4370d9
Author: Sergey Sharybin
Date:   Fri Apr 1 17:44:08 2016 +0200
Branches: master
https://developer.blender.org/rB0f6f9218985957aace8ae2135ac91133fb4370d9

Cycles: Temporarily revert index sort commit for spatial split

There are in fact some missing parts to it (Split BVH builder should
be creating bins from result of Object Split constructor).

Doable, but need to quickly fix issue for the studio here, easier to
revert for now.

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

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

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

diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index 4f6aba5..54ea28a 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -246,8 +246,6 @@ BVHNode* BVHBuild::run()
 		foreach(BVHSpatialStorage &storage, spatial_storage) {
 			storage.right_bounds.clear();
 			storage.right_bounds.resize(num_bins);
-			storage.reference_indices.clear();
-			storage.reference_indices.reserve(num_bins);
 		}
 	}
 
@@ -425,7 +423,7 @@ BVHNode* BVHBuild::build_node(const BVHRange& range, int level)
 	}
 
 	/* splitting test */
-	BVHMixedSplit split(*this, &spatial_storage[0], range, level);
+	BVHMixedSplit split(this, &spatial_storage[0], range, level);
 
 	if(!(range.size() > 0 && params.top_level && level == 0)) {
 		if(split.no_split) {
diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h
index 022ecbc..cf683df 100644
--- a/intern/cycles/bvh/bvh_params.h
+++ b/intern/cycles/bvh/bvh_params.h
@@ -189,11 +189,6 @@ struct BVHSpatialStorage {
 	/* 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,
 	 */
diff --git a/intern/cycles/bvh/bvh_sort.cpp b/intern/cycles/bvh/bvh_sort.cpp
index 8088dcc..3140bf2 100644
--- a/intern/cycles/bvh/bvh_sort.cpp
+++ b/intern/cycles/bvh/bvh_sort.cpp
@@ -65,54 +65,5 @@ void bvh_reference_sort(int start, int end, BVHReference *data, int dim)
 	sort(data+start, data+end, compare);
 }
 
-struct BVHReferenceCompareIndexed {
-public:
-	BVHReferenceCompareIndexed(int dim, const BVHReference *data, int start)
-	: dim_(dim),
-	  start_(start),
-	  data_(data)
-	{}
-
-	bool operator()(const int a, const int b)
-	{
-		const BVHReference& ra = data_[start_ + a];
-		const BVHReference& rb = data_[start_ + b];
-		NO_EXTENDED_PRECISION float ca = ra.bounds().min[dim_] + ra.bounds().max[dim_];
-		NO_EXTENDED_PRECISION float cb = rb.bounds().min[dim_] + rb.bounds().max[dim_];
-
-		if(ca < cb) return true;
-		else if(ca > cb) return false;
-		else if(ra.prim_object() < rb.prim_object()) return true;
-		else if(ra.prim_object() > rb.prim_object()) return false;
-		else if(ra.prim_index() < rb.prim_index()) return true;
-		else if(ra.prim_index() > rb.prim_index()) return false;
-		else if(ra.prim_type() < rb.prim_type()) return true;
-		else if(ra.prim_type() > rb.prim_type()) return false;
-
-		return false;
-	}
-
-private:
-	int dim_, start_;
-	const BVHReference *data_;
-};
-
-/* NOTE: indices are always from 0 to count, even in the cases when start is not
- * zero. This is to simplify indexing in the object splitter. Index array is also
- * always zero-based index.
- */
-void bvh_reference_sort_indices(int start,
-                                int end,
-                                const BVHReference *data,
-                                int *indices,
-                                int dim)
-{
-	const int count = end - start;
-	for(int i = 0; i < count; ++i) {
-		indices[i] = i;
-	}
-	BVHReferenceCompareIndexed compare(dim, data, start);
-	sort(indices, indices+count, compare);
-}
-
 CCL_NAMESPACE_END
+
diff --git a/intern/cycles/bvh/bvh_sort.h b/intern/cycles/bvh/bvh_sort.h
index ec6edc4..18aafb5 100644
--- a/intern/cycles/bvh/bvh_sort.h
+++ b/intern/cycles/bvh/bvh_sort.h
@@ -21,11 +21,6 @@
 CCL_NAMESPACE_BEGIN
 
 void bvh_reference_sort(int start, int end, BVHReference *data, int dim);
-void bvh_reference_sort_indices(int start,
-                                int end,
-                                const BVHReference *data,
-                                int *indices,
-                                int dim);
 
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp
index 7ca0767..288cc7e 100644
--- a/intern/cycles/bvh/bvh_split.cpp
+++ b/intern/cycles/bvh/bvh_split.cpp
@@ -28,7 +28,7 @@ CCL_NAMESPACE_BEGIN
 
 /* Object Split */
 
-BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
+BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
                                BVHSpatialStorage *storage,
                                const BVHRange& range,
                                float nodeSAH)
@@ -39,28 +39,21 @@ BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
   right_bounds(BoundBox::empty),
   storage_(storage)
 {
-	const BVHReference *ref_ptr = &builder.references[range.start()];
+	const BVHReference *ref_ptr = &builder->references[range.start()];
 	float min_sah = FLT_MAX;
 
-	storage->reference_indices.resize(range.size());
-	int *indices = &storage->reference_indices[0];
-
 	for(int dim = 0; dim < 3; dim++) {
-		/* Sort references.
-		 * We only sort indices, to save amount of memory being sent back
-		 * and forth.
-		 */
-		bvh_reference_sort_indices(range.start(),
-		                           range.end(),
-		                           &builder.references[0],
-		                           indices,
-		                           dim);
+		/* Sort references. */
+		bvh_reference_sort(range.start(),
+		                   range.end(),
+		                   &builder->references[0],
+		                   dim);
 
 		/* sweep right to left and determine bounds. */
 		BoundBox right_bounds = BoundBox::empty;
 
 		for(int i = range.size() - 1; i > 0; i--) {
-			right_bounds.grow(ref_ptr[indices[i]].bounds());
+			right_bounds.grow(ref_ptr[i].bounds());
 			storage_->right_bounds[i - 1] = right_bounds;
 		}
 
@@ -68,12 +61,12 @@ BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
 		BoundBox left_bounds = BoundBox::empty;
 
 		for(int i = 1; i < range.size(); i++) {
-			left_bounds.grow(ref_ptr[indices[i - 1]].bounds());
+			left_bounds.grow(ref_ptr[i - 1].bounds());
 			right_bounds = storage_->right_bounds[i - 1];
 
 			float sah = nodeSAH +
-				left_bounds.safe_area() * builder.params.primitive_cost(i) +
-				right_bounds.safe_area() * builder.params.primitive_cost(range.size() - i);
+				left_bounds.safe_area() * builder->params.primitive_cost(i) +
+				right_bounds.safe_area() * builder->params.primitive_cost(range.size() - i);
 
 			if(sah < min_sah) {
 				min_sah = sah;
diff --git a/intern/cycles/bvh/bvh_split.h b/intern/cycles/bvh/bvh_split.h
index 8ccc1aa..9448a21 100644
--- a/intern/cycles/bvh/bvh_split.h
+++ b/intern/cycles/bvh/bvh_split.h
@@ -37,7 +37,7 @@ public:
 	BoundBox right_bounds;
 
 	BVHObjectSplit() {}
-	BVHObjectSplit(const BVHBuild& builder,
+	BVHObjectSplit(BVHBuild *builder,
 	               BVHSpatialStorage *storage,
 	               const BVHRange& range,
 	               float nodeSAH);
@@ -137,7 +137,7 @@ public:
 
 	bool no_split;
 
-	__forceinline BVHMixedSplit(const BVHBuild& builder,
+	__forceinline BVHMixedSplit(BVHBuild *builder,
 	                            BVHSpatialStorage *storage,
 	                            const BVHRange& range,
 	                            int level)
@@ -145,22 +145,22 @@ public:
 		/* find split candidates. */
 		float area = range.bounds().safe_area();
 
-		leafSAH = area * builder.params.primitive_cost(range.size());
-		nodeSAH = area * builder.params.node_cost(2);
+		leafSAH = area * builder->params.primitive_cost(range.size());
+		nodeSAH = area * builder->params.node_cost(2);
 
 		object = BVHObjectSplit(builder, storage, range, nodeSAH);
 
-		if(builder.params.use_spatial_split && level < BVHParams::MAX_SPATIAL_DEPTH) {
+		if(builder->params.use_spatial_split && level < BVHParams::MAX_SPATIAL_DEPTH) {
 			BoundBox overlap = object.left_bounds;
 			overlap.intersect(object.right_bounds);
 
-			if(overlap.safe_area() >= builder.spatial_min_overlap)
-				spatial = BVHSpatialSplit(builder, storage, range, nodeSAH);
+			if(overlap.safe_area() >= builder->spatial_min_overlap)
+				spatial = BVHSpatialSplit(*builder, storage, range, nodeSAH);
 		}
 
 		/* leaf SAH is the lowest => create leaf. */
 		minSAH = min(min(leafSAH, object.sah), spatial.sah);
-		no_split = (minSAH == leafSAH && builder.range_within_max_leaf_size(range));
+		no_split = (minSAH == leafSAH && builder->range_within_max_leaf_size(range));
 	}
 
 	__forceinline void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range)




More information about the Bf-blender-cvs mailing list