Put in infrastructure for tessellation, geometry, and compute stages, and partially flesh out with built-in functions.

Added the built-in functions EmitVertex(), EndPrimitive(), barrier(), memoryBarrier(), memoryBarrierAtomicCounter(), memoryBarrierBuffer(), memoryBarrierImage(), memoryBarrierShared(), and groupMemoryBarrier().

Have not added any new built-in variables.

Also changed the linear performance relateToOperator() to a high-performance version.


git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22659 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-08-09 17:14:49 +00:00
parent 317f1af217
commit c027579631
28 changed files with 520 additions and 299 deletions

View file

@ -213,6 +213,19 @@ enum TOperator {
EOpMatrixInverse,
EOpTranspose,
EOpEmitVertex, // geometry only
EOpEndPrimitive, // geometry only
EOpEmitStreamVertex, // geometry only
EOpEndStreamPrimitive, // geometry only
EOpBarrier,
EOpMemoryBarrier,
EOpMemoryBarrierAtomicCounter,
EOpMemoryBarrierBuffer,
EOpMemoryBarrierImage,
EOpMemoryBarrierShared, // compute only
EOpGroupMemoryBarrier, // compute only
EOpAny,
EOpAll,

View file

@ -402,6 +402,11 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TType& returnType,
newConstArray = new constUnion[1];
break;
case EOpEmitStreamVertex:
case EOpEndStreamPrimitive:
// These don't actually fold
return 0;
default:
newConstArray = new constUnion[objectSize];
}

View file

