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:

https://github.com/dfelinto/blender/blob/master/intern/cycles/blender/blender_object.cpp#L516

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:

1 Like

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: https://developer.blender.org/T77533

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: http://www.multithreadingandvfx.org

1 Like

Hi @brecht,

Do you have any news on the parallelization of this loop? I know there is a “TaskPool geom_task_pool”, but that pool for geometry nodes/instances doesn’t bring any speedup. Do you have any idea for parallelization?

Thanks.

That loop’s been parallelized (assuming you mean the object sync part of the render). Just not at the top level.

There’s ideas to multithread instances syncing, but it requires a big change to the Blender API. No concrete news on when that might be tackled.