Cycles: Use proper node counter to allocate QBVH nodes
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 17 Dec 2014 16:49:35 +0000 (21:49 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 24 Dec 2014 21:50:49 +0000 (02:50 +0500)
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.

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

index 15bd814b8d5bff0e4dfb56f6f148d66088bbf8b7..43b16a62207ba19be46175990128648c77356278 100644 (file)
@@ -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();
index 7cc9bd333b070c99cea665c6b822efb22fe018dc..8294690da7d2e437a5c9e4f6d858d52601870a9b 100644 (file)
@@ -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 */
        }
index a0d10a46bfc6af34591516bb5375dd981b678bb4..1656bb367a48156bdeea13a4f670697527feb662 100644 (file)
@@ -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;