Implement non-square matrices, and make a few type improvements. Cleaned up a few old issues. Added two tests.

Details
 - added all the new non-square types
 - separated concepts of matrix size and vector size
 - removed VS 6.0 comments/workarounds
 - removed obsolete concept of matrix fields



git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20436 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-02-04 23:54:58 +00:00
parent 1c809955ba
commit f0fdc53e2a
17 changed files with 532 additions and 492 deletions

22
Test/matrixError.vert Normal file
View File

@ -0,0 +1,22 @@
#version 120
attribute vec3 v3;
uniform mat3x2 m32;
const mat2x4 m24 = mat2x4(1.0, 2.0,
3.0, 4.0,
3.0, 4.0,
3.0, 4.0, 5.0);
void main()
{
mat2x3 m23;
vec3 a, b;
a = v3 * m23;
b = m32 * v3;
m23.xy;
gl_Position = vec4(m23 * m32 * v3, m24[2][4]);
}

25
Test/nonSquare.vert Normal file
View File

@ -0,0 +1,25 @@
#version 120
attribute vec3 v3;
attribute vec4 v4;
uniform mat3x2 m32;
const vec2 cv2 = vec2(10.0, 20.0);
const mat2x4 m24 = mat2x4(3.0);
const mat4x2 m42 = mat4x2(1.0, 2.0,
3.0, 4.0,
5.0, 6.0,
7.0, 8.0);
void main()
{
mat2x3 m23;
vec2 a, b;
a = v3 * m23;
b = m32 * v3;
gl_Position = vec4(m23 * m32 * v3, m24[1][3]) +
(m24 * m42) * v4 + cv2 * m42 + m24 * cv2 + vec4(cv2[1], cv2.x, m42[2][1], m42[2][0]);
}

View File

@ -10,3 +10,6 @@ versionsErrors.vert
130.frag 130.frag
140.frag 140.frag
precision.frag precision.frag
nonSquare.vert
matrixError.vert

View File

@ -54,22 +54,12 @@
#pragma warning(disable : 4201) // nameless union #pragma warning(disable : 4201) // nameless union
#endif #endif
// #include <set>
// Doing the push and pop below for warnings does not leave the warning state #include <vector>
// the way it was. This seems like a defect in the compiler. We would like #include <map>
// to do this, but since it does not work correctly right now, it is turned #include <list>
// off. #include <string>
// #include <stdio.h>
//??#pragma warning(push, 3)
#include <set>
#include <vector>
#include <map>
#include <list>
#include <string>
#include <stdio.h>
//??#pragma warning(pop)
typedef int TSourceLoc; typedef int TSourceLoc;

View File

@ -113,7 +113,6 @@ private:
unsigned char* mem; // beginning of our allocation (pts to header) unsigned char* mem; // beginning of our allocation (pts to header)
TAllocation* prevAlloc; // prior allocation in the chain TAllocation* prevAlloc; // prior allocation in the chain
// Support MSVC++ 6.0
const static unsigned char guardBlockBeginVal; const static unsigned char guardBlockBeginVal;
const static unsigned char guardBlockEndVal; const static unsigned char guardBlockEndVal;
const static unsigned char userDataFill; const static unsigned char userDataFill;

View File

