diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-08 20:10:32 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-01-09 14:14:20 +0300 |
commit | 8044e5f2d771a1c3ee1a116132ddc09ce3452cbb (patch) | |
tree | a30b0f3f2e90b197e9ebaebae6ceab108d9548d2 /intern/cycles/bvh/bvh.cpp | |
parent | b486088218f66810b97294f38f246e4650d32f2b (diff) |
Cycles: Make BVH wider prior to packing
This allows to do more non-trivial tree modifications to make
it more dense and more friendly for vectorization.
Diffstat (limited to 'intern/cycles/bvh/bvh.cpp')
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index ac0614e3659..af012bbf3ac 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -127,10 +127,26 @@ void BVH::build(Progress& progress, Stats*) pack.prim_time, params, progress); - BVHNode *root = bvh_build.run(); + BVHNode *bvh2_root = bvh_build.run(); if(progress.get_cancel()) { - if(root) root->deleteSubtree(); + if(bvh2_root != NULL) { + bvh2_root->deleteSubtree(); + } + return; + } + + /* BVH builder returns tree in a binary mode (with two children per inner + * node. Need to adopt that for a wider BVH implementations. */ + BVHNode *root = widen_children_nodes(bvh2_root); + if(root != bvh2_root) { + bvh2_root->deleteSubtree(); + } + + if(progress.get_cancel()) { + if(root != NULL) { + root->deleteSubtree(); + } return; } @@ -232,37 +248,6 @@ void BVH::refit_primitives(int start, int end, BoundBox& bbox, uint& visibility) } } -bool BVH::leaf_check(const BVHNode *node, BVH_TYPE bvh) -{ - if(node->is_leaf()) { - return node->is_unaligned; - } - else { - return node_is_unaligned(node, bvh); - } -} - -bool BVH::node_is_unaligned(const BVHNode *node, BVH_TYPE bvh) -{ - const BVHNode *node0 = node->get_child(0); - const BVHNode *node1 = node->get_child(1); - - switch(bvh) { - case bvh2: - return node0->is_unaligned || node1->is_unaligned; - break; - case bvh4: - return leaf_check(node0, bvh2) || leaf_check(node1, bvh2); - break; - case bvh8: - return leaf_check(node0, bvh4) || leaf_check(node1, bvh4); - break; - default: - assert(0); - return false; - } -} - /* Triangles */ void BVH::pack_triangle(int idx, float4 tri_verts[3]) |