[Bf-blender-cvs] [5bfbe64] master: Fix T40831: Shrink wrap modifier causes very high CPU usage when targeting meshes with shaped keys

Sergey Sharybin noreply at git.blender.org
Mon Jul 28 12:15:07 CEST 2014


Commit: 5bfbe64a21bea22e442bafee3f5720d5d5d28bdf
Author: Sergey Sharybin
Date:   Mon Jul 28 16:13:47 2014 +0600
Branches: master
https://developer.blender.org/rB5bfbe64a21bea22e442bafee3f5720d5d5d28bdf

Fix T40831: Shrink wrap modifier causes very high CPU usage when targeting meshes with shaped keys

Same issue as revious one -- need to start OMP threads only
when there's enough data to crunch.

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

M	source/blender/blenkernel/intern/shrinkwrap.c
M	source/blender/blenlib/intern/BLI_kdopbvh.c

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

diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c
index e2cc7b8..757b457 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.c
+++ b/source/blender/blenkernel/intern/shrinkwrap.c
@@ -50,6 +50,7 @@
 #include "BKE_lattice.h"
 
 #include "BKE_deform.h"
+#include "BKE_mesh.h"  /* for OMP limits. */
 #include "BKE_subsurf.h"
 #include "BKE_editmesh.h"
 
@@ -135,12 +136,12 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc)
 		OUT_OF_MEMORY();
 		return;
 	}
-
+	
 	/* Setup nearest */
 	nearest.index = -1;
 	nearest.dist_sq = FLT_MAX;
 #ifndef __APPLE__
-#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData, calc) schedule(static)
+#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData, calc) schedule(static) if(calc->numVerts > BKE_MESH_OMP_LIMIT)
 #endif
 	for (i = 0; i < calc->numVerts; ++i) {
 		float *co = calc->vertexCos[i];
@@ -335,7 +336,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc, bool for
 	{
 
 #ifndef __APPLE__
-#pragma omp parallel for private(i, hit) schedule(static)
+#pragma omp parallel for private(i, hit) schedule(static) if (calc->numVerts > BKE_MESH_OMP_LIMIT)
 #endif
 		for (i = 0; i < calc->numVerts; ++i) {
 			float *co = calc->vertexCos[i];
@@ -445,7 +446,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
 
 	/* Find the nearest vertex */
 #ifndef __APPLE__
-#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc, treeData) schedule(static)
+#pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(calc, treeData) schedule(static) if(calc->numVerts > BKE_MESH_OMP_LIMIT)
 #endif
 	for (i = 0; i < calc->numVerts; ++i) {
 		float *co = calc->vertexCos[i];
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index e4f9df5..7b7463c 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -45,6 +45,15 @@
 
 #define MAX_TREETYPE 32
 
+/* Setting zero so we can catch bugs in OpenMP/KDOPBVH.
+ * TODO(sergey): Deduplicate the limits with PBVH from BKE.
+ */
+#ifdef DEBUG
+#  define KDOPBVH_OMP_LIMIT 0
+#else
+#  define KDOPBVH_OMP_LIMIT 1024
+#endif
+
 typedef unsigned char axis_t;
 
 typedef struct BVHNode {
@@ -749,7 +758,8 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array,
 		int j;
 
 		/* Loop all branches on this level */
-#pragma omp parallel for private(j) schedule(static)
+
+//#pragma omp parallel for private(j) schedule(static) if (num_leafs > KDOPBVH_OMP_LIMIT)
 		for (j = i; j < end_j; j++) {
 			int k;
 			const int parent_level_index = j - i;
@@ -1102,7 +1112,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int
 		data[j]->stop_axis  = min_axis(tree1->stop_axis,  tree2->stop_axis);
 	}
 
-#pragma omp parallel for private(j) schedule(static)
+//#pragma omp parallel for private(j) schedule(static)  if (tree1->totleaf > KDOPBVH_OMP_LIMIT)
 	for (j = 0; j < MIN2(tree1->tree_type, tree1->nodes[tree1->totleaf]->totnode); j++) {
 		traverse(data[j], tree1->nodes[tree1->totleaf]->children[j], tree2->nodes[tree2->totleaf]);
 	}




More information about the Bf-blender-cvs mailing list