summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-28 09:23:08 -0700
committerGitHub <noreply@github.com>2024-08-28 09:23:08 -0700
commit638e5fb000d4e242a91e8b653da4a72daec0efda (patch)
treecfcd15c1fc6bdee624eb33abac3268241b086dec /source/slang/slang-lower-to-ir.cpp
parent16595a8379e9dbfa1845fd72f3531ff3372da3ef (diff)
Make tuple types work in autodiff. (#4923)
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp20
1 files changed, 17 insertions, 3 deletions
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 : ExprLoweringVisitorBase<LValueExprLoweringVis
}
};
+ LoweredValInfo result;
+
// As required by the implementation of 'assign' and as a small
// optimization, we will detect if the base expression has also lowered
// into a swizzle and only return a single swizzle instead of nested
@@ -5435,7 +5437,7 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis
swizzledLValue->elementIndices);
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 : ExprLoweringVisitorBase<LValueExprLoweringVis
swizzledLValue->elementCoords);
context->shared->extValues.add(swizzledLValue);
- return LoweredValInfo::swizzledMatrixLValue(swizzledLValue);
+ result = LoweredValInfo::swizzledMatrixLValue(swizzledLValue);
}
else
{
@@ -5464,8 +5466,20 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis
swizzledLValue->base = 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<TupleType>(expr->base->type) != nullptr;
+ if (shouldUseSimpleLVal)
+ {
+ auto addr = getAddress(context, result, expr->loc);
+ return LoweredValInfo::ptr(addr);
}
+ return result;
}
};