Page MenuHome

Fix T73593: Drivers on hide_viewport and hide_render are unreliable
ClosedPublic

Authored by Sybren A. Stüvel (sybren) on Feb 21 2020, 11:40 AM.

Details

Summary

This fixes a threading issue (T73593) between drivers that write to the same memory address. Driver nodes in the depsgraph now get relations to each other in order to ensure serialisation.

These relations are only added between drivers that target the same struct in RNA, which is determined by removing everything after the last period. For example, a driver with data path pose.bones["Arm_L"].rotation_euler[2] will be grouped with all other drivers on that datablock with a data path that starts with pose.bones["Arm_L"] to form a 'driver group'.

To find a suitable relation within such a driver group, say the relation (from → to), a depth-first search is performed to see whether this will create a cycle, and to see whether there already is such a connection (direct or transitive). This is done by recursively inspecting the incoming connections of the 'to' node and thereby moving it towards the 'from' node. This is an order of magnitde faster than inspecting the outgoing connections of the 'from' node.

This approach generalises the special case for array properties, so the code to support that special case has been removed from DepsgraphRelationBuilder::build_animdata_drivers().

A test on the Spring rig [1] shows that this process adds approximately 9% to the build time of the dependency graph (28 ms for this process on a total 329 ms construction time). I have experimented with a simple cache to keep track of known-connected (from, to) node pairs, but this did not significantly improve the timing.

[1] https://cloud.blender.org/p/spring/5d30a1076249366fa1939cf1

PS: Ignore the TIMEIT_START() and TIMEIT_END() calls and the corresponding #include, I'll remove those before committing to master.

Diff Detail

Repository
rB Blender

Event Timeline

  • Removed some unnecessary comments

Speedup by using the return value of seen.insert(prev_node), thereby avoiding an extra search in the set. This reduces the time cost on the Spring rig from 40ms to 34ms.

Yet another speedup, reducing the time from 40ms to 28ms.
Sorry for the noise in your mailbox!

Sergey Sharybin (sergey) requested changes to this revision.Feb 21 2020, 12:37 PM

Seems fine, just some more tidy-ing to be done ;)

But logic and implementation seems fine.

source/blender/depsgraph/intern/builder/deg_builder_relations.cc
2682

shifting -> waling is more commonly used terminology i would think.

2710

Ignore in release.

OR! Respect --debug-depsgraph-time.

2743

No need to explicitly initialize to empty string.

2756

Make it obvious that nodes are connected within the same group.

2767

How about making a little pseudo-graphic 3 nodes (A -> B -> C) example to visualize exactly?

source/blender/depsgraph/intern/builder/deg_builder_relations.h
94

Not needed here since it's unsued in the header.

This revision now requires changes to proceed.Feb 21 2020, 12:37 PM
Sybren A. Stüvel (sybren) marked 6 inline comments as done.Feb 21 2020, 12:50 PM
  • Feedback from Sergey + more constness

I'm fine with the overall approach, will leave it to Sergey to review the implementation details.

This revision is now accepted and ready to land.Feb 21 2020, 4:30 PM