[Bf-blender-cvs] [19dda334973] functions: optimization for the case when particle indices are trivial

Jacques Lucke noreply at git.blender.org
Sat Jun 29 16:25:58 CEST 2019


Commit: 19dda334973ecc710d2458785f13f1c2fd8db248
Author: Jacques Lucke
Date:   Sat Jun 29 15:36:51 2019 +0200
Branches: functions
https://developer.blender.org/rB19dda334973ecc710d2458785f13f1c2fd8db248

optimization for the case when particle indices are trivial

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

M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 1475fc02a23..e46660ca7ee 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -260,6 +260,21 @@ struct ParticleSet {
   {
     return m_particle_indices.size();
   }
+
+  /**
+   * Returns true when get_particle_index(i) == i for all i, otherwise false.
+   */
+  bool indices_are_trivial()
+  {
+    if (m_particle_indices.size() == 0) {
+      return true;
+    }
+    else {
+      /* This works due to the invariants mentioned above. */
+      return m_particle_indices.first() == 0 &&
+             m_particle_indices.last() == m_particle_indices.size() - 1;
+    }
+  }
 };
 
 class Force {
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index ca86fdbc688..a311ba6c81a 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -92,10 +92,18 @@ BLI_NOINLINE static void forward_particles_to_next_event_or_end(
     auto values = particles.attributes().get_float3(name);
     auto offsets = attribute_offsets.get_float3(attribute_index);
 
-    for (uint i : particles.range()) {
-      uint pindex = particles.get_particle_index(i);
-      float time_factor = time_factors_to_next_event[i];
-      values[pindex] += time_factor * offsets[pindex];
+    if (particles.indices_are_trivial()) {
+      for (uint pindex = 0; pindex < particles.size(); pindex++) {
+        float time_factor = time_factors_to_next_event[pindex];
+        values[pindex] += time_factor * offsets[pindex];
+      }
+    }
+    else {
+      for (uint i : particles.range()) {
+        uint pindex = particles.get_particle_index(i);
+        float time_factor = time_factors_to_next_event[i];
+        values[pindex] += time_factor * offsets[pindex];
+      }
     }
   }
 }



More information about the Bf-blender-cvs mailing list