Preparation step for nuking OMP from multires code.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 11 Jan 2018 16:56:18 +0000 (17:56 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 11 Jan 2018 16:56:18 +0000 (17:56 +0100)
Remove the critical OMP sections used to protect mem allocation.

First one can be done in a separate loop before main, parallelized one.

Second one only affect 'private' data, so we only need to ensure
guardedalloc thread safety is enabled.

This is committed as separated step to ease troubleshooting in case
bisecting becomes necesary.

source/blender/blenkernel/intern/multires.c

index 9679b585e6fa18510fd5aa8eb3ae146b01362183..4eb550a9f4c73791af910cd9c40c3eb50ec5e35d 100644 (file)
@@ -44,6 +44,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
+#include "BLI_task.h"
 
 #include "BKE_pbvh.h"
 #include "BKE_ccg.h"
@@ -1052,6 +1053,16 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm
 
        k = 0; /*current loop/mdisp index within the mloop array*/
 
+       /* when adding new faces in edit mode, need to allocate disps */
+       for (i = 0; i < totloop; ++i) {
+               if (mdisps[i].disps == NULL) {
+                       multires_reallocate_mdisps(totloop, mdisps, totlvl);
+                       break;
+               }
+       }
+
+       BLI_begin_threaded_malloc();
+
 #pragma omp parallel for private(i) if (totloop * gridSize * gridSize >= CCG_OMP_LIMIT)
 
        for (i = 0; i < totpoly; ++i) {
@@ -1065,24 +1076,15 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm
                        CCGElem *subgrid = subGridData[gIndex];
                        float (*dispgrid)[3] = NULL;
 
-                       /* when adding new faces in edit mode, need to allocate disps */
-                       if (!mdisp->disps)
-#pragma omp critical
-                       {
-                               multires_reallocate_mdisps(totloop, mdisps, totlvl);
-                       }
-
                        dispgrid = mdisp->disps;
 
                        /* if needed, reallocate multires paint mask */
                        if (gpm && gpm->level < key.level) {
                                gpm->level = key.level;
-#pragma omp critical
-                               {
-                                       if (gpm->data)
-                                               MEM_freeN(gpm->data);
-                                       gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data");
+                               if (gpm->data) {
+                                       MEM_freeN(gpm->data);
                                }
+                               gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data");
                        }
 
                        for (y = 0; y < gridSize; y++) {
@@ -1142,6 +1144,8 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm
                }
        }
        
+       BLI_end_threaded_malloc();
+
        if (op == APPLY_DISPLACEMENTS) {
                ccgSubSurf_stitchFaces(ccgdm->ss, 0, NULL, 0);
                ccgSubSurf_updateNormals(ccgdm->ss, NULL, 0);