Commit: 8f344b530a6ed8530ceb780110006af68430c9d5
Author: Hans Goudey
Date:   Thu Apr 7 11:44:32 2022 -0500
Branches: master
https://developer.blender.org/rB8f344b530a6ed8530ceb780110006af68430c9d5

Geometry Nodes: Parallelize mesh line node

I observed a 4-5x performance improvement (from 50ms to 12ms)
with five million points, though obviously the change depends on
the hardware.

In the future we may want to disable the parallelization in
`parallel_invoke` when there is a small amount of points.

Differential Revision: https://developer.blender.org/D14590

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

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

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

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
index cbad4544860..8c1dea90f44 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc
@@ -169,15 +169,6 @@ static void node_geo_exec(GeoNodeExecParams params)
 
 namespace blender::nodes {
 
-static void fill_edge_data(MutableSpan<MEdge> edges)
-{
-  for (const int i : edges.index_range()) {
-    edges[i].v1 = i;
-    edges[i].v2 = i + 1;
-    edges[i].flag |= ME_LOOSEEDGE;
-  }
-}
-
 Mesh *create_line_mesh(const float3 start, const float3 delta, const int count)
 {
   if (count < 1) {
@@ -189,11 +180,23 @@ Mesh *create_line_mesh(const float3 start, const float3 
delta, const int count)
   MutableSpan<MVert> verts{mesh->mvert, mesh->totvert};
   MutableSpan<MEdge> edges{mesh->medge, mesh->totedge};
 
-  for (const int i : verts.index_range()) {
-    copy_v3_v3(verts[i].co, start + delta * i);
-  }
-
-  fill_edge_data(edges);
+  threading::parallel_invoke(
+      [&]() {
+        threading::parallel_for(verts.index_range(), 4096, [&](IndexRange 
range) {
+          for (const int i : range) {
+            copy_v3_v3(verts[i].co, start + delta * i);
+          }
+        });
+      },
+      [&]() {
+        threading::parallel_for(edges.index_range(), 4096, [&](IndexRange 
range) {
+          for (const int i : range) {
+            edges[i].v1 = i;
+            edges[i].v2 = i + 1;
+            edges[i].flag |= ME_LOOSEEDGE;
+          }
+        });
+      });
 
   return mesh;
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to