From 7ef980f79447f8deec2aaf4a501df29f97cf1a39 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 2 May 2024 19:46:59 -0400 Subject: Fix unzipping logic for inout non-diff parameters and adjust tests (#4090) * Fix unzipping logic for inout non-diff parameters and adjust tests + Removed `-g0` from `struct-this-parameter.slang` test. Works correctly with the new unzipping logic. + Removed `-g0` from `was/warped-sampling-1d.slang` test. Works correctly with DX12 & CS_5_1. CS_5_0 appears to run into an FXC compiler bug with detecting infinite loops where there don't appear to be any. * Update slang-ir-autodiff-unzip.h * Update warped-sampling-1d.slang --- source/slang/slang-ir-autodiff-unzip.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ir-autodiff-unzip.h b/source/slang/slang-ir-autodiff-unzip.h index c57dc300f..771a3977e 100644 --- a/source/slang/slang-ir-autodiff-unzip.h +++ b/source/slang/slang-ir-autodiff-unzip.h @@ -372,10 +372,32 @@ struct DiffUnzipPass } else { - // For non differentiable arguments, we can simply pass the argument as is - // if this isn't a `out` parameter, in which case it is removed from propagate call. - if (!as(arg->getDataType())) + if (auto inOutType = as(resolvedPrimalFuncType->getParamType(ii))) + { + // For 'inout' parameter we need to create a temp var to hold the value + // before the primal call. This logic is similar to the 'inout' case for differentiable params + // only we don't need to deal with pair types. + // + auto tempPrimalVar = primalBuilder->emitVar(as(arg->getDataType())->getValueType()); + + auto storeUse = findUniqueStoredVal(cast(arg)); + auto storeInst = cast(storeUse->getUser()); + auto storedVal = storeInst->getVal(); + + primalBuilder->emitStore(tempPrimalVar, storedVal); + + diffArgs.add(tempPrimalVar); + } + else + { + // For pure 'in' type. Simply re-use the original argument inst. + // + // For 'out' type parameters, it doesn't really matter what we pass in here, since + // the tranposition logic will discard the argument anyway (we'll pass in the old arg, + // just to keep the number of arguments consistent) + // diffArgs.add(arg); + } } } -- cgit v1.2.3