Use temporary parser for mangled names

Use a temporary parser to retrieve the mangled names of specific
function overloads. This is necessary for GL_EXT_texture_shadow_lod.
This commit is contained in:
Nathaniel Cesario 2023-08-23 22:44:33 -06:00 committed by arcady-lunarg
parent ffefbcd9f3
commit 0bbe74c709
3 changed files with 73 additions and 47 deletions

View File

@ -51,8 +51,10 @@
// including identifying what extensions are needed if a version does not allow a symbol // including identifying what extensions are needed if a version does not allow a symbol
// //
#include "../Include/intermediate.h"
#include "Initialize.h" #include "Initialize.h"
#include "../Include/intermediate.h"
#include "ScanContext.h"
#include "preprocessor/PpContext.h"
namespace glslang { namespace glslang {
@ -322,6 +324,32 @@ const CustomFunction CustomFunctions[] = {
{ EOpNull } { EOpNull }
}; };
// Creates a parser that is separate from the main parsing context and meant for temporary use
struct TempParser {
TempParser(const TString& str, EShLanguage language, int version, EProfile profile, SpvVersion spvVersion)
: interm(language), parseContext(table, interm, false, version, profile, spvVersion, language, sink, true,
EShMsgDefault, &dummyEntryPoint),
inputStr(str.data()), stringSize(str.size())
{
table.push();
parseContext.setScanContext(&scanContext);
parseContext.setPpContext(&context);
parseContext.parseShaderStrings(context, input, false);
}
TSymbolTable table;
TIntermediate interm;
TInfoSink sink;
TString dummyEntryPoint;
TParseContext parseContext;
TShader::ForbidIncluder includer;
TPpContext context{parseContext, "", includer};
TScanContext scanContext{parseContext};
const char* inputStr;
size_t stringSize;
TInputScanner input{1, &inputStr, &stringSize};
};
// For the given table of functions, add all the indicated prototypes for each // For the given table of functions, add all the indicated prototypes for each
// one, to be returned in the passed in decls. // one, to be returned in the passed in decls.
void AddTabledBuiltin(TString& decls, const BuiltInFunction& function) void AddTabledBuiltin(TString& decls, const BuiltInFunction& function)
@ -4823,29 +4851,30 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
// GL_EXT_texture_shadow_lod overloads // GL_EXT_texture_shadow_lod overloads
if (profile == EEsProfile) { // ES if (profile == EEsProfile) { // ES
if (version >= 300) { if (version >= 300) {
commonBuiltins.append("float texture(sampler2DArrayShadow, vec4, float);" textureShadowLodFunctions += "float texture(sampler2DArrayShadow, vec4, float);"
"float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);"
"float textureLod(sampler2DArrayShadow, vec4, float);" "float textureLod(sampler2DArrayShadow, vec4, float);"
"float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);"
"\n"); "\n";
} }
if (version >= 320) { if (version >= 320) {
commonBuiltins.append("float texture(samplerCubeArrayShadow, vec4, float, float);" textureShadowLodFunctions += "float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureLod(samplerCubeShadow, vec4, float);" "float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);" "float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"\n"); "\n";
} }
} else if (version >= 130) { // Desktop } else if (version >= 130) { // Desktop
commonBuiltins.append("float texture(sampler2DArrayShadow, vec4, float);" textureShadowLodFunctions += "float texture(sampler2DArrayShadow, vec4, float);"
"float texture(samplerCubeArrayShadow, vec4, float, float);" "float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureOffset(sampler2DArrayShadow, vec4, ivec2);" "float textureOffset(sampler2DArrayShadow, vec4, ivec2);"
"float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);"
"float textureLod(sampler2DArrayShadow, vec4, float);" "float textureLod(sampler2DArrayShadow, vec4, float);"
"float textureLod(samplerCubeShadow, vec4, float);" "float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);" "float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);"
"\n"); "\n";
} }
commonBuiltins.append(textureShadowLodFunctions);
//============================================================================ //============================================================================
// //
@ -8769,34 +8798,11 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setFunctionExtensions("textureBlockMatchSSDQCOM", 1, &E_GL_QCOM_image_processing); symbolTable.setFunctionExtensions("textureBlockMatchSSDQCOM", 1, &E_GL_QCOM_image_processing);
} }
// GL_EXT_texture_shadow_lod {
// NOTE: These are the mangled names of individual overloads, since this extension adds overloads for TempParser parser(textureShadowLodFunctions, language, version, profile, spvVersion);
// existing built-in functions. parser.table.processAllSymbols([&symbolTable](TSymbol* sym) {
if (profile == EEsProfile) { symbolTable.setSingleFunctionExtensions(sym->getMangledName().data(), 1, &E_GL_EXT_texture_shadow_lod);
if (version >= 300) { });
symbolTable.setSingleFunctionExtensions("texture(sAS21;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureOffset(sAS21;vf4;vi2;f1;", 1,
&E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sAS21;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLodOffset(sAS21;vf4;f1;vi2;", 1,
&E_GL_EXT_texture_shadow_lod);
}
if (version >= 320) {
symbolTable.setSingleFunctionExtensions("texture(sASC1;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("texture(sASC1;vf4;f1;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sASC1;vf4;f1;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sSC1;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
}
} else if (version >= 130) {
symbolTable.setSingleFunctionExtensions("texture(sAS21;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("texture(sASC1;vf4;f1;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureOffset(sAS21;vf4;vi2;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureOffset(sAS21;vf4;vi2;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sAS21;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sASC1;vf4;f1;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLod(sSC1;vf4;f1;", 1, &E_GL_EXT_texture_shadow_lod);
symbolTable.setSingleFunctionExtensions("textureLodOffset(sAS21;vf4;f1;vi2;", 1,
&E_GL_EXT_texture_shadow_lod);
} }
break; break;

View File

@ -105,6 +105,11 @@ protected:
const char* postfixes[5]; const char* postfixes[5];
const char* prefixes[EbtNumTypes]; const char* prefixes[EbtNumTypes];
int dimMap[EsdNumDims]; int dimMap[EsdNumDims];
private:
// Holds the function declarations for GL_EXT_texture_shadow_lod
// This extension is somewhat unique in the sense it defines overloads for built-in functions, rather than new functions.
TString textureShadowLodFunctions;
}; };
// change this back to false if depending on textual spellings of texturing calls when consuming the AST // change this back to false if depending on textual spellings of texturing calls when consuming the AST

View File

@ -487,6 +487,12 @@ public:
return (*it).second; return (*it).second;
} }
template <typename ProcSymFn> void processAllSymbols(ProcSymFn procSym) const
{
for (auto itr : level)
procSym(itr.second);
}
void findFunctionNameList(const TString& name, TVector<const TFunction*>& list) void findFunctionNameList(const TString& name, TVector<const TFunction*>& list)
{ {
size_t parenAt = name.find_first_of('('); size_t parenAt = name.find_first_of('(');
@ -796,6 +802,15 @@ public:
return symbol; return symbol;
} }
template <typename ProcSymFn> void processAllSymbols(ProcSymFn procSym)
{
int level = currentLevel();
do {
table[level]->processAllSymbols(procSym);
--level;
} while (level >= 0);
}
void retargetSymbol(const TString& from, const TString& to) { void retargetSymbol(const TString& from, const TString& to) {
int level = currentLevel(); int level = currentLevel();
table[level]->retargetSymbol(from, to); table[level]->retargetSymbol(from, to);