shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

AD Cleanup: Move AST-side synthesis for the differential methods `dadd`, `dmul` and `dzero` entirely to the IR side #4407

Open saipraveenb25 opened 2 weeks ago

saipraveenb25 commented 2 weeks ago

We seem to have two versions of synthesis for dadd, dmul and dzero. One on the AST side (trySynthesizeDifferentialMethodRequirementWitness in slang-check-decl.cpp), and then again on the IR side (fillDifferentialTypeImplementationForStruct in slang-ir-autodiff.cpp).

The IR-side synthesis is pretty much necessary because some differentiable struct types (such as the intermediate context) are generated during IR passes.

We could simply bottleneck all differential type synthesis through the IR-side machinery, and only generate function headers on the AST side, and cut down on redundant code.