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:
parent
3f02132668
commit
5ff0c048b7
15 changed files with 443 additions and 92 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -105,11 +105,6 @@ 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
|
||||
|
|
|
|||
|
|
@ -2172,6 +2172,37 @@ 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) {
|
||||
featureString = fnCandidate.getName();
|
||||
if (callNode.getOp() == EOpTexture)
|
||||
featureString += "(..., float bias)";
|
||||
else
|
||||
featureString += "(..., float lod)";
|
||||
feature = featureString.c_str();
|
||||
|
||||
if ((fnCandidate[0].type->getSampler().dim == Esd2D && fnCandidate[0].type->getSampler().arrayed) || //2D Array Shadow
|
||||
(fnCandidate[0].type->getSampler().dim == EsdCube && fnCandidate[0].type->getSampler().arrayed && fnCandidate.getParamCount() > 3) || // Cube Array Shadow
|
||||
(fnCandidate[0].type->getSampler().dim == EsdCube && callNode.getOp() == EOpTextureLod)) { // Cube Shadow
|
||||
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
|
||||
if (isEsProfile()) {
|
||||
if (version < 320 &&
|
||||
!extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
|
||||
error(loc, "GL_EXT_texture_shadow_lod not supported for this ES version", feature, "");
|
||||
else
|
||||
profileRequires(loc, EEsProfile, 320, nullptr, feature);
|
||||
} else { // Desktop
|
||||
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EOpSparseTextureGather:
|
||||
case EOpSparseTextureGatherOffset:
|
||||
case EOpSparseTextureGatherOffsets:
|
||||
|
|
@ -2286,12 +2317,36 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
|
|||
if (callNode.getOp() == EOpTextureOffset) {
|
||||
TSampler s = arg0->getType().getSampler();
|
||||
if (s.is2D() && s.isArrayed() && s.isShadow()) {
|
||||
if (isEsProfile())
|
||||
if (
|
||||
((*argp)[1]->getAsTyped()->getType().getBasicType() == EbtFloat) &&
|
||||
((*argp)[1]->getAsTyped()->getType().getVectorSize() == 4) &&
|
||||
(fnCandidate.getParamCount() == 4)) {
|
||||
featureString = fnCandidate.getName() + " for sampler2DArrayShadow";
|
||||
feature = featureString.c_str();
|
||||
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
|
||||
profileRequires(loc, EEsProfile, 300, nullptr, feature);
|
||||
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
|
||||
}
|
||||
else if (isEsProfile())
|
||||
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "ES Profile");
|
||||
else if (version <= 420)
|
||||
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "version <= 420");
|
||||
}
|
||||
}
|
||||
|
||||
if (callNode.getOp() == EOpTextureLodOffset) {
|
||||
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, 300, nullptr, feature);
|
||||
profileRequires(loc, ~EEsProfile, 130, nullptr, feature);
|
||||
requireExtensions(loc, 1, &E_GL_EXT_texture_shadow_lod, feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -492,12 +492,6 @@ public:
|
|||
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('(');
|
||||
|
|
@ -807,15 +801,6 @@ public:
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue