[Bf-blender-cvs] [1eca32bb842] functions: improve usage of TBB

Jacques Lucke noreply at git.blender.org
Sat Dec 28 11:30:02 CET 2019


Commit: 1eca32bb8422565e52ec6a676045dad47f92a24e
Author: Jacques Lucke
Date:   Sat Dec 28 11:29:34 2019 +0100
Branches: functions
https://developer.blender.org/rB1eca32bb8422565e52ec6a676045dad47f92a24e

improve usage of TBB

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

M	source/blender/simulations/CMakeLists.txt
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index f78d6b76ab4..f4ade69f4fa 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -60,4 +60,12 @@ set(LIB
   bf_blenkernel
 )
 
+if(WITH_TBB)
+  add_definitions(-DWITH_TBB)
+
+  list(APPEND INC_SYS
+    ${TBB_INCLUDE_DIRS}
+  )
+endif()
+
 blender_add_lib(bf_simulations "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index f191e7f8a4e..c3eedf2cdae 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -17,7 +17,10 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
 
-#include "tbb/tbb.h"
+#ifdef WITH_TBB
+#  define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
+#  include "tbb/tbb.h"
+#endif
 
 #define WRAPPERS(T1, T2) \
   inline T1 unwrap(T2 value) \
@@ -148,10 +151,14 @@ static Mesh *distribute_tetrahedons(ArrayRef<float3> centers,
           &mesh->ldata, CD_MLOOPCOL, CD_DEFAULT, nullptr, mesh->totloop, "Color"),
       mesh->totloop);
 
+#if WITH_TBB
   tbb::parallel_for(
       tbb::blocked_range<uint>(0, amount, 1000), [&](const tbb::blocked_range<uint> &range) {
         distribute_tetrahedons_range(mesh, loop_colors, range, centers, scales, colors);
       });
+#else
+  distribute_tetrahedons_range(mesh, loop_colors, IndexRange(amount), centers, scales, colors);
+#endif
 
   return mesh;
 }
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 1452cb9b6d7..1f46c03a774 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -8,9 +8,10 @@
 
 #include "simulate.hpp"
 
-// #ifdef WITH_TBB
-#include "tbb/tbb.h"
-// #endif
+#ifdef WITH_TBB
+#  define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
+#  include "tbb/tbb.h"
+#endif
 
 namespace BParticles {
 
@@ -350,7 +351,7 @@ BLI_NOINLINE static void simulate_blocks_for_time_span(
     FloatInterval time_span,
     SimulationState &simulation_state)
 {
-  tbb::parallel_for((uint)0, blocks.size(), [&](uint block_index) {
+  auto func = [&](uint block_index) {
     AttributesBlock &block = *blocks[block_index];
 
     StringRef particle_system_name = simulation_state.particles().particle_container_name(
@@ -368,7 +369,15 @@ BLI_NOINLINE static void simulate_blocks_for_time_span(
                             time_span.end());
 
     delete_tagged_particles_and_reorder(block);
-  });
+  };
+
+#ifdef WITH_TBB
+  tbb::parallel_for((uint)0, blocks.size(), func);
+#else
+  for (uint i : blocks.index_iterator()) {
+    func(i);
+  }
+#endif
 }
 
 BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
@@ -378,7 +387,7 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
     float end_time,
     SimulationState &simulation_state)
 {
-  tbb::parallel_for((uint)0, blocks.size(), [&](uint block_index) {
+  auto func = [&](uint block_index) {
     AttributesBlock &block = *blocks[block_index];
 
     StringRef particle_system_name = simulation_state.particles().particle_container_name(
@@ -395,7 +404,15 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time(
         simulation_state, particle_allocator, block.as_ref(), system_info, durations, end_time);
 
     delete_tagged_particles_and_reorder(block);
-  });
+  };
+
+#ifdef WITH_TBB
+  tbb::parallel_for((uint)0, blocks.size(), func);
+#else
+  for (uint i : blocks.index_iterator()) {
+    func(i);
+  }
+#endif
 }
 
 BLI_NOINLINE static Vector<AttributesBlock *> get_all_blocks_to_simulate(
@@ -462,6 +479,7 @@ void simulate_particles(SimulationState &simulation_state,
   Vector<AttributesBlock *> newly_created_blocks;
   {
     ParticleAllocator particle_allocator(particles_state);
+#ifdef WITH_TBB
     tbb::parallel_invoke(
         [&]() {
           simulate_all_existing_blocks(
@@ -471,6 +489,12 @@ void simulate_particles(SimulationState &simulation_state,
           create_particles_from_emitters(
               simulation_state, particle_allocator, emitters, simulation_time_span);
         });
+#else
+    simulate_all_existing_blocks(
+        simulation_state, systems_to_simulate, particle_allocator, simulation_time_span);
+    create_particles_from_emitters(
+        simulation_state, particle_allocator, emitters, simulation_time_span);
+#endif
     newly_created_blocks = particle_allocator.allocated_blocks();
   }



More information about the Bf-blender-cvs mailing list