[Bf-blender-cvs] [17bff65c6bb] functions: Use multithreading when moving particles forward
Jacques Lucke
noreply at git.blender.org
Tue Jun 18 12:39:12 CEST 2019
Commit: 17bff65c6bb70599c7506229e66e397aed560b96
Author: Jacques Lucke
Date: Tue Jun 18 12:35:22 2019 +0200
Branches: functions
https://developer.blender.org/rB17bff65c6bb70599c7506229e66e397aed560b96
Use multithreading when moving particles forward
Timings in my current test file (nanoseconds per particle per time step):
* Debug Build: 150ns
* Optimized Build: 47ns
* With threading: 9ns
===================================================================
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 226e2471449..9d6d24ac625 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -4,6 +4,7 @@
#include "playground_solver.hpp"
#include "emitter.hpp"
#include "BLI_noise.h"
+#include "BLI_timeit.hpp"
#define WRAPPERS(T1, T2) \
inline T1 unwrap(T2 value) \
@@ -139,6 +140,7 @@ void BParticles_state_step(BParticlesSolver solver_c,
BParticlesState state_c,
float elapsed_seconds)
{
+ SCOPED_TIMER("step");
Solver *solver = unwrap(solver_c);
WrappedState *wrapped_state = unwrap(state_c);
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index 4d99d179e75..74925c801dc 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -1,4 +1,5 @@
#include "BLI_small_vector.hpp"
+#include "BLI_task.h"
#include "particles_container.hpp"
#include "playground_solver.hpp"
@@ -82,14 +83,33 @@ class SimpleSolver : public Solver {
std::cout << "Block amount: " << particles.active_blocks().size() << "\n";
}
+ struct StepBlocksParallelData {
+ SimpleSolver *solver;
+ MyState &state;
+ ArrayRef<ParticlesBlock *> blocks;
+ float elapsed_seconds;
+ };
+
BLI_NOINLINE void step_blocks(MyState &state,
ArrayRef<ParticlesBlock *> blocks,
float elapsed_seconds)
{
- for (ParticlesBlock *block : blocks) {
- AttributeArrays attributes = block->slice_active();
- this->step_slice(state, attributes, elapsed_seconds);
- }
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+
+ StepBlocksParallelData data = {this, state, blocks, elapsed_seconds};
+
+ BLI_task_parallel_range(0, blocks.size(), (void *)&data, step_block_cb, &settings);
+ }
+
+ static void step_block_cb(void *__restrict userdata,
+ const int index,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
+ {
+ StepBlocksParallelData *data = (StepBlocksParallelData *)userdata;
+ ParticlesBlock *block = data->blocks[index];
+ AttributeArrays attributes = block->slice_active();
+ data->solver->step_slice(data->state, attributes, data->elapsed_seconds);
}
BLI_NOINLINE void step_slice(MyState &state, AttributeArrays buffers, float elapsed_seconds)
More information about the Bf-blender-cvs
mailing list