AcademySoftwareFoundation / OpenShadingLanguage

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

Make recent run-layer optimizations optional, and fix init ops-related false positive #1672

Closed chellmuth closed 1 year ago

chellmuth commented 1 year ago

Description

My initial implementation of the run layer check optimizations didn’t account for the fact that init ops for symbols have their llvm code generated before we build basic blocks from the OSL IR.

This caused the code to be wrong in two ways: 1) the set of known run layer calls was being reset between instances too late in the pipeline, so a useparam inside an init op would actually be checking the previously compiled layer’s set, and 2) even when reset earlier, it assumed valid basic block ids existed for the init ops when they did not.

So, if a layer had a useparam inside one of its init ops that generally matched the same code location as a useparam in the previously compiled layer, the run layer check could be incorrectly omitted.

I’ve updated the code so that the default optimization behavior is reverted to the way it was before #1665, and added a new option opt_useparam that can be turned on to enable a fixed, restricted version of the optimization that only applies to code in the main section.

Tests

I'm working on a test that properly triggers the issue.

Checklist:

AlexMWells commented 1 year ago

Is the new opt_useparam just to allow a way to turn this off in case there is a bug or to measure its individual improvement? Seems like, if its correct (the big question) you would always want it.