Front-end: Handle simultaneous use of SPIR-V or non-SPIR-V.

Symbol table sharing has different sets of symbols for different
versions. This needs to take into account that SPIR-V has different
symbols than non-SPIR-V.
This commit is contained in:
John Kessenich 2016-06-28 16:16:43 -06:00
parent e5a807276f
commit 1011971981

View File

@ -81,42 +81,70 @@ TBuiltInParseables* CreateBuiltInParseables(TInfoSink& infoSink, EShSource sourc
// Local mapping functions for making arrays of symbol tables.... // Local mapping functions for making arrays of symbol tables....
const int VersionCount = 15; // index range in MapVersionToIndex
int MapVersionToIndex(int version) int MapVersionToIndex(int version)
{ {
int index = 0;
switch (version) { switch (version) {
case 100: return 0; case 100: index = 0; break;
case 110: return 1; case 110: index = 1; break;
case 120: return 2; case 120: index = 2; break;
case 130: return 3; case 130: index = 3; break;
case 140: return 4; case 140: index = 4; break;
case 150: return 5; case 150: index = 5; break;
case 300: return 6; case 300: index = 6; break;
case 330: return 7; case 330: index = 7; break;
case 400: return 8; case 400: index = 8; break;
case 410: return 9; case 410: index = 9; break;
case 420: return 10; case 420: index = 10; break;
case 430: return 11; case 430: index = 11; break;
case 440: return 12; case 440: index = 12; break;
case 310: return 13; case 310: index = 13; break;
case 450: return 14; case 450: index = 14; break;
default: // | default: break;
return 0; // | }
} // |
} // V assert(index < VersionCount);
const int VersionCount = 15; // number of case statements above
return index;
}
const int SpvVersionCount = 3; // index range in MapSpvVersionToIndex
int MapSpvVersionToIndex(const SpvVersion& spvVersion)
{
int index = 0;
if (spvVersion.openGl > 0)
index = 1;
else if (spvVersion.vulkan > 0)
index = 2;
assert(index < SpvVersionCount);
return index;
}
const int ProfileCount = 4; // index range in MapProfileToIndex
int MapProfileToIndex(EProfile profile) int MapProfileToIndex(EProfile profile)
{ {
int index = 0;
switch (profile) { switch (profile) {
case ENoProfile: return 0; case ENoProfile: index = 0; break;
case ECoreProfile: return 1; case ECoreProfile: index = 1; break;
case ECompatibilityProfile: return 2; case ECompatibilityProfile: index = 2; break;
case EEsProfile: return 3; case EEsProfile: index = 3; break;
default: // | default: break;
return 0; // | }
} // |
} // V assert(index < ProfileCount);
const int ProfileCount = 4; // number of case statements above
return index;
}
// only one of these needed for non-ES; ES needs 2 for different precision defaults of built-ins // only one of these needed for non-ES; ES needs 2 for different precision defaults of built-ins
enum EPrecisionClass { enum EPrecisionClass {
@ -133,8 +161,8 @@ enum EPrecisionClass {
// Each has a different set of built-ins, and we want to preserve that from // Each has a different set of built-ins, and we want to preserve that from
// compile to compile. // compile to compile.
// //
TSymbolTable* CommonSymbolTable[VersionCount][ProfileCount][EPcCount] = {}; TSymbolTable* CommonSymbolTable[VersionCount][SpvVersionCount][ProfileCount][EPcCount] = {};
TSymbolTable* SharedSymbolTables[VersionCount][ProfileCount][EShLangCount] = {}; TSymbolTable* SharedSymbolTables[VersionCount][SpvVersionCount][ProfileCount][EShLangCount] = {};
TPoolAllocator* PerProcessGPA = 0; TPoolAllocator* PerProcessGPA = 0;
@ -275,8 +303,9 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
// See if it's already been done for this version/profile combination // See if it's already been done for this version/profile combination
int versionIndex = MapVersionToIndex(version); int versionIndex = MapVersionToIndex(version);
int spvVersionIndex = MapSpvVersionToIndex(spvVersion);
int profileIndex = MapProfileToIndex(profile); int profileIndex = MapProfileToIndex(profile);
if (CommonSymbolTable[versionIndex][profileIndex][EPcGeneral]) { if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][EPcGeneral]) {
glslang::ReleaseGlobalLock(); glslang::ReleaseGlobalLock();
return; return;
@ -304,17 +333,18 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
// Copy the local symbol tables from the new pool to the global tables using the process-global pool // Copy the local symbol tables from the new pool to the global tables using the process-global pool
for (int precClass = 0; precClass < EPcCount; ++precClass) { for (int precClass = 0; precClass < EPcCount; ++precClass) {
if (! commonTable[precClass]->isEmpty()) { if (! commonTable[precClass]->isEmpty()) {
CommonSymbolTable[versionIndex][profileIndex][precClass] = new TSymbolTable; CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass] = new TSymbolTable;
CommonSymbolTable[versionIndex][profileIndex][precClass]->copyTable(*commonTable[precClass]); CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass]->copyTable(*commonTable[precClass]);
CommonSymbolTable[versionIndex][profileIndex][precClass]->readOnly(); CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass]->readOnly();
} }
} }
for (int stage = 0; stage < EShLangCount; ++stage) { for (int stage = 0; stage < EShLangCount; ++stage) {
if (! stageTables[stage]->isEmpty()) { if (! stageTables[stage]->isEmpty()) {
SharedSymbolTables[versionIndex][profileIndex][stage] = new TSymbolTable; SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage] = new TSymbolTable;
SharedSymbolTables[versionIndex][profileIndex][stage]->adoptLevels(*CommonSymbolTable[versionIndex][profileIndex][CommonIndex(profile, (EShLanguage)stage)]); SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->adoptLevels(*CommonSymbolTable
SharedSymbolTables[versionIndex][profileIndex][stage]->copyTable(*stageTables[stage]); [versionIndex][spvVersionIndex][profileIndex][CommonIndex(profile, (EShLanguage)stage)]);
SharedSymbolTables[versionIndex][profileIndex][stage]->readOnly(); SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->copyTable(*stageTables[stage]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->readOnly();
} }
} }
@ -616,6 +646,7 @@ bool ProcessDeferred(
SetupBuiltinSymbolTable(version, profile, spvVersion, source); SetupBuiltinSymbolTable(version, profile, spvVersion, source);
TSymbolTable* cachedTable = SharedSymbolTables[MapVersionToIndex(version)] TSymbolTable* cachedTable = SharedSymbolTables[MapVersionToIndex(version)]
[MapSpvVersionToIndex(spvVersion)]
[MapProfileToIndex(profile)] [MapProfileToIndex(profile)]
[compiler->getLanguage()]; [compiler->getLanguage()];
@ -1049,19 +1080,23 @@ void ShDestruct(ShHandle handle)
int __fastcall ShFinalize() int __fastcall ShFinalize()
{ {
for (int version = 0; version < VersionCount; ++version) { for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) { for (int p = 0; p < ProfileCount; ++p) {
for (int lang = 0; lang < EShLangCount; ++lang) { for (int lang = 0; lang < EShLangCount; ++lang) {
delete SharedSymbolTables[version][p][lang]; delete SharedSymbolTables[version][spvVersion][p][lang];
SharedSymbolTables[version][p][lang] = 0; SharedSymbolTables[version][spvVersion][p][lang] = 0;
}
} }
} }
} }
for (int version = 0; version < VersionCount; ++version) { for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) { for (int p = 0; p < ProfileCount; ++p) {
for (int pc = 0; pc < EPcCount; ++pc) { for (int pc = 0; pc < EPcCount; ++pc) {
delete CommonSymbolTable[version][p][pc]; delete CommonSymbolTable[version][spvVersion][p][pc];
CommonSymbolTable[version][p][pc] = 0; CommonSymbolTable[version][spvVersion][p][pc] = 0;
}
} }
} }
} }