[Bf-blender-cvs] [d8a3f3595af] master: Task: Use TBB as Task Scheduler

Brecht Van Lommel noreply at git.blender.org
Thu Apr 30 08:10:22 CEST 2020


Commit: d8a3f3595af0fb3ca5937e41c2728fd750d986ef
Author: Brecht Van Lommel
Date:   Thu Apr 30 07:59:23 2020 +0200
Branches: master
https://developer.blender.org/rBd8a3f3595af0fb3ca5937e41c2728fd750d986ef

Task: Use TBB as Task Scheduler

This patch enables TBB as the default task scheduler. TBB stands for Threading Building Blocks and is developed by Intel. The library contains several threading patters. This patch maps blenders BLI_task_* function to their counterpart. After this patch we can add more patterns. A promising one is TBB:graph that can be used for depsgraph, draw manager and compositor.

Performance changes depends on the actual hardware. It was tested on different hardwares from laptops to workstations and we didn't detected any downgrade of the performance.
* Linux Xeon E5-2699 v4 got FPS boost from 12 to 17 using Spring's 04_010_A.anim.blend.
* AMD Ryzen Threadripper 2990WX 32-Core Animation playback goes from 9.5-10.5 FPS to 13.0-14.0 FPS on Agent 327 , 10_03_B.anim.blend.

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D7475

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

M	build_files/cmake/Modules/GTestTesting.cmake
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/editmesh_tangent.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/blenkernel/intern/mesh_tangent.c
M	source/blender/blenkernel/intern/ocean.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenlib/BLI_task.h
M	source/blender/blenlib/BLI_threads.h
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenlib/intern/task_iterator.c
M	source/blender/blenlib/intern/task_pool.cc
R058	source/blender/blenkernel/intern/pbvh_parallel.cc	source/blender/blenlib/intern/task_range.cc
A	source/blender/blenlib/intern/task_scheduler.cc
M	source/blender/blenlib/intern/threads.c
M	source/blender/depsgraph/intern/eval/deg_eval.cc
M	source/blender/draw/intern/draw_cache_extract_mesh.c
M	source/blender/editors/mesh/editmesh_undo.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_cloth.c
M	source/blender/editors/sculpt_paint/sculpt_face_set.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mask.c
M	source/blender/editors/sculpt_paint/sculpt_filter_mesh.c
M	source/blender/editors/sculpt_paint/sculpt_mask_expand.c
M	source/blender/editors/sculpt_paint/sculpt_multiplane_scrape.c
M	source/blender/editors/sculpt_paint/sculpt_pose.c
M	source/blender/editors/sculpt_paint/sculpt_smooth.c
M	source/blender/editors/sculpt_paint/sculpt_transform.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_clip/clip_editor.c
M	source/blender/editors/space_clip/clip_ops.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/imbuf/intern/imageprocess.c
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/creator/creator.c
M	tests/gtests/blenlib/BLI_linklist_lockfree_test.cc
M	tests/gtests/blenlib/BLI_task_test.cc

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

diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake
index 04e1670aef6..c36b264a300 100644
--- a/build_files/cmake/Modules/GTestTesting.cmake
+++ b/build_files/cmake/Modules/GTestTesting.cmake
@@ -66,6 +66,9 @@ macro(BLENDER_SRC_GTEST_EX)
     if(UNIX AND NOT APPLE)
       target_link_libraries(${TARGET_NAME} bf_intern_libc_compat)
     endif()
+    if(WITH_TBB)
+      target_link_libraries(${TARGET_NAME} ${TBB_LIBRARIES})
+    endif()
 
     get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
     if(GENERATOR_IS_MULTI_CONFIG)
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 94f0e544a6b..6b0861769c3 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -49,6 +49,7 @@ struct PBVH;
 struct PBVHNode;
 struct SubdivCCG;
 struct TaskParallelTLS;
+struct TaskParallelSettings;
 
 typedef struct PBVH PBVH;
 typedef struct PBVHNode PBVHNode;
@@ -456,30 +457,10 @@ bool pbvh_has_face_sets(PBVH *bvh);
 void pbvh_show_face_sets_set(PBVH *bvh, bool show_face_sets);
 
 /* Parallelization */
-typedef void (*PBVHParallelRangeFunc)(void *__restrict userdata,
-                                      const int iter,
-                                      const struct TaskParallelTLS *__restrict tls);
-typedef void (*PBVHParallelReduceFunc)(const void *__restrict userdata,
-                                       void *__restrict chunk_join,
-                                       void *__restrict chunk);
-
-typedef struct PBVHParallelSettings {
-  bool use_threading;
-  void *userdata_chunk;
-  size_t userdata_chunk_size;
-  PBVHParallelReduceFunc func_reduce;
-} PBVHParallelSettings;
-
-void BKE_pbvh_parallel_range_settings(struct PBVHParallelSettings *settings,
+void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings,
                                       bool use_threading,
                                       int totnode);
 
-void BKE_pbvh_parallel_range(const int start,
-                             const int stop,
-                             void *userdata,
-                             PBVHParallelRangeFunc func,
-                             const struct PBVHParallelSettings *settings);
-
 struct MVert *BKE_pbvh_get_verts(const PBVH *bvh);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index bdf8778651d..40c8c2c9ad2 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -197,7 +197,6 @@ set(SRC
   intern/particle_system.c
   intern/pbvh.c
   intern/pbvh_bmesh.c
-  intern/pbvh_parallel.cc
   intern/pointcache.c
   intern/pointcloud.c
   intern/report.c
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c
index c3ae2a54e13..6fcaf84d4ca 100644
--- a/source/blender/blenkernel/intern/editmesh_tangent.c
+++ b/source/blender/blenkernel/intern/editmesh_tangent.c
@@ -251,9 +251,7 @@ finally:
   pRes[3] = fSign;
 }
 
