Clean the implementation of GL_EXT_texture_shadow_lod.

Move the parameter verifictation to a centralized place where all the builtins
are verified for correctness.

Add verification for the new builtins with version and extension check
These builtins are supported on GLSL since version 130 and GLES since
version 300.
This commit is contained in:
Pankaj Mistry 2023-10-02 12:10:11 -07:00 committed by GitHub
parent 3f02132668
commit 5ff0c048b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 443 additions and 92 deletions

View file

@ -52,9 +52,6 @@
//
#include "Initialize.h"
#include "../Include/intermediate.h"
#include "ScanContext.h"
#include "preprocessor/PpContext.h"
namespace glslang {
@ -324,32 +321,6 @@ 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)
@ -4137,6 +4108,19 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"\n");
}
// Builtins for GL_EXT_texture_shadow_lod
if ((profile == EEsProfile && version >= 300) || ((profile != EEsProfile && version >= 130))) {
commonBuiltins.append(
"float texture(sampler2DArrayShadow, vec4, float);"
"float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureLod(sampler2DArrayShadow, vec4, float);"
"float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"float textureLodOffset(sampler2DArrayShadow, vec4, float, ivec2);"
"float textureOffset(sampler2DArrayShadow, vec4 , ivec2, float);"
"\n");
}
if (profile != EEsProfile && version >= 450) {
stageBuiltins[EShLangFragment].append(derivativesAndControl64bits);
stageBuiltins[EShLangFragment].append(
@ -4863,32 +4847,6 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
}
// GL_EXT_texture_shadow_lod overloads
if (profile == EEsProfile) { // ES
if (version >= 300) {
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) {
textureShadowLodFunctions += "float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"\n";
}
} else if (version >= 130) { // Desktop
textureShadowLodFunctions += "float texture(sampler2DArrayShadow, vec4, float);"
"float texture(samplerCubeArrayShadow, vec4, float, float);"
"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);
//============================================================================
//
@ -8816,13 +8774,6 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
symbolTable.setFunctionExtensions("textureBlockMatchSADQCOM", 1, &E_GL_QCOM_image_processing);
symbolTable.setFunctionExtensions("textureBlockMatchSSDQCOM", 1, &E_GL_QCOM_image_processing);
}
{
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;
case EShLangCompute: