Skip to content

Commit 8db7a3e

Browse files
WGSL: document a known limitation of the nested-constituent fold
A reviewer-identified edge case: an aggregate that is both a nested constituent and used directly (a named `static const` array shared as an element of another `static const` array and also independently runtime-indexed) is not folded inline, so it stays a separate `var<private>` declaration that the enclosing converted array's initializer references by name -- invalid WGSL. The shape is not constructible from typical anonymous nested literals and is not a regression (such a constant was rejected before this change too, as a runtime-indexed `const`). Record it where the fold decision is made. Co-authored-by: Harsh Aggarwal <haaggarwal@nvidia.com>
1 parent 9f4c902 commit 8db7a3e

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

source/slang/slang-emit-wgsl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,14 @@ void WGSLSourceEmitter::emitCallArg(IRInst* inst)
14261426
// of a larger aggregate, never used directly (e.g. it is not the base of a runtime GetElement).
14271427
// Such a constituent must be inlined into its enclosing aggregate's initializer; an aggregate
14281428
// used directly is the outermost one and must stay a declaration.
1429+
//
1430+
// Known limitation: an aggregate that is BOTH a nested constituent AND used directly (e.g. a
1431+
// named `static const` array shared as an element of another `static const` array and also
1432+
// independently runtime-indexed) returns false here, so it stays a separate `var<private>`
1433+
// declaration that the enclosing converted array's initializer then references by name —
1434+
// invalid WGSL. This shape is not constructible from typical anonymous nested literals (whose
1435+
// inner Make* insts are used only as the parent's operands); fully handling it would require
1436+
// inlining a duplicate copy of the constituent into the enclosing initializer.
14291437
static bool isOnlyUsedAsAggregateConstituent(IRInst* inst)
14301438
{
14311439
bool hasUse = false;

0 commit comments

Comments
 (0)