@ -75,13 +75,6 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
// Initialize all the built-in strings for parsing.
//
TString BuiltInFunctions;
TString BuiltInFunctionsVertex;
TString BuiltInFunctionsFragment;
TString StandardVertexVaryings;
TString StandardFragmentVaryings;
TString StandardVertexAttributes;
TString StandardUniforms;
{
//============================================================================
@ -90,7 +83,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
//============================================================================
TString& s = BuiltInFunctions;
TString& s = commonBuiltins;
//
// Angle and Trigonometric Functions.
@ -655,7 +648,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
//============================================================================
TString& s = BuiltInFunctionsVertex;
TString& s = stageBuiltins[EShLangVertex];
//
// Geometric Functions.
@ -685,6 +678,45 @@ void TBuiltIns::initialize(int version, EProfile profile)
}
s.append(TString("\n"));
}
if (profile != EEsProfile && version >= 150) {
//============================================================================
//
// Prototypes for built-in functions seen by geometry shaders only.
//
//============================================================================
TString& s = stageBuiltins[EShLangGeometry];
if (version >= 400) {
s.append(TString("void EmitStreamVertex(int);"));
s.append(TString("void EndStreamPrimitive(int);"));
}
s.append(TString("void EmitVertex();"));
s.append(TString("void EndPrimitive();"));
s.append(TString("\n"));
}
if (profile != EEsProfile) {
//============================================================================
//
// Prototypes for all control functions.
//
//============================================================================
if (version >= 400)
stageBuiltins[EShLangTessControl].append("void barrier();");
if (version >= 430)
stageBuiltins[EShLangCompute].append("void barrier();");
if (version >= 420)
commonBuiltins.append("void memoryBarrier();");
if (version >= 430) {
commonBuiltins.append("void memoryBarrierAtomicCounter();");
commonBuiltins.append("void memoryBarrierBuffer();");
commonBuiltins.append("void memoryBarrierImage();");
stageBuiltins[EShLangCompute].append("void memoryBarrierShared();");
stageBuiltins[EShLangCompute].append("void groupMemoryBarrier();");
}
}
{
//============================================================================
//
@ -692,7 +724,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
//============================================================================
TString& s = BuiltInFunctionsFragment;
TString& s = stageBuiltins[EShLangFragment];
//
// Original-style texture Functions with bias.
@ -739,7 +771,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//
//============================================================================
TString& s = StandardUniforms;
TString& s = commonBuiltins;
//
// Depth range in window coordinates, p. 33
@ -884,7 +916,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//============================================================================
if (profile != EEsProfile) {
TString& s = StandardVertexAttributes;
TString& s = stageBuiltins[EShLangVertex];
if (version < 130) {
s.append(TString("attribute vec4 gl_Color;"));
@ -925,7 +957,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//============================================================================
if (profile != EEsProfile) {
TString& s = StandardVertexVaryings;
TString& s = stageBuiltins[EShLangVertex];
if (version < 130) {
s.append(TString("varying vec4 gl_FrontColor;"));
@ -953,7 +985,7 @@ void TBuiltIns::initialize(int version, EProfile profile)
//============================================================================
if (profile != EEsProfile) {
TString& s = StandardFragmentVaryings;
TString& s = stageBuiltins[EShLangFragment];
if (version < 130) {
s.append(TString("varying vec4 gl_Color;"));
s.append(TString("varying vec4 gl_SecondaryColor;"));
@ -970,29 +1002,8 @@ void TBuiltIns::initialize(int version, EProfile profile)
}
}
builtInStrings[EShLangFragment].push_back(BuiltInFunctions);
builtInStrings[EShLangFragment].push_back(BuiltInFunctionsFragment);
builtInStrings[EShLangFragment].push_back(StandardUniforms);
builtInStrings[EShLangFragment].push_back(StandardFragmentVaryings);
builtInStrings[EShLangVertex].push_back(BuiltInFunctions);
builtInStrings[EShLangVertex].push_back(BuiltInFunctionsVertex);
builtInStrings[EShLangVertex].push_back(StandardVertexVaryings);
builtInStrings[EShLangVertex].push_back(StandardVertexAttributes);
builtInStrings[EShLangVertex].push_back(StandardUniforms);
if (version >= 130)
add2ndGenerationSamplingImaging(version, profile);
#ifdef TEST_MODE
printf("VERTEX SYMBOLS \n");
for (unsigned int i = 0; i < builtInStrings[EShLangVertex].size(); ++i)
printf("%s", builtInStrings[EShLangVertex][i].c_str());
printf("FRAGMENT SYMBOLS \n");
for (unsigned int i = 0; i < builtInStrings[EShLangFragment].size(); ++i)
printf("%s", builtInStrings[EShLangFragment][i].c_str());
#endif
}
void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile)
@ -1074,7 +1085,7 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int versi
if (version < 430 && sampler.image)
return;
TString s;
TString& s = commonBuiltins;
if (profile == EEsProfile)
s.append("highp ");
int dims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0);
@ -1093,8 +1104,6 @@ void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int versi
s.append(",int);\n");
else
s.append(");\n");
builtInStrings[EShLangFragment].push_back(s);
builtInStrings[EShLangVertex].push_back(s);
// TODO: 4.2 Functionality: imaging functions
}
@ -1268,9 +1277,12 @@ void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int ve
if (! bias) {
functions[EShLangVertex].append(s);
// all stages other than fragment get this here too
functions[EShLangGeometry].append(s);
functions[EShLangTessControl].append(s);
functions[EShLangTessEvaluation].append(s);
functions[EShLangCompute].append(s);
}
functions[EShLangFragment].append(s);
commonBuiltins.append(s);
}
}
}
@ -1278,9 +1290,6 @@ void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int ve
}
}
}
builtInStrings[EShLangVertex].push_back(functions[EShLangVertex]);
builtInStrings[EShLangFragment].push_back(functions[EShLangFragment]);
}
void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, EShLanguage language)
@ -1288,8 +1297,6 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
//
// Initialize the context-dependent (resource-dependent) built-in strings for parsing.
//
TString StandardUniforms;
{
//============================================================================
//
@ -1297,7 +1304,7 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
//
//============================================================================
TString& s = StandardUniforms;
TString& s = commonBuiltins;
const int maxSize = 80;
char builtInConstant[maxSize];
@ -1435,9 +1442,6 @@ void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProf
s.append(TString("\n"));
}
builtInStrings[EShLangFragment].push_back(StandardUniforms);
builtInStrings[EShLangVertex].push_back(StandardUniforms);
}
void IdentifyBuiltIns(int version, EProfile profile, EShLanguage language, TSymbolTable& symbolTable)
@ -1448,6 +1452,30 @@ void IdentifyBuiltIns(int version, EProfile profile, EShLanguage language, TSymb
// the built-in text strings.
//
switch(language) {
case EShLangVertex:
pq = profile == EEsProfile ? EpqHigh : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EvqPosition, pq, 4)));
pq = profile == EEsProfile ? (version > 100 ? EpqHigh : EpqMedium) : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EvqPointSize, pq, 1)));
if (profile != EEsProfile)
symbolTable.insert(*new TVariable(NewPoolTString("gl_ClipVertex"), TType(EbtFloat, EvqClipVertex, 4)));
if (version >= 130) {
pq = profile == EEsProfile ? EpqHigh : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_VertexID"), TType(EbtInt, EvqVertexId, pq, 1)));
if (version >= 140)
symbolTable.insert(*new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EvqInstanceId, pq, 1)));
}
break;
case EShLangTessControl:
case EShLangTessEvaluation:
case EShLangGeometry:
// TODO: desktop functionality: support new stages
break;
case EShLangFragment:
symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EvqFace, 1)));
@ -1473,28 +1501,9 @@ void IdentifyBuiltIns(int version, EProfile profile, EShLanguage language, TSymb
}
break;
case EShLangVertex:
pq = profile == EEsProfile ? EpqHigh : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EvqPosition, pq, 4)));
pq = profile == EEsProfile ? (version > 100 ? EpqHigh : EpqMedium) : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EvqPointSize, pq, 1)));
if (profile != EEsProfile)
symbolTable.insert(*new TVariable(NewPoolTString("gl_ClipVertex"), TType(EbtFloat, EvqClipVertex, 4)));
if (version >= 130) {
pq = profile == EEsProfile ? EpqHigh : EpqNone;
symbolTable.insert(*new TVariable(NewPoolTString("gl_VertexID"), TType(EbtInt, EvqVertexId, pq, 1)));
if (version >= 140)
symbolTable.insert(*new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EvqInstanceId, pq, 1)));
}
break;
case EShLangTessControl:
case EShLangTessEvaluation:
case EShLangGeometry:
case EShLangCompute:
// TODO: desktop functionality: support new stages
break;
default:
assert(false && "Language not supported");
@ -1593,19 +1602,40 @@ void IdentifyBuiltIns(int version, EProfile profile, EShLanguage language, TSymb
symbolTable.relateToOperator("any", EOpAny);
symbolTable.relateToOperator("all", EOpAll);
switch(language) {
symbolTable.relateToOperator("barrier", EOpBarrier);
symbolTable.relateToOperator("memoryBarrier", EOpMemoryBarrier);
symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter);
symbolTable.relateToOperator("memoryBarrierBuffer", EOpMemoryBarrierBuffer);
symbolTable.relateToOperator("memoryBarrierImage", EOpMemoryBarrierImage);
switch(language) {
case EShLangVertex:
break;
case EShLangTessControl:
case EShLangTessEvaluation:
break;
case EShLangGeometry:
symbolTable.relateToOperator("EmitStreamVertex", EOpEmitStreamVertex);
symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive);
symbolTable.relateToOperator("EmitVertex", EOpEmitVertex);
symbolTable.relateToOperator("EndPrimitive", EOpEndPrimitive);
break;
case EShLangFragment:
symbolTable.relateToOperator("dFdx", EOpDPdx);
symbolTable.relateToOperator("dFdy", EOpDPdy);
symbolTable.relateToOperator("fwidth", EOpFwidth);
break;
default: assert(false && "Language not supported");
case EShLangCompute:
symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared);
symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier);
break;
default:
assert(false && "Language not supported");
}
}
@ -1628,6 +1658,7 @@ void IdentifyBuiltIns(int version, EProfile profile, EShLanguage language, TSymb
}
break;
default: break;
default:
break;
}
}

View file

@ -43,8 +43,6 @@
#include "SymbolTable.h"
#include "Versions.h"
typedef TVector<TString> TBuiltInStrings;
class TBuiltIns {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
@ -52,7 +50,8 @@ public:
virtual ~TBuiltIns();
void initialize(int version, EProfile);
void initialize(const TBuiltInResource& resources, int version, EProfile, EShLanguage);
TBuiltInStrings* getBuiltInStrings() { return builtInStrings; }
const TString& getCommonString() const { return commonBuiltins; }
const TString& getStageString(EShLanguage language) const { return stageBuiltins[language]; }
protected:
void add2ndGenerationSamplingImaging(int version, EProfile profile);
@ -60,7 +59,8 @@ protected:
void addImageFunctions(TSampler, TString& typeName, int version, EProfile profile);
void addSamplingFunctions(TSampler, TString& typeName, int version, EProfile profile);
TBuiltInStrings builtInStrings[EShLangCount];
TString commonBuiltins;
TString stageBuiltins[EShLangCount];
// Helpers for making text
const char* postfixes[5];

View file

@ -264,7 +264,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
return node;
}
TIntermTyped* TIntermediate::addBuiltInFunctionCall(TOperator op, bool unary, TIntermNode* childNode, const TType& returnType)
TIntermTyped* TIntermediate::addBuiltInFunctionCall(TSourceLoc loc, TOperator op, bool unary, TIntermNode* childNode, const TType& returnType)
{
if (unary) {
//
@ -279,9 +279,11 @@ TIntermTyped* TIntermediate::addBuiltInFunctionCall(TOperator op, bool unary, TI
return 0;
}
if (child->getAsConstantUnion())
return child->getAsConstantUnion()->fold(op, returnType, infoSink);
if (child->getAsConstantUnion()) {
TIntermTyped* folded = child->getAsConstantUnion()->fold(op, returnType, infoSink);
if (folded)
return folded;
}
TIntermUnary* node = new TIntermUnary(op);
node->setLoc(child->getLoc());
@ -299,7 +301,7 @@ TIntermTyped* TIntermediate::addBuiltInFunctionCall(TOperator op, bool unary, TI
return node;
} else {
// setAggregateOperater() calls fold() for constant folding
TIntermTyped* node = setAggregateOperator(childNode, op, returnType, childNode->getLoc());
TIntermTyped* node = setAggregateOperator(childNode, op, returnType, loc);
TPrecisionQualifier correctPrecision = returnType.getQualifier().precision;
if (correctPrecision == EpqNone && profile == EEsProfile) {

View file

@ -81,7 +81,7 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, bool pb,
defaultPrecision[EbtSampler] = EpqLow;
break;
default:
infoSink.info.message(EPrefixError, "unexpected language");
infoSink.info.message(EPrefixError, "unexpected es-profile stage");
}
}
@ -1965,13 +1965,11 @@ void TParseContext::updateTypedDefaults(TSourceLoc loc, TQualifier qualifier, co
if (qualifier.layoutPacking != ElpNone)
error(loc, "cannot specify packing on a variable declaration", id->c_str(), "");
} else if (qualifier.storage == EvqVaryingIn) {
if (qualifier.hasLayout() && language != EShLangVertex) {
if (qualifier.hasLayout() && language != EShLangVertex)
error(loc, "can only use location layout qualifier on a vertex input or fragment output", id->c_str(), "");
}
} else if (qualifier.storage == EvqVaryingOut) {
if (qualifier.hasLayout() && language != EShLangFragment) {
if (qualifier.hasLayout() && language != EShLangFragment)
error(loc, "can only use location layout qualifier on a vertex input or fragment output", id->c_str(), "");
}
} else {
if (qualifier.layoutMatrix != ElmNone ||
qualifier.layoutPacking != ElpNone)

View file

@ -89,7 +89,7 @@ TSymbolTable* SharedSymbolTables[VersionCount][EProfileCount][EShLangCount] = {}
TPoolAllocator* PerProcessGPA = 0;
bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfile profile, EShLanguage language, TInfoSink& infoSink,
bool InitializeSymbolTable(const TBuiltIns& builtIns, int version, EProfile profile, EShLanguage language, TInfoSink& infoSink,
const TBuiltInResource* resources, TSymbolTable* symbolTables)
{
TIntermediate intermediate(infoSink, version, profile);
@ -119,26 +119,25 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
symbolTable->push();
for (TBuiltInStrings::iterator i = BuiltInStrings[parseContext.language].begin();
i != BuiltInStrings[parseContext.language].end(); ++i) {
const char* builtInShaders[1];
int builtInLengths[1];
const char* builtInShaders[2];
int builtInLengths[2];
builtInShaders[0] = builtIns.getCommonString().c_str();
builtInLengths[0] = builtIns.getCommonString().size();
builtInShaders[1] = builtIns.getStageString(language).c_str();
builtInLengths[1] = builtIns.getStageString(language).size();
builtInShaders[0] = (*i).c_str();
builtInLengths[0] = (int) (*i).size();
if (! parseContext.parseShaderStrings(ppContext, const_cast<char**>(builtInShaders), builtInLengths, 1) != 0) {
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
printf("Unable to parse built-ins\n");
if (! parseContext.parseShaderStrings(ppContext, const_cast<char**>(builtInShaders), builtInLengths, 2) != 0) {
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
printf("Unable to parse built-ins\n");
return false;
}
return false;
}
if (resources) {
if (resources)
IdentifyBuiltIns(version, profile, parseContext.language, *symbolTable, *resources);
} else {
else
IdentifyBuiltIns(version, profile, parseContext.language, *symbolTable);
}
return true;
}
@ -147,8 +146,16 @@ bool GenerateBuiltInSymbolTable(TInfoSink& infoSink, TSymbolTable* symbolTables,
TBuiltIns builtIns;
builtIns.initialize(version, profile);
InitializeSymbolTable(builtIns.getBuiltInStrings(), version, profile, EShLangVertex, infoSink, 0, symbolTables);
InitializeSymbolTable(builtIns.getBuiltInStrings(), version, profile, EShLangFragment, infoSink, 0, symbolTables);
InitializeSymbolTable(builtIns, version, profile, EShLangVertex, infoSink, 0, symbolTables);
if (profile != EEsProfile && version >= 400) {
InitializeSymbolTable(builtIns, version, profile, EShLangTessControl, infoSink, 0, symbolTables);
InitializeSymbolTable(builtIns, version, profile, EShLangTessEvaluation, infoSink, 0, symbolTables);
}
if (profile != EEsProfile && version >= 150)
InitializeSymbolTable(builtIns, version, profile, EShLangGeometry, infoSink, 0, symbolTables);
InitializeSymbolTable(builtIns, version, profile, EShLangFragment, infoSink, 0, symbolTables);
if (profile != EEsProfile && version >= 430)
InitializeSymbolTable(builtIns, version, profile, EShLangCompute, infoSink, 0, symbolTables);
return true;
}
@ -158,7 +165,7 @@ bool AddContextSpecificSymbols(const TBuiltInResource* resources, TInfoSink& inf
TBuiltIns builtIns;
builtIns.initialize(*resources, version, profile, language);
InitializeSymbolTable(builtIns.getBuiltInStrings(), version, profile, language, infoSink, resources, symbolTables);
InitializeSymbolTable(builtIns, version, profile, language, infoSink, resources, symbolTables);
return true;
}
@ -207,10 +214,12 @@ void SetupBuiltinSymbolTable(int version, EProfile profile)
SetThreadPoolAllocator(*PerProcessGPA);
// Copy the symbol table from the new pool to the process-global pool
SharedSymbolTables[versionIndex][profile][EShLangVertex] = new TSymbolTable;
SharedSymbolTables[versionIndex][profile][EShLangVertex]->copyTable(symTables[EShLangVertex]);
SharedSymbolTables[versionIndex][profile][EShLangFragment] = new TSymbolTable;
SharedSymbolTables[versionIndex][profile][EShLangFragment]->copyTable(symTables[EShLangFragment]);
for (int stage = 0; stage < EShLangCount; ++stage) {
if (! symTables[stage].isEmpty()) {
SharedSymbolTables[versionIndex][profile][stage] = new TSymbolTable;
SharedSymbolTables[versionIndex][profile][stage]->copyTable(symTables[stage]);
}
}
delete builtInPoolAllocator;
SetThreadPoolAllocator(savedGPA);
@ -416,9 +425,18 @@ int ShCompile(
TIntermediate intermediate(compiler->infoSink, version, profile);
SetupBuiltinSymbolTable(version, profile);
TSymbolTable symbolTable(*SharedSymbolTables[MapVersionToIndex(version)]
[profile]
[compiler->getLanguage()]);
TSymbolTable* cachedTable = SharedSymbolTables[MapVersionToIndex(version)]
[profile]
[compiler->getLanguage()];
TSymbolTable* errorTable = 0;
if (! cachedTable) {
errorTable = new TSymbolTable;
cachedTable = errorTable;
}
TSymbolTable symbolTable(*cachedTable);
if (errorTable)
delete errorTable;
// Add built-in symbols that are potentially context dependent;
// they get popped again further down.
@ -436,13 +454,13 @@ int ShCompile(
if (! goodProfile)
parseContext.error(beginning, "incorrect", "#version", "");
parseContext.initializeExtensionBehavior();
if (versionStatementMissing)
parseContext.warn(beginning, "statement missing: use #version on first line of shader", "#version", "");
else if (profile == EEsProfile && version >= 300 && versionNotFirst)
parseContext.error(beginning, "statement must appear first in ESSL shader; before comments or newlines", "#version", "");
parseContext.initializeExtensionBehavior();
//
// Parse the application's shaders. All the following symbol table
// work will be throw-away, so push a new allocation scope that can

View file

@ -188,19 +188,20 @@ TSymbolTableLevel::~TSymbolTableLevel()
//
// Change all function entries in the table with the non-mangled name
// to be related to the provided built-in operation. This is a low
// performance operation, and only intended for symbol tables that
// live across a large number of compiles.
// to be related to the provided built-in operation.
//
void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
{
tLevel::iterator it;
for (it = level.begin(); it != level.end(); ++it) {
TFunction* function = (*it).second->getAsFunction();
if (function) {
if (function->getName() == name)
function->relateToOperator(op);
}
tLevel::const_iterator candidate = level.lower_bound(name);
while (candidate != level.end()) {
const TString& candidateName = (*candidate).first;
TString::size_type parenAt = candidateName.find_first_of('(');
if (parenAt != candidateName.npos && candidateName.substr(0, parenAt) == name) {
TFunction* function = (*candidate).second->getAsFunction();
function->relateToOperator(op);
} else
break;
++candidate;
}
}

View file

@ -373,10 +373,12 @@ public:
}
explicit TSymbolTable(TSymbolTable& symTable)
{
table.push_back(symTable.table[0]);
adoptedLevels = 1;
uniqueId = symTable.uniqueId;
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
if (! symTable.isEmpty()) {
table.push_back(symTable.table[0]);
adoptedLevels = 1;
uniqueId = symTable.uniqueId;
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
} // else should only be to handle error paths
}
~TSymbolTable()
{
@ -391,6 +393,9 @@ public:
// built-ins specific to a compile are at level 1 and the shader
// globals are at level 2.
//
// TODO: compile-time memory: have an even earlier level for all built-ins
// common to all stages. Currently, each stage has copy.
//
bool isEmpty() { return table.size() == 0; }
bool atBuiltInLevel() { return atSharedBuiltInLevel() || atDynamicBuiltInLevel(); }
bool atSharedBuiltInLevel() { return table.size() == 1; }

View file

@ -491,7 +491,7 @@ function_call
op = fnCandidate->getBuiltInOp();
if (builtIn && op != EOpNull) {
// A function call mapped to a built-in operation.
$$ = parseContext.intermediate.addBuiltInFunctionCall(op, fnCandidate->getParamCount() == 1, $1.intermNode, fnCandidate->getReturnType());
$$ = parseContext.intermediate.addBuiltInFunctionCall($1.loc, op, fnCandidate->getParamCount() == 1, $1.intermNode, fnCandidate->getReturnType());
if ($$ == 0) {
parseContext.error($1.intermNode->getLoc(), " wrong operand type", "Internal Error",
"built in unary operator function. Type: %s",

View file

@ -260,6 +260,9 @@ bool OutputUnary(bool /* preVisit */, TIntermUnary* node, TIntermTraverser* it)
case EOpAny: out.debug << "any"; break;
case EOpAll: out.debug << "all"; break;
case EOpEmitStreamVertex: out.debug << "EmitStreamVertex"; break;
case EOpEndStreamPrimitive: out.debug << "EndStreamPrimitive"; break;
default: out.debug.message(EPrefixError, "Bad unary op");
}
@ -355,6 +358,17 @@ bool OutputAggregate(bool /* preVisit */, TIntermAggregate* node, TIntermTravers
case EOpMul: out.debug << "component-wise multiply"; break;
case EOpOuterProduct: out.debug << "outer product"; break;
case EOpEmitVertex: out.debug << "EmitVertex"; break;
case EOpEndPrimitive: out.debug << "EndPrimitive"; break;
case EOpBarrier: out.debug << "Barrier"; break;
case EOpMemoryBarrier: out.debug << "MemoryBarrier"; break;
case EOpMemoryBarrierAtomicCounter: out.debug << "MemoryBarrierAtomicCounter"; break;
case EOpMemoryBarrierBuffer: out.debug << "MemoryBarrierBuffer"; break;
case EOpMemoryBarrierImage: out.debug << "MemoryBarrierImage"; break;
case EOpMemoryBarrierShared: out.debug << "MemoryBarrierShared"; break;
case EOpGroupMemoryBarrier: out.debug << "GroupMemoryBarrier"; break;
default: out.debug.message(EPrefixError, "Bad aggregation op");
}

View file

@ -60,7 +60,7 @@ public:
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc);
TIntermTyped* addUnaryMath(TOperator, TIntermNode* child, TSourceLoc);
TIntermTyped* addBuiltInFunctionCall(TOperator, bool unary, TIntermNode*, const TType& returnType);
TIntermTyped* addBuiltInFunctionCall(TSourceLoc line, TOperator, bool unary, TIntermNode*, const TType& returnType);
bool canImplicitlyPromote(TBasicType from, TBasicType to);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc);