diff options
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 26 |
2 files changed, 21 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index 92170325113..d7b9d20d7b0 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -34,6 +34,9 @@ /* struct DerivedMesh is used directly */ #include "BKE_DerivedMesh.h" +/* Thread sync primitives used directly. */ +#include "BLI_threads.h" + struct CCGElem; struct DMFlagMat; struct DMGridAdjacency; @@ -140,6 +143,9 @@ typedef struct CCGDerivedMesh { } multires; struct EdgeHash *ehash; + + ThreadRWMutex loops_cache_rwlock; + ThreadRWMutex origindex_cache_rwlock; } CCGDerivedMesh; #ifdef WITH_OPENSUBDIV diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index f8025f8df84..1386c23e234 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -90,9 +90,6 @@ /* assumes MLoop's are layed out 4 for each poly, in order */ #define USE_LOOP_LAYOUT_FAST -static ThreadRWMutex loops_cache_rwlock = BLI_RWLOCK_INITIALIZER; -static ThreadRWMutex origindex_cache_rwlock = BLI_RWLOCK_INITIALIZER; - static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int drawInteriorEdges, int useSubsurfUv, @@ -1492,7 +1489,7 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop) /* DMFlagMat *faceFlags = ccgdm->faceFlags; */ /* UNUSED */ if (!ccgdm->ehash) { - BLI_rw_mutex_lock(&loops_cache_rwlock, THREAD_LOCK_WRITE); + BLI_rw_mutex_lock(&ccgdm->loops_cache_rwlock, THREAD_LOCK_WRITE); if (!ccgdm->ehash) { MEdge *medge; @@ -1503,10 +1500,10 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop) BLI_edgehash_insert(ccgdm->ehash, medge[i].v1, medge[i].v2, SET_INT_IN_POINTER(i)); } } - BLI_rw_mutex_unlock(&loops_cache_rwlock); + BLI_rw_mutex_unlock(&ccgdm->loops_cache_rwlock); } - BLI_rw_mutex_lock(&loops_cache_rwlock, THREAD_LOCK_READ); + BLI_rw_mutex_lock(&ccgdm->loops_cache_rwlock, THREAD_LOCK_READ); totface = ccgSubSurf_getNumFaces(ss); mv = mloop; for (index = 0; index < totface; index++) { @@ -1549,7 +1546,7 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop) } } } - BLI_rw_mutex_unlock(&loops_cache_rwlock); + BLI_rw_mutex_unlock(&ccgdm->loops_cache_rwlock); } static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *mpoly) @@ -4050,6 +4047,10 @@ static void ccgDM_release(DerivedMesh *dm) MEM_freeN(ccgdm->edgeMap); MEM_freeN(ccgdm->faceMap); } + + BLI_rw_mutex_end(&ccgdm->loops_cache_rwlock); + BLI_rw_mutex_end(&ccgdm->origindex_cache_rwlock); + MEM_freeN(ccgdm); } } @@ -4064,14 +4065,14 @@ static void *ccgDM_get_vert_data_layer(DerivedMesh *dm, int type) int a, index, totnone, totorig; /* Avoid re-creation if the layer exists already */ - BLI_rw_mutex_lock(&origindex_cache_rwlock, THREAD_LOCK_READ); + BLI_rw_mutex_lock(&ccgdm->origindex_cache_rwlock, THREAD_LOCK_READ); origindex = DM_get_vert_data_layer(dm, CD_ORIGINDEX); - BLI_rw_mutex_unlock(&origindex_cache_rwlock); + BLI_rw_mutex_unlock(&ccgdm->origindex_cache_rwlock); if (origindex) { return origindex; } - BLI_rw_mutex_lock(&origindex_cache_rwlock, THREAD_LOCK_WRITE); + BLI_rw_mutex_lock(&ccgdm->origindex_cache_rwlock, THREAD_LOCK_WRITE); DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL); origindex = DM_get_vert_data_layer(dm, CD_ORIGINDEX); @@ -4086,7 +4087,7 @@ static void *ccgDM_get_vert_data_layer(DerivedMesh *dm, int type) CCGVert *v = ccgdm->vertMap[index].vert; origindex[a] = ccgDM_getVertMapIndex(ccgdm->ss, v); } - BLI_rw_mutex_unlock(&origindex_cache_rwlock); + BLI_rw_mutex_unlock(&ccgdm->origindex_cache_rwlock); return origindex; } @@ -5041,6 +5042,9 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, ccgdm->dm.numLoopData = ccgdm->dm.numPolyData * 4; ccgdm->dm.numTessFaceData = 0; + BLI_rw_mutex_init(&ccgdm->loops_cache_rwlock); + BLI_rw_mutex_init(&ccgdm->origindex_cache_rwlock); + return ccgdm; } |