[Bf-blender-cvs] [12ad52c887b] soc-2019-embree-gpu: Pre-reserve memory to reduce reallocation

MATILLAT Quentin noreply at git.blender.org
Fri Jul 19 11:32:32 CEST 2019


Commit: 12ad52c887b889c6a1abfd3c28c6f16486eed681
Author: MATILLAT Quentin
Date:   Fri Jul 19 11:32:02 2019 +0200
Branches: soc-2019-embree-gpu
https://developer.blender.org/rB12ad52c887b889c6a1abfd3c28c6f16486eed681

Pre-reserve memory to reduce reallocation

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

M	intern/cycles/bvh/bvh_embree_converter.cpp

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

diff --git a/intern/cycles/bvh/bvh_embree_converter.cpp b/intern/cycles/bvh/bvh_embree_converter.cpp
index 6b92e2bc008..162485a621a 100644
--- a/intern/cycles/bvh/bvh_embree_converter.cpp
+++ b/intern/cycles/bvh/bvh_embree_converter.cpp
@@ -671,11 +671,25 @@ void pack_inner(const BVHStackEntry &e, const BVHStackEntry &c0, const BVHStackE
 }
 
 void BVHEmbreeConverter::fillPack(PackedBVH &pack, vector<Object *> objects) {
+    int num_prim = 0;
+
+    for (size_t i = 0; i < this->s->size(); i++) {
+	const auto tree = this->s->get(i);
+        if(tree != nullptr)
+            num_prim += 4 * tree->size();
+    }
+
     pack.prim_visibility.clear();
+    pack.prim_visibility.reserve(num_prim);
     pack.prim_object.clear();
+    pack.prim_object.reserve(num_prim);
     pack.prim_type.clear();
+    pack.prim_type.reserve(num_prim);
     pack.prim_index.clear();
+    pack.prim_index.reserve(num_prim);
     pack.prim_tri_index.clear();
+    pack.prim_tri_index.reserve(num_prim);
+
     pack.prim_tri_verts.clear();
 
     this->pack = &pack;



More information about the Bf-blender-cvs mailing list