Page MenuHome

Edit Mesh: multi-thread auto-smooth & custom normal calculations
ClosedPublic

Authored by Campbell Barton (campbellbarton) on Jul 15 2021, 6:51 AM.
Tags
None
Subscribers
None
Tokens
"Like" token, awarded by erickblender."Love" token, awarded by jimman2003."Burninate" token, awarded by gilberto_rodrigues."Love" token, awarded by Lumpengnom."Love" token, awarded by Rusculleda."Love" token, awarded by Zino."Love" token, awarded by Kickflipkid687."Yellow Medal" token, awarded by chironamo.

Details

Summary

Supported multi-threading for bm_mesh_loops_calc_normals.

This is done by operating on vertex-loops instead of face-loops.

Single threaded operation still loops over faces since iterating
over vertices adds some overhead in the case of custom-normals
as the order used for accessing loops must be the same as iterating
of a faces loops.

From isolated timing tests of bm_mesh_loops_calc_normals on high
poly models, this gives between 3.5x to 10x speedup,
with larger gains for meshes with custom-normals.

NOTE: this is the first part of two for multi-threading auto-smooth, tagging edges as sharp is still single threaded (coming next).

Notes:

  • This change is limited to multi-threading existing logic. Some other optimizations may be worth looking into but I would rather do them separately to this patch as it makes the patch harder to review and complicates debugging any regressions they could cause.
  • For faster overall performance, tagging sharp edges could be multi-threaded as well - perhaps making it part of the bm_mesh_loops_calc_normals to avoid a separate blocking loop over all edges.

Other changes made as part of this patch:

Diff Detail

Repository
rB Blender
Branch
TEMP-BMESH-AUTOSMOOTH-MT
Build Status
Buildable 15973
Build 15973: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) requested review of this revision.Jul 15 2021, 6:51 AM
Campbell Barton (campbellbarton) created this revision.
  • Use simpler (orderless) operation when there is no custom normal data.
  • Remove loop over faces & loops (when loop indices are already set).
  • Removing redundant headers
Campbell Barton (campbellbarton) retitled this revision from Multi-thread auto-smooth & custom normal calculations to Edit Mesh: multi-thread auto-smooth & custom normal calculations.Jul 15 2021, 7:57 AM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
  • Simplify loops of edge iteration

Generally LGTM, did not dive into all the details of the changes though... Minor comments below, nothing blocking though.

source/blender/blenkernel/intern/mesh_normals.cc
535

won't doesn't ;)

source/blender/bmesh/intern/bmesh_mesh_normals.c
533

Unless am missing something, this does not matches the asserts below?

888

Don't think we need that assert, the case is already explicitly excluded in check above?

This revision is now accepted and ready to land.Jul 22 2021, 1:03 PM
Campbell Barton (campbellbarton) marked 3 inline comments as done.

Update based on review