From fddf3ce3a1f4306706f724a01d92013c9a838584 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 10 Jun 2013 21:56:23 +0000 Subject: [PATCH] Unify constant floats and constant doubles; they can all be constant doubles. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@21921 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- Test/testlist | 2 +- glslang/Include/ConstantUnion.h | 71 ++++++++++++----------------- glslang/MachineIndependent/Constant.cpp | 55 +++++++++++----------- glslang/MachineIndependent/Intermediate.cpp | 24 ++++------ glslang/MachineIndependent/glslang.l | 8 ++-- glslang/MachineIndependent/glslang.y | 7 ++- glslang/MachineIndependent/intermOut.cpp | 10 +--- glslang/MachineIndependent/parseConst.cpp | 2 +- 8 files changed, 73 insertions(+), 106 deletions(-) diff --git a/Test/testlist b/Test/testlist index db8abda..654f87f 100644 --- a/Test/testlist +++ b/Test/testlist @@ -1,4 +1,4 @@ -.rsample.frag +sample.frag sample.vert specExamples.frag specExamples.vert diff --git a/glslang/Include/ConstantUnion.h b/glslang/Include/ConstantUnion.h index 7fd7ca8..b565297 100644 --- a/glslang/Include/ConstantUnion.h +++ b/glslang/Include/ConstantUnion.h @@ -42,22 +42,34 @@ class constUnion { public: POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) - void setIConst(int i) {iConst = i; type = EbtInt; } - void setUConst(unsigned int u) {uConst = u; type = EbtUint; } - void setFConst(float f) {fConst = f; type = EbtFloat; } - void setDConst(double d) {dConst = d; type = EbtDouble; } - void setBConst(bool b) {bConst = b; type = EbtBool; } - - int getIConst() { return iConst; } - unsigned int getUConst() { return uConst; } - float getFConst() { return fConst; } - double getDConst() { return dConst; } - bool getBConst() { return bConst; } - int getIConst() const { return iConst; } + void setIConst(int i) + { + iConst = i; + type = EbtInt; + } + + void setUConst(unsigned int u) + { + uConst = u; + type = EbtUint; + } + + void setDConst(double d) + { + dConst = d; + type = EbtDouble; + } + + void setBConst(bool b) + { + bConst = b; + type = EbtBool; + } + + int getIConst() const { return iConst; } unsigned int getUConst() const { return uConst; } - float getFConst() const { return fConst; } - double getDConst() const { return dConst; } - bool getBConst() const { return bConst; } + double getDConst() const { return dConst; } + bool getBConst() const { return bConst; } bool operator==(const int i) const { @@ -75,14 +87,6 @@ public: return false; } - bool operator==(const float f) const - { - if (f == fConst) - return true; - - return false; - } - bool operator==(const double d) const { if (d == dConst) @@ -115,11 +119,6 @@ public: return true; break; - case EbtFloat: - if (constant.fConst == fConst) - return true; - - break; case EbtDouble: if (constant.dConst == dConst) return true; @@ -176,11 +175,6 @@ public: return true; return false; - case EbtFloat: - if (fConst > constant.fConst) - return true; - - return false; case EbtDouble: if (dConst > constant.dConst) return true; @@ -208,11 +202,6 @@ public: return true; return false; - case EbtFloat: - if (fConst < constant.fConst) - return true; - - return false; case EbtDouble: if (dConst < constant.dConst) return true; @@ -233,7 +222,6 @@ public: switch (type) { case EbtInt: returnValue.setIConst(iConst + constant.iConst); break; case EbtUint: returnValue.setUConst(uConst + constant.uConst); break; - case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break; case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break; default: assert(false && "Default missing"); } @@ -248,7 +236,6 @@ public: switch (type) { case EbtInt: returnValue.setIConst(iConst - constant.iConst); break; case EbtUint: returnValue.setUConst(uConst - constant.uConst); break; - case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break; case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break; default: assert(false && "Default missing"); } @@ -263,7 +250,6 @@ public: switch (type) { case EbtInt: returnValue.setIConst(iConst * constant.iConst); break; case EbtUint: returnValue.setUConst(uConst * constant.uConst); break; - case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break; case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break; default: assert(false && "Default missing"); } @@ -414,8 +400,7 @@ private: int iConst; // used for ivec, scalar ints unsigned int uConst; // used for uvec, scalar uints bool bConst; // used for bvec, scalar bools - float fConst; // used for vec, mat, scalar floats - double dConst; // used for dvec, dmat, scalar doubles + double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles } ; TBasicType type; diff --git a/glslang/MachineIndependent/Constant.cpp b/glslang/MachineIndependent/Constant.cpp index f973cc1..f635586 100644 --- a/glslang/MachineIndependent/Constant.cpp +++ b/glslang/MachineIndependent/Constant.cpp @@ -34,7 +34,7 @@ //POSSIBILITY OF SUCH DAMAGE. // -#include "float.h" +//??#include "float.h" #include "localintermediate.h" namespace { @@ -160,10 +160,10 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod newConstArray = new constUnion[getMatrixRows() * node->getMatrixCols()]; for (int row = 0; row < getMatrixRows(); row++) { for (int column = 0; column < node->getMatrixCols(); column++) { - float sum = 0.0f; + double sum = 0.0f; for (int i = 0; i < node->getMatrixRows(); i++) - sum += unionArray[i * getMatrixRows() + row].getFConst() * rightUnionArray[column * node->getMatrixRows() + i].getFConst(); - newConstArray[column * getMatrixRows() + row].setFConst(sum); + sum += unionArray[i * getMatrixRows() + row].getDConst() * rightUnionArray[column * node->getMatrixRows() + i].getDConst(); + newConstArray[column * getMatrixRows() + row].setDConst(sum); } } returnType = TType(getType().getBasicType(), EvqConst, 0, getMatrixRows(), node->getMatrixCols()); @@ -174,9 +174,9 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod switch (getType().getBasicType()) { case EbtFloat: if (rightUnionArray[i] == 0.0f) { - newConstArray[i].setFConst(FLT_MAX); + newConstArray[i].setDConst(FLT_MAX); // TODO: double support } else - newConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst()); + newConstArray[i].setDConst(unionArray[i].getDConst() / rightUnionArray[i].getDConst()); break; case EbtInt: @@ -202,11 +202,11 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod case EOpMatrixTimesVector: newConstArray = new constUnion[getMatrixRows()]; for (int i = 0; i < getMatrixRows(); i++) { - float sum = 0.0f; + double sum = 0.0f; for (int j = 0; j < node->getVectorSize(); j++) { - sum += unionArray[j*getMatrixRows() + i].getFConst() * rightUnionArray[j].getFConst(); + sum += unionArray[j*getMatrixRows() + i].getDConst() * rightUnionArray[j].getDConst(); } - newConstArray[i].setFConst(sum); + newConstArray[i].setDConst(sum); } returnType = TType(getBasicType(), EvqConst, getMatrixRows()); @@ -215,10 +215,10 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod case EOpVectorTimesMatrix: newConstArray = new constUnion[node->getMatrixCols()]; for (int i = 0; i < node->getMatrixCols(); i++) { - float sum = 0.0f; + double sum = 0.0f; for (int j = 0; j < getVectorSize(); j++) - sum += unionArray[j].getFConst() * rightUnionArray[i*node->getMatrixRows() + j].getFConst(); - newConstArray[i].setFConst(sum); + sum += unionArray[j].getDConst() * rightUnionArray[i*node->getMatrixRows() + j].getDConst(); + newConstArray[i].setDConst(sum); } returnType = TType(getBasicType(), EvqConst, node->getMatrixCols()); @@ -392,13 +392,13 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, { double sum = 0; for (int i = 0; i < objectSize; i++) - sum += double(unionArray[i].getFConst()) * unionArray[i].getFConst(); + sum += double(unionArray[i].getDConst()) * unionArray[i].getDConst(); double length = sqrt(sum); if (op == EOpLength) - newConstArray[0].setFConst(float(length)); + newConstArray[0].setDConst(length); else { for (int i = 0; i < objectSize; i++) - newConstArray[i].setFConst(float(unionArray[i].getFConst() / length)); + newConstArray[i].setDConst(unionArray[i].getDConst() / length); } break; } @@ -406,12 +406,11 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, break; } - // TODO: Functionality: constant folding: separate component-wise from non-component-wise for (int i = 0; i < objectSize; i++) { switch (op) { case EOpNegative: switch (getType().getBasicType()) { - case EbtFloat: newConstArray[i].setFConst(-unionArray[i].getFConst()); break; + case EbtFloat: newConstArray[i].setDConst(-unionArray[i].getDConst()); break; case EbtInt: newConstArray[i].setIConst(-unionArray[i].getIConst()); break; case EbtUint: newConstArray[i].setUConst(static_cast(-static_cast(unionArray[i].getUConst()))); break; default: @@ -432,28 +431,28 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, newConstArray[i] = ~unionArray[i]; break; case EOpRadians: - newConstArray[i].setFConst(static_cast(unionArray[i].getFConst() * pi / 180.0)); + newConstArray[i].setDConst(unionArray[i].getDConst() * pi / 180.0); break; case EOpDegrees: - newConstArray[i].setFConst(static_cast(unionArray[i].getFConst() * 180.0 / pi)); + newConstArray[i].setDConst(unionArray[i].getDConst() * 180.0 / pi); break; case EOpSin: - newConstArray[i].setFConst(sin(unionArray[i].getFConst())); + newConstArray[i].setDConst(sin(unionArray[i].getDConst())); break; case EOpCos: - newConstArray[i].setFConst(cos(unionArray[i].getFConst())); + newConstArray[i].setDConst(cos(unionArray[i].getDConst())); break; case EOpTan: - newConstArray[i].setFConst(tan(unionArray[i].getFConst())); + newConstArray[i].setDConst(tan(unionArray[i].getDConst())); break; case EOpAsin: - newConstArray[i].setFConst(asin(unionArray[i].getFConst())); + newConstArray[i].setDConst(asin(unionArray[i].getDConst())); break; case EOpAcos: - newConstArray[i].setFConst(acos(unionArray[i].getFConst())); + newConstArray[i].setDConst(acos(unionArray[i].getDConst())); break; case EOpAtan: - newConstArray[i].setFConst(atan(unionArray[i].getFConst())); + newConstArray[i].setDConst(atan(unionArray[i].getDConst())); break; case EOpLength: @@ -465,7 +464,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType, case EOpDPdy: case EOpFwidth: // The derivatives are all mandated to create a constant 0. - newConstArray[i].setFConst(0.0f); + newConstArray[i].setDConst(0.0); break; // TODO: Functionality: constant folding: the rest of the ops have to be fleshed out @@ -583,9 +582,9 @@ TIntermTyped* TIntermediate::fold(TIntermAggregate* aggrNode) case EOpMax: for (int i = 0; i < objectSize; i++) { if (aggrNode->getOp() == EOpMax) - newConstArray[i].setFConst(std::max(childConstUnions[0]->getFConst(), childConstUnions[1]->getFConst())); + newConstArray[i].setDConst(std::max(childConstUnions[0]->getDConst(), childConstUnions[1]->getDConst())); else - newConstArray[i].setFConst(std::min(childConstUnions[0]->getFConst(), childConstUnions[1]->getFConst())); + newConstArray[i].setDConst(std::min(childConstUnions[0]->getDConst(), childConstUnions[1]->getDConst())); } break; diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 6c8e484..771bb17 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -1343,19 +1343,19 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC case EbtFloat: switch (node->getType().getBasicType()) { case EbtInt: - leftUnionArray[i].setFConst(static_cast(rightUnionArray[i].getIConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getIConst())); break; case EbtUint: - leftUnionArray[i].setFConst(static_cast(rightUnionArray[i].getUConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getUConst())); break; case EbtBool: - leftUnionArray[i].setFConst(static_cast(rightUnionArray[i].getBConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getBConst())); break; case EbtFloat: leftUnionArray[i] = rightUnionArray[i]; break; case EbtDouble: - leftUnionArray[i].setFConst(static_cast(rightUnionArray[i].getBConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getBConst())); break; default: infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine()); @@ -1365,17 +1365,15 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC case EbtDouble: switch (node->getType().getBasicType()) { case EbtInt: - leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getIConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getIConst())); break; case EbtUint: - leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getUConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getUConst())); break; case EbtBool: - leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getBConst())); + leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getBConst())); break; case EbtFloat: - leftUnionArray[i].setDConst(static_cast(rightUnionArray[i].getFConst())); - break; case EbtDouble: leftUnionArray[i] = rightUnionArray[i]; break; @@ -1396,8 +1394,6 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC leftUnionArray[i].setIConst(static_cast(rightUnionArray[i].getBConst())); break; case EbtFloat: - leftUnionArray[i].setIConst(static_cast(rightUnionArray[i].getFConst())); - break; case EbtDouble: leftUnionArray[i].setIConst(static_cast(rightUnionArray[i].getDConst())); break; @@ -1418,8 +1414,6 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC leftUnionArray[i].setUConst(static_cast(rightUnionArray[i].getBConst())); break; case EbtFloat: - leftUnionArray[i].setUConst(static_cast(rightUnionArray[i].getFConst())); - break; case EbtDouble: leftUnionArray[i].setUConst(static_cast(rightUnionArray[i].getDConst())); break; @@ -1440,10 +1434,8 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC leftUnionArray[i] = rightUnionArray[i]; break; case EbtFloat: - leftUnionArray[i].setBConst(rightUnionArray[i].getFConst() != 0.0f); - break; case EbtDouble: - leftUnionArray[i].setBConst(rightUnionArray[i].getDConst() != 0.0f); + leftUnionArray[i].setBConst(rightUnionArray[i].getDConst() != 0.0); break; default: infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine()); diff --git a/glslang/MachineIndependent/glslang.l b/glslang/MachineIndependent/glslang.l index e572991..bfb33c0 100644 --- a/glslang/MachineIndependent/glslang.l +++ b/glslang/MachineIndependent/glslang.l @@ -544,10 +544,10 @@ int yy_input(char* buf, int max_size); 0{D}+{U} { pyylval->lex.line = yylineno; parseContext.error(yylineno, "Invalid Octal number.", yytext, "", ""); parseContext.recover(); return 0;} {D}+{U} { pyylval->lex.line = yylineno; pyylval->lex.u = strtoul(yytext, 0, 0); return UINTCONSTANT; } -{D}+{F} { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast(atof(yytext)); return FLOATCONSTANT; } -{D}+{E}{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast(atof(yytext)); return FLOATCONSTANT; } -{D}+"."{D}*({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast(atof(yytext)); return FLOATCONSTANT; } -"."{D}+({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.f = static_cast(atof(yytext)); return FLOATCONSTANT; } +{D}+{F} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; } +{D}+{E}{F}? { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; } +{D}+"."{D}*({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; } +"."{D}+({E})?{F}? { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return FLOATCONSTANT; } {D}+{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return DOUBLECONSTANT; } {D}+{E}{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return DOUBLECONSTANT; } diff --git a/glslang/MachineIndependent/glslang.y b/glslang/MachineIndependent/glslang.y index dcc08d7..a8c16ee 100644 --- a/glslang/MachineIndependent/glslang.y +++ b/glslang/MachineIndependent/glslang.y @@ -80,7 +80,6 @@ extern void yyerror(const char*); TSourceLoc line; union { TString *string; - float f; int i; unsigned int u; bool b; @@ -278,7 +277,7 @@ primary_expression } | FLOATCONSTANT { constUnion *unionArray = new constUnion[1]; - unionArray->setFConst($1.f); + unionArray->setDConst($1.d); $$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $1.line); } | DOUBLECONSTANT { @@ -360,7 +359,7 @@ postfix_expression if ($$ == 0) { constUnion *unionArray = new constUnion[1]; - unionArray->setFConst(0.0f); + unionArray->setDConst(0.0); $$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $2.line); } else { TType newType($1->getType()); @@ -594,7 +593,7 @@ function_call // error message was put out by PaFindFunction() // Put on a dummy node for error recovery constUnion *unionArray = new constUnion[1]; - unionArray->setFConst(0.0f); + unionArray->setDConst(0.0); $$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $1.line); parseContext.recover(); } diff --git a/glslang/MachineIndependent/intermOut.cpp b/glslang/MachineIndependent/intermOut.cpp index f442a60..944dedd 100644 --- a/glslang/MachineIndependent/intermOut.cpp +++ b/glslang/MachineIndependent/intermOut.cpp @@ -410,19 +410,11 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) out.debug << "\n"; break; case EbtFloat: - { - const int maxSize = 300; - char buf[maxSize]; - snprintf(buf, maxSize, "%f (%s)", node->getUnionArrayPointer()[i].getFConst(), "const float"); - - out.debug << buf << "\n"; - } - break; case EbtDouble: { const int maxSize = 300; char buf[maxSize]; - snprintf(buf, maxSize, "%f (%s)", node->getUnionArrayPointer()[i].getDConst(), "const double"); + snprintf(buf, maxSize, "%f", node->getUnionArrayPointer()[i].getDConst()); out.debug << buf << "\n"; } diff --git a/glslang/MachineIndependent/parseConst.cpp b/glslang/MachineIndependent/parseConst.cpp index a5b0bdf..5ddb177 100644 --- a/glslang/MachineIndependent/parseConst.cpp +++ b/glslang/MachineIndependent/parseConst.cpp @@ -221,7 +221,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) if (index - i == 0 || (i - index) % (matrixRows + 1) == 0 ) leftUnionArray[i] = rightUnionArray[count]; else - leftUnionArray[i].setFConst(0.0f); + leftUnionArray[i].setDConst(0.0); (oit->index)++; -- 2.7.4