From 638e5fb000d4e242a91e8b653da4a72daec0efda Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 28 Aug 2024 09:23:08 -0700 Subject: Make tuple types work in autodiff. (#4923) --- source/slang/slang-lower-to-ir.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 31427e616..87199734a 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -5401,6 +5401,8 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBaseelementIndices); context->shared->extValues.add(swizzledLValue); - return LoweredValInfo::swizzledLValue(swizzledLValue); + result = LoweredValInfo::swizzledLValue(swizzledLValue); } else if(loweredBase.flavor == LoweredValInfo::Flavor::SwizzledMatrixLValue) { @@ -5455,7 +5457,7 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBaseelementCoords); context->shared->extValues.add(swizzledLValue); - return LoweredValInfo::swizzledMatrixLValue(swizzledLValue); + result = LoweredValInfo::swizzledMatrixLValue(swizzledLValue); } else { @@ -5464,8 +5466,20 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBasebase = loweredBase; swizzledLValue->elementIndices = expr->elementIndices; context->shared->extValues.add(swizzledLValue); - return LoweredValInfo::swizzledLValue(swizzledLValue); + result = LoweredValInfo::swizzledLValue(swizzledLValue); + } + + // For a one-element swizzle on a tuple, we can just return the pointer to the member + // instead of a SwizzledLValue because they can't follow the same folding logic as + // vectors and matrices. + // + bool shouldUseSimpleLVal = elementCount == 1 && as(expr->base->type) != nullptr; + if (shouldUseSimpleLVal) + { + auto addr = getAddress(context, result, expr->loc); + return LoweredValInfo::ptr(addr); } + return result; } }; -- cgit v1.2.3