@ -74,8 +74,9 @@ class TPublicType {
public: public:
TBasicType type; TBasicType type;
TQualifier qualifier; TQualifier qualifier;
int size; // size of vector or matrix, not size of array int vectorSize : 4;
bool matrix; int matrixCols : 4;
int matrixRows : 4;
bool array; bool array;
int arraySize; int arraySize;
TType* userDef; TType* userDef;
@ -84,8 +85,9 @@ public:
void initType(int ln = 0) void initType(int ln = 0)
{ {
type = EbtVoid; type = EbtVoid;
size = 1; vectorSize = 1;
matrix = false; matrixRows = 0;
matrixCols = 0;
array = false; array = false;
arraySize = 0; arraySize = 0;
userDef = 0; userDef = 0;
@ -104,10 +106,16 @@ public:
initQualifiers(global); initQualifiers(global);
} }
void setAggregate(int s, bool m = false) void setVector(int s)
{ {
size = s; vectorSize = s;
matrix = m; }
void setMatrix(int c, int r)
{
matrixRows = r;
matrixCols = c;
vectorSize = 0;
} }
void setArray(bool a, int s = 0) void setArray(bool a, int s = 0)
@ -125,15 +133,16 @@ typedef std::map<TTypeList*, TTypeList*>::iterator TStructureMapIterator;
class TType { class TType {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator) POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
explicit TType(TBasicType t, TStorageQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) : explicit TType(TBasicType t, TStorageQualifier q = EvqTemporary, int vs = 1, int mc = 0, int mr = 0) :
type(t), size(s), matrix(m), array(a), arraySize(0), type(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), array(false), arraySize(0),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0),
fieldName(0), mangled(0), typeName(0) { fieldName(0), mangled(0), typeName(0)
{
qualifier.storage = q; qualifier.storage = q;
qualifier.precision = EpqNone; qualifier.precision = EpqNone;
} }
explicit TType(const TPublicType &p) : explicit TType(const TPublicType &p) :
type(p.type), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize), type(p.type), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), array(p.array), arraySize(p.arraySize),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0) structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
{ {
qualifier = p.qualifier; qualifier = p.qualifier;
@ -143,8 +152,9 @@ public:
} }
} }
explicit TType(TTypeList* userDef, const TString& n) : explicit TType(TTypeList* userDef, const TString& n) :
type(EbtStruct), size(1), matrix(false), array(false), arraySize(0), type(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0), array(false), arraySize(0),
structure(userDef), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0) { structure(userDef), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0)
{
qualifier.storage = EvqTemporary; qualifier.storage = EvqTemporary;
qualifier.precision = EpqNone; qualifier.precision = EpqNone;
typeName = NewPoolTString(n.c_str()); typeName = NewPoolTString(n.c_str());
@ -158,8 +168,9 @@ public:
{ {
type = copyOf.type; type = copyOf.type;
qualifier = copyOf.qualifier; qualifier = copyOf.qualifier;
size = copyOf.size; vectorSize = copyOf.vectorSize;
matrix = copyOf.matrix; matrixCols = copyOf.matrixCols;
matrixRows = copyOf.matrixRows;
array = copyOf.array; array = copyOf.array;
arraySize = copyOf.arraySize; arraySize = copyOf.arraySize;
@ -205,16 +216,30 @@ public:
return newType; return newType;
} }
virtual void setType(TBasicType t, int s, bool m, bool a, int aS = 0) virtual void dereference()
{ type = t; size = s; matrix = m; array = a; arraySize = aS; } {
virtual void setType(TBasicType t, int s, bool m, TType* userDef = 0) if (array) {
{ type = t; array = false;
size = s; arraySize = 0;
matrix = m; maxArraySize = 0;
if (userDef) } else if (matrixCols > 0) {
structure = userDef->getStruct(); vectorSize = matrixRows;
// leave array information intact. matrixCols = 0;
} matrixRows = 0;
} else if (vectorSize > 1)
vectorSize = 1;
}
virtual void setElementType(TBasicType t, int s, int mc, int mr, TType* userDef)
{
type = t;
vectorSize = s;
matrixCols = mc;
matrixRows = mr;
if (userDef)
structure = userDef->getStruct();
// leave array information intact.
}
virtual void setTypeName(const TString& n) { typeName = NewPoolTString(n.c_str()); } virtual void setTypeName(const TString& n) { typeName = NewPoolTString(n.c_str()); }
virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); } virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); }
virtual const TString& getTypeName() const virtual const TString& getTypeName() const
@ -232,29 +257,20 @@ public:
virtual TBasicType getBasicType() const { return type; } virtual TBasicType getBasicType() const { return type; }
virtual TQualifier& getQualifier() { return qualifier; } virtual TQualifier& getQualifier() { return qualifier; }
virtual const TQualifier& getQualifier() const { return qualifier; } virtual const TQualifier& getQualifier() const { return qualifier; }
virtual int getVectorSize() const { return vectorSize; }
virtual int getMatrixCols() const { return matrixCols; }
virtual int getMatrixRows() const { return matrixRows; }
// One-dimensional size of single instance type virtual bool isMatrix() const { return matrixCols ? true : false; }
virtual int getNominalSize() const { return size; }
// Full-dimensional size of single instance of type
virtual int getInstanceSize() const
{
if (matrix)
return size * size;
else
return size;
}
virtual bool isMatrix() const { return matrix ? true : false; }
virtual bool isArray() const { return array ? true : false; } virtual bool isArray() const { return array ? true : false; }
int getArraySize() const { return arraySize; } int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; } void setArraySize(int s) { array = true; arraySize = s; }
void setMaxArraySize (int s) { maxArraySize = s; } void setMaxArraySize (int s) { maxArraySize = s; }
int getMaxArraySize () const { return maxArraySize; } int getMaxArraySize () const { return maxArraySize; }
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
void setArrayInformationType(TType* t) { arrayInformationType = t; } void setArrayInformationType(TType* t) { arrayInformationType = t; }
TType* getArrayInformationType() { return arrayInformationType; } TType* getArrayInformationType() { return arrayInformationType; }
virtual bool isVector() const { return size > 1 && !matrix; } virtual bool isVector() const { return vectorSize > 1; }
static char* getBasicString(TBasicType t) { static char* getBasicString(TBasicType t) {
switch (t) { switch (t) {
case EbtVoid: return "void"; break; case EbtVoid: return "void"; break;
@ -285,10 +301,10 @@ public:
if (getBasicType() == EbtStruct) if (getBasicType() == EbtStruct)
totalSize = getStructSize(); totalSize = getStructSize();
else if (matrix) else if (matrixCols)
totalSize = size * size; totalSize = matrixCols * matrixRows;
else else
totalSize = size; totalSize = vectorSize;
if (isArray()) if (isArray())
totalSize *= Max(getArraySize(), getMaxArraySize()); totalSize *= Max(getArraySize(), getMaxArraySize());
@ -307,17 +323,19 @@ public:
return *mangled; return *mangled;
} }
bool sameElementType(const TType& right) const { bool sameElementType(const TType& right) const {
return type == right.type && return type == right.type &&
size == right.size && vectorSize == right.vectorSize &&
matrix == right.matrix && matrixCols == right.matrixCols &&
structure == right.structure; matrixRows == right.matrixRows &&
structure == right.structure;
} }
bool operator==(const TType& right) const { bool operator==(const TType& right) const {
return type == right.type && return type == right.type &&
size == right.size && vectorSize == right.vectorSize &&
matrix == right.matrix && matrixCols == right.matrixCols &&
array == right.array && (!array || arraySize == right.arraySize) && matrixRows == right.matrixRows &&
structure == right.structure; array == right.array && (!array || arraySize == right.arraySize) &&
structure == right.structure;
// don't check the qualifier, it's not ever what's being sought after // don't check the qualifier, it's not ever what's being sought after
} }
bool operator!=(const TType& right) const { bool operator!=(const TType& right) const {
@ -330,8 +348,9 @@ protected:
int getStructSize() const; int getStructSize() const;
TBasicType type : 8; TBasicType type : 8;
int size : 8; // size of vector or matrix, not size of array int vectorSize : 4;
unsigned int matrix : 1; int matrixCols : 4;
int matrixRows : 4;
unsigned int array : 1; unsigned int array : 1;
TQualifier qualifier; TQualifier qualifier;

View File

@ -184,6 +184,7 @@ enum TOperator {
// Constructors // Constructors
// //
EOpConstructGuardStart,
EOpConstructInt, EOpConstructInt,
EOpConstructBool, EOpConstructBool,
EOpConstructFloat, EOpConstructFloat,
@ -191,16 +192,35 @@ enum TOperator {
EOpConstructVec2, EOpConstructVec2,
EOpConstructVec3, EOpConstructVec3,
EOpConstructVec4, EOpConstructVec4,
EOpConstructDVec2,
EOpConstructDVec3,
EOpConstructDVec4,
EOpConstructBVec2, EOpConstructBVec2,
EOpConstructBVec3, EOpConstructBVec3,
EOpConstructBVec4, EOpConstructBVec4,
EOpConstructIVec2, EOpConstructIVec2,
EOpConstructIVec3, EOpConstructIVec3,
EOpConstructIVec4, EOpConstructIVec4,
EOpConstructMat2, EOpConstructMat2x2,
EOpConstructMat3, EOpConstructMat2x3,
EOpConstructMat4, EOpConstructMat2x4,
EOpConstructMat3x2,
EOpConstructMat3x3,
EOpConstructMat3x4,
EOpConstructMat4x2,
EOpConstructMat4x3,
EOpConstructMat4x4,
EOpConstructDMat2x2,
EOpConstructDMat2x3,
EOpConstructDMat2x4,
EOpConstructDMat3x2,
EOpConstructDMat3x3,
EOpConstructDMat3x4,
EOpConstructDMat4x2,
EOpConstructDMat4x3,
EOpConstructDMat4x4,
EOpConstructStruct, EOpConstructStruct,
EOpConstructGuardEnd,
// //
// moves // moves
@ -286,8 +306,10 @@ public:
virtual TBasicType getBasicType() const { return type.getBasicType(); } virtual TBasicType getBasicType() const { return type.getBasicType(); }
virtual TQualifier& getQualifier() { return type.getQualifier(); } virtual TQualifier& getQualifier() { return type.getQualifier(); }
virtual void propagatePrecision(TPrecisionQualifier); virtual void propagatePrecision(TPrecisionQualifier);
virtual int getNominalSize() const { return type.getNominalSize(); } virtual int getVectorSize() const { return type.getVectorSize(); }
virtual int getSize() const { return type.getInstanceSize(); } virtual int getMatrixCols() const { return type.getMatrixCols(); }
virtual int getMatrixRows() const { return type.getMatrixRows(); }
//virtual int getSize() const { return type.getInstanceSize(); }
virtual bool isMatrix() const { return type.isMatrix(); } virtual bool isMatrix() const { return type.isMatrix(); }
virtual bool isArray() const { return type.isArray(); } virtual bool isArray() const { return type.isArray(); }
virtual bool isVector() const { return type.isVector(); } virtual bool isVector() const { return type.isVector(); }

View File

@ -934,7 +934,7 @@ void IdentifyBuiltIns(EShLanguage language, TSymbolTable& symbolTable, const TBu
case EShLangFragment: { case EShLangFragment: {
// Set up gl_FragData. The array size. // Set up gl_FragData. The array size.
TType fragData(EbtFloat, EvqFragColor, 4, false, true); TType fragData(EbtFloat, EvqFragColor, 4);
fragData.setArraySize(resources.maxDrawBuffers); fragData.setArraySize(resources.maxDrawBuffers);
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
} }

View File

@ -132,26 +132,19 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn
node->setRight(right); node->setRight(right);
if (! node->promote(infoSink)) if (! node->promote(infoSink))
return 0; return 0;
//
// If they are both constants, they must be folded.
//
TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion(); TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion();
TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion(); TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();
if (leftTempConstant && rightTempConstant) {
if (leftTempConstant) TIntermTyped* folded = leftTempConstant->fold(node->getOp(), rightTempConstant, infoSink);
leftTempConstant = left->getAsConstantUnion(); if (folded)
return folded;
if (rightTempConstant) else
rightTempConstant = right->getAsConstantUnion(); infoSink.info.message(EPrefixInternalError, "Constant folding failed", line);
//
// See if we can fold constants.
//
TIntermTyped* typedReturnNode = 0;
if ( leftTempConstant && rightTempConstant) {
typedReturnNode = leftTempConstant->fold(node->getOp(), rightTempConstant, infoSink);
if (typedReturnNode)
return typedReturnNode;
} }
return node; return node;
@ -253,9 +246,9 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
} }
if (newType != EbtVoid) { if (newType != EbtVoid) {
child = addConversion(op, TType(newType, EvqTemporary, child->getNominalSize(), child = addConversion(op, TType(newType, EvqTemporary, child->getVectorSize(),
child->isMatrix(), child->getMatrixCols(),
child->isArray()), child->getMatrixRows()),
child); child);
if (child == 0) if (child == 0)
return 0; return 0;
@ -456,7 +449,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
return 0; return 0;
} }
TType type(promoteTo, EvqTemporary, node->getNominalSize(), node->isMatrix(), node->isArray()); TType type(promoteTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows());
newNode = new TIntermUnary(newOp, type); newNode = new TIntermUnary(newOp, type);
newNode->setLine(node->getLine()); newNode->setLine(node->getLine());
newNode->setOperand(node); newNode->setOperand(node);
@ -742,27 +735,7 @@ bool TIntermOperator::modifiesState() const
// //
bool TIntermOperator::isConstructor() const bool TIntermOperator::isConstructor() const
{ {
switch (op) { return op > EOpConstructGuardStart && op < EOpConstructGuardEnd;
case EOpConstructVec2:
case EOpConstructVec3:
case EOpConstructVec4:
case EOpConstructMat2:
case EOpConstructMat3:
case EOpConstructMat4:
case EOpConstructFloat:
case EOpConstructIVec2:
case EOpConstructIVec3:
case EOpConstructIVec4:
case EOpConstructInt:
case EOpConstructBVec2:
case EOpConstructBVec3:
case EOpConstructBVec4:
case EOpConstructBool:
case EOpConstructStruct:
return true;
default:
return false;
}
} }
// //
// Make sure the type of a unary operator is appropriate for its // Make sure the type of a unary operator is appropriate for its
@ -814,12 +787,6 @@ bool TIntermUnary::promote(TInfoSink&)
// //
bool TIntermBinary::promote(TInfoSink& infoSink) bool TIntermBinary::promote(TInfoSink& infoSink)
{ {
int size = left->getNominalSize();
if (right->getNominalSize() > size)
size = right->getNominalSize();
TBasicType basicType = left->getBasicType();
// //
// Arrays have to be exact matches. // Arrays have to be exact matches.
// //
@ -870,7 +837,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// //
// All scalars. Code after this test assumes this case is removed! // All scalars. Code after this test assumes this case is removed!
// //
if (size == 1) { if (left->getVectorSize() == 1 && right->getVectorSize() == 1) {
switch (op) { switch (op) {
@ -930,40 +897,45 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
return true; return true;
} }
//
// Are the sizes compatible?
//
if ( left->getNominalSize() != size && left->getNominalSize() != 1 ||
right->getNominalSize() != size && right->getNominalSize() != 1)
return false;
// //
// Can these two operands be combined? // Can these two operands be combined?
// //
TBasicType basicType = left->getBasicType();
switch (op) { switch (op) {
case EOpMul: case EOpMul:
if (!left->isMatrix() && right->isMatrix()) { if (!left->isMatrix() && right->isMatrix()) {
if (left->isVector()) if (left->isVector()) {
if (left->getVectorSize() != right->getMatrixRows())
return false;
op = EOpVectorTimesMatrix; op = EOpVectorTimesMatrix;
else { setType(TType(basicType, EvqTemporary, right->getMatrixCols()));
} else {
op = EOpMatrixTimesScalar; op = EOpMatrixTimesScalar;
setType(TType(basicType, EvqTemporary, size, true)); setType(TType(basicType, EvqTemporary, 0, right->getMatrixCols(), right->getMatrixRows()));
} }
} else if (left->isMatrix() && !right->isMatrix()) { } else if (left->isMatrix() && !right->isMatrix()) {
if (right->isVector()) { if (right->isVector()) {
if (left->getMatrixCols() != right->getVectorSize())
return false;
op = EOpMatrixTimesVector; op = EOpMatrixTimesVector;
setType(TType(basicType, EvqTemporary, size, false)); setType(TType(basicType, EvqTemporary, left->getMatrixRows()));
} else { } else {
op = EOpMatrixTimesScalar; op = EOpMatrixTimesScalar;
} }
} else if (left->isMatrix() && right->isMatrix()) { } else if (left->isMatrix() && right->isMatrix()) {
if (left->getMatrixCols() != right->getMatrixRows())
return false;
op = EOpMatrixTimesMatrix; op = EOpMatrixTimesMatrix;
setType(TType(basicType, EvqTemporary, 0, right->getMatrixCols(), left->getMatrixRows()));
} else if (!left->isMatrix() && !right->isMatrix()) { } else if (!left->isMatrix() && !right->isMatrix()) {
if (left->isVector() && right->isVector()) { if (left->isVector() && right->isVector()) {
if (left->getVectorSize() != right->getVectorSize())
return false;
// leave as component product // leave as component product
} else if (left->isVector() || right->isVector()) { } else if (left->isVector() || right->isVector()) {
op = EOpVectorTimesScalar; op = EOpVectorTimesScalar;
setType(TType(basicType, EvqTemporary, size, false)); if (right->getVectorSize() > 1)
setType(TType(basicType, EvqTemporary, right->getVectorSize()));
} }
} else { } else {
infoSink.info.message(EPrefixInternalError, "Missing elses", getLine()); infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
@ -972,9 +944,11 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
break; break;
case EOpMulAssign: case EOpMulAssign:
if (!left->isMatrix() && right->isMatrix()) { if (!left->isMatrix() && right->isMatrix()) {
if (left->isVector()) if (left->isVector()) {
if (left->getVectorSize() != right->getMatrixRows() || left->getVectorSize() != right->getMatrixCols())
return false;
op = EOpVectorTimesMatrixAssign; op = EOpVectorTimesMatrixAssign;
else { } else {
return false; return false;
} }
} else if (left->isMatrix() && !right->isMatrix()) { } else if (left->isMatrix() && !right->isMatrix()) {
@ -984,6 +958,8 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
op = EOpMatrixTimesScalarAssign; op = EOpMatrixTimesScalarAssign;
} }
} else if (left->isMatrix() && right->isMatrix()) { } else if (left->isMatrix() && right->isMatrix()) {
if (left->getMatrixCols() != left->getMatrixRows() || left->getMatrixCols() != right->getMatrixCols() || left->getMatrixCols() != right->getMatrixRows())
return false;
op = EOpMatrixTimesMatrixAssign; op = EOpMatrixTimesMatrixAssign;
} else if (!left->isMatrix() && !right->isMatrix()) { } else if (!left->isMatrix() && !right->isMatrix()) {
if (left->isVector() && right->isVector()) { if (left->isVector() && right->isVector()) {
@ -992,7 +968,6 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
if (! left->isVector()) if (! left->isVector())
return false; return false;
op = EOpVectorTimesScalarAssign; op = EOpVectorTimesScalarAssign;
setType(TType(basicType, EvqTemporary, size, false));
} }
} else { } else {
infoSink.info.message(EPrefixInternalError, "Missing elses", getLine()); infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
@ -1000,7 +975,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
} }
break; break;
case EOpAssign: case EOpAssign:
if (left->getNominalSize() != right->getNominalSize()) if (left->getVectorSize() != right->getVectorSize() || left->getMatrixCols() != right->getMatrixCols() || left->getMatrixRows() != right->getMatrixRows())
return false; return false;
// fall through // fall through
case EOpAdd: case EOpAdd:
@ -1015,7 +990,12 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
left->isVector() && right->isMatrix() || left->isVector() && right->isMatrix() ||
left->getBasicType() != right->getBasicType()) left->getBasicType() != right->getBasicType())
return false; return false;
setType(TType(basicType, EvqTemporary, size, left->isMatrix() || right->isMatrix())); if (left->isMatrix() && right->isMatrix() && (left->getMatrixCols() != right->getMatrixCols() || left->getMatrixRows() != right->getMatrixRows()))
return false;
if (left->isVector() && right->isVector() && left->getVectorSize() != right->getVectorSize())
return false;
if (right->isVector() || right->isMatrix())
setType(TType(basicType, EvqTemporary, right->getVectorSize(), right->getMatrixCols(), right->getMatrixRows()));
break; break;
case EOpEqual: case EOpEqual:
@ -1031,7 +1011,7 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
setType(TType(EbtBool)); setType(TType(EbtBool));
break; break;
default: default:
return false; return false;
} }
@ -1135,7 +1115,7 @@ bool CompareStructure(const TType& leftNodeType, constUnion* rightUnionArray, co
{ {
if (leftNodeType.isArray()) { if (leftNodeType.isArray()) {
TType typeWithoutArrayness = leftNodeType; TType typeWithoutArrayness = leftNodeType;
typeWithoutArrayness.clearArrayness(); typeWithoutArrayness.dereference();
int arraySize = leftNodeType.getArraySize(); int arraySize = leftNodeType.getArraySize();
@ -1159,7 +1139,7 @@ bool CompareStructure(const TType& leftNodeType, constUnion* rightUnionArray, co
TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink) TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode, TInfoSink& infoSink)
{ {
constUnion *unionArray = getUnionArrayPointer(); constUnion *unionArray = getUnionArrayPointer();
int objectSize = getType().getObjectSize(); int objectSize = getType().getObjectSize();
if (constantNode) { // binary operations if (constantNode) { // binary operations
@ -1167,17 +1147,22 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
constUnion *rightUnionArray = node->getUnionArrayPointer(); constUnion *rightUnionArray = node->getUnionArrayPointer();
TType returnType = getType(); TType returnType = getType();
// for a case like float f = 1.2 + vec4(2,3,4,5); if (getType().getBasicType() != node->getBasicType()) {
infoSink.info.message(EPrefixInternalError, "Constant folding basic types don't match", getLine());
return 0;
}
if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) { if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) {
// for a case like float f = vec4(2,3,4,5) + 1.2;
rightUnionArray = new constUnion[objectSize]; rightUnionArray = new constUnion[objectSize];
for (int i = 0; i < objectSize; ++i) for (int i = 0; i < objectSize; ++i)
rightUnionArray[i] = *node->getUnionArrayPointer(); rightUnionArray[i] = *node->getUnionArrayPointer();
returnType = getType();
} else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) { } else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) {
// for a case like float f = vec4(2,3,4,5) + 1.2; // for a case like float f = 1.2 + vec4(2,3,4,5);
rightUnionArray = node->getUnionArrayPointer();
unionArray = new constUnion[constantNode->getType().getObjectSize()]; unionArray = new constUnion[constantNode->getType().getObjectSize()];
for (int i = 0; i < constantNode->getType().getObjectSize(); ++i) for (int i = 0; i < constantNode->getType().getObjectSize(); ++i)
unionArray[i] = *getUnionArrayPointer(); unionArray[i] = *getUnionArrayPointer();
returnType = node->getType(); returnType = node->getType();
objectSize = constantNode->getType().getObjectSize(); objectSize = constantNode->getType().getObjectSize();
} }
@ -1189,182 +1174,142 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
switch(op) { switch(op) {
case EOpAdd: case EOpAdd:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] + rightUnionArray[i];
tempConstArray[i] = unionArray[i] + rightUnionArray[i];
}
break; break;
case EOpSub: case EOpSub:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] - rightUnionArray[i];
tempConstArray[i] = unionArray[i] - rightUnionArray[i];
}
break; break;
case EOpMul: case EOpMul:
case EOpVectorTimesScalar: case EOpVectorTimesScalar:
case EOpMatrixTimesScalar: case EOpMatrixTimesScalar:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] * rightUnionArray[i];
tempConstArray[i] = unionArray[i] * rightUnionArray[i];
}
break; break;
case EOpMatrixTimesMatrix: case EOpMatrixTimesMatrix:
if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat) { tempConstArray = new constUnion[getMatrixRows() * node->getMatrixCols()];
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", getLine()); for (int row = 0; row < getMatrixRows(); row++) {
return 0; for (int column = 0; column < node->getMatrixCols(); column++) {
} float sum = 0.0f;
{// support MSVC++6.0 for (int i = 0; i < node->getMatrixRows(); i++)
int size = getNominalSize(); sum += unionArray[i * getMatrixRows() + row].getFConst() * rightUnionArray[column * node->getMatrixRows() + i].getFConst();
tempConstArray = new constUnion[size*size]; tempConstArray[column * getMatrixRows() + row].setFConst(sum);
for (int row = 0; row < size; row++) {
for (int column = 0; column < size; column++) {
tempConstArray[size * column + row].setFConst(0.0f);
for (int i = 0; i < size; i++) {
tempConstArray[size * column + row].setFConst(tempConstArray[size * column + row].getFConst() + unionArray[i * size + row].getFConst() * (rightUnionArray[column * size + i].getFConst()));
}
}
} }
} }
returnType = TType(getType().getBasicType(), EvqConst, 0, getMatrixRows(), node->getMatrixCols());
break; break;
case EOpDiv: case EOpDiv:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++) {
for (int i = 0; i < objectSize; i++) { switch (getType().getBasicType()) {
switch (getType().getBasicType()) { case EbtFloat:
case EbtFloat: if (rightUnionArray[i] == 0.0f) {
if (rightUnionArray[i] == 0.0f) { infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); tempConstArray[i].setFConst(FLT_MAX);
tempConstArray[i].setFConst(FLT_MAX); } else
} else tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst()); break;
break;
case EbtInt: case EbtInt:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == 0) {
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
tempConstArray[i].setIConst(INT_MAX); tempConstArray[i].setIConst(INT_MAX);
} else } else
tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst()); tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine()); infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine());
return 0; return 0;
}
} }
} }
break; break;
case EOpMatrixTimesVector: case EOpMatrixTimesVector:
if (node->getBasicType() != EbtFloat) { tempConstArray = new constUnion[getMatrixRows()];
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", getLine()); for (int i = 0; i < getMatrixRows(); i++) {
return 0; float sum = 0.0f;
} for (int j = 0; j < node->getVectorSize(); j++) {
tempConstArray = new constUnion[getNominalSize()]; sum += unionArray[j*getMatrixRows() + i].getFConst() * rightUnionArray[j].getFConst();
{// support MSVC++6.0
for (int size = getNominalSize(), i = 0; i < size; i++) {
tempConstArray[i].setFConst(0.0f);
for (int j = 0; j < size; j++) {
tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j*size + i].getFConst()) * rightUnionArray[j].getFConst()));
}
} }
tempConstArray[i].setFConst(sum);
} }
tempNode = new TIntermConstantUnion(tempConstArray, node->getType()); tempNode = new TIntermConstantUnion(tempConstArray, TType(getBasicType(), EvqConst, getMatrixRows()));
tempNode->setLine(getLine()); tempNode->setLine(getLine());
return tempNode; return tempNode;
case EOpVectorTimesMatrix: case EOpVectorTimesMatrix:
if (getType().getBasicType() != EbtFloat) { tempConstArray = new constUnion[node->getMatrixCols()];
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", getLine()); for (int i = 0; i < node->getMatrixCols(); i++) {
return 0; float sum = 0.0f;
} for (int j = 0; j < getVectorSize(); j++)
sum += unionArray[j].getFConst() * rightUnionArray[i*node->getMatrixRows() + j].getFConst();
tempConstArray = new constUnion[getNominalSize()]; tempConstArray[i].setFConst(sum);
{// support MSVC++6.0
for (int size = getNominalSize(), i = 0; i < size; i++) {
tempConstArray[i].setFConst(0.0f);
for (int j = 0; j < size; j++) {
tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j].getFConst()) * rightUnionArray[i*size + j].getFConst()));
}
}
} }
break;
tempNode = new TIntermConstantUnion(tempConstArray, TType(getBasicType(), EvqConst, node->getMatrixCols()));
tempNode->setLine(getLine());
return tempNode;
case EOpMod: case EOpMod:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] % rightUnionArray[i];
tempConstArray[i] = unionArray[i] % rightUnionArray[i];
}
break; break;
case EOpRightShift: case EOpRightShift:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] >> rightUnionArray[i];
tempConstArray[i] = unionArray[i] >> rightUnionArray[i];
}
break; break;
case EOpLeftShift: case EOpLeftShift:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] << rightUnionArray[i];
tempConstArray[i] = unionArray[i] << rightUnionArray[i];
}
break; break;
case EOpAnd: case EOpAnd:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] & rightUnionArray[i];
tempConstArray[i] = unionArray[i] & rightUnionArray[i];
}
break; break;
case EOpInclusiveOr: case EOpInclusiveOr:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] | rightUnionArray[i];
tempConstArray[i] = unionArray[i] | rightUnionArray[i];
}
break; break;
case EOpExclusiveOr: case EOpExclusiveOr:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] ^ rightUnionArray[i];
tempConstArray[i] = unionArray[i] ^ rightUnionArray[i];
}
break; break;
case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] && rightUnionArray[i];
tempConstArray[i] = unionArray[i] && rightUnionArray[i];
}
break; break;
case EOpLogicalOr: // this code is written for possible future use, will not get executed currently case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) tempConstArray[i] = unionArray[i] || rightUnionArray[i];
tempConstArray[i] = unionArray[i] || rightUnionArray[i];
}
break; break;
case EOpLogicalXor: case EOpLogicalXor:
tempConstArray = new constUnion[objectSize]; tempConstArray = new constUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++) {
for (int i = 0; i < objectSize; i++) switch (getType().getBasicType()) {
switch (getType().getBasicType()) { case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break;
case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break; default: assert(false && "Default missing");
default: assert(false && "Default missing"); }
}
} }
break; break;
@ -1500,13 +1445,15 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node) TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node)
{ {
if (node->getType().isArray())
infoSink.info.message(EPrefixInternalError, "Cannot promote array", node->getLine());
constUnion *rightUnionArray = node->getUnionArrayPointer(); constUnion *rightUnionArray = node->getUnionArrayPointer();
int size = node->getType().getObjectSize(); int size = node->getType().getObjectSize();
constUnion *leftUnionArray = new constUnion[size]; constUnion *leftUnionArray = new constUnion[size];
for (int i=0; i < size; i++) { for (int i=0; i < size; i++) {
switch (promoteTo) { switch (promoteTo) {
case EbtFloat: case EbtFloat:
switch (node->getType().getBasicType()) { switch (node->getType().getBasicType()) {
@ -1560,14 +1507,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
default: default:
infoSink.info.message(EPrefixInternalError, "Incorrect data type found", node->getLine()); infoSink.info.message(EPrefixInternalError, "Incorrect data type found", node->getLine());
return 0; return 0;
} }
} }
const TType& t = node->getType(); const TType& t = node->getType();
return addConstantUnion(leftUnionArray, TType(promoteTo, t.getQualifier().storage, t.getNominalSize(), t.isMatrix(), return addConstantUnion(leftUnionArray, TType(promoteTo, t.getQualifier().storage, t.getVectorSize(), t.getMatrixCols(), t.getMatrixRows()),
t.isArray()), node->getLine()); node->getLine());
} }
void TIntermAggregate::addToPragmaTable(const TPragmaTable& pTable) void TIntermAggregate::addToPragmaTable(const TPragmaTable& pTable)

View File

@ -150,55 +150,6 @@ bool TParseContext::parseVectorFields(const TString& compString, int vecSize, TV
return true; return true;
} }
//
// Look at a '.' field selector string and change it into offsets
// for a matrix.
//
bool TParseContext::parseMatrixFields(const TString& compString, int matSize, TMatrixFields& fields, int line)
{
fields.wholeRow = false;
fields.wholeCol = false;
fields.row = -1;
fields.col = -1;
if (compString.size() != 2) {
error(line, "illegal length of matrix field selection", compString.c_str(), "");
return false;
}
if (compString[0] == '_') {
if (compString[1] < '0' || compString[1] > '3') {
error(line, "illegal matrix field selection", compString.c_str(), "");
return false;
}
fields.wholeCol = true;
fields.col = compString[1] - '0';
} else if (compString[1] == '_') {
if (compString[0] < '0' || compString[0] > '3') {
error(line, "illegal matrix field selection", compString.c_str(), "");
return false;
}
fields.wholeRow = true;
fields.row = compString[0] - '0';
} else {
if (compString[0] < '0' || compString[0] > '3' ||
compString[1] < '0' || compString[1] > '3') {
error(line, "illegal matrix field selection", compString.c_str(), "");
return false;
}
fields.row = compString[0] - '0';
fields.col = compString[1] - '0';
}
if (fields.row >= matSize || fields.col >= matSize) {
error(line, "matrix field selection out of range", compString.c_str(), "");
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// Errors // Errors
@ -261,7 +212,7 @@ void TParseContext::unaryOpError(int line, char* op, TString operand)
// //
void TParseContext::binaryOpError(int line, char* op, TString left, TString right) void TParseContext::binaryOpError(int line, char* op, TString left, TString right)
{ {
error(line, " wrong operand types ", op, error(line, " wrong operand types:", op,
"no operation '%s' exists that takes a left-hand operand of type '%s' and " "no operation '%s' exists that takes a left-hand operand of type '%s' and "
"a right operand of type '%s' (or there is no acceptable conversion)", "a right operand of type '%s' (or there is no acceptable conversion)",
op, left.c_str(), right.c_str()); op, left.c_str(), right.c_str());
@ -425,7 +376,7 @@ bool TParseContext::constErrorCheck(TIntermTyped* node)
// //
bool TParseContext::integerErrorCheck(TIntermTyped* node, char* token) bool TParseContext::integerErrorCheck(TIntermTyped* node, char* token)
{ {
if (node->getBasicType() == EbtInt && node->getNominalSize() == 1) if (node->getBasicType() == EbtInt && node->getVectorSize() == 1)
return false; return false;
error(node->getLine(), "integer expression required", token, ""); error(node->getLine(), "integer expression required", token, "");
@ -487,9 +438,24 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction
bool constructingMatrix = false; bool constructingMatrix = false;
switch(op) { switch(op) {
case EOpConstructMat2: case EOpConstructMat2x2:
case EOpConstructMat3: case EOpConstructMat2x3:
case EOpConstructMat4: case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
constructingMatrix = true; constructingMatrix = true;
break; break;
default: default:
@ -608,7 +574,7 @@ bool TParseContext::boolErrorCheck(int line, const TIntermTyped* type)
// //
bool TParseContext::boolErrorCheck(int line, const TPublicType& pType) bool TParseContext::boolErrorCheck(int line, const TPublicType& pType)
{ {
if (pType.type != EbtBool || pType.array || pType.matrix || (pType.size > 1)) { if (pType.type != EbtBool || pType.array || pType.matrixCols > 1 || (pType.vectorSize > 1)) {
error(line, "boolean expression expected", "", ""); error(line, "boolean expression expected", "", "");
return true; return true;
} }
@ -1138,7 +1104,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
TType elementType = *type; TType elementType = *type;
if (type->isArray()) if (type->isArray())
elementType.clearArrayness(); elementType.dereference();
bool singleArg; bool singleArg;
if (aggrNode) { if (aggrNode) {
@ -1246,13 +1212,35 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType* type, TOperator op, T
case EOpConstructVec2: case EOpConstructVec2:
case EOpConstructVec3: case EOpConstructVec3:
case EOpConstructVec4: case EOpConstructVec4:
case EOpConstructMat2: case EOpConstructMat2x2:
case EOpConstructMat3: case EOpConstructMat2x3:
case EOpConstructMat4: case EOpConstructMat2x4:
case EOpConstructMat3x2:
case EOpConstructMat3x3:
case EOpConstructMat3x4:
case EOpConstructMat4x2:
case EOpConstructMat4x3:
case EOpConstructMat4x4:
case EOpConstructFloat: case EOpConstructFloat:
basicOp = EOpConstructFloat; basicOp = EOpConstructFloat;
break; break;
case EOpConstructDVec2:
case EOpConstructDVec3:
case EOpConstructDVec4:
case EOpConstructDMat2x2:
case EOpConstructDMat2x3:
case EOpConstructDMat2x4:
case EOpConstructDMat3x2:
case EOpConstructDMat3x3:
case EOpConstructDMat3x4:
case EOpConstructDMat4x2:
case EOpConstructDMat4x3:
case EOpConstructDMat4x4:
case EOpConstructDouble:
basicOp = EOpConstructDouble;
break;
case EOpConstructIVec2: case EOpConstructIVec2:
case EOpConstructIVec3: case EOpConstructIVec3:
case EOpConstructIVec4: case EOpConstructIVec4:
@ -1345,7 +1333,7 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy
for (int i = 0; i < fields.num; i++) { for (int i = 0; i < fields.num; i++) {
if (fields.offsets[i] >= node->getType().getObjectSize()) { if (fields.offsets[i] >= node->getType().getObjectSize()) {
error(line, "", "[", "vector field selection out of range '%d'", fields.offsets[i]); error(line, "", "[", "vector index out of range '%d'", fields.offsets[i]);
recover(); recover();
fields.offsets[i] = 0; fields.offsets[i] = 0;
} }
@ -1368,7 +1356,7 @@ TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, T
TIntermTyped* typedNode; TIntermTyped* typedNode;
TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion(); TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
if (index >= node->getType().getNominalSize()) { if (index >= node->getType().getMatrixCols()) {
error(line, "", "[", "matrix field selection out of range '%d'", index); error(line, "", "[", "matrix field selection out of range '%d'", index);
recover(); recover();
index = 0; index = 0;
@ -1376,7 +1364,8 @@ TIntermTyped* TParseContext::addConstMatrixNode(int index, TIntermTyped* node, T
if (tempConstantNode) { if (tempConstantNode) {
constUnion* unionArray = tempConstantNode->getUnionArrayPointer(); constUnion* unionArray = tempConstantNode->getUnionArrayPointer();
int size = tempConstantNode->getType().getNominalSize(); int size = tempConstantNode->getType().getMatrixRows();
// Note: the type is corrected (dereferenced) by the caller
typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line); typedNode = intermediate.addConstantUnion(&unionArray[size*index], tempConstantNode->getType(), line);
} else { } else {
error(line, "Cannot offset into the matrix", "Error", ""); error(line, "Cannot offset into the matrix", "Error", "");
@ -1401,10 +1390,10 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, TS
TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion(); TIntermConstantUnion* tempConstantNode = node->getAsConstantUnion();
int arraySize = node->getType().getArraySize(); int arraySize = node->getType().getArraySize();
TType arrayElementType = node->getType(); TType arrayElementType = node->getType();
arrayElementType.clearArrayness(); arrayElementType.dereference();
if (index >= node->getType().getArraySize()) { if (index >= node->getType().getArraySize()) {
error(line, "", "[", "array field selection out of range '%d'", index); error(line, "", "[", "array index out of range '%d'", index);
recover(); recover();
index = 0; index = 0;
} }

View File

@ -100,7 +100,6 @@ struct TParseContext {
void recover(); void recover();
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line); bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);
void assignError(int line, const char* op, TString left, TString right); void assignError(int line, const char* op, TString left, TString right);
void unaryOpError(int line, char* op, TString operand); void unaryOpError(int line, char* op, TString operand);
void binaryOpError(int line, char* op, TString left, TString right); void binaryOpError(int line, char* op, TString left, TString right);

View File

@ -175,7 +175,6 @@ TPoolAllocator::~TPoolAllocator()
} }
} }
// Support MSVC++ 6.0
const unsigned char TAllocation::guardBlockBeginVal = 0xfb; const unsigned char TAllocation::guardBlockBeginVal = 0xfb;
const unsigned char TAllocation::guardBlockEndVal = 0xfe; const unsigned char TAllocation::guardBlockEndVal = 0xfe;
const unsigned char TAllocation::userDataFill = 0xcd; const unsigned char TAllocation::userDataFill = 0xcd;

View File

@ -399,21 +399,19 @@ int ShLinkExt(
THandleList cObjects; THandleList cObjects;
{// support MSVC++6.0 for (int i = 0; i < numHandles; ++i) {
for (int i = 0; i < numHandles; ++i) { if (compHandles[i] == 0)
if (compHandles[i] == 0) return 0;
return 0; TShHandleBase* base = reinterpret_cast<TShHandleBase*>(compHandles[i]);
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(compHandles[i]); if (base->getAsLinker()) {
if (base->getAsLinker()) { cObjects.push_back(base->getAsLinker());
cObjects.push_back(base->getAsLinker());
}
if (base->getAsCompiler())
cObjects.push_back(base->getAsCompiler());
if (cObjects[i] == 0)
return 0;
} }
if (base->getAsCompiler())
cObjects.push_back(base->getAsCompiler());
if (cObjects[i] == 0)
return 0;
} }
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(linkHandle); TShHandleBase* base = reinterpret_cast<TShHandleBase*>(linkHandle);
@ -424,13 +422,11 @@ int ShLinkExt(
linker->infoSink.info.erase(); linker->infoSink.info.erase();
{// support MSVC++6.0 for (int i = 0; i < numHandles; ++i) {
for (int i = 0; i < numHandles; ++i) { if (cObjects[i]->getAsCompiler()) {
if (cObjects[i]->getAsCompiler()) { if (! cObjects[i]->getAsCompiler()->linkable()) {
if (! cObjects[i]->getAsCompiler()->linkable()) { linker->infoSink.info.message(EPrefixError, "Not all shaders have valid object code.");
linker->infoSink.info.message(EPrefixError, "Not all shaders have valid object code."); return 0;
return 0;
}
} }
} }
} }

View File

@ -70,17 +70,21 @@ void TType::buildMangledName(TString& mangledName)
mangledName += "struct-"; mangledName += "struct-";
if (typeName) if (typeName)
mangledName += *typeName; mangledName += *typeName;
{// support MSVC++6.0 for (unsigned int i = 0; i < structure->size(); ++i) {
for (unsigned int i = 0; i < structure->size(); ++i) { mangledName += '-';
mangledName += '-'; (*structure)[i].type->buildMangledName(mangledName);
(*structure)[i].type->buildMangledName(mangledName);
}
} }
default: default:
break; break;
} }
mangledName += static_cast<char>('0' + getNominalSize()); if (getVectorSize() > 0)
mangledName += static_cast<char>('0' + getVectorSize());
else {
mangledName += static_cast<char>('0' + getMatrixCols());
mangledName += static_cast<char>('0' + getMatrixRows());
}
if (isArray()) { if (isArray()) {
const int maxSize = 10; const int maxSize = 10;
char buf[maxSize]; char buf[maxSize];

View File

@ -306,8 +306,10 @@ postfix_expression
} }
} else { } else {
if ($3->getQualifier().storage == EvqConst) { if ($3->getQualifier().storage == EvqConst) {
if (($1->isVector() || $1->isMatrix()) && $1->getType().getNominalSize() <= $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst() && !$1->isArray() ) { int index = $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst();
parseContext.error($2.line, "", "[", "field selection out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst()); if (! $1->isArray() && ($1->isVector() && $1->getType().getVectorSize() <= index ||
$1->isMatrix() && $1->getType().getMatrixCols() <= index)) {
parseContext.error($2.line, "", "[", "index out of range '%d'", $3->getAsConstantUnion()->getUnionArrayPointer()->getIConst());
parseContext.recover(); parseContext.recover();
} else { } else {
if ($1->isArray()) { if ($1->isArray()) {
@ -339,24 +341,13 @@ postfix_expression
constUnion *unionArray = new constUnion[1]; constUnion *unionArray = new constUnion[1];
unionArray->setFConst(0.0f); unionArray->setFConst(0.0f);
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $2.line); $$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $2.line);
} else if ($1->isArray()) { } else {
if ($1->getType().getStruct()) TType newType = $1->getType();
$$->setType(TType($1->getType().getStruct(), $1->getType().getTypeName())); newType.dereference();
else $$->setType(newType);
$$->setType(TType($1->getBasicType(), EvqTemporary, $1->getNominalSize(), $1->isMatrix())); //?? why didn't the code above get the type right?
//?? write a deference test
if ($1->getType().getQualifier().storage == EvqConst) }
$$->getTypePointer()->getQualifier().storage = EvqConst;
} else if ($1->isMatrix() && $1->getType().getQualifier().storage == EvqConst)
$$->setType(TType($1->getBasicType(), EvqConst, $1->getNominalSize()));
else if ($1->isMatrix())
$$->setType(TType($1->getBasicType(), EvqTemporary, $1->getNominalSize()));
else if ($1->isVector() && $1->getType().getQualifier().storage == EvqConst)
$$->setType(TType($1->getBasicType(), EvqConst));
else if ($1->isVector())
$$->setType(TType($1->getBasicType(), EvqTemporary));
else
$$->setType($1->getType());
} }
| function_call { | function_call {
$$ = $1; $$ = $1;
@ -381,7 +372,7 @@ postfix_expression
} }
} else if ($1->isVector()) { } else if ($1->isVector()) {
TVectorFields fields; TVectorFields fields;
if (! parseContext.parseVectorFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { if (! parseContext.parseVectorFields(*$3.string, $1->getVectorSize(), fields, $3.line)) {
fields.num = 1; fields.num = 1;
fields.offsets[0] = 0; fields.offsets[0] = 0;
parseContext.recover(); parseContext.recover();
@ -410,30 +401,8 @@ postfix_expression
} }
} }
} else if ($1->isMatrix()) { } else if ($1->isMatrix()) {
TMatrixFields fields; parseContext.error($2.line, "field selection not allowed on matrix", ".", "");
if (! parseContext.parseMatrixFields(*$3.string, $1->getNominalSize(), fields, $3.line)) { parseContext.recover();
fields.wholeRow = false;
fields.wholeCol = false;
fields.row = 0;
fields.col = 0;
parseContext.recover();
}
if (fields.wholeRow || fields.wholeCol) {
parseContext.error($2.line, " non-scalar fields not implemented yet", ".", "");
parseContext.recover();
constUnion *unionArray = new constUnion[1];
unionArray->setIConst(0);
TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), $3.line);
$$ = parseContext.intermediate.addIndex(EOpIndexDirect, $1, index, $2.line);
$$->setType(TType($1->getBasicType(), EvqTemporary, $1->getNominalSize()));
} else {
constUnion *unionArray = new constUnion[1];
unionArray->setIConst(fields.col * $1->getNominalSize() + fields.row);
TIntermTyped* index = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtInt, EvqConst), $3.line);
$$ = parseContext.intermediate.addIndex(EOpIndexDirect, $1, index, $2.line);
$$->setType(TType($1->getBasicType()));
}
} else if ($1->getBasicType() == EbtStruct) { } else if ($1->getBasicType() == EbtStruct) {
bool fieldFound = false; bool fieldFound = false;
TTypeList* fields = $1->getType().getStruct(); TTypeList* fields = $1->getType().getStruct();
@ -455,8 +424,7 @@ postfix_expression
if ($$ == 0) { if ($$ == 0) {
parseContext.recover(); parseContext.recover();
$$ = $1; $$ = $1;
} } else {
else {
$$->setType(*(*fields)[i].type); $$->setType(*(*fields)[i].type);
// change the qualifier of the return type, not of the structure field // change the qualifier of the return type, not of the structure field
// as the structure definition is shared between various structures. // as the structure definition is shared between various structures.
@ -476,6 +444,7 @@ postfix_expression
} }
} }
} else { } else {
//?? fix message
parseContext.error($2.line, " field selection requires structure, vector, or matrix on left hand side", $3.string->c_str(), ""); parseContext.error($2.line, " field selection requires structure, vector, or matrix on left hand side", $3.string->c_str(), "");
parseContext.recover(); parseContext.recover();
$$ = $1; $$ = $1;
@ -692,14 +661,32 @@ function_identifier
TOperator op = EOpNull; TOperator op = EOpNull;
switch ($1.type) { switch ($1.type) {
case EbtFloat: case EbtFloat:
if ($1.matrix) { if ($1.matrixCols) {
switch($1.size) { switch ($1.matrixCols) {
case 2: op = EOpConstructMat2; break; case 2:
case 3: op = EOpConstructMat3; break; switch ($1.matrixRows) {
case 4: op = EOpConstructMat4; break; case 2: op = EOpConstructMat2x2; break;
case 3: op = EOpConstructMat2x3; break;
case 4: op = EOpConstructMat2x4; break;
}
break;
case 3:
switch ($1.matrixRows) {
case 2: op = EOpConstructMat3x2; break;
case 3: op = EOpConstructMat3x3; break;
case 4: op = EOpConstructMat3x4; break;
}
break;
case 4:
switch ($1.matrixRows) {
case 2: op = EOpConstructMat4x2; break;
case 3: op = EOpConstructMat4x3; break;
case 4: op = EOpConstructMat4x4; break;
}
break;
} }
} else { } else {
switch($1.size) { switch($1.vectorSize) {
case 1: op = EOpConstructFloat; break; case 1: op = EOpConstructFloat; break;
case 2: op = EOpConstructVec2; break; case 2: op = EOpConstructVec2; break;
case 3: op = EOpConstructVec3; break; case 3: op = EOpConstructVec3; break;
@ -707,8 +694,42 @@ function_identifier
} }
} }
break; break;
case EbtDouble:
if ($1.matrixCols) {
switch ($1.matrixCols) {
case 2:
switch ($1.matrixRows) {
case 2: op = EOpConstructDMat2x2; break;
case 3: op = EOpConstructDMat2x3; break;
case 4: op = EOpConstructDMat2x4; break;
}
break;
case 3:
switch ($1.matrixRows) {
case 2: op = EOpConstructDMat3x2; break;
case 3: op = EOpConstructDMat3x3; break;
case 4: op = EOpConstructDMat3x4; break;
}
break;
case 4:
switch ($1.matrixRows) {
case 2: op = EOpConstructDMat4x2; break;
case 3: op = EOpConstructDMat4x3; break;
case 4: op = EOpConstructDMat4x4; break;
}
break;
}
} else {
switch($1.vectorSize) {
case 1: op = EOpConstructDouble; break;
case 2: op = EOpConstructDVec2; break;
case 3: op = EOpConstructDVec3; break;
case 4: op = EOpConstructDVec4; break;
}
}
break;
case EbtInt: case EbtInt:
switch($1.size) { switch($1.vectorSize) {
case 1: op = EOpConstructInt; break; case 1: op = EOpConstructInt; break;
case 2: op = EOpConstructIVec2; break; case 2: op = EOpConstructIVec2; break;
case 3: op = EOpConstructIVec3; break; case 3: op = EOpConstructIVec3; break;
@ -716,7 +737,7 @@ function_identifier
} }
break; break;
case EbtBool: case EbtBool:
switch($1.size) { switch($1.vectorSize) {
case 1: op = EOpConstructBool; break; case 1: op = EOpConstructBool; break;
case 2: op = EOpConstructBVec2; break; case 2: op = EOpConstructBVec2; break;
case 3: op = EOpConstructBVec3; break; case 3: op = EOpConstructBVec3; break;
@ -1874,209 +1895,197 @@ type_specifier_nonarray
| VEC2 { | VEC2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(2); $$.setVector(2);
} }
| VEC3 { | VEC3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(3); $$.setVector(3);
} }
| VEC4 { | VEC4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4); $$.setVector(4);
} }
| DVEC2 { | DVEC2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(2); $$.setVector(2);
} }
| DVEC3 { | DVEC3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(3); $$.setVector(3);
} }
| DVEC4 { | DVEC4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4); $$.setVector(4);
} }
| BVEC2 { | BVEC2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtBool; $$.type = EbtBool;
$$.setAggregate(2); $$.setVector(2);
} }
| BVEC3 { | BVEC3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtBool; $$.type = EbtBool;
$$.setAggregate(3); $$.setVector(3);
} }
| BVEC4 { | BVEC4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtBool; $$.type = EbtBool;
$$.setAggregate(4); $$.setVector(4);
} }
| IVEC2 { | IVEC2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(2); $$.setVector(2);
} }
| IVEC3 { | IVEC3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(3); $$.setVector(3);
} }
| IVEC4 { | IVEC4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(4); $$.setVector(4);
} }
| UVEC2 { | UVEC2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(2); $$.setVector(2);
} }
| UVEC3 { | UVEC3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(3); $$.setVector(3);
} }
| UVEC4 { | UVEC4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtInt; $$.type = EbtInt;
$$.setAggregate(4); $$.setVector(4);
} }
| MAT2 { | MAT2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(2, true); $$.setMatrix(2, 2);
} }
| MAT3 { | MAT3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(3, true); $$.setMatrix(3, 3);
} }
| MAT4 { | MAT4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(4, 4);
} }
| MAT2X2 { | MAT2X2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(2, true); $$.setMatrix(2, 2);
} }
| MAT2X3 { | MAT2X3 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(3, true); $$.setMatrix(2, 3);
} }
| MAT2X4 { | MAT2X4 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(2, 4);
} }
| MAT3X2 { | MAT3X2 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(3, true); $$.setMatrix(3, 2);
} }
| MAT3X3 { | MAT3X3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(3, true); $$.setMatrix(3, 3);
} }
| MAT3X4 { | MAT3X4 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(3, 4);
} }
| MAT4X2 { | MAT4X2 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(4, 2);
} }
| MAT4X3 { | MAT4X3 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(4, 3);
} }
| MAT4X4 { | MAT4X4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtFloat; $$.type = EbtFloat;
$$.setAggregate(4, true); $$.setMatrix(4, 4);
} }
| DMAT2 { | DMAT2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(2, true); $$.setMatrix(2, 2);
} }
| DMAT3 { | DMAT3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(3, true); $$.setMatrix(3, 3);
} }
| DMAT4 { | DMAT4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(4, 4);
} }
| DMAT2X2 { | DMAT2X2 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(2, true); $$.setMatrix(2, 2);
} }
| DMAT2X3 { | DMAT2X3 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(3, true); $$.setMatrix(2, 3);
} }
| DMAT2X4 { | DMAT2X4 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(2, 4);
} }
| DMAT3X2 { | DMAT3X2 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(3, true); $$.setMatrix(3, 2);
} }
| DMAT3X3 { | DMAT3X3 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(3, true); $$.setMatrix(3, 3);
} }
| DMAT3X4 { | DMAT3X4 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(3, 4);
} }
| DMAT4X2 { | DMAT4X2 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(4, 2);
} }
| DMAT4X3 { | DMAT4X3 {
// TODO: implement this type
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(4, 3);
} }
| DMAT4X4 { | DMAT4X4 {
$$.init($1.line, parseContext.symbolTable.atGlobalLevel()); $$.init($1.line, parseContext.symbolTable.atGlobalLevel());
$$.type = EbtDouble; $$.type = EbtDouble;
$$.setAggregate(4, true); $$.setMatrix(4, 4);
} }
| ATOMIC_UINT { | ATOMIC_UINT {
// TODO: add type // TODO: add type
@ -2511,7 +2520,7 @@ struct_declaration
// //
// Careful not to replace already know aspects of type, like array-ness // Careful not to replace already know aspects of type, like array-ness
// //
(*$$)[i].type->setType($1.type, $1.size, $1.matrix, $1.userDef); (*$$)[i].type->setElementType($1.type, $1.vectorSize, $1.matrixCols, $1.matrixRows, $1.userDef);
if ($1.array) if ($1.array)
(*$$)[i].type->setArraySize($1.arraySize); (*$$)[i].type->setArraySize($1.arraySize);
@ -2529,7 +2538,7 @@ struct_declaration
// //
// Careful not to replace already know aspects of type, like array-ness // Careful not to replace already know aspects of type, like array-ness
// //
(*$$)[i].type->setType($2.type, $2.size, $2.matrix, $2.userDef); (*$$)[i].type->setElementType($2.type, $2.vectorSize, $2.matrixCols, $2.matrixRows, $2.userDef);
if ($2.array) if ($2.array)
(*$$)[i].type->setArraySize($2.arraySize); (*$$)[i].type->setArraySize($2.arraySize);
@ -2924,7 +2933,6 @@ function_definition
parseContext.loopNestingLevel = 0; parseContext.loopNestingLevel = 0;
} }
compound_statement_no_new_scope { compound_statement_no_new_scope {
//?? Check that all paths return a value if return type != void ?
// May be best done as post process phase on intermediate code // May be best done as post process phase on intermediate code
if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue) { if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue) {
parseContext.error($1.line, "function does not return a value:", "", $1.function->getName().c_str()); parseContext.error($1.line, "function does not return a value:", "", $1.function->getName().c_str());

View File

@ -66,10 +66,10 @@ TString TType::getCompleteString() const
p += sprintf_s(p, end - p, "array of "); p += sprintf_s(p, end - p, "array of ");
if (qualifier.precision != EpqNone) if (qualifier.precision != EpqNone)
p += sprintf_s(p, end - p, "%s ", getPrecisionQualifierString()); p += sprintf_s(p, end - p, "%s ", getPrecisionQualifierString());
if (matrix) if (matrixCols > 0)
p += sprintf_s(p, end - p, "%dX%d matrix of ", size, size); p += sprintf_s(p, end - p, "%dX%d matrix of ", matrixCols, matrixRows);
else if (size > 1) else if (vectorSize > 1)
p += sprintf_s(p, end - p, "%d-component vector of ", size); p += sprintf_s(p, end - p, "%d-component vector of ", vectorSize);
sprintf_s(p, end - p, "%s", getBasicString()); sprintf_s(p, end - p, "%s", getBasicString());
@ -276,9 +276,24 @@ bool OutputAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTravers
case EOpConstructIVec2: out.debug << "Construct ivec2"; break; case EOpConstructIVec2: out.debug << "Construct ivec2"; break;
case EOpConstructIVec3: out.debug << "Construct ivec3"; break; case EOpConstructIVec3: out.debug << "Construct ivec3"; break;
case EOpConstructIVec4: out.debug << "Construct ivec4"; break; case EOpConstructIVec4: out.debug << "Construct ivec4"; break;
case EOpConstructMat2: out.debug << "Construct mat2"; break; case EOpConstructMat2x2: out.debug << "Construct mat2"; break;
case EOpConstructMat3: out.debug << "Construct mat3"; break; case EOpConstructMat2x3: out.debug << "Construct mat2x3"; break;
case EOpConstructMat4: out.debug << "Construct mat4"; break; case EOpConstructMat2x4: out.debug << "Construct mat2x4"; break;
case EOpConstructMat3x2: out.debug << "Construct mat3x2"; break;
case EOpConstructMat3x3: out.debug << "Construct mat3"; break;
case EOpConstructMat3x4: out.debug << "Construct mat3x4"; break;
case EOpConstructMat4x2: out.debug << "Construct mat4x2"; break;
case EOpConstructMat4x3: out.debug << "Construct mat4x3"; break;
case EOpConstructMat4x4: out.debug << "Construct mat4"; break;
case EOpConstructDMat2x2: out.debug << "Construct dmat2"; break;
case EOpConstructDMat2x3: out.debug << "Construct dmat2x3"; break;
case EOpConstructDMat2x4: out.debug << "Construct dmat2x4"; break;
case EOpConstructDMat3x2: out.debug << "Construct dmat3x2"; break;
case EOpConstructDMat3x3: out.debug << "Construct dmat3"; break;
case EOpConstructDMat3x4: out.debug << "Construct dmat3x4"; break;
case EOpConstructDMat4x2: out.debug << "Construct dmat4x2"; break;
case EOpConstructDMat4x3: out.debug << "Construct dmat4x3"; break;
case EOpConstructDMat4x4: out.debug << "Construct dmat4"; break;
case EOpConstructStruct: out.debug << "Construct structure"; break; case EOpConstructStruct: out.debug << "Construct structure"; break;
case EOpLessThan: out.debug << "Compare Less Than"; break; case EOpLessThan: out.debug << "Compare Less Than"; break;
@ -398,8 +413,8 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
sprintf_s(buf, maxSize, "%d (%s)", node->getUnionArrayPointer()[i].getIConst(), "const int"); sprintf_s(buf, maxSize, "%d (%s)", node->getUnionArrayPointer()[i].getIConst(), "const int");
out.debug << buf << "\n"; out.debug << buf << "\n";
break;
} }
break;
default: default:
out.info.message(EPrefixInternalError, "Unknown constant", node->getLine()); out.info.message(EPrefixInternalError, "Unknown constant", node->getLine());
break; break;

