Question about creating and using cycle session

We’re using stand alone cycles in a rendering app. Currently, when our app renders, it creates a session, fills the scene with textures and geometry, renders and then disposes of the session.

What I am curious about is if this is how Session class is supposed to be used or can we keep the session around and update only changed items like textures and geometries. Keeping it around would greatly speed things up.

I noticed there is no way to update the number of threads in the TaskScheduler once init is called on it.

Yes, you can keep around the session and update it incrementally. Blender does this for viewport rendering and for the persistent data final render option.

Some changes do require recreating the session indeed, including changing the number of threads. This could be made to work without recreating the session, but we haven’t really had a good reason to spend time on that.

I did notice the TaskScheduler init is called anyway when new sessions are created so I don’t see things being harmed by merely calling TaskScheduler::init with the number of threads. It does look like I have to kill and restart if I change devices. I have the texture situation well in hand I just have to update meshes properly.

We are also trying to implement viewport preview render with cycles. The persist data final option seems like a good idea. Also for movie making.

@brecht On the delete_node of objects
If I create an object then a geometry that I attach to the object and then create shaders I attach to the geometry do I have to separately called delete_node on each component I created or can I call delete_node on the object and it will delete all those sub components? What forces nodes referenced to 0 count to be permanently deleted?

You have to delete all the components, there’s no reference counting to automatically delete them.