Infrastructure: Make shared symbol-table cache complete, delete work around.

Fixes issue #370 and replaces PR #371.
This commit is contained in:
John Kessenich 2016-08-09 19:15:17 -06:00
parent 0b5214486b
commit 0a6fb85494
4 changed files with 43 additions and 54 deletions

View file

@ -146,6 +146,23 @@ int MapProfileToIndex(EProfile profile)
return index;
}
const int SourceCount = 2;
int MapSourceToIndex(EShSource source)
{
int index = 0;
switch (source) {
case EShSourceGlsl: index = 0; break;
case EShSourceHlsl: index = 1; break;
default: break;
}
assert(index < SourceCount);
return index;
}
// only one of these needed for non-ES; ES needs 2 for different precision defaults of built-ins
enum EPrecisionClass {
EPcGeneral,
@ -161,8 +178,8 @@ enum EPrecisionClass {
// Each has a different set of built-ins, and we want to preserve that from
// compile to compile.
//
TSymbolTable* CommonSymbolTable[VersionCount][SpvVersionCount][ProfileCount][EPcCount] = {};
TSymbolTable* SharedSymbolTables[VersionCount][SpvVersionCount][ProfileCount][EShLangCount] = {};
TSymbolTable* CommonSymbolTable[VersionCount][SpvVersionCount][ProfileCount][SourceCount][EPcCount] = {};
TSymbolTable* SharedSymbolTables[VersionCount][SpvVersionCount][ProfileCount][SourceCount][EShLangCount] = {};
TPoolAllocator* PerProcessGPA = 0;
@ -305,7 +322,8 @@ void SetupBuiltinSymbolTable(int version, EProfile profile, const SpvVersion& sp
int versionIndex = MapVersionToIndex(version);
int spvVersionIndex = MapSpvVersionToIndex(spvVersion);
int profileIndex = MapProfileToIndex(profile);
if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][EPcGeneral]) {
int sourceIndex = MapSourceToIndex(source);
if (CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][EPcGeneral]) {
glslang::ReleaseGlobalLock();
return;
@ -333,18 +351,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
for (int precClass = 0; precClass < EPcCount; ++precClass) {
if (! commonTable[precClass]->isEmpty()) {
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass] = new TSymbolTable;
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass]->copyTable(*commonTable[precClass]);
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][precClass]->readOnly();
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass] = new TSymbolTable;
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass]->copyTable(*commonTable[precClass]);
CommonSymbolTable[versionIndex][spvVersionIndex][profileIndex][sourceIndex][precClass]->readOnly();
}
}
for (int stage = 0; stage < EShLangCount; ++stage) {
if (! stageTables[stage]->isEmpty()) {
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage] = new TSymbolTable;
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->adoptLevels(*CommonSymbolTable
[versionIndex][spvVersionIndex][profileIndex][CommonIndex(profile, (EShLanguage)stage)]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->copyTable(*stageTables[stage]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][stage]->readOnly();
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage] = new TSymbolTable;
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->adoptLevels(*CommonSymbolTable
[versionIndex][spvVersionIndex][profileIndex][sourceIndex][CommonIndex(profile, (EShLanguage)stage)]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->copyTable(*stageTables[stage]);
SharedSymbolTables[versionIndex][spvVersionIndex][profileIndex][sourceIndex][stage]->readOnly();
}
}
@ -656,6 +674,7 @@ bool ProcessDeferred(
TSymbolTable* cachedTable = SharedSymbolTables[MapVersionToIndex(version)]
[MapSpvVersionToIndex(spvVersion)]
[MapProfileToIndex(profile)]
[MapSourceToIndex(source)]
[compiler->getLanguage()];
// Dynamically allocate the symbol table so we can control when it is deallocated WRT the pool.
@ -1092,9 +1111,11 @@ int __fastcall ShFinalize()
for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) {
for (int lang = 0; lang < EShLangCount; ++lang) {
delete SharedSymbolTables[version][spvVersion][p][lang];
SharedSymbolTables[version][spvVersion][p][lang] = 0;
for (int source = 0; source < SourceCount; ++source) {
for (int stage = 0; stage < EShLangCount; ++stage) {
delete SharedSymbolTables[version][spvVersion][p][source][stage];
SharedSymbolTables[version][spvVersion][p][source][stage] = 0;
}
}
}
}
@ -1103,9 +1124,11 @@ int __fastcall ShFinalize()
for (int version = 0; version < VersionCount; ++version) {
for (int spvVersion = 0; spvVersion < SpvVersionCount; ++spvVersion) {
for (int p = 0; p < ProfileCount; ++p) {
for (int pc = 0; pc < EPcCount; ++pc) {
delete CommonSymbolTable[version][spvVersion][p][pc];
CommonSymbolTable[version][spvVersion][p][pc] = 0;
for (int source = 0; source < SourceCount; ++source) {
for (int pc = 0; pc < EPcCount; ++pc) {
delete CommonSymbolTable[version][spvVersion][p][source][pc];
CommonSymbolTable[version][spvVersion][p][source][pc] = 0;
}
}
}
}