AcademySoftwareFoundation / MaterialX

MaterialX is an open standard for the exchange of rich material and look-development content across applications and renderers.
http://www.materialx.org/
Apache License 2.0
1.83k stars 336 forks source link

CodeGen: Update codegen optimization code to handle `ifgreatereq` #1527

Closed kwokcb closed 12 months ago

kwokcb commented 1 year ago

Issue:

compare was removed in 1.37 but not updated in code optimization for igreatereq which was added.

Proposal

Consider adding this optimization back in to test if the upstream decision argument is a constant. If so then add back in code optimization.

It might be worthwhile to consider making optimizations based on conditionals to be a code generation option. This way if an integration wants to not have to regenerate on conditional changes they can.

jstone-lucasfilm commented 1 year ago

As with #1526, I'd recommend that we consider this in the context of broader improvements to the interface reduction rules in MaterialX shader generation, rather than simply restoring a feature from 1.37.

Since these constant folding optimizations represent tradeoffs for the client, improving runtime performance but requiring additional shader recompilation when inputs are modified, it seems important to implement them with broad user controls over which categories of optimizations are applied to shader generation.

JGamache-autodesk commented 1 year ago

I would recommend pruning to be done as a "constant propagation" pass. Which means it would be initiated by the presence of constant nodes (and probably with a shadergen option to enable that optimization pass).

A good constant propagation pass would:

It would be extremely interesting to code, but we need to consider that both the GLSL and OSL compilers are supposed to have a fully functioning optimizer, so maybe we should simply make sure that a constant node with the value 0.18 ends up writing nothing but:

const float myConstant_value = 0.18;

In the generated code, and does not create a uniform shader parameter, thus properly signaling the GLSL and OSL compilers that these values are constant as far as the compiler and optimizer are concerned. A lot less interesting, but also easier to achieve.

jstone-lucasfilm commented 12 months ago

Let's close out this issue along with #1526, in order to keep the focus on designing client-side controls for constant folding and reduced interfaces in shader generation.