AcademySoftwareFoundation / OpenShadingLanguage

Advanced shading language for production GI renderers
BSD 3-Clause "New" or "Revised" License
2.05k stars 347 forks source link

Add lazytrace option to avoid combinatoric optixTrace inlining #1815

Closed chellmuth closed 1 month ago

chellmuth commented 1 month ago

OptiX inlines all calls to optixTrace at module compilation time. Due to OSL's lazy layer evaluation, if layer A calls layer B M times, and layer B calls layer C N times, that can lead to M*N inlines of optixTrace if layer C contains a trace operation.

In practice we've observed single trace ops being inlined hundreds of times, leading to minutes-long shader compilations.

This patch adds a new option, lazytrace, to run layers with trace ops unconditionally at the start of shader evaluation. This costs some potential performance in cases where the trace layer would never be evaluated, but removes all the compilation penalties that the inlining was presenting.

Tests

Added a new test, lazytrace, that checks via printf to make sure the non-lazy execution ordering rules were correctly followed when lazytrace=0.

Checklist: