From 83a42cb76feb1f702ff730040f359cabc01c571a Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 4 Apr 2025 15:25:20 +0800 Subject: Do no fail on missing no_diff annotation on non-differentiable (inputs and output) function outputs (#6737) Closes https://github.com/shader-slang/slang/issues/6632 --- source/slang/slang-ir-check-differentiability.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source/slang/slang-ir-check-differentiability.cpp') diff --git a/source/slang/slang-ir-check-differentiability.cpp b/source/slang/slang-ir-check-differentiability.cpp index 9001295e0..7f3c7bf01 100644 --- a/source/slang/slang-ir-check-differentiability.cpp +++ b/source/slang/slang-ir-check-differentiability.cpp @@ -487,18 +487,25 @@ public: { if (auto call = as(inst)) { + const auto callee = call->getCallee(); // If inst's type is differentiable, and it is in expectDiffInstWorkList, // then some user is expecting the result of the call to produce a derivative. // In this case we need to issue a diagnostic. if (isDifferentiableType(diffTypeContext, inst->getFullType()) && - !isDifferentiableFunc(call->getCallee(), requiredDiffLevel)) + !isDifferentiableFunc(callee, requiredDiffLevel)) { - sink->diagnose( - inst, - Diagnostics::lossOfDerivativeDueToCallOfNonDifferentiableFunction, - getResolvedInstForDecorations(call->getCallee()), - requiredDiffLevel == DifferentiableLevel::Forward ? "forward" - : "backward"); + // No need to fail here if the function is no_diff in + // both inputs and all outputs, this is equivalent of + // inserting no_diff on this inst. + if (!isNeverDiffFuncType(cast(callee->getDataType()))) + { + sink->diagnose( + inst, + Diagnostics::lossOfDerivativeDueToCallOfNonDifferentiableFunction, + getResolvedInstForDecorations(call->getCallee()), + requiredDiffLevel == DifferentiableLevel::Forward ? "forward" + : "backward"); + } } } } -- cgit v1.2.3