Commit e141d5c9 by John Kessenich

Replace flat 110 sampler type space with an orthogonalized 430 sampler type…

Replace flat 110 sampler type space with an orthogonalized 430 sampler type space. Invoke it for all the sampler types in the 4.3 grammar. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20652 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent e396a226
......@@ -38,33 +38,20 @@
#define _BASICTYPES_INCLUDED_
//
// Basic type. Arrays, vectors, etc., are orthogonal to this.
// Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
//
enum TBasicType {
EbtVoid,
EbtFloat,
EbtDouble,
EbtInt,
EbtUint,
EbtBool,
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler1D,
EbtSampler2D,
EbtSampler3D,
EbtSamplerCube,
EbtSampler1DShadow,
EbtSampler2DShadow,
EbtSamplerRect, // ARB_texture_rectangle
EbtSamplerRectShadow, // ARB_texture_rectangle
EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtSampler,
EbtStruct,
EbtNumTypes
};
__inline bool IsSampler(TBasicType type)
{
return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
}
//
// Qualifiers and built-ins. These are mainly used to see what can be read
// or written, and by the machine dependent translator to know which registers
......
......@@ -41,6 +41,68 @@
#include "../Include/BaseTypes.h"
//
// Details within a sampler type
//
enum TSamplerDim {
EsdNone,
Esd1D,
Esd2D,
Esd3D,
EsdCube,
EsdRect,
EsdBuffer
};
struct TSampler {
TBasicType type : 8; // type returned by sampler
TSamplerDim dim : 8;
bool arrayed : 1;
bool shadow : 1;
bool ms : 1;
bool image : 1;
void clear()
{
type = EbtVoid;
dim = EsdNone;
arrayed = false;
shadow = false;
ms = false;
image = false;
}
void set(TBasicType t, TSamplerDim d, bool a = false, bool s = false, bool m = false)
{
type = t;
dim = d;
arrayed = a;
shadow = s;
ms = m;
image = false;
}
void setImage(TBasicType t, TSamplerDim d, bool a = false, bool s = false, bool m = false)
{
type = t;
dim = d;
arrayed = a;
shadow = s;
ms = m;
image = true;
}
bool operator==(const TSampler& right) const
{
return type == right.type &&
dim == right.dim &&
arrayed == right.arrayed &&
shadow == right.shadow &&
ms == right.ms &&
image == right.image;
}
};
//
// Need to have association of line numbers to types in a list for building structs.
//
class TType;
......@@ -93,6 +155,7 @@ public:
class TPublicType {
public:
TBasicType type;
TSampler sampler;
TQualifier qualifier;
int vectorSize : 4;
int matrixCols : 4;
......@@ -121,6 +184,7 @@ public:
void init(int line = 0, bool global = false)
{
initType(line);
sampler.clear();
initQualifiers(global);
}
......@@ -150,16 +214,18 @@ public:
explicit TType(TBasicType t, TStorageQualifier q = EvqTemporary, int vs = 1, int mc = 0, int mr = 0) :
type(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(0),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0),
fieldName(0), mangled(0), typeName(0)
fieldName(0), mangled(0), typeName(0)
{
sampler.clear();
qualifier.storage = q;
qualifier.precision = EpqNone;
}
TType(TBasicType t, TStorageQualifier q, TPrecisionQualifier p, int vs = 1, int mc = 0, int mr = 0) :
type(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(0),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0),
fieldName(0), mangled(0), typeName(0)
fieldName(0), mangled(0), typeName(0)
{
sampler.clear();
qualifier.storage = q;
qualifier.precision = p;
assert(p >= 0 && p <= EpqHigh);
......@@ -168,6 +234,7 @@ public:
type(p.type), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), arraySizes(p.arraySizes),
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
{
sampler = p.sampler;
qualifier = p.qualifier;
if (p.userDef) {
structure = p.userDef->getStruct();
......@@ -176,8 +243,9 @@ public:
}
explicit TType(TTypeList* userDef, const TString& n) :
type(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0), arraySizes(0),
structure(userDef), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0)
structure(userDef), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0)
{
sampler.clear();
qualifier.storage = EvqTemporary;
qualifier.precision = EpqNone;
typeName = NewPoolTString(n.c_str());
......@@ -190,6 +258,7 @@ public:
void copyType(const TType& copyOf, const TStructureMap& remapper)
{
type = copyOf.type;
sampler = copyOf.sampler;
qualifier = copyOf.qualifier;
vectorSize = copyOf.vectorSize;
matrixCols = copyOf.matrixCols;
......@@ -257,7 +326,7 @@ public:
}
virtual void setElementType(TBasicType t, int s, int mc, int mr, const TType* userDef)
{
{
type = t;
vectorSize = s;
matrixCols = mc;
......@@ -283,7 +352,7 @@ public:
virtual TBasicType getBasicType() const { return type; }
virtual TQualifier& getQualifier() { 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; }
......@@ -305,20 +374,13 @@ public:
virtual bool isVector() const { return vectorSize > 1; }
static const char* getBasicString(TBasicType t) {
switch (t) {
case EbtVoid: return "void"; break;
case EbtFloat: return "float"; break;
case EbtDouble: return "double"; break;
case EbtInt: return "int"; break;
case EbtBool: return "bool"; break;
case EbtSampler1D: return "sampler1D"; break;
case EbtSampler2D: return "sampler2D"; break;
case EbtSampler3D: return "sampler3D"; break;
case EbtSamplerCube: return "samplerCube"; break;
case EbtSampler1DShadow: return "sampler1DShadow"; break;
case EbtSampler2DShadow: return "sampler2DShadow"; break;
case EbtSamplerRect: return "samplerRect"; break; // ARB_texture_rectangle
case EbtSamplerRectShadow: return "samplerRectShadow"; break; // ARB_texture_rectangle
case EbtStruct: return "structure"; break;
case EbtVoid: return "void";
case EbtFloat: return "float";
case EbtDouble: return "double";
case EbtInt: return "int";
case EbtBool: return "bool";
case EbtSampler: return "sampler/image";
case EbtStruct: return "structure";
default: return "unknown type";
}
}
......@@ -345,7 +407,8 @@ public:
}
TTypeList* getStruct() const { return structure; }
TString& getMangledName() {
TString& getMangledName()
{
if (!mangled) {
mangled = NewPoolTString("");
buildMangledName(*mangled);
......@@ -354,25 +417,30 @@ public:
return *mangled;
}
bool sameElementType(const TType& right) const {
bool sameElementType(const TType& right) const
{
return type == right.type &&
sampler == right.sampler &&
vectorSize == right.vectorSize &&
matrixCols == right.matrixCols &&
matrixRows == right.matrixRows &&
structure == right.structure;
}
bool operator==(const TType& right) const {
return type == right.type &&
vectorSize == right.vectorSize &&
matrixCols == right.matrixCols &&
matrixRows == right.matrixRows &&
(arraySizes == 0 && right.arraySizes == 0 || (arraySizes && right.arraySizes && *arraySizes == *right.arraySizes)) &&
structure == right.structure;
bool operator==(const TType& right) const
{
return sameElementType(right) &&
(arraySizes == 0 && right.arraySizes == 0 ||
(arraySizes && right.arraySizes && *arraySizes == *right.arraySizes));
// 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
{
return !operator==(right);
}
TString getCompleteString() const;
protected:
......@@ -383,6 +451,7 @@ protected:
int vectorSize : 4;
int matrixCols : 4;
int matrixRows : 4;
TSampler sampler;
TQualifier qualifier;
TArraySizes arraySizes;
......
......@@ -347,14 +347,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
//
switch (node->getBasicType()) {
case EbtVoid:
case EbtSampler1D:
case EbtSampler2D:
case EbtSampler3D:
case EbtSamplerCube:
case EbtSampler1DShadow:
case EbtSampler2DShadow:
case EbtSamplerRect: // ARB_texture_rectangle
case EbtSamplerRectShadow: // ARB_texture_rectangle
case EbtSampler:
return 0;
default: break;
}
......
......@@ -54,13 +54,12 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, E
case EShLangVertex:
defaultPrecision[EbtInt] = EpqHigh;
defaultPrecision[EbtFloat] = EpqHigh;
defaultPrecision[EbtSampler2D] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow;
defaultPrecision[EbtSampler] = EpqLow;
//?? what about different sampler types?
break;
case EShLangFragment:
defaultPrecision[EbtInt] = EpqMedium;
defaultPrecision[EbtSampler2D] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow;
defaultPrecision[EbtSampler] = EpqLow;
// TODO: give error when using float in frag shader without default precision
break;
default:
......@@ -339,14 +338,7 @@ bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* nod
// Type that can't be written to?
//
switch (node->getBasicType()) {
case EbtSampler1D:
case EbtSampler2D:
case EbtSampler3D:
case EbtSamplerCube:
case EbtSampler1DShadow:
case EbtSampler2DShadow:
case EbtSamplerRect: // ARB_texture_rectangle
case EbtSamplerRectShadow: // ARB_texture_rectangle
case EbtSampler:
message = "can't modify a sampler";
break;
case EbtVoid:
......@@ -562,7 +554,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction
error(line, "constructor argument does not have a type", "constructor", "");
return true;
}
if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) {
if (op != EOpConstructStruct && typed->getBasicType() == EbtSampler) {
error(line, "cannot convert a sampler", "constructor", "");
return true;
}
......@@ -626,7 +618,7 @@ bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const
}
return false;
} else if (IsSampler(pType.type)) {
} else if (pType.type == EbtSampler) {
error(line, reason, TType::getBasicString(pType.type), "");
return true;
......@@ -670,7 +662,7 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType
return true;
}
if (pType.qualifier.storage != EvqUniform && samplerErrorCheck(line, pType, "samplers must be uniform"))
if (pType.qualifier.storage != EvqUniform && samplerErrorCheck(line, pType, "samplers and images must be uniform"))
return true;
return false;
......@@ -678,7 +670,8 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType
void TParseContext::setDefaultPrecision(int line, TBasicType type, TPrecisionQualifier qualifier)
{
if (IsSampler(type) || type == EbtInt || type == EbtFloat) {
//?? what about different sampler types?
if (type == EbtSampler || type == EbtInt || type == EbtFloat) {
defaultPrecision[type] = qualifier;
} else {
error(line, "cannot apply precision statement to this type", TType::getBasicString(type), "");
......@@ -689,7 +682,7 @@ void TParseContext::setDefaultPrecision(int line, TBasicType type, TPrecisionQua
bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier qualifier, const TType& type)
{
if ((qualifier == EvqOut || qualifier == EvqInOut) &&
type.getBasicType() != EbtStruct && IsSampler(type.getBasicType())) {
type.getBasicType() != EbtStruct && type.getBasicType() == EbtSampler) {
error(line, "samplers cannot be output parameters", type.getBasicString(), "");
return true;
}
......@@ -699,7 +692,7 @@ bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier quali
bool TParseContext::containsSampler(const TType& type)
{
if (IsSampler(type.getBasicType()))
if (type.getBasicType() == EbtSampler)
return true;
if (type.getBasicType() == EbtStruct) {
......
......@@ -60,14 +60,28 @@ void TType::buildMangledName(TString& mangledName)
case EbtDouble: mangledName += 'd'; break;
case EbtInt: mangledName += 'i'; break;
case EbtBool: mangledName += 'b'; break;
case EbtSampler1D: mangledName += "s1"; break;
case EbtSampler2D: mangledName += "s2"; break;
case EbtSampler3D: mangledName += "s3"; break;
case EbtSamplerCube: mangledName += "sC"; break;
case EbtSampler1DShadow: mangledName += "sS1"; break;
case EbtSampler2DShadow: mangledName += "sS2"; break;
case EbtSamplerRect: mangledName += "sR2"; break; // ARB_texture_rectangle
case EbtSamplerRectShadow: mangledName += "sSR2"; break; // ARB_texture_rectangle
case EbtSampler:
switch (sampler.type) {
case EbtInt: mangledName += "i"; break;
case EbtUint: mangledName += "u"; break;
}
if (sampler.image)
mangledName += "I";
else
mangledName += "s";
if (sampler.arrayed)
mangledName += "A";
if (sampler.shadow)
mangledName += "S";
switch (sampler.dim) {
case Esd1D: mangledName += "1"; break;
case Esd2D: mangledName += "2"; break;
case Esd3D: mangledName += "3"; break;
case EsdCube: mangledName += "C"; break;
case EsdRect: mangledName += "R2"; break;
case EsdBuffer: mangledName += "B"; break;
}
break;
case EbtStruct:
mangledName += "struct-";
if (typeName)
......
......@@ -77,9 +77,37 @@ TString TType::getCompleteString() const
else if (vectorSize > 1)
p += snprintf(p, end - p, "%d-component vector of ", vectorSize);
snprintf(p, end - p, "%s", getBasicString());
*p = 0;
TString s(buf);
if (type == EbtSampler) {
switch (sampler.type) {
case EbtFloat: break;
case EbtInt: s.append("i"); break;
case EbtUint: s.append("u"); break;
}
if (sampler.image)
s.append("image");
else
s.append("sampler");
switch (sampler.dim) {
case Esd1D: s.append("1D"); break;
case Esd2D: s.append("2D"); break;
case Esd3D: s.append("3D"); break;
case EsdCube: s.append("Cube"); break;
case EsdRect: s.append("Rect"); break;
case EsdBuffer: s.append("Buffer"); break;
}
if (sampler.arrayed)
s.append("Array");
if (sampler.shadow)
s.append("Shadow");
if (sampler.ms)
s.append("MS");
} else
s.append(getBasicString());
return TString(buf);
return s;
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment