Skip to content

Isolation needed for the TBB task group hierarchy, to prevent some crashes in applications which are using the Embree library #560

@nsirgien

Description

@nsirgien

Blender application, which has been using Embree for a long time at this point, discovered quite a peculiar issue between Blender, Embree and TBB. They have worked around it on their side, but it looks like something needs to be changed/fixed on the Embree side as well. More details are available here (https://projects.blender.org/blender/blender/issues/143662) but overall the problem was a crash, because:

Ok I think the issue is actually this:

  1. Cycles GeometryManager::device_update creates a TaskPool on the stack,
  2. And then it does geom->compute_bvh inside a lambda in parallel.
  3. That goes into BVHEmbree::build -> rtcNewScene -> eventually creates its own TBB task group from inside of Embree; that one has a lifetime of the scene.
  4. Now Embree does BVH build from inside of rtcCommitScene, which seems to do some amount of TBB isolation, and two (I think?) nested parallelism levels.
  5. However, for the embree work job that happens to be executing on the "main" cycles thread, eventually the task group that is stored in Embree Scene gets it's my_parent assigned to the on-stack group created in step 1.

It seems that normally these "group hierarchies" are not used at all, except when doing TBB group cancellation. Which is what this bug exercises, since Blender thumbnails do it. And so since Cycles has "persistent data" set in this repro, the Embree Scene still lives on, as well as the TBB group it has. Which still happily points to "yeah my parent was there", which points to what used to be on-stack variable ages ago. And some sort of TBB per-thread information for "this thread" still has that group in the linked list of "groups for this thread", which is walked during group cancellation.

And then boom crash.

Although it is not fully clear right now at the moment if this is something that really needs to be done on the Embree side, it is worth checking it and tracking it in this ticket.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions