Page MenuHome

Fix T96810: Bitmap race condition in PBVH normal calculation
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on May 19 2022, 1:00 PM.

Details

Summary

The final normalization step of sculpt normal calculation iterates over
all unique vertices in each node and marks them as done. However,
storing the done mask in a bitmap meant that multiple threads could
write to a single byte at the same time, because the bits for separate
threads could be stored in the same byte. This is not threadsafe.

Fixing this issue seems to improve performance as well. First I tested
just clearing the entire bitmap after the normal calculation. Then I
tested using an array of booleans instead, which turned out to be
slightly better, and simplifies code a bit.

I tested on a Ryzen 3800x, on an 8 million polygon subdivided
Suzanne by using the grab brush with a radius large enough to
affect most of the mesh.

BeforeClear Entire BitmapBoolean Array
67.9 ms59.1 ms57.9 ms
1.0x1.15x1.17x

I don't really have a preference between clearing the entire bitmap
or using a Boolean array, I would be happy to apply that solution too.

Diff Detail

Repository
rB Blender

Event Timeline

Either seems fine.

This revision is now accepted and ready to land.May 19 2022, 2:04 PM