[Bf-blender-cvs] [e69a0ab] master: Cycles: Pass BVH builder by const reference to spatial splitters

Sergey Sharybin noreply at git.blender.org
Thu Mar 31 10:23:29 CEST 2016


Commit: e69a0ab5fcd54dbc9e4172739e41650bc07905c6
Author: Sergey Sharybin
Date:   Sun Feb 21 16:36:57 2016 +0100
Branches: master
https://developer.blender.org/rBe69a0ab5fcd54dbc9e4172739e41650bc07905c6

Cycles: Pass BVH builder by const reference to spatial splitters

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

M	intern/cycles/bvh/bvh_build.cpp
M	intern/cycles/bvh/bvh_build.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 ce15e1b..9f1fb9c 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -339,7 +339,7 @@ void BVHBuild::thread_build_node(InnerNode *inner, int child, BVHObjectBinning *
 	}
 }
 
-bool BVHBuild::range_within_max_leaf_size(const BVHRange& range)
+bool BVHBuild::range_within_max_leaf_size(const BVHRange& range) const
 {
 	size_t size = range.size();
 	size_t max_leaf_size = max(params.max_triangle_leaf_size, params.max_curve_leaf_size);
@@ -352,7 +352,7 @@ bool BVHBuild::range_within_max_leaf_size(const BVHRange& range)
 	size_t num_motion_curves = 0;
 
 	for(int i = 0; i < size; i++) {
-		BVHReference& ref = references[range.start() + i];
+		const BVHReference& ref = references[range.start() + i];
 
 		if(ref.prim_type() & PRIMITIVE_CURVE)
 			num_curves++;
@@ -424,7 +424,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_build.h b/intern/cycles/bvh/bvh_build.h
index 5857ae7..667ae98 100644
--- a/intern/cycles/bvh/bvh_build.h
+++ b/intern/cycles/bvh/bvh_build.h
@@ -78,7 +78,7 @@ protected:
 	                                    int start,
 	                                    int nun);
 
-	bool range_within_max_leaf_size(const BVHRange& range);
+	bool range_within_max_leaf_size(const BVHRange& range) const;
 
 	/* threads */
 	enum { THREAD_TASK_SIZE = 4096 };
diff --git a/intern/cycles/bvh/bvh_split.cpp b/intern/cycles/bvh/bvh_split.cpp
index ff0142f..cafee25 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(BVHBuild *builder,
+BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
                                BVHSpatialStorage *storage,
                                const BVHRange& range,
                                float nodeSAH)
@@ -39,7 +39,7 @@ BVHObjectSplit::BVHObjectSplit(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->spatial_indices.resize(range.size());
@@ -52,7 +52,7 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
 		 */
 		bvh_reference_sort_indices(range.start(),
 		                           range.end(),
-		                           &builder->references[0],
+		                           &builder.references[0],
 		                           indices,
 		                           dim);
 
@@ -72,8 +72,8 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
 			right_bounds = storage_->spatial_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;
@@ -101,7 +101,7 @@ void BVHObjectSplit::split(BVHBuild *builder, BVHRange& left, BVHRange& right, c
 
 /* Spatial Split */
 
-BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
+BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
                                  BVHSpatialStorage *storage,
                                  const BVHRange& range,
                                  float nodeSAH)
@@ -127,7 +127,7 @@ BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
 
 	/* chop references into bins. */
 	for(unsigned int refIdx = range.start(); refIdx < range.end(); refIdx++) {
-		const BVHReference& ref = builder->references[refIdx];
+		const BVHReference& ref = builder.references[refIdx];
 		float3 firstBinf = (ref.bounds().min - origin) * invBinSize;
 		float3 lastBinf = (ref.bounds().max - origin) * invBinSize;
 		int3 firstBin = make_int3((int)firstBinf.x, (int)firstBinf.y, (int)firstBinf.z);
@@ -174,8 +174,8 @@ BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
 			rightNum -= storage_->spatial_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);
+				left_bounds.safe_area() * builder.params.primitive_cost(leftNum) +
+				storage_->spatial_right_bounds[i - 1].safe_area() * builder.params.primitive_cost(rightNum);
 
 			if(sah < this->sah) {
 				this->sah = sah;
@@ -225,7 +225,7 @@ void BVHSpatialSplit::split(BVHBuild *builder, BVHRange& left, BVHRange& right,
 	while(left_end < right_start) {
 		/* split reference. */
 		BVHReference lref, rref;
-		split_reference(builder, lref, rref, refs[left_end], this->dim, this->pos);
+		split_reference(*builder, lref, rref, refs[left_end], this->dim, this->pos);
 
 		/* compute SAH for duplicate/unsplit candidates. */
 		BoundBox lub = left_bounds;		// Unsplit to left:		new left-hand bounds.
@@ -425,7 +425,7 @@ void BVHSpatialSplit::split_object_reference(const Object *object,
 	}
 }
 
-void BVHSpatialSplit::split_reference(BVHBuild *builder,
+void BVHSpatialSplit::split_reference(const BVHBuild& builder,
                                       BVHReference& left,
                                       BVHReference& right,
                                       const BVHReference& ref,
@@ -437,7 +437,7 @@ void BVHSpatialSplit::split_reference(BVHBuild *builder,
 	BoundBox right_bounds = BoundBox::empty;
 
 	/* loop over vertices/edges. */
-	Object *ob = builder->objects[ref.prim_object()];
+	const Object *ob = builder.objects[ref.prim_object()];
 	const Mesh *mesh = ob->mesh;
 
 	if(ref.prim_type() & PRIMITIVE_ALL_TRIANGLE) {
diff --git a/intern/cycles/bvh/bvh_split.h b/intern/cycles/bvh/bvh_split.h
index cc61899..8ccc1aa 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(BVHBuild *builder,
+	BVHObjectSplit(const BVHBuild& builder,
 	               BVHSpatialStorage *storage,
 	               const BVHRange& range,
 	               float nodeSAH);
@@ -61,13 +61,13 @@ public:
 	float pos;
 
 	BVHSpatialSplit() : sah(FLT_MAX), dim(0), pos(0.0f) {}
-	BVHSpatialSplit(BVHBuild *builder,
+	BVHSpatialSplit(const BVHBuild& builder,
 	                BVHSpatialStorage *storage,
 	                const BVHRange& range,
 	                float nodeSAH);
 
 	void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range);
-	void split_reference(BVHBuild *builder,
+	void split_reference(const BVHBuild& builder,
 	                     BVHReference& left,
 	                     BVHReference& right,
 	                     const BVHReference& ref,
@@ -137,7 +137,7 @@ public:
 
 	bool no_split;
 
-	__forceinline BVHMixedSplit(BVHBuild *builder,
+	__forceinline BVHMixedSplit(const 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)
+			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