From 1a486813ef0bc7f7a2eb6eaeec2921fd71a2bd05 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Tue, 17 Jan 2023 20:21:01 -0500 Subject: Added switch-case support; fixed non-diff parameter transposition (#2596) --- source/slang/slang-ir-autodiff-rev.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'source/slang/slang-ir-autodiff-rev.cpp') diff --git a/source/slang/slang-ir-autodiff-rev.cpp b/source/slang/slang-ir-autodiff-rev.cpp index 8d6419cf2..de4fbe182 100644 --- a/source/slang/slang-ir-autodiff-rev.cpp +++ b/source/slang/slang-ir-autodiff-rev.cpp @@ -666,14 +666,15 @@ namespace Slang builder->setInsertInto(fwdDiffParameterBlock); - // 1. Turn fwd-diff versions of the parameters into reverse-diff versions by wrapping them as InOutType<> - for (auto child = fwdDiffParameterBlock->getFirstParam(); child;) + List fwdParams; + for (auto child = fwdDiffParameterBlock->getFirstParam(); child; child = child->getNextParam()) { - IRParam* nextChild = child->getNextParam(); + fwdParams.add(child); + } - auto fwdParam = as(child); - SLANG_ASSERT(fwdParam); - + // 1. Turn fwd-diff versions of the parameters into reverse-diff versions by wrapping them as InOutType<> + for (auto fwdParam : fwdParams) + { // TODO: Handle ptr types. if (auto diffPairType = as(fwdParam->getDataType())) { @@ -690,10 +691,11 @@ namespace Slang else { // Default case (parameter has nothing to do with differentiation) - // Do nothing. + // Simply move the parameter to the end. + // + fwdParam->removeFromParent(); + fwdDiffParameterBlock->addParam(fwdParam); } - - child = nextChild; } auto paramCount = as(diffFunc->getDataType())->getParamCount(); -- cgit v1.2.3