imageworks/OpenShadingLanguage — pull request #182 by lgritz (2012-12-07 18:21:00+00:00)
Title: Merge identical shader instances within a group.

In complex shader networks/groups, sometimes there are (inadvertently, for convenience, or as an artifact of the lookdev tools) multiple nodes/layers that are exact copies of each other. For example, at SPI, our character shaders are often organized into sub-nets for conceptual "layers" (skin, oil, wet, etc.), each of which is structurally similar and often may contain true redundancies including texture-reading shaders that reference the same textures at the same coordinates.

This patch adds code that searches shader networks for pairs of shaders that are identical -- same code, same parameter values, same upstream connections, etc. -- and eliminate the redundant one, redirecting downstream connections from the excised one to the retained one.

The cost for this is small: 3-4 seconds for our very complex scenes that take many hours to render. The results vary from scene to scene; sometimes there's no change, but other shots have up to a 20% improvement in both time and memory.

This new optimization can be disabled by setting the attribute "opt_merge_instances" to 0.