View File

@ -41,7 +41,8 @@
class TConstTraverser : public TIntermTraverser { class TConstTraverser : public TIntermTraverser {
public: public:
TConstTraverser(constUnion* cUnion, bool singleConstParam, TOperator constructType, TInfoSink& sink, TSymbolTable& symTable, TType& t) : unionArray(cUnion), type(t), TConstTraverser(constUnion* cUnion, bool singleConstParam, TOperator constructType, TInfoSink& sink, TSymbolTable& symTable, TType& t) : unionArray(cUnion), type(t),
constructorType(constructType), singleConstantParam(singleConstParam), infoSink(sink), symbolTable(symTable), error(false), isMatrix(false), matrixSize(0) { index = 0; tOp = EOpNull;} constructorType(constructType), singleConstantParam(singleConstParam), infoSink(sink), symbolTable(symTable), error(false), isMatrix(false),
matrixCols(0), matrixRows(0) { index = 0; tOp = EOpNull;}
int index ; int index ;
constUnion *unionArray; constUnion *unionArray;
TOperator tOp; TOperator tOp;
@ -53,7 +54,8 @@ public:
bool error; bool error;
int size; // size of the constructor ( 4 for vec4) int size; // size of the constructor ( 4 for vec4)
bool isMatrix; bool isMatrix;
int matrixSize; // dimension of the matrix (nominal size and not the instance size) int matrixCols;
int matrixRows;
}; };
// //
@ -128,15 +130,15 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse
} }
bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion(); bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion();
if (flag) if (flag) {
{
oit->singleConstantParam = true; oit->singleConstantParam = true;
oit->constructorType = node->getOp(); oit->constructorType = node->getOp();
oit->size = node->getType().getObjectSize(); oit->size = node->getType().getObjectSize();
if (node->getType().isMatrix()) { if (node->getType().isMatrix()) {
oit->isMatrix = true; oit->isMatrix = true;
oit->matrixSize = node->getType().getNominalSize(); oit->matrixCols = node->getType().getMatrixCols();
oit->matrixRows = node->getType().getMatrixRows();
} }
} }
@ -154,7 +156,8 @@ bool ParseAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTraverse
oit->constructorType = EOpNull; oit->constructorType = EOpNull;
oit->size = 0; oit->size = 0;
oit->isMatrix = false; oit->isMatrix = false;
oit->matrixSize = 0; oit->matrixCols = 0;
oit->matrixRows = 0;
} }
return false; return false;
@ -189,12 +192,13 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
(oit->index)++; (oit->index)++;
} }
} else { } else {
int size, totalSize, matrixSize; int size, totalSize, matrixCols, matrixRows;
bool isMatrix = false; bool isMatrix = false;
size = oit->size; size = oit->size;
matrixSize = oit->matrixSize; matrixCols = oit->matrixCols;
matrixRows = oit->matrixRows;
isMatrix = oit->isMatrix; isMatrix = oit->isMatrix;
totalSize = oit->index + size ; totalSize = oit->index + size;
constUnion *rightUnionArray = node->getUnionArrayPointer(); constUnion *rightUnionArray = node->getUnionArrayPointer();
if (!isMatrix) { if (!isMatrix) {
int count = 0; int count = 0;
@ -215,7 +219,7 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
for (int i = index; i < totalSize; i++) { for (int i = index; i < totalSize; i++) {
if (i >= instanceSize) if (i >= instanceSize)
return; return;
if (index - i == 0 || (i - index) % (matrixSize + 1) == 0 ) if (index - i == 0 || (i - index) % (matrixRows + 1) == 0 )
leftUnionArray[i] = rightUnionArray[count]; leftUnionArray[i] = rightUnionArray[count];
else else
leftUnionArray[i].setFConst(0.0f); leftUnionArray[i].setFConst(0.0f);