WIP: HLSL: support global const initializers from non-constant rvalues

Semantic test left over from other source languages is removed, since this is permitted by HLSL.
Also, to support the functionality, a targeted test is performed for this case and it is
turned into a EvqGlobal qualifier to create an AST initialization segment when needed.

Constness is now propagated up aggregate chains during initializer construction.  This
handles hierarchical cases such as the distinction between:

    static const float2 a[2] = { { 1, 2 }, { 3, 4} };

vs

    static const float2 a[2] = { { 1, 2 }, { cbuffer_member, 4} };

The first of which can use a first class constant initalization, and the second cannot.
This commit is contained in:
LoopDawg
2017-07-10 15:43:40 -06:00
parent 652db16ff1
commit 0fca0bafaf
5 changed files with 219 additions and 5 deletions

View File

@@ -2553,8 +2553,19 @@ bool HlslGrammar::acceptInitializer(TIntermTyped*& node)
expected("assignment expression in initializer list");
return false;
}
const bool firstNode = (node == nullptr);
node = intermediate.growAggregate(node, expr, loc);
// If every sub-node in the list has qualifier EvqConst, the returned node becomes
// EvqConst. Otherwise, it becomes EvqTemporary. That doesn't happen with e.g.
// EvqIn or EvqPosition, since the collection isn't EvqPosition if all the members are.
if (firstNode && expr->getQualifier().storage == EvqConst)
node->getQualifier().storage = EvqConst;
else if (expr->getQualifier().storage != EvqConst)
node->getQualifier().storage = EvqTemporary;
// COMMA
if (acceptTokenClass(EHTokComma)) {
if (acceptTokenClass(EHTokRightBrace)) // allow trailing comma