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.
This commit is contained in:
Sergey Sharybin 2014-07-28 16:13:47 +06:00
parent df01833477
commit 5bfbe64a21
Notes: blender-bot 2023-02-14 10:25:56 +01:00
Referenced by issue #40831, Shrink wrap modifier causes very high CPU usage when targeting meshes with shaped keys
2 changed files with 17 additions and 6 deletions

View File

@ -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];

View File

@ -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]);
}