Multithreading the sync portion of cycles

Hi there, I’m looking to learn and multi-thread some portions of the render process in Cycles. I thought I’d ask if anyone else had looked at this or had any suggestions. From what I can tell, one part of the render process is the object syncing part, seen here:

On the face of it, this loop could be parallelized with something like TBB (which we already include it looks like), though obviously there would need to be some re-work of underlying data structures (like in the syncObject(…) method). I was just wondering if anyone’s looked at this before, or had any thoughts/suggestions about the endeavour. I realize that in most renders this is a small amount of time, though in some renders like the Barbershop, it seems to take much longer, but I think it’s a useful exercise to try out.

Thanks in advance :slight_smile:

I’m not aware of existing code for this.

The dependency graph object instance iterator is single-threaded and the BL::Object of instances is only temporary and gets removed when iterating to the next object. So that would need deeper changes on the Blender side to be fully multi-threaded.

Export of things like mesh geometry and material does not have that problem, and could be scheduled to own tasks. Note that these may be shared by multiple objects, so some locking is needed to make that threaded safe.

And of course also editing data structures like e.g. the list of all objects needs to be done in a thread-safe way, either with locking or each thread having their own list which is later merged.

Overall this is a very complex project, so if you are just starting development on Cycles it may not be the best place to begin.

1 Like

brecht actually added a tast to the Cycles board a few days ago:

This task is a “move Cycles thread scheduler to TBB” planned for after the upgrade to Blender’s C++ version.

Ooh, thanks! Yeah, from my (admittedly limited) testing, TBB scales really well across multiple cores, so it would be good to use under a unified umbrella. I don’t know if Blender uses a node network type evaluation system like Maya or Houdini, but we’d need to look at using the task arena’s isolate functionality to make sure things like priority inversions don’t happen.

Regarding parallel evaluations, the SIGGRAPH course notes “Multithreading and VFX” might be helpful: