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 @@ ...@@ -38,33 +38,20 @@
#define _BASICTYPES_INCLUDED_ #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 { enum TBasicType {
EbtVoid, EbtVoid,
EbtFloat, EbtFloat,
EbtDouble, EbtDouble,
EbtInt, EbtInt,
EbtUint,
EbtBool, EbtBool,
EbtGuardSamplerBegin, // non type: see implementation of IsSampler() EbtSampler,
EbtSampler1D,
EbtSampler2D,
EbtSampler3D,
EbtSamplerCube,
EbtSampler1DShadow,
EbtSampler2DShadow,
EbtSamplerRect, // ARB_texture_rectangle
EbtSamplerRectShadow, // ARB_texture_rectangle
EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtStruct, EbtStruct,
EbtNumTypes 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 // 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 // or written, and by the machine dependent translator to know which registers
......
...@@ -41,6 +41,68 @@ ...@@ -41,6 +41,68 @@
#include "../Include/BaseTypes.h" #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. // Need to have association of line numbers to types in a list for building structs.
// //
class TType; class TType;
...@@ -93,6 +155,7 @@ public: ...@@ -93,6 +155,7 @@ public:
class TPublicType { class TPublicType {
public: public:
TBasicType type; TBasicType type;
TSampler sampler;
TQualifier qualifier; TQualifier qualifier;
int vectorSize : 4; int vectorSize : 4;
int matrixCols : 4; int matrixCols : 4;
...@@ -121,6 +184,7 @@ public: ...@@ -121,6 +184,7 @@ public:
void init(int line = 0, bool global = false) void init(int line = 0, bool global = false)
{ {
initType(line); initType(line);
sampler.clear();
initQualifiers(global); initQualifiers(global);
} }
...@@ -152,6 +216,7 @@ public: ...@@ -152,6 +216,7 @@ public:
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)
{ {
sampler.clear();
qualifier.storage = q; qualifier.storage = q;
qualifier.precision = EpqNone; qualifier.precision = EpqNone;
} }
...@@ -160,6 +225,7 @@ public: ...@@ -160,6 +225,7 @@ public:
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)
{ {
sampler.clear();
qualifier.storage = q; qualifier.storage = q;
qualifier.precision = p; qualifier.precision = p;
assert(p >= 0 && p <= EpqHigh); assert(p >= 0 && p <= EpqHigh);
...@@ -168,6 +234,7 @@ public: ...@@ -168,6 +234,7 @@ public:
type(p.type), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), arraySizes(p.arraySizes), 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) structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
{ {
sampler = p.sampler;
qualifier = p.qualifier; qualifier = p.qualifier;
if (p.userDef) { if (p.userDef) {
structure = p.userDef->getStruct(); structure = p.userDef->getStruct();
...@@ -178,6 +245,7 @@ public: ...@@ -178,6 +245,7 @@ public:
type(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0), arraySizes(0), 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.storage = EvqTemporary;
qualifier.precision = EpqNone; qualifier.precision = EpqNone;
typeName = NewPoolTString(n.c_str()); typeName = NewPoolTString(n.c_str());
...@@ -190,6 +258,7 @@ public: ...@@ -190,6 +258,7 @@ public:
void copyType(const TType& copyOf, const TStructureMap& remapper) void copyType(const TType& copyOf, const TStructureMap& remapper)
{ {
type = copyOf.type; type = copyOf.type;
sampler = copyOf.sampler;
qualifier = copyOf.qualifier; qualifier = copyOf.qualifier;
vectorSize = copyOf.vectorSize; vectorSize = copyOf.vectorSize;
matrixCols = copyOf.matrixCols; matrixCols = copyOf.matrixCols;
...@@ -305,20 +374,13 @@ public: ...@@ -305,20 +374,13 @@ public:
virtual bool isVector() const { return vectorSize > 1; } virtual bool isVector() const { return vectorSize > 1; }
static const char* getBasicString(TBasicType t) { static const char* getBasicString(TBasicType t) {
switch (t) { switch (t) {
case EbtVoid: return "void"; break; case EbtVoid: return "void";
case EbtFloat: return "float"; break; case EbtFloat: return "float";
case EbtDouble: return "double"; break; case EbtDouble: return "double";
case EbtInt: return "int"; break; case EbtInt: return "int";
case EbtBool: return "bool"; break; case EbtBool: return "bool";
case EbtSampler1D: return "sampler1D"; break; case EbtSampler: return "sampler/image";
case EbtSampler2D: return "sampler2D"; break; case EbtStruct: return "structure";
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;
default: return "unknown type"; default: return "unknown type";
} }
} }
...@@ -345,7 +407,8 @@ public: ...@@ -345,7 +407,8 @@ public:
} }
TTypeList* getStruct() const { return structure; } TTypeList* getStruct() const { return structure; }
TString& getMangledName() { TString& getMangledName()
{
if (!mangled) { if (!mangled) {
mangled = NewPoolTString(""); mangled = NewPoolTString("");
buildMangledName(*mangled); buildMangledName(*mangled);
...@@ -354,25 +417,30 @@ public: ...@@ -354,25 +417,30 @@ 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 &&
sampler == right.sampler &&
vectorSize == right.vectorSize && vectorSize == right.vectorSize &&
matrixCols == right.matrixCols && matrixCols == right.matrixCols &&
matrixRows == right.matrixRows && matrixRows == right.matrixRows &&
structure == right.structure; structure == right.structure;
} }
bool operator==(const TType& right) const {
return type == right.type && bool operator==(const TType& right) const
vectorSize == right.vectorSize && {
matrixCols == right.matrixCols && return sameElementType(right) &&
matrixRows == right.matrixRows && (arraySizes == 0 && right.arraySizes == 0 ||
(arraySizes == 0 && right.arraySizes == 0 || (arraySizes && right.arraySizes && *arraySizes == *right.arraySizes)) && (arraySizes && right.arraySizes && *arraySizes == *right.arraySizes));
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
{
return !operator==(right); return !operator==(right);
} }
TString getCompleteString() const; TString getCompleteString() const;
protected: protected:
...@@ -383,6 +451,7 @@ protected: ...@@ -383,6 +451,7 @@ protected:
int vectorSize : 4; int vectorSize : 4;
int matrixCols : 4; int matrixCols : 4;
int matrixRows : 4; int matrixRows : 4;
TSampler sampler;
TQualifier qualifier; TQualifier qualifier;
TArraySizes arraySizes; TArraySizes arraySizes;
......
...@@ -347,14 +347,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt ...@@ -347,14 +347,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
// //
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtVoid: case EbtVoid:
case EbtSampler1D: case EbtSampler:
case EbtSampler2D:
case EbtSampler3D:
case EbtSamplerCube:
case EbtSampler1DShadow:
case EbtSampler2DShadow:
case EbtSamplerRect: // ARB_texture_rectangle
case EbtSamplerRectShadow: // ARB_texture_rectangle
return 0; return 0;
default: break; default: break;
} }
......
...@@ -54,13 +54,12 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, E ...@@ -54,13 +54,12 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, E
case EShLangVertex: case EShLangVertex:
defaultPrecision[EbtInt] = EpqHigh; defaultPrecision[EbtInt] = EpqHigh;
defaultPrecision[EbtFloat] = EpqHigh; defaultPrecision[EbtFloat] = EpqHigh;
defaultPrecision[EbtSampler2D] = EpqLow; defaultPrecision[EbtSampler] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow; //?? what about different sampler types?
break; break;
case EShLangFragment: case EShLangFragment:
defaultPrecision[EbtInt] = EpqMedium; defaultPrecision[EbtInt] = EpqMedium;
defaultPrecision[EbtSampler2D] = EpqLow; defaultPrecision[EbtSampler] = EpqLow;
defaultPrecision[EbtSamplerCube] = EpqLow;
// TODO: give error when using float in frag shader without default precision // TODO: give error when using float in frag shader without default precision
break; break;
default: default:
...@@ -339,14 +338,7 @@ bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* nod ...@@ -339,14 +338,7 @@ bool TParseContext::lValueErrorCheck(int line, const char* op, TIntermTyped* nod
// Type that can't be written to? // Type that can't be written to?
// //
switch (node->getBasicType()) { switch (node->getBasicType()) {
case EbtSampler1D: case EbtSampler:
case EbtSampler2D:
case EbtSampler3D:
case EbtSamplerCube:
case EbtSampler1DShadow:
case EbtSampler2DShadow:
case EbtSamplerRect: // ARB_texture_rectangle
case EbtSamplerRectShadow: // ARB_texture_rectangle
message = "can't modify a sampler"; message = "can't modify a sampler";
break; break;
case EbtVoid: case EbtVoid:
...@@ -562,7 +554,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction ...@@ -562,7 +554,7 @@ bool TParseContext::constructorErrorCheck(int line, TIntermNode* node, TFunction
error(line, "constructor argument does not have a type", "constructor", ""); error(line, "constructor argument does not have a type", "constructor", "");
return true; return true;
} }
if (op != EOpConstructStruct && IsSampler(typed->getBasicType())) { if (op != EOpConstructStruct && typed->getBasicType() == EbtSampler) {
error(line, "cannot convert a sampler", "constructor", ""); error(line, "cannot convert a sampler", "constructor", "");
return true; return true;
} }
...@@ -626,7 +618,7 @@ bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const ...@@ -626,7 +618,7 @@ bool TParseContext::samplerErrorCheck(int line, const TPublicType& pType, const
} }
return false; return false;
} else if (IsSampler(pType.type)) { } else if (pType.type == EbtSampler) {
error(line, reason, TType::getBasicString(pType.type), ""); error(line, reason, TType::getBasicString(pType.type), "");
return true; return true;
...@@ -670,7 +662,7 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType ...@@ -670,7 +662,7 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType
return true; 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 true;
return false; return false;
...@@ -678,7 +670,8 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType ...@@ -678,7 +670,8 @@ bool TParseContext::structQualifierErrorCheck(int line, const TPublicType& pType
void TParseContext::setDefaultPrecision(int line, TBasicType type, TPrecisionQualifier qualifier) 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; defaultPrecision[type] = qualifier;
} else { } else {
error(line, "cannot apply precision statement to this type", TType::getBasicString(type), ""); error(line, "cannot apply precision statement to this type", TType::getBasicString(type), "");
...@@ -689,7 +682,7 @@ void TParseContext::setDefaultPrecision(int line, TBasicType type, TPrecisionQua ...@@ -689,7 +682,7 @@ void TParseContext::setDefaultPrecision(int line, TBasicType type, TPrecisionQua
bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier qualifier, const TType& type) bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier qualifier, const TType& type)
{ {
if ((qualifier == EvqOut || qualifier == EvqInOut) && 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(), ""); error(line, "samplers cannot be output parameters", type.getBasicString(), "");
return true; return true;
} }
...@@ -699,7 +692,7 @@ bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier quali ...@@ -699,7 +692,7 @@ bool TParseContext::parameterSamplerErrorCheck(int line, TStorageQualifier quali
bool TParseContext::containsSampler(const TType& type) bool TParseContext::containsSampler(const TType& type)
{ {
if (IsSampler(type.getBasicType())) if (type.getBasicType() == EbtSampler)
return true; return true;
if (type.getBasicType() == EbtStruct) { if (type.getBasicType() == EbtStruct) {
......
...@@ -60,14 +60,28 @@ void TType::buildMangledName(TString& mangledName) ...@@ -60,14 +60,28 @@ void TType::buildMangledName(TString& mangledName)
case EbtDouble: mangledName += 'd'; break; case EbtDouble: mangledName += 'd'; break;
case EbtInt: mangledName += 'i'; break; case EbtInt: mangledName += 'i'; break;
case EbtBool: mangledName += 'b'; break; case EbtBool: mangledName += 'b'; break;
case EbtSampler1D: mangledName += "s1"; break; case EbtSampler:
case EbtSampler2D: mangledName += "s2"; break; switch (sampler.type) {
case EbtSampler3D: mangledName += "s3"; break; case EbtInt: mangledName += "i"; break;
case EbtSamplerCube: mangledName += "sC"; break; case EbtUint: mangledName += "u"; break;
case EbtSampler1DShadow: mangledName += "sS1"; break; }
case EbtSampler2DShadow: mangledName += "sS2"; break; if (sampler.image)
case EbtSamplerRect: mangledName += "sR2"; break; // ARB_texture_rectangle mangledName += "I";
case EbtSamplerRectShadow: mangledName += "sSR2"; break; // ARB_texture_rectangle 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: case EbtStruct:
mangledName += "struct-"; mangledName += "struct-";
if (typeName) if (typeName)
......
...@@ -77,9 +77,37 @@ TString TType::getCompleteString() const ...@@ -77,9 +77,37 @@ TString TType::getCompleteString() const
else if (vectorSize > 1) else if (vectorSize > 1)
p += snprintf(p, end - p, "%d-component vector of ", vectorSize); 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