[Bf-blender-cvs] [713852affbc] master: Preparation step for nuking OMP from multires code.

Bastien Montagne noreply at git.blender.org
Thu Jan 11 19:42:16 CET 2018


Commit: 713852affbc2d48d52582e2c298c722539c09603
Author: Bastien Montagne
Date:   Thu Jan 11 17:56:18 2018 +0100
Branches: master
https://developer.blender.org/rB713852affbc2d48d52582e2c298c722539c09603

Preparation step for nuking OMP from multires code.

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.

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

M	source/blender/blenkernel/intern/multires.c

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

diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 9679b585e6f..4eb550a9f4c 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -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);



More information about the Bf-blender-cvs mailing list