Cleanup: remove remainings of OMP in sculptpaint area.
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 20 Jan 2016 19:39:18 +0000 (20:39 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 20 Jan 2016 19:39:18 +0000 (20:39 +0100)
source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/editors/sculpt_paint/paint_mask.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_intern.h
source/blender/editors/sculpt_paint/sculpt_undo.c

index 8dc266750edcaf9a0d0ddaed995ef8d67338081a..aad9df1a9784db9c5894c47f94f3a013947991ff 100644 (file)
  * removed eventually (TODO) */
 #include "sculpt_intern.h"
 
-#ifdef _OPENMP
-#include <omp.h>
-#endif
-
 /* TODOs:
  *
  * Some of the cursor drawing code is doing non-draw stuff
index 5d9afb18bdf74b30f0046ee74c30961775a0b4eb..27025280b4c2892a5bdba7581a7ffa667c915639 100644 (file)
@@ -156,7 +156,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
 
        BLI_task_parallel_range(
                    0, totnode, &data, mask_flood_fill_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
        if (multires)
                multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED);
@@ -300,7 +300,7 @@ int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *r
 
                        BLI_task_parallel_range(
                                    0, totnode, &data, mask_box_select_task_cb,
-                                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
                        if (nodes)
                                MEM_freeN(nodes);
@@ -480,7 +480,7 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
 
                                BLI_task_parallel_range(
                                            0, totnode, &data, mask_gesture_lasso_task_cb,
-                                           ((sd->flags & SCULPT_USE_OPENMP) && (totnode > SCULPT_OMP_LIMIT)));
+                                           ((sd->flags & SCULPT_USE_OPENMP) && (totnode > SCULPT_THREADED_LIMIT)));
 
                                if (nodes)
                                        MEM_freeN(nodes);
index 602fe686e7e9c1c4535ae9ce97be930413a6950c..da2a987f4c75718e753d06a883d964d526f8e812 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef _OPENMP
-#include <omp.h>
-#endif
-
-#if defined(__APPLE__) && defined _OPENMP
-#include <sys/sysctl.h>
-
-/* Query how many cores not counting HT aka physical cores we've got. */
-static int system_physical_thread_count(void)
-{
-       int pcount;
-       size_t pcount_len = sizeof(pcount);
-       sysctlbyname("hw.physicalcpu", &pcount, &pcount_len, NULL, 0);
-       return pcount;
-}
-#endif  /* __APPLE__ */
-
 /** \name Tool Capabilities
  *
  * Avoid duplicate checks, internal logic only,
@@ -513,7 +496,7 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
 
        BLI_task_parallel_range(
                    0, totnode, &data, paint_mesh_restore_co_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && !ss->bm && totnode > SCULPT_OMP_LIMIT));
+                   ((sd->flags & SCULPT_USE_OPENMP) && !ss->bm && totnode > SCULPT_THREADED_LIMIT));
 
        if (nodes)
                MEM_freeN(nodes);
@@ -969,7 +952,7 @@ static void calc_area_center(
 
        BLI_task_parallel_range(
                    0, totnode, &data, calc_area_normal_and_center_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
        BLI_mutex_end(&data.mutex);
 
@@ -1009,7 +992,7 @@ static void calc_area_normal(
 
        BLI_task_parallel_range(
                    0, totnode, &data, calc_area_normal_and_center_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
        BLI_mutex_end(&data.mutex);
 
@@ -1047,7 +1030,7 @@ static void calc_area_normal_and_center(
 
        BLI_task_parallel_range(
                    0, totnode, &data, calc_area_normal_and_center_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
        BLI_mutex_end(&data.mutex);
 
@@ -1172,14 +1155,14 @@ static float tex_strength(SculptSession *ss, Brush *br,
                           const float len,
                           const short vno[3],
                           const float fno[3],
-                          const float mask)
+                          const float mask,
+                          const int thread_id)
 {
        StrokeCache *cache = ss->cache;
        const Scene *scene = cache->vc->scene;
        MTex *mtex = &br->mtex;
        float avg = 1;
        float rgba[4];
-       int thread_num;
 
        if (!mtex->tex) {
                avg = 1;
@@ -1222,12 +1205,7 @@ static float tex_strength(SculptSession *ss, Brush *br,
                        x += br->mtex.ofs[0];
                        y += br->mtex.ofs[1];
 
-#ifdef _OPENMP
-                       thread_num = omp_get_thread_num();
-#else
-                       thread_num = 0;
-#endif
-                       avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_num);
+                       avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_id);
 
                        avg += br->texture_sample_bias;
                }
@@ -1564,7 +1542,8 @@ typedef struct SculptDoBrushSmoothGridDataChunk {
        size_t tmpgrid_size;
 } SculptDoBrushSmoothGridDataChunk;
 
-static void do_smooth_brush_mesh_task_cb(void *userdata, int n)
+static void do_smooth_brush_mesh_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -1585,7 +1564,8 @@ static void do_smooth_brush_mesh_task_cb(void *userdata, int n)
                if (sculpt_brush_test(&test, vd.co)) {
                        const float fade = bstrength * tex_strength(
                                               ss, brush, vd.co, test.dist, vd.no, vd.fno,
-                                              smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f));
+                                              smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f),
+                                              thread_id);
                        if (smooth_mask) {
                                float val = neighbor_average_mask(ss, vd.vert_indices[vd.i]) - *vd.mask;
                                val *= fade * bstrength;
@@ -1610,7 +1590,8 @@ static void do_smooth_brush_mesh_task_cb(void *userdata, int n)
        BKE_pbvh_vertex_iter_end;
 }
 
-static void do_smooth_brush_bmesh_task_cb(void *userdata, int n)
+static void do_smooth_brush_bmesh_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -1630,7 +1611,8 @@ static void do_smooth_brush_bmesh_task_cb(void *userdata, int n)
        {
                if (sculpt_brush_test(&test, vd.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, smooth_mask ? 0.0f : *vd.mask);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, smooth_mask ? 0.0f : *vd.mask,
+                                              thread_id);
                        if (smooth_mask) {
                                float val = bmesh_neighbor_average_mask(vd.bm_vert, vd.cd_vert_mask_offset) - *vd.mask;
                                val *= fade * bstrength;
@@ -1656,7 +1638,7 @@ static void do_smooth_brush_bmesh_task_cb(void *userdata, int n)
 }
 
 static void do_smooth_brush_multires_task_cb_ex(
-        void *userdata, void *userdata_chunk, const int n, const int UNUSED(thread_id))
+        void *userdata, void *userdata_chunk, const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptDoBrushSmoothGridDataChunk *data_chunk = userdata_chunk;
@@ -1768,7 +1750,8 @@ static void do_smooth_brush_multires_task_cb_ex(
 
                                if (sculpt_brush_test(&test, co)) {
                                        const float strength_mask = (smooth_mask ? 0.0f : *mask);
-                                       const float fade = bstrength * tex_strength(ss, brush, co, test.dist, NULL, fno, strength_mask);
+                                       const float fade = bstrength * tex_strength(
+                                                              ss, brush, co, test.dist, NULL, fno, strength_mask, thread_id);
                                        float f = 1.0f / 16.0f;
 
                                        if (x == 0 || x == gridsize - 1)
@@ -1842,20 +1825,20 @@ static void smooth(
 
                                BLI_task_parallel_range_ex(
                                            0, totnode, &data, data_chunk, size, do_smooth_brush_multires_task_cb_ex,
-                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT), false);
+                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 
                                MEM_freeN(data_chunk);
                                break;
                        }
                        case PBVH_FACES:
-                               BLI_task_parallel_range(
-                                           0, totnode, &data, do_smooth_brush_mesh_task_cb,
-                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                               BLI_task_parallel_range_ex(
+                                           0, totnode, &data, NULL, 0, do_smooth_brush_mesh_task_cb_ex,
+                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
                                break;
                        case PBVH_BMESH:
-                               BLI_task_parallel_range(
-                                           0, totnode, &data, do_smooth_brush_bmesh_task_cb,
-                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                               BLI_task_parallel_range_ex(
+                                           0, totnode, &data, NULL, 0, do_smooth_brush_bmesh_task_cb_ex,
+                                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
                                break;
                }
 
@@ -1870,7 +1853,8 @@ static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
        smooth(sd, ob, nodes, totnode, ss->cache->bstrength, false);
 }
 
-static void do_mask_brush_draw_task_cb(void *userdata, const int n)
+static void do_mask_brush_draw_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -1885,7 +1869,7 @@ static void do_mask_brush_draw_task_cb(void *userdata, const int n)
        BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
        {
                if (sculpt_brush_test(&test, vd.co)) {
-                       const float fade = tex_strength(ss, brush, vd.co, test.dist, vd.no, vd.fno, 0.0f);
+                       const float fade = tex_strength(ss, brush, vd.co, test.dist, vd.no, vd.fno, 0.0f, thread_id);
 
                        (*vd.mask) += fade * bstrength;
                        CLAMP(*vd.mask, 0, 1);
@@ -1906,9 +1890,9 @@ static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int tot
            .sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_mask_brush_draw_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_mask_brush_draw_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
 static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
@@ -1926,7 +1910,8 @@ static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
        }
 }
 
-static void do_draw_brush_task_cb(void *userdata, const int n)
+static void do_draw_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -1945,7 +1930,8 @@ static void do_draw_brush_task_cb(void *userdata, const int n)
        {
                if (sculpt_brush_test(&test, vd.co)) {
                        /* offset vertex */
-                       const float fade = tex_strength(ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                       const float fade = tex_strength(
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], offset, fade);
 
@@ -1974,12 +1960,13 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
            .offset = offset,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_draw_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_draw_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_crease_brush_task_cb(void *userdata, const int n)
+static void do_crease_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2001,7 +1988,7 @@ static void do_crease_brush_task_cb(void *userdata, const int n)
                if (sculpt_brush_test(&test, vd.co)) {
                        /* offset vertex */
                        const float fade = tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
                        float val1[3];
                        float val2[3];
 
@@ -2061,12 +2048,13 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
            .spvc = &spvc, .offset = offset, .flippedbstrength = flippedbstrength,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_crease_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_crease_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_pinch_brush_task_cb(void *userdata, const int n)
+static void do_pinch_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2085,7 +2073,7 @@ static void do_pinch_brush_task_cb(void *userdata, const int n)
        {
                if (sculpt_brush_test(&test, vd.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
                        float val[3];
 
                        sub_v3_v3v3(val, test.location, vd.co);
@@ -2106,12 +2094,13 @@ static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
            .sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_pinch_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_pinch_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_grab_brush_task_cb(void *userdata, const int n)
+static void do_grab_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2136,7 +2125,8 @@ static void do_grab_brush_task_cb(void *userdata, const int n)
 
                if (sculpt_brush_test(&test, orig_data.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f,
+                                              thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], grab_delta, fade);
 
@@ -2169,12 +2159,13 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
            .grab_delta = grab_delta,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_grab_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_grab_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_nudge_brush_task_cb(void *userdata, const int n)
+static void do_nudge_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2193,8 +2184,8 @@ static void do_nudge_brush_task_cb(void *userdata, const int n)
        BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE)
        {
                if (sculpt_brush_test(&test, vd.co)) {
-                       const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist,
-                                                                   vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                       const float fade = bstrength * tex_strength(
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], cono, fade);
 
@@ -2222,12 +2213,13 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
            .cono = cono,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_nudge_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_nudge_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_snake_hook_brush_task_cb(void *userdata, const int n)
+static void do_snake_hook_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2247,7 +2239,7 @@ static void do_snake_hook_brush_task_cb(void *userdata, const int n)
        {
                if (sculpt_brush_test(&test, vd.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], grab_delta, fade);
 
@@ -2284,12 +2276,13 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
            .grab_delta = grab_delta,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_snake_hook_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_snake_hook_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_thumb_brush_task_cb(void *userdata, const int n)
+static void do_thumb_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2314,7 +2307,8 @@ static void do_thumb_brush_task_cb(void *userdata, const int n)
 
                if (sculpt_brush_test(&test, orig_data.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f,
+                                              thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], cono, fade);
 
@@ -2342,12 +2336,13 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
            .cono = cono,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_thumb_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_thumb_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_rotate_brush_task_cb(void *userdata, const int n)
+static void do_rotate_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2373,7 +2368,8 @@ static void do_rotate_brush_task_cb(void *userdata, const int n)
                if (sculpt_brush_test(&test, orig_data.co)) {
                        float vec[3], rot[3][3];
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, orig_data.co, test.dist, orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f,
+                                              thread_id);
 
                        sub_v3_v3v3(vec, orig_data.co, ss->cache->location);
                        axis_angle_normalized_to_mat3(rot, ss->cache->sculpt_normal_symm, angle * fade);
@@ -2401,12 +2397,13 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
            .angle = angle,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_rotate_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_rotate_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_layer_brush_task_cb(void *userdata, const int n)
+static void do_layer_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2438,7 +2435,7 @@ static void do_layer_brush_task_cb(void *userdata, const int n)
 
                if (sculpt_brush_test(&test, orig_data.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
                        float *disp = &layer_disp[vd.i];
                        float val[3];
 
@@ -2483,14 +2480,15 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode
        };
        BLI_mutex_init(&data.mutex);
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_layer_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_layer_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 
        BLI_mutex_end(&data.mutex);
 }
 
-static void do_inflate_brush_task_cb(void *userdata, const int n)
+static void do_inflate_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2509,7 +2507,7 @@ static void do_inflate_brush_task_cb(void *userdata, const int n)
        {
                if (sculpt_brush_test(&test, vd.co)) {
                        const float fade = bstrength * tex_strength(
-                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
                        float val[3];
 
                        if (vd.fno)
@@ -2535,9 +2533,9 @@ static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
            .sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_inflate_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_inflate_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
 static void calc_sculpt_plane(
@@ -2665,7 +2663,8 @@ static float get_offset(Sculpt *sd, SculptSession *ss)
        return rv;
 }
 
-static void do_flatten_brush_task_cb(void *userdata, const int n)
+static void do_flatten_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2694,7 +2693,8 @@ static void do_flatten_brush_task_cb(void *userdata, const int n)
 
                        if (plane_trim(ss->cache, brush, val)) {
                                const float fade = bstrength * tex_strength(
-                                                      ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                                      ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f,
+                                                      thread_id);
 
                                mul_v3_v3fl(proxy[vd.i], val, fade);
 
@@ -2733,12 +2733,13 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno
            .area_no = area_no, .area_co = area_co,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_flatten_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_flatten_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_clay_brush_task_cb(void *userdata, const int n)
+static void do_clay_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2771,7 +2772,8 @@ static void do_clay_brush_task_cb(void *userdata, const int n)
                                        /* note, the normal from the vertices is ignored,
                                         * causes glitch with planes, see: T44390 */
                                        const float fade = bstrength * tex_strength(
-                                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f,
+                                                              thread_id);
 
                                        mul_v3_v3fl(proxy[vd.i], val, fade);
 
@@ -2814,12 +2816,13 @@ static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
            .area_no = area_no, .area_co = area_co,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_clay_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_clay_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_clay_strips_brush_task_cb(void *userdata, const int n)
+static void do_clay_strips_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2854,7 +2857,7 @@ static void do_clay_strips_brush_task_cb(void *userdata, const int n)
                                         * causes glitch with planes, see: T44390 */
                                        const float fade = bstrength * tex_strength(
                                                               ss, brush, vd.co, ss->cache->radius * test.dist,
-                                                              vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                                              vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
 
                                        mul_v3_v3fl(proxy[vd.i], val, fade);
 
@@ -2922,12 +2925,13 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t
            .area_no_sp = area_no_sp, .area_co = area_co, .mat = mat,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_clay_strips_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_clay_strips_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_fill_brush_task_cb(void *userdata, const int n)
+static void do_fill_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -2958,7 +2962,7 @@ static void do_fill_brush_task_cb(void *userdata, const int n)
                                if (plane_trim(ss->cache, brush, val)) {
                                        const float fade = bstrength * tex_strength(
                                                               ss, brush, vd.co, sqrtf(test.dist),
-                                                              vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                                              vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, thread_id);
 
                                        mul_v3_v3fl(proxy[vd.i], val, fade);
 
@@ -2999,12 +3003,13 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
            .area_no = area_no, .area_co = area_co,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_fill_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_fill_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_scrape_brush_task_cb(void *userdata, const int n)
+static void do_scrape_brush_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -3034,7 +3039,8 @@ static void do_scrape_brush_task_cb(void *userdata, const int n)
 
                                if (plane_trim(ss->cache, brush, val)) {
                                        const float fade = bstrength * tex_strength(
-                                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f,
+                                                              thread_id);
 
                                        mul_v3_v3fl(proxy[vd.i], val, fade);
 
@@ -3075,12 +3081,13 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod
            .area_no = area_no, .area_co = area_co,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_scrape_brush_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_scrape_brush_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
-static void do_gravity_task_cb(void *userdata, const int n)
+static void do_gravity_task_cb_ex(
+        void *userdata, void *UNUSED(userdata_chunk), const int n, const int thread_id)
 {
        SculptThreadedTaskData *data = userdata;
        SculptSession *ss = data->ob->sculpt;
@@ -3098,7 +3105,8 @@ static void do_gravity_task_cb(void *userdata, const int n)
        BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
                if (sculpt_brush_test_sq(&test, vd.co)) {
                        const float fade = tex_strength(
-                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f);
+                                              ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f,
+                                              thread_id);
 
                        mul_v3_v3fl(proxy[vd.i], offset, fade);
 
@@ -3129,9 +3137,9 @@ static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, fl
            .offset = offset,
        };
 
-       BLI_task_parallel_range(
-                   0, totnode, &data, do_gravity_task_cb,
-                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+       BLI_task_parallel_range_ex(
+                   0, totnode, &data, NULL, 0, do_gravity_task_cb_ex,
+                   ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT), false);
 }
 
 
@@ -3274,7 +3282,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
 
                BLI_task_parallel_range(
                            0, totnode, &task_data, do_brush_action_task_cb,
-                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
                if (sculpt_brush_needs_normal(brush))
                        update_sculpt_normal(sd, ob, nodes, totnode);
@@ -3455,7 +3463,7 @@ static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
 
                BLI_task_parallel_range(
                            0, totnode, &data, sculpt_combine_proxies_task_cb,
-                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
        }
 
        if (nodes)
@@ -3536,7 +3544,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob)
 
                BLI_task_parallel_range(
                            0, totnode, &data, sculpt_flush_stroke_deform_task_cb,
-                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
                if (vertCos) {
                        sculpt_vertcos_to_key(ob, ss->kb, vertCos);
index 51af8788e60629a723d48bfa789be38cbbac14a8..108fe3532e31340a744475030116775dbd16237e 100644 (file)
@@ -124,11 +124,6 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]);
 
 void sculpt_update_object_bounding_box(struct Object *ob);
 
-/* Setting zero so we can catch bugs in OpenMP/sculpt. */
-#ifdef DEBUG
-#  define SCULPT_OMP_LIMIT 0
-#else
-#  define SCULPT_OMP_LIMIT 4
-#endif
+#define SCULPT_THREADED_LIMIT 4
 
 #endif
index 8fcac496e5e1bf7266ce3247952249fbfc19a861..46cfc1c20350d92e8de56983b679ad3011a1836a 100644 (file)
@@ -296,7 +296,7 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C,
 
                BLI_task_parallel_range(
                            0, totnode, nodes, sculpt_undo_bmesh_restore_generic_task_cb,
-                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_OMP_LIMIT));
+                           ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT));
 
                if (nodes)
                        MEM_freeN(nodes);