From 6d2b07dc3952739b7d540cc326a21eff8c3ef935 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sun, 20 Mar 2016 18:45:23 -0600 Subject: [PATCH] Front-end: propagate specialization-constness through conversions and swizzles. --- glslang/Include/Types.h | 1 + glslang/MachineIndependent/Intermediate.cpp | 10 ++++++++-- glslang/MachineIndependent/ParseHelper.cpp | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index 1d126569..05681c9a 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -740,6 +740,7 @@ public: } void makeSpecConstant() { + storage = EvqConst; specConstant = true; } static const char* getLayoutPackingString(TLayoutPacking packing) diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index bb4e14bc..777de2d6 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -262,6 +262,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermTyped* child, TSo // // For constructors, we are now done, it was all in the conversion. + // TODO: but, did this bypass constant folding? // switch (op) { case EOpConstructInt: @@ -291,7 +292,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermTyped* child, TSo if (child->getAsConstantUnion()) return child->getAsConstantUnion()->fold(op, node->getType()); - // If it's a specialiation constant, the result is too. + // If it's a specialization constant, the result is too. if (child->getType().getQualifier().isSpecConstant()) node->getWritableType().getQualifier().makeSpecConstant(); @@ -616,6 +617,12 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt newNode->setLoc(node->getLoc()); newNode->setOperand(node); + // TODO: it seems that some unary folding operations should occur here, but are not + + // Propagate specialization-constant-ness. + if (node->getType().getQualifier().isSpecConstant()) + newNode->getWritableType().getQualifier().makeSpecConstant(); + return newNode; } @@ -883,7 +890,6 @@ TIntermConstantUnion* TIntermediate::addConstantUnion(double d, TBasicType baseT TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, const TSourceLoc& loc) { - TIntermAggregate* node = new TIntermAggregate(EOpSequence); node->setLoc(loc); diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index cd745a9d..d6f41151 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -820,6 +820,9 @@ TIntermTyped* TParseContext::handleDotDereference(const TSourceLoc& loc, TInterm return result; else { TType type(base->getBasicType(), EvqTemporary, fields.num); + // Swizzle operations propagate specialization-constantness + if (base->getQualifier().isSpecConstant()) + type.getQualifier().makeSpecConstant(); return addConstructor(loc, base, type, mapTypeToConstructorOp(type)); } } @@ -837,6 +840,9 @@ TIntermTyped* TParseContext::handleDotDereference(const TSourceLoc& loc, TInterm result = intermediate.addIndex(EOpVectorSwizzle, base, index, loc); result->setType(TType(base->getBasicType(), EvqTemporary, base->getType().getQualifier().precision, (int) vectorString.size())); } + // Swizzle operations propagate specialization-constantness + if (base->getType().getQualifier().isSpecConstant()) + result->getWritableType().getQualifier().makeSpecConstant(); } } else if (base->getBasicType() == EbtStruct || base->getBasicType() == EbtBlock) { const TTypeList* fields = base->getType().getStruct();