Front-end: move to rational internal array-of-array interfaces and design. (A-of-A is not yet implemented though.)
This commit is contained in:
parent
dcab977055
commit
e0603a441e
17 changed files with 236 additions and 64 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include "../Include/Common.h"
|
||||
#include "../Include/BaseTypes.h"
|
||||
#include "../Public/ShaderLang.h"
|
||||
#include "arrays.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
|
|
@ -168,29 +169,6 @@ typedef TVector<TTypeLoc> TTypeList;
|
|||
|
||||
typedef TVector<TString*> TIdentifierList;
|
||||
|
||||
//
|
||||
// TODO: memory: TArraySizes can be replaced by something smaller.
|
||||
// Almost all arrays could be handled by two sizes each fitting
|
||||
// in 16 bits, needing a real vector only in the cases where there
|
||||
// are more than 3 sizes or a size needing more than 16 bits.
|
||||
//
|
||||
// The type is a pointer, so that it can be non-allocated and zero
|
||||
// for the vast majority of non-array types. Note that means if it
|
||||
// is used, it will be containing at least one size.
|
||||
|
||||
struct TArraySizes {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TArraySizes() : implicitArraySize(1) { }
|
||||
int getSize() { return sizes.front(); } // TArraySizes only exists if there is at least one dimension
|
||||
void setSize(int s) { sizes.push_back(s); }
|
||||
bool isArrayOfArrays() { return sizes.size() > 1; }
|
||||
protected:
|
||||
TVector<int> sizes;
|
||||
friend class TType;
|
||||
int implicitArraySize; // for tracking maximum referenced index, before an explicit size is given
|
||||
};
|
||||
|
||||
//
|
||||
// Following are a series of helper enums for managing layouts and qualifiers,
|
||||
// used for TPublicType, TType, others.
|
||||
|
|
@ -962,7 +940,7 @@ public:
|
|||
vectorSize = copyOf.vectorSize;
|
||||
matrixCols = copyOf.matrixCols;
|
||||
matrixRows = copyOf.matrixRows;
|
||||
arraySizes = copyOf.arraySizes;
|
||||
arraySizes = copyOf.arraySizes; // copying the pointer only, not the contents
|
||||
structure = copyOf.structure;
|
||||
fieldName = copyOf.fieldName;
|
||||
typeName = copyOf.typeName;
|
||||
|
|
@ -1064,9 +1042,9 @@ public:
|
|||
virtual int getVectorSize() const { return vectorSize; }
|
||||
virtual int getMatrixCols() const { return matrixCols; }
|
||||
virtual int getMatrixRows() const { return matrixRows; }
|
||||
virtual int getArraySize() const { return arraySizes->sizes.front(); }
|
||||
virtual bool isArrayOfArrays() const { return arraySizes && arraySizes->isArrayOfArrays(); }
|
||||
virtual int getImplicitArraySize () const { return arraySizes->implicitArraySize; }
|
||||
virtual int getArraySize() const { return arraySizes->getOuterSize(); }
|
||||
virtual bool isArrayOfArrays() const { return arraySizes && arraySizes->getNumDims() > 1; }
|
||||
virtual int getImplicitArraySize() const { return arraySizes->getImplicitSize(); }
|
||||
|
||||
virtual bool isScalar() const { return vectorSize == 1 && ! isStruct() && ! isArray(); }
|
||||
virtual bool isVector() const { return vectorSize > 1; }
|
||||
|
|
@ -1147,17 +1125,20 @@ public:
|
|||
{
|
||||
// For when we may already be sharing existing array descriptors,
|
||||
// keeping the pointers the same, just updating the contents.
|
||||
assert(arraySizes != nullptr);
|
||||
assert(type.arraySizes != nullptr);
|
||||
*arraySizes = *type.arraySizes;
|
||||
}
|
||||
void setArraySizes(TArraySizes* s)
|
||||
{
|
||||
// For setting a fresh new set of array sizes, not yet worrying about sharing.
|
||||
arraySizes = new TArraySizes;
|
||||
assert(s != nullptr);
|
||||
*arraySizes = *s;
|
||||
}
|
||||
void setArraySizes(const TType& type) { setArraySizes(type.arraySizes); }
|
||||
void changeArraySize(int s) { arraySizes->sizes.front() = s; }
|
||||
void setImplicitArraySize (int s) { arraySizes->implicitArraySize = s; }
|
||||
void changeArraySize(int s) { arraySizes->changeOuterSize(s); }
|
||||
void setImplicitArraySize (int s) { arraySizes->setImplicitSize(s); }
|
||||
|
||||
// Recursively make the implicit array size the explicit array size, through the type tree.
|
||||
void adoptImplicitArraySizes()
|
||||
|
|
@ -1265,12 +1246,12 @@ public:
|
|||
p += snprintf(p, end - p, "writeonly ");
|
||||
p += snprintf(p, end - p, "%s ", getStorageQualifierString());
|
||||
if (arraySizes) {
|
||||
if (arraySizes->sizes.front() == 0) {
|
||||
if (arraySizes->getOuterSize() == 0) {
|
||||
p += snprintf(p, end - p, "implicitly-sized array of ");
|
||||
} else {
|
||||
for(int i = 0; i < (int)arraySizes->sizes.size() ; ++i) {
|
||||
for(int i = 0; i < (int)arraySizes->getNumDims() ; ++i) {
|
||||
// p += snprintf(p, end - p, "%s%d", (i == 0 ? "" : "x"), arraySizes->sizes[numDimensions-1-i]);
|
||||
p += snprintf(p, end - p, "%d-element array of ", arraySizes->sizes[i]);
|
||||
p += snprintf(p, end - p, "%d-element array of ", (*arraySizes)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1395,7 +1376,7 @@ public:
|
|||
bool sameArrayness(const TType& right) const
|
||||
{
|
||||
return ((arraySizes == 0 && right.arraySizes == 0) ||
|
||||
(arraySizes && right.arraySizes && arraySizes->sizes == right.arraySizes->sizes));
|
||||
(arraySizes && right.arraySizes && *arraySizes == *right.arraySizes));
|
||||
}
|
||||
|
||||
// See if two type's elements match in all ways except basic type
|
||||
|
|
@ -1433,7 +1414,7 @@ protected:
|
|||
TSampler sampler;
|
||||
TQualifier qualifier;
|
||||
|
||||
TArraySizes* arraySizes; // 0 unless this is an array; can be shared across types
|
||||
TArraySizes* arraySizes; // 0 unless an array; can be shared across types
|
||||
TTypeList* structure; // 0 unless this is a struct; can be shared across types
|
||||
TString *fieldName; // for structure field names
|
||||
TString *typeName; // for structure type name
|
||||
|
|
|
|||
174
glslang/Include/arrays.h
Normal file
174
glslang/Include/arrays.h
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
//
|
||||
// Implement types for tracking GLSL arrays, arrays of arrays, etc.
|
||||
//
|
||||
|
||||
#ifndef _ARRAYS_INCLUDED
|
||||
#define _ARRAYS_INCLUDED
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
|
||||
// It has generic-container semantics, while TArraySizes has array-of-array semantics.
|
||||
//
|
||||
struct TSmallArrayVector {
|
||||
//
|
||||
// TODO: memory: TSmallArrayVector is intended to be smaller.
|
||||
// Almost all arrays could be handled by two sizes each fitting
|
||||
// in 16 bits, needing a real vector only in the cases where there
|
||||
// are more than 3 sizes or a size needing more than 16 bits.
|
||||
//
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TSmallArrayVector() : sizes(0) { }
|
||||
virtual ~TSmallArrayVector() { dealloc(); }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TSmallArrayVector& operator=(const TSmallArrayVector& from)
|
||||
{
|
||||
if (from.sizes == nullptr)
|
||||
sizes = nullptr;
|
||||
else {
|
||||
alloc();
|
||||
*sizes = *from.sizes;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int size()
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
return 0;
|
||||
return (int)sizes->size();
|
||||
}
|
||||
|
||||
unsigned int front()
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
return sizes->front();
|
||||
}
|
||||
|
||||
void changeFront(unsigned int s)
|
||||
{
|
||||
assert(sizes != nullptr);
|
||||
sizes->front() = s;
|
||||
}
|
||||
|
||||
void push_back(unsigned int e)
|
||||
{
|
||||
alloc();
|
||||
sizes->push_back(e);
|
||||
}
|
||||
|
||||
unsigned int operator[](int i)
|
||||
{
|
||||
assert(sizes && (int)sizes->size() > i);
|
||||
return (*sizes)[i];
|
||||
}
|
||||
|
||||
bool operator==(const TSmallArrayVector& rhs)
|
||||
{
|
||||
if (sizes == nullptr && rhs.sizes == nullptr)
|
||||
return true;
|
||||
if (sizes == nullptr || rhs.sizes == nullptr)
|
||||
return false;
|
||||
return *sizes == *rhs.sizes;
|
||||
}
|
||||
|
||||
protected:
|
||||
TSmallArrayVector(const TSmallArrayVector&);
|
||||
|
||||
void alloc()
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
sizes = new TVector<unsigned int>;
|
||||
}
|
||||
void dealloc()
|
||||
{
|
||||
delete sizes;
|
||||
}
|
||||
|
||||
TVector<unsigned int>* sizes; // will either hold such a pointer, or in the future, hold the two array sizes
|
||||
};
|
||||
|
||||
//
|
||||
// Represent an array, or array of arrays, to arbitrary depth. This is not
|
||||
// done through a hierarchy of types, but localized into this single cumulative object.
|
||||
//
|
||||
// The arrayness in TTtype is a pointer, so that it can be non-allocated and zero
|
||||
// for the vast majority of types that are non-array types.
|
||||
//
|
||||
struct TArraySizes {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TArraySizes() : implicitArraySize(1) { }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TArraySizes& operator=(const TArraySizes& from)
|
||||
{
|
||||
implicitArraySize = from.implicitArraySize;
|
||||
sizes = from.sizes;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// translate from array-of-array semantics to container semantics
|
||||
int getNumDims() { return sizes.size(); }
|
||||
int getOuterSize() { return sizes.front(); }
|
||||
void setOuterSize(int s) { sizes.push_back((unsigned)s); }
|
||||
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
|
||||
int getImplicitSize() { return (int)implicitArraySize; }
|
||||
void setImplicitSize(int s) { implicitArraySize = s; }
|
||||
int operator[](int i) { return sizes[i]; }
|
||||
bool operator==(const TArraySizes& rhs) { return sizes == rhs.sizes; }
|
||||
|
||||
protected:
|
||||
TSmallArrayVector sizes;
|
||||
|
||||
TArraySizes(const TArraySizes&);
|
||||
|
||||
// for tracking maximum referenced index, before an explicit size is given
|
||||
// applies only to the outer-most dimension
|
||||
int implicitArraySize;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _ARRAYS_INCLUDED_
|
||||
Loading…
Add table
Add a link
Reference in a new issue