[Bf-blender-cvs] [fb512bfa3d3] functions: initial working version with ParticleSet

Jacques Lucke noreply at git.blender.org
Thu Jan 2 16:37:51 CET 2020


Commit: fb512bfa3d393fc1a693e8dbad0a89b6d4902613
Author: Jacques Lucke
Date:   Thu Jan 2 13:18:12 2020 +0100
Branches: functions
https://developer.blender.org/rBfb512bfa3d393fc1a693e8dbad0a89b6d4902613

initial working version with ParticleSet

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

M	source/blender/blenlib/BLI_multi_map.h
M	source/blender/blenlib/BLI_vector.h
M	source/blender/simulations/bparticles/particle_allocator.cpp
M	source/blender/simulations/bparticles/particle_allocator.hpp
M	source/blender/simulations/bparticles/particle_set.cpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/blenlib/BLI_multi_map.h b/source/blender/blenlib/BLI_multi_map.h
index 514ab363b93..cdf7e34990a 100644
--- a/source/blender/blenlib/BLI_multi_map.h
+++ b/source/blender/blenlib/BLI_multi_map.h
@@ -101,6 +101,12 @@ template<typename K, typename V, uint N = 4> class MultiMap {
     return newly_inserted;
   }
 
+  template<uint OtherN> void add_multiple(MultiMap<K, V, OtherN> &other)
+  {
+    BLI_assert(this != &other);
+    other.foreach_item([&](const K &key, ArrayRef<V> values) { this->add_multiple(key, values); });
+  }
+
   void add_multiple(const K &key, ArrayRef<V> values)
   {
     for (const V &value : values) {
@@ -159,6 +165,15 @@ template<typename K, typename V, uint N = 4> class MultiMap {
       }
     }
   }
