diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-07 19:44:32 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-07 19:44:32 +0300 |
commit | 8f344b530a6ed8530ceb780110006af68430c9d5 (patch) | |
tree | aba3689b98cfc2422d89623394a66a2e2a753cfc /source/blender/nodes/geometry | |
parent | f8c21937d2ba1140533c5e6f70426099f9680609 (diff) |
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
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_line.cc | 31 |
1 files changed, 17 insertions, 14 deletions
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; } |