Skip to content

Commit

Permalink
Cleaning the implementation of GL_EXT_texture_shadow_lod. Moving the
Browse files Browse the repository at this point in the history
parameter verifictation to a centralized place where all ther builtins
are verified for correctness.
  • Loading branch information
pmistryNV committed Sep 28, 2023
1 parent 2bfacda commit fe61826
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Test/baseResults/spv.ext.texture_shadow_lod.error.frag.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spv.ext.texture_shadow_lod.error.frag
ERROR: 0:11: 'textureLod' : required extension not requested: GL_EXT_texture_shadow_lod
ERROR: 0:11: 'textureLod(..., float lod)' : required extension not requested: GL_EXT_texture_shadow_lod
ERROR: 1 compilation errors. No code generated.


Expand Down
71 changes: 17 additions & 54 deletions glslang/MachineIndependent/Initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
//

#include "Initialize.h"
#include "../Include/intermediate.h"
#include "ScanContext.h"
#include "preprocessor/PpContext.h"

namespace glslang {

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -4851,29 +4822,28 @@ 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";
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");
}
if (version >= 320) {
textureShadowLodFunctions += "float texture(samplerCubeArrayShadow, vec4, float, float);"
"float textureLod(samplerCubeShadow, vec4, float);"
"float textureLod(samplerCubeArrayShadow, vec4, float, float);"
"\n";
commonBuiltins.append("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("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);

//============================================================================
//
Expand Down Expand Up @@ -8796,13 +8766,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:
Expand Down
5 changes: 0 additions & 5 deletions glslang/MachineIndependent/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ class TBuiltIns : public TBuiltInParseables {
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
Expand Down
50 changes: 50 additions & 0 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,43 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
}
break;
}

case EOpTexture:
case EOpTextureLod:
{
if ((fnCandidate.getParamCount() > 2) &&
((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) &&
fnCandidate[0].type->getSampler().shadow &&
!isEsProfile() && version >= 400) {

featureString = fnCandidate.getName();
if (callNode.getOp() == EOpTexture)
featureString += "(..., float bias)";
else
featureString += "(..., float lod)";
feature = featureString.c_str();

//2D Array Shadow
if (fnCandidate[0].type->getSampler().dim == Esd2D && fnCandidate[0].type->getSampler().arrayed)
{
profileRequires(loc, ~EEsProfile, 400, nullptr, feature);
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
} else if(fnCandidate[0].type->getSampler().dim == EsdCube && fnCandidate[0].type->getSampler().arrayed) {
// Cube Array Shadow
if (fnCandidate.getParamCount() > 3 ) {
profileRequires(loc, ~EEsProfile, 400, nullptr, feature);
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
}
} else if (fnCandidate[0].type->getSampler().dim == EsdCube && callNode.getOp() == EOpTextureLod) {
// Cube Array
profileRequires(loc, ~EEsProfile, 400, nullptr, feature);
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
}
}
break;
}

case EOpSparseTextureGather:
case EOpSparseTextureGatherOffset:
case EOpSparseTextureGatherOffsets:
Expand Down Expand Up @@ -2292,6 +2329,19 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "version <= 420");
}
}
if (callNode.getOp() == EOpTextureLodOffset ||
callNode.getOp() == EOpTextureOffset) {
TSampler s = arg0->getType().getSampler();
if (s.is2D() && s.isArrayed() && s.isShadow() &&
((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) &&
(fnCandidate.getParamCount() == 4)) {
featureString = fnCandidate.getName() + " for sampler2DArrayShadow";
feature = featureString.c_str();
profileRequires(loc, ~EEsProfile, 400, nullptr, feature);
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
}
}
}

break;
Expand Down
15 changes: 0 additions & 15 deletions glslang/MachineIndependent/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,6 @@ class TSymbolTableLevel {
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)
{
size_t parenAt = name.find_first_of('(');
Expand Down Expand Up @@ -807,15 +801,6 @@ class TSymbolTable {
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) {
int level = currentLevel();
table[level]->retargetSymbol(from, to);
Expand Down

0 comments on commit fe61826

Please sign in to comment.