Cycles: Add maximum depth stat to bvh builder
authorMai Lavelle <mai.lavelle@gmail.com>
Wed, 23 Aug 2017 04:40:35 +0000 (00:40 -0400)
committerMai Lavelle <mai.lavelle@gmail.com>
Wed, 23 Aug 2017 10:54:26 +0000 (06:54 -0400)
intern/cycles/bvh/bvh_build.cpp
intern/cycles/bvh/bvh_node.cpp
intern/cycles/bvh/bvh_node.h

index eb1d89729fbfe30a26dba7711067e458f73d86e2..d70988065690f9fb8ba1d57acf7241269aca99c6 100644 (file)
@@ -529,7 +529,9 @@ BVHNode* BVHBuild::run()
                                << "  Allocation slop factor: "
                                       << ((prim_type.capacity() != 0)
                                               ? (float)prim_type.size() / prim_type.capacity()
-                                              : 1.0f) << "\n";
+                                              : 1.0f) << "\n"
+                               << "  Maximum depth: "
+                               << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_DEPTH))  << "\n";
                }
        }
 
index 4237c62ab5b58b8e58de44bbe49da015dc024f12..ab6df4d265d6074944571f80bc2aede939c06333 100644 (file)
@@ -132,6 +132,17 @@ int BVHNode::getSubtreeSize(BVH_STAT stat) const
                case BVH_STAT_UNALIGNED_LEAF_COUNT:
                        cnt = (is_leaf() && is_unaligned) ? 1 : 0;
                        break;
+               case BVH_STAT_DEPTH:
+                       if(is_leaf()) {
+                               cnt = 1;
+                       }
+                       else {
+                               for(int i = 0; i < num_children(); i++) {
+                                       cnt = max(cnt, get_child(i)->getSubtreeSize(stat));
+                               }
+                               cnt += 1;
+                       }
+                       return cnt;
                default:
                        assert(0); /* unknown mode */
        }
index 1c875f5a52454de2d55d154f095d95a19b62096d..94cf5ab730c2e2353817a23243ee222c02bf515f 100644 (file)
@@ -38,6 +38,7 @@ enum BVH_STAT {
        BVH_STAT_UNALIGNED_INNER_QNODE_COUNT,
        BVH_STAT_ALIGNED_LEAF_COUNT,
        BVH_STAT_UNALIGNED_LEAF_COUNT,
+       BVH_STAT_DEPTH,
 };
 
 class BVHParams;