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
This commit is contained in:
Hans Goudey 2022-04-07 11:44:32 -05:00
parent f8c21937d2
commit 8f344b530a
1 changed files with 17 additions and 14 deletions

View File

@ -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;
}