Page MenuHome

Cycles: Fix builtin images being loaded even when they are not actually in use
Needs ReviewPublic

Authored by Patrick Mours (pmoursnv) on Tue, May 19, 2:57 PM.

Details

Summary

This fixes a regression introduced by commit 6cf4861c3ac09fd65a765e8f8e3584713cc5303b reported to me.
Previously Cycles would only load images when they are actually in use in the shader graph. After this commit this was only true for images loaded from file, images from Blender on the other hand would now load always, which caused spikes in memory usage in some scenes.

Diff Detail

Repository
rB Blender
Branch
cycles_fix_image_culling (branched from master)
Build Status
Buildable 8121
Build 8121: arc lint + arc unit

Event Timeline

Patrick Mours (pmoursnv) requested review of this revision.Tue, May 19, 2:57 PM
Patrick Mours (pmoursnv) created this revision.

This brings back the crash from T67718: Point density texture crashes.

The problem is that we can't safely access Blender data after it has been synchronized and Cycles no longer holds a lock on it.

This is mainly an issue for interactively tweaking properties of point density textures. But it is also possible for a Blender image to get deleted or have its resolution change or get deleted before Cycles can load it, though it's rather unlikely.

Also, creating the image handle does not actually load the image, it's BlenderSession::builtin_images_load that forces it.

In BlenderSync::sync_materials we have a mechanism for simplifying the shader graph and removing unused nodes early (see D2285). But it is not enabled for viewport rendering, because it makes shader node editing slower due to reloading attributes and images often, and also locks the Blender scene longer.

I'm not immediately sure about the best solution here, I need to think about this a bit.