diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index e3c54d0f..fc0a36fa 100755 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -51,8 +51,10 @@ // including identifying what extensions are needed if a version does not allow a symbol // -#include "../Include/intermediate.h" #include "Initialize.h" +#include "../Include/intermediate.h" +#include "ScanContext.h" +#include "preprocessor/PpContext.h" namespace glslang { @@ -322,6 +324,32 @@ const CustomFunction CustomFunctions[] = { { 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 // one, to be returned in the passed in decls. 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 if (profile == EEsProfile) { // ES if (version >= 300) { - commonBuiltins.append("float texture(sampler2DArrayShadow, vec4, float);" - "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" - "float textureLod(sampler2DArrayShadow, vec4, float);" - "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" - "\n"); + textureShadowLodFunctions += "float texture(sampler2DArrayShadow, vec4, float);" + "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" + "float textureLod(sampler2DArrayShadow, vec4, float);" + "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" + "\n"; } if (version >= 320) { - commonBuiltins.append("float texture(samplerCubeArrayShadow, vec4, float, float);" - "float textureLod(samplerCubeShadow, vec4, float);" - "float textureLod(samplerCubeArrayShadow, vec4, float, float);" - "\n"); + textureShadowLodFunctions += "float texture(samplerCubeArrayShadow, vec4, float, float);" + "float textureLod(samplerCubeShadow, vec4, float);" + "float textureLod(samplerCubeArrayShadow, vec4, float, float);" + "\n"; } } else if (version >= 130) { // Desktop - commonBuiltins.append("float texture(sampler2DArrayShadow, vec4, float);" - "float texture(samplerCubeArrayShadow, vec4, float, float);" - "float textureOffset(sampler2DArrayShadow, vec4, ivec2);" - "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" - "float textureLod(sampler2DArrayShadow, vec4, float);" - "float textureLod(samplerCubeShadow, vec4, float);" - "float textureLod(samplerCubeArrayShadow, vec4, float, float);" - "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" - "\n"); + textureShadowLodFunctions += "float texture(sampler2DArrayShadow, vec4, float);" + "float texture(samplerCubeArrayShadow, vec4, float, float);" + "float textureOffset(sampler2DArrayShadow, vec4, ivec2);" + "float textureOffset(sampler2DArrayShadow, vec4, ivec2, float);" + "float textureLod(sampler2DArrayShadow, vec4, float);" + "float textureLod(samplerCubeShadow, vec4, float);" + "float textureLod(samplerCubeArrayShadow, vec4, float, float);" + "float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);" + "\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); } - // GL_EXT_texture_shadow_lod - // NOTE: These are the mangled names of individual overloads, since this extension adds overloads for - // existing built-in functions. - if (profile == EEsProfile) { - 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); + { + TempParser parser(textureShadowLodFunctions, language, version, profile, spvVersion); + parser.table.processAllSymbols([&symbolTable](TSymbol* sym) { + symbolTable.setSingleFunctionExtensions(sym->getMangledName().data(), 1, &E_GL_EXT_texture_shadow_lod); + }); } break; diff --git a/glslang/MachineIndependent/Initialize.h b/glslang/MachineIndependent/Initialize.h index 42c32ddb..b5652d37 100644 --- a/glslang/MachineIndependent/Initialize.h +++ b/glslang/MachineIndependent/Initialize.h @@ -105,6 +105,11 @@ protected: const char* postfixes[5]; const char* prefixes[EbtNumTypes]; 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 diff --git a/glslang/MachineIndependent/SymbolTable.h b/glslang/MachineIndependent/SymbolTable.h index edc79cb5..da23bbb8 100644 --- a/glslang/MachineIndependent/SymbolTable.h +++ b/glslang/MachineIndependent/SymbolTable.h @@ -487,6 +487,12 @@ public: return (*it).second; } + template void processAllSymbols(ProcSymFn procSym) const + { + for (auto itr : level) + procSym(itr.second); + } + void findFunctionNameList(const TString& name, TVector& list) { size_t parenAt = name.find_first_of('('); @@ -796,6 +802,15 @@ public: return symbol; } + template void processAllSymbols(ProcSymFn procSym) + { + int level = currentLevel(); + do { + table[level]->processAllSymbols(procSym); + --level; + } while (level >= 0); + } + void retargetSymbol(const TString& from, const TString& to) { int level = currentLevel(); table[level]->retargetSymbol(from, to);