[Bf-blender-cvs] [0ba061c3bc9] master: Edit Mesh: Parallelize bounds calculation with deform modifiers

Hans Goudey noreply at git.blender.org
Thu Apr 14 01:49:30 CEST 2022


Commit: 0ba061c3bc9bf299c17e064c5fc0f6ae9ac906a1
Author: Hans Goudey
Date:   Wed Apr 13 18:49:11 2022 -0500
Branches: master
https://developer.blender.org/rB0ba061c3bc9bf299c17e064c5fc0f6ae9ac906a1

Edit Mesh: Parallelize bounds calculation with deform modifiers

When displaying a deform modifier in edit mode, a cached
array of positions is used. Parallelizing bounds calculation when
that array exists can improve the framerate when editing slightly
(a few percent). I observed an improvement of the min/max itself
of about 10x (4-5ms to 0.4ms).

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

M	source/blender/blenkernel/intern/editmesh_cache.cc

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

diff --git a/source/blender/blenkernel/intern/editmesh_cache.cc b/source/blender/blenkernel/intern/editmesh_cache.cc
index c2ce1405111..438d287fb28 100644
--- a/source/blender/blenkernel/intern/editmesh_cache.cc
+++ b/source/blender/blenkernel/intern/editmesh_cache.cc
@@ -8,7 +8,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_bounds.hh"
 #include "BLI_math_vector.h"
+#include "BLI_span.hh"
 
 #include "DNA_mesh_types.h"
 
@@ -114,18 +116,20 @@ bool BKE_editmesh_cache_calc_minmax(struct BMEditMesh *em,
                                     float min[3],
                                     float max[3])
 {
+  using namespace blender;
   BMesh *bm = em->bm;
-  BMVert *eve;
-  BMIter iter;
-  int i;
 
   if (bm->totvert) {
     if (emd->vertexCos) {
-      BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
-        minmax_v3v3_v3(min, max, emd->vertexCos[i]);
-      }
+      Span<float3> vert_coords(reinterpret_cast<const float3 *>(emd->vertexCos), bm->totvert);
+      std::optional<bounds::MinMaxResult<float3>> bounds = bounds::min_max(vert_coords);
+      BLI_assert(bounds.has_value());
+      copy_v3_v3(min, math::min(bounds->min, float3(min)));
+      copy_v3_v3(max, math::max(bounds->max, float3(max)));
     }
     else {
+      BMVert *eve;
+      BMIter iter;
       BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
         minmax_v3v3_v3(min, max, eve->co);
       }



More information about the Bf-blender-cvs mailing list