[Bf-blender-cvs] [fe49052] master: Cycles: Use proper node counter to allocate QBVH nodes

Sergey Sharybin noreply at git.blender.org
Wed Dec 24 22:56:12 CET 2014


Commit: fe4905288dc4b8ddf193abdf3b287c47feedb597
Author: Sergey Sharybin
Date:   Wed Dec 17 21:49:35 2014 +0500
Branches: master
https://developer.blender.org/rBfe4905288dc4b8ddf193abdf3b287c47feedb597

Cycles: Use proper node counter to allocate QBVH nodes

Before all the nodes were counted and allocated, leading to situations when
bunch of allocated memory is not used because reasonable amount of nodes are
simply ignored.

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

M	intern/cycles/bvh/bvh.cpp
M	intern/cycles/bvh/bvh_node.cpp
M	intern/cycles/bvh/bvh_node.h

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

diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index 15bd814..43b16a6 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -794,7 +794,7 @@ void QBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num)
 
 void QBVH::pack_nodes(const array<int>& prims, const BVHNode *root)
 {
-	size_t node_size = root->getSubtreeSize(BVH_STAT_NODE_COUNT);
+	size_t node_size = root->getSubtreeSize(BVH_STAT_QNODE_COUNT);
 
 	/* resize arrays */
 	pack.nodes.clear();
diff --git a/intern/cycles/bvh/bvh_node.cpp b/intern/cycles/bvh/bvh_node.cpp
index 7cc9bd3..8294690 100644
--- a/intern/cycles/bvh/bvh_node.cpp
+++ b/intern/cycles/bvh/bvh_node.cpp
@@ -47,6 +47,20 @@ int BVHNode::getSubtreeSize(BVH_STAT stat) const
 		case BVH_STAT_CHILDNODE_COUNT:
 			cnt = num_children();
 			break;
+		case BVH_STAT_QNODE_COUNT:
+			cnt = 1;
+			for(int i = 0; i < num_children(); i++) {
+				BVHNode *node = get_child(i);
+				if(node->is_leaf()) {
+					cnt += 1;
+				}
+				else {
+					for(int j = 0; j < node->num_children(); j++) {
+						cnt += node->get_child(j)->getSubtreeSize(stat);
+					}
+				}
+			}
+			return cnt;
 		default:
 			assert(0); /* unknown mode */
 	}
diff --git a/intern/cycles/bvh/bvh_node.h b/intern/cycles/bvh/bvh_node.h
index a0d10a4..1656bb3 100644
--- a/intern/cycles/bvh/bvh_node.h
+++ b/intern/cycles/bvh/bvh_node.h
@@ -30,7 +30,8 @@ enum BVH_STAT
 	BVH_STAT_INNER_COUNT,
 	BVH_STAT_LEAF_COUNT,
 	BVH_STAT_TRIANGLE_COUNT,
-	BVH_STAT_CHILDNODE_COUNT
+	BVH_STAT_CHILDNODE_COUNT,
+	BVH_STAT_QNODE_COUNT,
 };
 
 class BVHParams;




More information about the Bf-blender-cvs mailing list