-static void emDM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool),
-                                           void *taskdata,
-                                           int UNUSED(threadid))
+static void emDM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool), void *taskdata)
 {
   struct SGLSLEditMeshToTangent *mesh2tangent = taskdata;
   /* new computation method */
@@ -362,9 +360,8 @@ void BKE_editmesh_loop_tangent_calc(BMEditMesh *em,
 #endif
     /* Calculation */
     if (em->tottri != 0) {
-      TaskScheduler *scheduler = BLI_task_scheduler_get();
       TaskPool *task_pool;
-      task_pool = BLI_task_pool_create(scheduler, NULL, TASK_PRIORITY_LOW);
+      task_pool = BLI_task_pool_create(NULL, TASK_PRIORITY_LOW);
 
       tangent_mask_curr = 0;
       /* Calculate tangent layers */
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 78991ad063d..f0d19f01aab 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -1300,7 +1300,7 @@ static void loop_split_worker_do(LoopSplitTaskDataCommon *common_data,
   }
 }
 
-static void loop_split_worker(TaskPool *__restrict pool, void *taskdata, int UNUSED(threadid))
+static void loop_split_worker(TaskPool *__restrict pool, void *taskdata)
 {
   LoopSplitTaskDataCommon *common_data = BLI_task_pool_user_data(pool);
   LoopSplitTaskData *data = taskdata;
@@ -1704,11 +1704,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
     loop_split_generator(NULL, &common_data);
   }
   else {
-    TaskScheduler *task_scheduler;
-    TaskPool *task_pool;
-
-    task_scheduler = BLI_task_scheduler_get();
-    task_pool = BLI_task_pool_create(task_scheduler, &common_data, TASK_PRIORITY_HIGH);
+    TaskPool *task_pool = BLI_task_pool_create(&common_data, TASK_PRIORITY_HIGH);
 
     loop_split_generator(task_pool, &common_data);
 
diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c
index a2a198cdb0d..d6f945cf34f 100644
--- a/source/blender/blenkernel/intern/mesh_tangent.c
+++ b/source/blender/blenkernel/intern/mesh_tangent.c
@@ -452,9 +452,7 @@ finally:
   pRes[3] = fSign;
 }
 
-static void DM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool),
-                                         void *taskdata,
-                                         int UNUSED(threadid))
+static void DM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool), void *taskdata)
 {
   struct SGLSLMeshToTangent *mesh2tangent = taskdata;
   /* new computation method */
@@ -658,9 +656,7 @@ void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert,
 
     /* Calculation */
     if (looptri_len != 0) {
-      TaskScheduler *scheduler = BLI_task_scheduler_get();
-      TaskPool *task_pool;
-      task_pool = BLI_task_pool_create(scheduler, NULL, TASK_PRIORITY_LOW);
+      TaskPool *task_pool = BLI_task_pool_create(NULL, TASK_PRIORITY_LOW);
 
       tangent_mask_curr = 0;
       /* Calculate tangent layers */
diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index 4835a4c6a62..8957628c76a 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -453,9 +453,7 @@ static void ocean_compute_htilda(void *__restrict userdata,
   }
 }
 
-static void ocean_compute_displacement_y(TaskPool *__restrict pool,
-                                         void *UNUSED(taskdata),
-                                         int UNUSED(threadid))
+static void ocean_compute_displacement_y(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -463,9 +461,7 @@ static void ocean_compute_displacement_y(TaskPool *__restrict pool,
   fftw_execute(o->_disp_y_plan);
 }
 
-static void ocean_compute_displacement_x(TaskPool *__restrict pool,
-                                         void *UNUSED(taskdata),
-                                         int UNUSED(threadid))
+static void ocean_compute_displacement_x(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -494,9 +490,7 @@ static void ocean_compute_displacement_x(TaskPool *__restrict pool,
   fftw_execute(o->_disp_x_plan);
 }
 
-static void ocean_compute_displacement_z(TaskPool *__restrict pool,
-                                         void *UNUSED(taskdata),
-                                         int UNUSED(threadid))
+static void ocean_compute_displacement_z(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -525,9 +519,7 @@ static void ocean_compute_displacement_z(TaskPool *__restrict pool,
   fftw_execute(o->_disp_z_plan);
 }
 
-static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool,
-                                       void *UNUSED(taskdata),
-                                       int UNUSED(threadid))
+static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -560,9 +552,7 @@ static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool,
   }
 }
 
-static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool,
-                                       void *UNUSED(taskdata),
-                                       int UNUSED(threadid))
+static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -595,9 +585,7 @@ static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool,
   }
 }
 
-static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool,
-                                       void *UNUSED(taskdata),
-                                       int UNUSED(threadid))
+static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -624,9 +612,7 @@ static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool,
   fftw_execute(o->_Jxz_plan);
 }
 
-static void ocean_compute_normal_x(TaskPool *__restrict pool,
-                                   void *UNUSED(taskdata),
-                                   int UNUSED(threadid))
+static void ocean_compute_normal_x(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {
   OceanSimulateData *osd = BLI_task_pool_user_data(pool);
   const Ocean *o = osd->o;
@@ -645,9 +631,7 @@ static void ocean_compute_normal_x(TaskPool *__restrict pool,
   fftw_execute(o->_N_x_plan);
 }
 
-static void ocean_compute_normal_z(TaskPool *__restrict pool,
-                                   void *UNUSED(taskdata),
-                                   int UNUSED(threadid))
+static void ocean_compute_normal_z(TaskPool *__restrict pool, void *UNUSED(taskdata))
 {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list