From 86fc50c5092fbccf6072dcf7bbdfafb8915f02c8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 8 Mar 2023 21:52:34 -0800 Subject: Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`. (#2691) * Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`. * Fix * Fix. * Cleanup. --------- Co-authored-by: Yong He --- source/slang/slang-ast-modifier.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/slang/slang-ast-modifier.h') diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index 7dd0819d8..80c770c3a 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -1151,6 +1151,24 @@ class BackwardDerivativeOfAttribute : public DerivativeOfAttribute SLANG_AST_CLASS(BackwardDerivativeOfAttribute) }; + /// The `[PrimalSubstitute(function)]` attribute specifies a custom function that should + /// be used as the primal function substitute when differentiating code that calls the primal function. +class PrimalSubstituteAttribute : public Attribute +{ + SLANG_AST_CLASS(PrimalSubstituteAttribute) + Expr* funcExpr; +}; + + /// The `[PrimalSubstituteOf(primalFunction)]` attribute marks the decorated function as + /// the substitute primal function in a forward or backward derivative function. +class PrimalSubstituteOfAttribute : public Attribute +{ + SLANG_AST_CLASS(PrimalSubstituteOfAttribute) + + Expr* funcExpr; + Expr* backDeclRef; // DeclRef to this derivative function when initiated from primalFunction. +}; + /// The `[NoDiffThis]` attribute is used to specify that the `this` parameter should not be /// included for differentiation. class NoDiffThisAttribute : public Attribute -- cgit v1.2.3