Page MenuHome

Parallelize BKE_mesh_calc_edges.
ClosedPublic

Authored by Jacques Lucke (JacquesLucke) on Oct 8 2020, 3:56 PM.

Details

Summary

While working on D9141: Volumes: new Volume to Mesh modifier, I noticed that BKE_mesh_calc_edges is significantly slower than openvdb::tools::volumeToMesh. Openvdb only takes ~115ms in my test setup, while computing the edges used to take ~960ms. With the optimization implemented by this patch, computing the edges only takes ~210ms on my hardware.

Parallelizing BKE_mesh_calc_edges is not entirely trivial, because it has to perform deduplication and some other things that have to happen in a certain order. Still, I managed to parallelize all the individual steps, even though the performance does not scale linearly with the number of cores. The speedup is mainly achieved by having multiple hash tables that are filled in parallel. The distribution of edges to hash tables is based on a hash.

This is the mesh I generate in my test file:

I moved the function to C++, because that made it easier for me to optimize it. Furthermore, I added BLI_task.hh which contains some light tbb wrappers.

Diff Detail

Repository
rB Blender

Event Timeline

Jacques Lucke (JacquesLucke) requested review of this revision.Oct 8 2020, 3:56 PM

While I'm not familier with the C++ API's, logic seems sound, only minor comment noted inline.

If there is a good reason to hard code the number of tasks, that should be described in a comment.

source/blender/blenkernel/intern/mesh_validate.cc
208

8 seems arbitrary. For people with many more cores.
wouldn't it be better have a fixed chunk size, allowing for systems with more cores to use all cores on a heavy mesh.

This revision is now accepted and ready to land.Oct 9 2020, 8:59 AM
This revision was automatically updated to reflect the committed changes.