[Bf-blender-cvs] [e0e6afb7660] master: Geometry Nodes: Parallelize mesh and curve edit hint transformation

Hans Goudey noreply at git.blender.org
Mon Jan 16 20:16:53 CET 2023


Commit: e0e6afb76604f89ceb68582876addeb2f23e6ca3
Author: Hans Goudey
Date:   Mon Jan 16 13:14:03 2023 -0600
Branches: master
https://developer.blender.org/rBe0e6afb76604f89ceb68582876addeb2f23e6ca3

Geometry Nodes: Parallelize mesh and curve edit hint transformation

Previously transforming and translating meshes (used by the object info
and transform geometry nodes) was single threaded. Now use the same
code path as other geometry types which already includes multithreading.

I observed a 5x performance improvement for a 4 million vert mesh on a
Ryzen 7950x.

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

M	source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc

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

diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc
index 425546c3406..281ffc768ef 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_transform_geometry.cc
@@ -55,13 +55,15 @@ static void transform_positions(MutableSpan<float3> positions, const float4x4 &m
 static void translate_mesh(Mesh &mesh, const float3 translation)
 {
   if (!math::is_zero(translation)) {
-    BKE_mesh_translate(&mesh, translation, false);
+    translate_positions(mesh.vert_positions_for_write(), translation);
+    BKE_mesh_tag_coords_changed_uniformly(&mesh);
   }
 }
 
 static void transform_mesh(Mesh &mesh, const float4x4 &transform)
 {
-  BKE_mesh_transform(&mesh, transform.values, false);
+  transform_positions(mesh.vert_positions_for_write(), transform);
+  BKE_mesh_tag_coords_changed(&mesh);
 }
 
 static void translate_pointcloud(PointCloud &pointcloud, const float3 translation)
@@ -162,16 +164,17 @@ static void translate_volume(GeoNodeExecParams &params,
 static void transform_curve_edit_hints(bke::CurvesEditHints &edit_hints, const float4x4 &transform)
 {
   if (edit_hints.positions.has_value()) {
-    for (float3 &pos : *edit_hints.positions) {
-      pos = transform * pos;
-    }
+    transform_positions(*edit_hints.positions, transform);
   }
   float3x3 deform_mat;
   copy_m3_m4(deform_mat.values, transform.values);
   if (edit_hints.deform_mats.has_value()) {
-    for (float3x3 &mat : *edit_hints.deform_mats) {
-      mat = deform_mat * mat;
-    }
+    MutableSpan<float3x3> deform_mats = *edit_hints.deform_mats;
+    threading::parallel_for(deform_mats.index_range(), 1024, [&](const IndexRange range) {
+      for (const int64_t i : range) {
+        deform_mats[i] = deform_mat * deform_mats[i];
+      }
+    });
   }
   else {
     edit_hints.deform_mats.emplace(edit_hints.curves_id_orig.geometry.point_num, deform_mat);
@@ -181,9 +184,7 @@ static void transform_curve_edit_hints(bke::CurvesEditHints &edit_hints, const f
 static void translate_curve_edit_hints(bke::CurvesEditHints &edit_hints, const float3 &translation)
 {
   if (edit_hints.positions.has_value()) {
-    for (float3 &pos : *edit_hints.positions) {
-      pos += translation;
-    }
+    translate_positions(*edit_hints.positions, translation);
   }
 }



More information about the Bf-blender-cvs mailing list