diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index 7f990e06152..b703e57fdd8 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -270,6 +270,7 @@ void bvh_done(VBVHTree *obj) pushup(root); pushdown(root); + pushup_simd(root); //Memory re-organize if(0) diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index 2f79b0f6e82..b77a51bbf65 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -144,6 +144,8 @@ void remove_useless(Node *node, Node **new_node) template void pushup(Node *parent) { + if(is_leaf(parent)) return; + float p_area = bb_area(parent->bb, parent->bb+3); Node **prev = &parent->child; for(Node *child = parent->child; RayObject_isAligned(child) && child; ) @@ -175,6 +177,38 @@ void pushup(Node *parent) pushup(child); } +/* + * try to optimize number of childs to be a multiple of SSize + */ +template +void pushup_simd(Node *parent) +{ + if(is_leaf(parent)) return; + + int n = count_childs(parent); + + Node **prev = &parent->child; + for(Node *child = parent->child; RayObject_isAligned(child) && child; ) + { + int cn = count_childs(child); + if(cn-1 <= (SSize - (n%SSize) ) % SSize && RayObject_isAligned(child->child) ) + { + n += (cn - 1); + append_sibling(child, child->child); + child = child->sibling; + *prev = child; + } + else + { + *prev = child; + prev = &(*prev)->sibling; + child = *prev; + } + } + + for(Node *child = parent->child; RayObject_isAligned(child) && child; child = child->sibling) + pushup_simd(child); +} /*