Added constant folding for relational (e.g. lessThan) built-ins, relational built-ins for uints, and bitwise ops for mixed scalars and vectors.

Also, allow comments to precede "#version 100".

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23974 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-11-09 00:18:22 +00:00
parent 0876a58203
commit 77d908af8a
10 changed files with 151 additions and 9 deletions

View file

@ -551,6 +551,12 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
case EOpMax:
case EOpMix:
case EOpClamp:
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpVectorEqual:
case EOpVectorNotEqual:
componentwise = true;
objectSize = children[0]->getAsConstantUnion()->getType().getObjectSize();
break;
@ -638,6 +644,24 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode)
newConstArray[comp].setUConst(std::min(std::max(childConstUnions[0][arg0comp].getUConst(), childConstUnions[1][arg1comp].getUConst()),
childConstUnions[2][arg2comp].getUConst()));
break;
case EOpLessThan:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]);
break;
case EOpGreaterThan:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]);
break;
case EOpLessThanEqual:
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] > childConstUnions[1][arg1comp]));
break;
case EOpGreaterThanEqual:
newConstArray[comp].setBConst(! (childConstUnions[0][arg0comp] < childConstUnions[1][arg1comp]));
break;
case EOpVectorEqual:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] == childConstUnions[1][arg1comp]);
break;
case EOpVectorNotEqual:
newConstArray[comp].setBConst(childConstUnions[0][arg0comp] != childConstUnions[1][arg1comp]);
break;
case EOpMix:
if (children[2]->getAsTyped()->getBasicType() == EbtBool)
newConstArray[comp].setDConst(childConstUnions[2][arg2comp].getBConst() ? childConstUnions[1][arg1comp].getDConst() :

View file

@ -616,6 +616,35 @@ void TBuiltIns::initialize(int version, EProfile profile)
"\n");
if (version >= 130) {
commonBuiltins.append(
"bvec2 lessThan(uvec2 x, uvec2 y);"
"bvec3 lessThan(uvec3 x, uvec3 y);"
"bvec4 lessThan(uvec4 x, uvec4 y);"
"bvec2 lessThanEqual(uvec2 x, uvec2 y);"
"bvec3 lessThanEqual(uvec3 x, uvec3 y);"
"bvec4 lessThanEqual(uvec4 x, uvec4 y);"
"bvec2 greaterThan(uvec2 x, uvec2 y);"
"bvec3 greaterThan(uvec3 x, uvec3 y);"
"bvec4 greaterThan(uvec4 x, uvec4 y);"
"bvec2 greaterThanEqual(uvec2 x, uvec2 y);"
"bvec3 greaterThanEqual(uvec3 x, uvec3 y);"
"bvec4 greaterThanEqual(uvec4 x, uvec4 y);"
"bvec2 equal(uvec2 x, uvec2 y);"
"bvec3 equal(uvec3 x, uvec3 y);"
"bvec4 equal(uvec4 x, uvec4 y);"
"bvec2 notEqual(uvec2 x, uvec2 y);"
"bvec3 notEqual(uvec3 x, uvec3 y);"
"bvec4 notEqual(uvec4 x, uvec4 y);"
"\n");
}
//
// Original-style texture functions existing in both stages.
// (Per-stage functions below.)

View file

@ -571,7 +571,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to)
{
if (profile == EEsProfile || version == 110)
return 0;
return false;
switch (to) {
case EbtDouble:
@ -596,6 +596,7 @@ bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to)
case EbtUint:
switch (from) {
case EbtInt:
return version >= 400;
case EbtUint:
return true;
default:
@ -1084,7 +1085,7 @@ bool TIntermBinary::promote()
case EOpLessThanEqual:
case EOpGreaterThanEqual:
// Relational comparisons need matching numeric types and will promote to scalar Boolean.
if (left->getBasicType() == EbtBool || left->getType().isMatrix())
if (left->getBasicType() == EbtBool || left->getType().isVector() || left->getType().isMatrix())
return false;
// Fall through
@ -1294,10 +1295,16 @@ bool TIntermBinary::promote()
case EOpSub:
case EOpDiv:
case EOpMod:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
case EOpModAssign:
case EOpAndAssign:
case EOpInclusiveOrAssign:
case EOpExclusiveOrAssign:
if ((left->isMatrix() && right->isVector()) ||
(left->isVector() && right->isMatrix()) ||
left->getBasicType() != right->getBasicType())

View file

@ -457,7 +457,7 @@ bool CompileDeferred(
bool versionNotFirst = userInput.scanVersion(version, profile);
bool versionNotFound = version == 0;
bool goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, version, profile);
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && versionNotFirst));
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
intermediate.setVersion(version);
intermediate.setProfile(profile);