Add full support for uniforms with initializers, including intra-stage link validation of aggregate constant initializers.

This included 
 - encapsulating aggregate constants
 - removal of constant-aggregate comparison algorithms, instead using a flattened and direct std::vector comparison
 - adding structure type comparison for independently declared structures that still might match types



git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23274 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-09-28 04:02:08 +00:00
parent b3345c422d
commit f2ee3dd46a
98 changed files with 3007 additions and 1715 deletions

View file

@ -106,7 +106,8 @@ public:
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
TVector() : std::vector<T, pool_allocator<T> >() {}
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
TVector(size_type i) : std::vector<T, pool_allocator<T> >(i) {}
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
};
template <class T> class TList : public TBaseList <T, pool_allocator<T> > {

View file

@ -41,8 +41,8 @@ namespace glslang {
class TConstUnion {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
void setIConst(int i)
{
iConst = i;
@ -394,9 +394,9 @@ public:
return returnValue;
}
TBasicType getType() { return type; }
private:
TBasicType getType() const { return type; }
private:
union {
int iConst; // used for ivec, scalar ints
unsigned int uConst; // used for uvec, scalar uints
@ -407,6 +407,61 @@ private:
TBasicType type;
};
// Encapsulate having a pointer to an array of TConstUnion,
// which only needs to be allocated if it's size is going to be
// bigger than 0.
//
// One convenience is being able to use [] to go inside the array, instead
// of C++ assuming it as an array of pointers to vectors.
//
// General usage is that the size is known up front, and it is
// created once with the proper size.
//
class TConstUnionArray {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TConstUnionArray() { unionArray = 0; }
explicit TConstUnionArray(int size)
{
if (size == 0)
unionArray = 0;
else
unionArray = new TVector<TConstUnion>(size);
}
TConstUnionArray(const TConstUnionArray& a) : unionArray(a.unionArray) { }
TConstUnionArray(const TConstUnionArray& a, int start, int size)
{
unionArray = new TVector<TConstUnion>(size);
for (int i = 0; i < size; ++i)
(*unionArray)[i] = a[start + i];
}
// Use this constructor for a smear operation
TConstUnionArray(int size, const TConstUnion& val)
{
unionArray = new TVector<TConstUnion>(size, val);
}
TConstUnion& operator[](int index) { return (*unionArray)[index]; }
const TConstUnion& operator[](int index) const { return (*unionArray)[index]; }
bool operator==(const TConstUnionArray& rhs) const
{
// this includes the case that both are unallocated
if (unionArray == rhs.unionArray)
return true;
return *unionArray == *rhs.unionArray;
}
bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
bool empty() const { return unionArray == 0; }
protected:
TVector<TConstUnion>* unionArray;
};
} // end namespace glslang
#endif // _CONSTANT_UNION_INCLUDED_

View file

@ -721,6 +721,42 @@ public:
name += ';' ;
}
// Do two structure types match? They could be declared independently,
// in different places, but still might satisfy the definition of matching.
// From the spec:
//
// "Structures must have the same name, sequence of type names, and
// type definitions, and member names to be considered the same type.
// This rule applies recursively for nested or embedded types."
//
bool sameStructType(const TType& right) const
{
// Most commonly, they are both 0, or the same pointer to the same actual structure
if (structure == right.structure)
return true;
// Both being 0 was caught above, now they both have to be structures of the same number of elements
if (structure == 0 || right.structure == 0 ||
structure->size() != right.structure->size())
return false;
// Structure names have to match
if (*typeName != *right.typeName)
return false;
// Compare the names and types of all the members, which have to match
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->getFieldName() != (*right.structure)[i].type->getFieldName())
return false;
if (*(*structure)[i].type != *(*right.structure)[i].type)
return false;
}
return true;
}
// See if two types match, in all aspects except arrayness
bool sameElementType(const TType& right) const
{
return basicType == right.basicType &&
@ -728,20 +764,20 @@ public:
vectorSize == right.vectorSize &&
matrixCols == right.matrixCols &&
matrixRows == right.matrixRows &&
structure == right.structure;
sameStructType(right);
}
// See if two types match in all ways (just the actual type, not qualification
bool operator==(const TType& right) const
{
return sameElementType(right) &&
(arraySizes == 0 && right.arraySizes == 0 ||
(arraySizes && right.arraySizes && arraySizes->sizes == right.arraySizes->sizes));
// don't check the qualifier, it's not ever what's being sought after
}
bool operator!=(const TType& right) const
{
return !operator==(right);
return ! operator==(right);
}
protected:
@ -764,7 +800,7 @@ protected:
TTypeList* structure; // 0 unless this is a struct
mutable int structureSize; // a cache, updated on first access
TString *fieldName; // for structure field names
TString *typeName; // for structure field type name
TString *typeName; // for structure type name
};
} // end namespace glslang

View file

@ -460,27 +460,29 @@ public:
// per process globalpoolallocator, then it causes increased memory usage per compile
// it is essential to use "symbol = sym" to assign to symbol
TIntermSymbol(int i, const TString& n, const TType& t) :
TIntermTyped(t), id(i) { name = n;}
TIntermTyped(t), id(i) { name = n;}
virtual int getId() const { return id; }
virtual const TString& getName() const { return name; }
virtual void traverse(TIntermTraverser*);
virtual TIntermSymbol* getAsSymbolNode() { return this; }
void setConstArray(const TConstUnionArray& c) { unionArray = c; }
const TConstUnionArray& getConstArray() const { return unionArray; }
protected:
int id;
TString name;
TConstUnionArray unionArray;
};
class TIntermConstantUnion : public TIntermTyped {
public:
TIntermConstantUnion(TConstUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }
TConstUnion* getUnionArrayPointer() const { return unionArrayPointer; }
void setUnionArrayPointer(TConstUnion *c) { unionArrayPointer = c; }
TIntermConstantUnion(const TConstUnionArray& ua, const TType& t) : TIntermTyped(t), unionArray(ua) { }
const TConstUnionArray& getConstArray() const { return unionArray; }
virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
virtual void traverse(TIntermTraverser* );
virtual TIntermTyped* fold(TOperator, TIntermTyped*);
virtual TIntermTyped* fold(TOperator, const TType&);
protected:
TConstUnion *unionArrayPointer;
const TConstUnionArray unionArray;
};
//