+
+  template<typename FuncT> void foreach_item(const FuncT &func)
+  {
+    for (auto item : m_map.items()) {
+      const K &key = item.key;
+      ArrayRef<V> values = item.value.get_slice(m_elements);
+      func(key, values);
+    }
+  }
 };
 
 } /* namespace BLI */
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index ee32c50a9ac..e65ce287be1 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -607,7 +607,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
     uint size = this->size();
 
     T *new_array = (T *)m_allocator.allocate_aligned(
-        min_capacity * (uint)sizeof(T), std::alignment_of<T>::value, __func__);
+        min_capacity * (uint)sizeof(T), std::alignment_of<T>::value, "grow BLI::Vector");
     uninitialized_relocate_n(m_begin, size, new_array);
 
     if (!this->is_small()) {
diff --git a/source/blender/simulations/bparticles/particle_allocator.cpp b/source/blender/simulations/bparticles/particle_allocator.cpp
index 483ed75daaf..6c76d9d9c92 100644
--- a/source/blender/simulations/bparticles/particle_allocator.cpp
+++ b/source/blender/simulations/bparticles/particle_allocator.cpp
@@ -38,7 +38,7 @@ AttributesRefGroup ParticleAllocator::request(StringRef particle_system_name, ui
 
   {
     std::lock_guard<std::mutex> lock(m_request_mutex);
-    m_allocated_particles.add(&main_set, particles);
+    m_allocated_particles.add(particle_system_name, particles);
   }
 
   Vector<ArrayRef<void *>> buffers;
diff --git a/source/blender/simulations/bparticles/particle_allocator.hpp b/source/blender/simulations/bparticles/particle_allocator.hpp
index 413500cbda0..21c4dd82b5b 100644
--- a/source/blender/simulations/bparticles/particle_allocator.hpp
+++ b/source/blender/simulations/bparticles/particle_allocator.hpp
@@ -14,7 +14,7 @@ using FN::AttributesRefGroup;
 class ParticleAllocator : BLI::NonCopyable, BLI::NonMovable {
  private:
   ParticlesState &m_state;
-  MultiMap<ParticleSet *, ParticleSet *> m_allocated_particles;
+  MultiMap<std::string, ParticleSet *> m_allocated_particles;
   std::mutex m_request_mutex;
 
  public:
diff --git a/source/blender/simulations/bparticles/particle_set.cpp b/source/blender/simulations/bparticles/particle_set.cpp
index 3ae8d9f01b1..6e16c7e12a9 100644
--- a/source/blender/simulations/bparticles/particle_set.cpp
+++ b/source/blender/simulations/bparticles/particle_set.cpp
@@ -36,6 +36,10 @@ void ParticleSet::update_attributes(const AttributesInfo *new_attributes_info)
   diff.update(m_capacity, m_size, m_attribute_buffers, new_buffers);
 
   m_attribute_buffers = std::move(new_buffers);
+
+  if (m_own_attributes_info) {
+    delete m_attributes_info;
+  }
   m_attributes_info = new_attributes_info;
 }
 
@@ -57,6 +61,7 @@ void ParticleSet::add_particles(ParticleSet &particles)
   MutableAttributesRef dst{
       *m_attributes_info, m_attribute_buffers, IndexRange(m_size, particles.size())};
   MutableAttributesRef::RelocateUninitialized(particles.attributes(), dst);
+  m_size = required_size;
 }
 
 void ParticleSet::realloc_particle_attributes(uint min_size)
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 68f6825ff57..f0c921df99f 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -347,101 +347,42 @@ BLI_NOINLINE static void delete_tagged_particles_and_reorder(ParticleSet &partic
   particles.destruct_and_reorder(indices_to_delete.as_ref());
 }
 
-// BLI_NOINLINE static void simulate_blocks_for_time_span(
-//     ParticleAllocator &particle_allocator,
-//     ArrayRef<AttributesBlock *> blocks,
-//     StringMap<ParticleSystemInfo> &systems_to_simulate,
-//     FloatInterval time_span,
-//     SimulationState &simulation_state)
-// {
-//   auto func = [&](uint block_index) {
-//     AttributesBlock &block = *blocks[block_index];
-
-//     StringRef particle_system_name = simulation_state.particles().particle_container_name(
-//         block.owner());
-//     ParticleSystemInfo &system_info = systems_to_simulate.lookup(particle_system_name);
-
-//     LargeScopedArray<float> remaining_durations(block.used_size());
-//     remaining_durations.fill(time_span.size());
-
-//     simulate_particle_chunk(simulation_state,
-//                             particle_allocator,
-//                             block.as_ref(),
-//                             system_info,
-//                             remaining_durations,
-//                             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(
-//     ParticleAllocator &particle_allocator,
-//     ArrayRef<AttributesBlock *> blocks,
-//     StringMap<ParticleSystemInfo> &systems_to_simulate,
-//     float end_time,
-//     SimulationState &simulation_state)
-// {
-//   auto func = [&](uint block_index) {
-//     AttributesBlock &block = *blocks[block_index];
-
-//     StringRef particle_system_name = simulation_state.particles().particle_container_name(
-//         block.owner());
-//     ParticleSystemInfo &system_info = systems_to_simulate.lookup(particle_system_name);
-
-//     uint active_amount = block.used_size();
-//     Vector<float> durations(active_amount);
-//     auto birth_times = block.as_ref().get<float>("Birth Time");
-//     for (uint i = 0; i < active_amount; i++) {
-//       durations[i] = end_time - birth_times[i];
-//     }
-//     simulate_particle_chunk(
-//         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(
-//     ParticlesState &state, StringMap<ParticleSystemInfo> &systems_to_simulate)
-// {
-//   Vector<AttributesBlock *> blocks;
-//   systems_to_simulate.foreach_key([&state, &blocks](StringRefNull particle_system_name) {
-//     AttributesBlockContainer &container = state.particle_container(particle_system_name);
-//     blocks.extend(container.active_blocks());
-//   });
-//   return blocks;
-// }
-
-// BLI_NOINLINE static void simulate_all_existing_blocks(
-//     SimulationState &simulation_state,
-//     StringMap<ParticleSystemInfo> &systems_to_simulate,
-//     ParticleAllocator &particle_allocator,
-//     FloatInterval time_span)
-// {
-//   simulation_state.particles().particle_containers().foreach_key_value_pair(
-//       [&](StringRef name, ParticleSet *particles) {});
-//   Vector<AttributesBlock *> blocks = get_all_blocks_to_simulate(simulation_state.particles(),
-//                                                                 systems_to_simulate);
-//   simulate_blocks_for_time_span(
-//       particle_allocator, blocks, systems_to_simulate, time_span, simulation_state);
-// }
+BLI_NOINLINE static void simulate_particles_for_time_span(SimulationState &simulation_state,
+                                                          ParticleAllocator &particle_allocator,
+                                                          ParticleSystemInfo &system_info,
+                                                          FloatInterval time_span,
+                                                          MutableAttributesRef particle_attributes)
+{
+  Array<float> remaining_durations(particle_attributes.size(), time_span.size());
+  simulate_particle_chunk(simulation_state,
+                          particle_allocator,
+                          particle_attributes,
+                          system_info,
+                          remaining_durations,
+                          time_span.end());
+}
+
+BLI_NOINLINE static void simulate_particles_from_birth_to_end_of_step(
+    SimulationState &simulation_state,
+    ParticleAllocator &particle_allocator,
+    ParticleSystemInfo &system_info,
+    float end_time,
+    MutableAttributesRef particle_attributes)
+{
+  ArrayRef<float> birth_times = particle_attributes.get<float>("Birth Time");
+
+  Array<float> remaining_durations(particle_attributes.size());
+  for (uint i : remaining_durations.index_iterator()) {
+    remaining_durations[i] = end_time - birth_times[i];
+  }
+
+  simulate_particle_chunk(simulation_state,
+                          particle_allocator,
+                          particle_attributes,
+                          system_info,
+                          remaining_durations,
+                          end_time);
+}
 
 BLI_NOINLINE static void create_particles_from_emitters(SimulationState &simulation_state,
                                                         ParticleAllocator &particle_allocator,
@@ -463,27 +404,61 @@ void simulate_particles(SimulationState &simulation_state,
   ParticlesState &particles_state = simulation_state.particles();
   FloatInterval simulation_time_span = simulation_state.time().current_update_time();
 
-  Vector<AttributesBlock *> newly_created_blocks;
+  MultiMap<std::

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list