From fb4f2333daa75beeb00747fbc1cb1e06b5077c40 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Fri, 9 Aug 2019 03:49:15 -0600 Subject: [PATCH] Web: Use isEsProfile() instead of run-time testing; remove more atomics Saves 2.5K, and design is better. --- SPIRV/GlslangToSpv.cpp | 4 + Test/baseResults/size | 2 +- glslang/Include/Types.h | 9 +- glslang/MachineIndependent/Initialize.cpp | 4 +- glslang/MachineIndependent/Intermediate.cpp | 12 +- .../MachineIndependent/ParseContextBase.cpp | 6 +- glslang/MachineIndependent/ParseHelper.cpp | 100 +++++++----- glslang/MachineIndependent/Scan.cpp | 150 +++++++++--------- glslang/MachineIndependent/ShaderLang.cpp | 2 - glslang/MachineIndependent/Versions.cpp | 8 +- glslang/MachineIndependent/glslang.m4 | 4 +- glslang/MachineIndependent/glslang.y | 4 +- glslang/MachineIndependent/glslang_tab.cpp | 4 +- glslang/MachineIndependent/linkValidate.cpp | 6 +- .../MachineIndependent/localintermediate.h | 3 + glslang/MachineIndependent/parseVersions.h | 2 + .../MachineIndependent/preprocessor/Pp.cpp | 2 +- 17 files changed, 168 insertions(+), 154 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index a91f1807..33c4db49 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -2075,6 +2075,7 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI spv::Builder::AccessChain::CoherentFlags lvalueCoherentFlags; +#ifndef GLSLANG_WEB if (node->getOp() == glslang::EOpAtomicCounterIncrement || node->getOp() == glslang::EOpAtomicCounterDecrement || node->getOp() == glslang::EOpAtomicCounter || @@ -2083,7 +2084,10 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI lvalueCoherentFlags = builder.getAccessChain().coherentFlags; lvalueCoherentFlags |= TranslateCoherent(operandNode->getAsTyped()->getType()); } else +#endif + { operand = accessChainLoad(node->getOperand()->getType()); + } OpDecorations decorations = { TranslatePrecisionDecoration(node->getOperationPrecision()), TranslateNoContractionDecoration(node->getType().getQualifier()), diff --git a/Test/baseResults/size b/Test/baseResults/size index 6de1c4d3..68d9adcc 100644 --- a/Test/baseResults/size +++ b/Test/baseResults/size @@ -1 +1 @@ -601088 ../build/install/bin/glslangValidator.exe +598528 ../build/install/bin/glslangValidator.exe diff --git a/glslang/Include/Types.h b/glslang/Include/Types.h index 9fa47faa..79c9efce 100644 --- a/glslang/Include/Types.h +++ b/glslang/Include/Types.h @@ -894,10 +894,6 @@ public: { return layoutPacking != ElpNone; } - bool hasOffset() const - { - return layoutOffset != layoutNotSet; - } bool hasAlign() const { return layoutAlign != layoutNotSet; @@ -921,6 +917,7 @@ public: return layoutBinding != layoutBindingEnd; } #ifdef GLSLANG_WEB + bool hasOffset() const { return false; } bool isNonPerspective() const { return false; } bool hasIndex() const { return false; } bool hasComponent() const { return false; } @@ -938,6 +935,10 @@ public: bool hasBufferReferenceAlign() const { return false; } bool isNonUniform() const { return false; } #else + bool hasOffset() const + { + return layoutOffset != layoutNotSet; + } bool isNonPerspective() const { return nopersp; } bool hasIndex() const { diff --git a/glslang/MachineIndependent/Initialize.cpp b/glslang/MachineIndependent/Initialize.cpp index 6e0090cc..798728ce 100644 --- a/glslang/MachineIndependent/Initialize.cpp +++ b/glslang/MachineIndependent/Initialize.cpp @@ -6166,14 +6166,14 @@ void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, c // enumerate all the types #ifdef GLSLANG_WEB const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint }; - const int image = 0; bool skipBuffer = true; bool skipCubeArrayed = true; + const int image = 0; #else const TBasicType bTypes[] = { EbtFloat, EbtInt, EbtUint, EbtFloat16 }; - for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140); bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130); + for (int image = 0; image <= 1; ++image) // loop over "bool" image vs sampler #endif { for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index fcc509dc..966040ba 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -1604,11 +1604,7 @@ bool TIntermediate::isFPIntegralConversion(TBasicType from, TBasicType to) const // bool TIntermediate::canImplicitlyPromote(TBasicType from, TBasicType to, TOperator op) const { -#ifdef GLSLANG_WEB - return false; -#endif - - if (profile == EEsProfile || version == 110) + if (isEsProfile() || version == 110) return false; if (from == to) @@ -1916,14 +1912,10 @@ static TBasicType getCorrespondingUnsignedType(TBasicType type) std::tuple TIntermediate::getConversionDestinatonType(TBasicType type0, TBasicType type1, TOperator op) const { -#ifdef GLSLANG_WEB - return std::make_tuple(EbtNumTypes, EbtNumTypes); -#endif - TBasicType res0 = EbtNumTypes; TBasicType res1 = EbtNumTypes; - if (profile == EEsProfile || version == 110) + if (isEsProfile() || version == 110) return std::make_tuple(res0, res1); if (getSource() == EShSourceHlsl) { diff --git a/glslang/MachineIndependent/ParseContextBase.cpp b/glslang/MachineIndependent/ParseContextBase.cpp index 9fbbe596..aebd834a 100644 --- a/glslang/MachineIndependent/ParseContextBase.cpp +++ b/glslang/MachineIndependent/ParseContextBase.cpp @@ -170,13 +170,13 @@ bool TParseContextBase::lValueErrorCheck(const TSourceLoc& loc, const char* op, case EbtSampler: message = "can't modify a sampler"; break; - case EbtAtomicUint: - message = "can't modify an atomic_uint"; - break; case EbtVoid: message = "can't modify void"; break; #ifndef GLSLANG_WEB + case EbtAtomicUint: + message = "can't modify an atomic_uint"; + break; case EbtAccStructNV: message = "can't modify accelerationStructureNV"; break; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index aa888e51..4ff266e2 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -60,9 +60,9 @@ TParseContext::TParseContext(TSymbolTable& symbolTable, TIntermediate& interm, b atomicUintOffsets(nullptr), anyIndexLimits(false) { // decide whether precision qualifiers should be ignored or respected - if (profile == EEsProfile || spvVersion.vulkan > 0) { + if (isEsProfile() || spvVersion.vulkan > 0) { precisionManager.respectPrecisionQualifiers(); - if (! parsingBuiltins && language == EShLangFragment && profile != EEsProfile && spvVersion.vulkan > 0) + if (! parsingBuiltins && language == EShLangFragment && !isEsProfile() && spvVersion.vulkan > 0) precisionManager.warnAboutDefaults(); } @@ -123,7 +123,7 @@ void TParseContext::setPrecisionDefaults() // replace with real precision defaults for those that have them if (obeyPrecisionQualifiers()) { - if (profile == EEsProfile) { + if (isEsProfile()) { // Most don't have defaults, a few default to lowp. TSampler sampler; sampler.set(EbtFloat, Esd2D); @@ -140,7 +140,7 @@ void TParseContext::setPrecisionDefaults() // is used to resolve the precision from the supplied arguments/operands instead. // So, we don't actually want to replace EpqNone with a default precision for built-ins. if (! parsingBuiltins) { - if (profile == EEsProfile && language == EShLangFragment) { + if (isEsProfile() && language == EShLangFragment) { defaultPrecision[EbtInt] = EpqMedium; defaultPrecision[EbtUint] = EpqMedium; } else { @@ -149,7 +149,7 @@ void TParseContext::setPrecisionDefaults() defaultPrecision[EbtFloat] = EpqHigh; } - if (profile != EEsProfile) { + if (!isEsProfile()) { // Non-ES profile // All sampler precisions default to highp. for (int type = 0; type < maxSamplerIndex; ++type) @@ -2049,7 +2049,7 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan } else { if (fnCandidate.getName().compare(0, 19, "imageAtomicExchange") != 0) error(loc, "only supported on integer images", fnCandidate.getName().c_str(), ""); - else if (imageType.getQualifier().getFormat() != ElfR32f && profile == EEsProfile) + else if (imageType.getQualifier().getFormat() != ElfR32f && isEsProfile()) error(loc, "only supported on image with format r32f", fnCandidate.getName().c_str(), ""); } @@ -2097,7 +2097,7 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan // // ES and desktop 4.3 and earlier: swizzles may not be used // desktop 4.4 and later: swizzles may be used - bool swizzleOkay = (profile != EEsProfile) && (version >= 440); + bool swizzleOkay = (!isEsProfile()) && (version >= 440); const TIntermTyped* base = TIntermediate::findLValueBase(arg0, swizzleOkay); if (base == nullptr || base->getType().getQualifier().storage != EvqVaryingIn) error(loc, "first argument must be an interpolant, or interpolant-array element", fnCandidate.getName().c_str(), ""); @@ -2318,7 +2318,7 @@ void TParseContext::nonOpBuiltInCheck(const TSourceLoc& loc, const TFunction& fn } else { if (fnCandidate.getName().compare(0, 19, "imageAtomicExchange") != 0) error(loc, "only supported on integer images", fnCandidate.getName().c_str(), ""); - else if (imageType.getQualifier().getFormat() != ElfR32f && profile == EEsProfile) + else if (imageType.getQualifier().getFormat() != ElfR32f && isEsProfile()) error(loc, "only supported on image with format r32f", fnCandidate.getName().c_str(), ""); } } @@ -2545,7 +2545,7 @@ bool TParseContext::lValueErrorCheck(const TSourceLoc& loc, const char* op, TInt case EvqFragDepth: intermediate.setDepthReplacing(); // "In addition, it is an error to statically write to gl_FragDepth in the fragment shader." - if (profile == EEsProfile && intermediate.getEarlyFragmentTests()) + if (isEsProfile() && intermediate.getEarlyFragmentTests()) message = "can't modify gl_FragDepth if using early_fragment_tests"; break; @@ -2639,7 +2639,7 @@ void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& ide // in undefined behavior." // however, before that, ES tests required an error. if (identifier.find("__") != TString::npos) { - if (profile == EEsProfile && version <= 300) + if (isEsProfile() && version <= 300) error(loc, "identifiers containing consecutive underscores (\"__\") are reserved, and an error if version <= 300", identifier.c_str(), ""); else warn(loc, "identifiers containing consecutive underscores (\"__\") are reserved", identifier.c_str(), ""); @@ -2664,13 +2664,13 @@ void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* iden else if (strncmp(identifier, "defined", 8) == 0) ppError(loc, "\"defined\" can't be (un)defined:", op, identifier); else if (strstr(identifier, "__") != 0) { - if (profile == EEsProfile && version >= 300 && + if (isEsProfile() && version >= 300 && (strcmp(identifier, "__LINE__") == 0 || strcmp(identifier, "__FILE__") == 0 || strcmp(identifier, "__VERSION__") == 0)) ppError(loc, "predefined names can't be (un)defined:", op, identifier); else { - if (profile == EEsProfile && version <= 300) + if (isEsProfile() && version <= 300) ppError(loc, "names containing consecutive underscores are reserved, and an error if version <= 300:", op, identifier); else ppWarn(loc, "names containing consecutive underscores are reserved:", op, identifier); @@ -2685,10 +2685,14 @@ void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* iden // bool TParseContext::lineContinuationCheck(const TSourceLoc& loc, bool endOfComment) { +#ifdef GLSLANG_WEB + return true; +#endif + const char* message = "line continuation"; - bool lineContinuationAllowed = (profile == EEsProfile && version >= 300) || - (profile != EEsProfile && (version >= 420 || extensionTurnedOn(E_GL_ARB_shading_language_420pack))); + bool lineContinuationAllowed = (isEsProfile() && version >= 300) || + (!isEsProfile() && (version >= 420 || extensionTurnedOn(E_GL_ARB_shading_language_420pack))); if (endOfComment) { if (lineContinuationAllowed) @@ -3414,8 +3418,8 @@ void TParseContext::mergeQualifiers(const TSourceLoc& loc, TQualifier& dst, cons error(loc, "can only have one interpolation qualifier (flat, smooth, noperspective, __explicitInterpAMD)", "", ""); // Ordering - if (! force && ((profile != EEsProfile && version < 420) || - (profile == EEsProfile && version < 310)) + if (! force && ((!isEsProfile() && version < 420) || + (isEsProfile() && version < 310)) && ! extensionTurnedOn(E_GL_ARB_shading_language_420pack)) { // non-function parameters if (src.isNoContraction() && (dst.invariant || dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone)) @@ -3752,16 +3756,15 @@ void TParseContext::arraySizesCheck(const TSourceLoc& loc, const TQualifier& qua error(loc, "only outermost dimension of an array of arrays can be a specialization constant", "[]", ""); // desktop always allows outer-dimension-unsized variable arrays, -#ifdef GLSLANG_WEB - return; -#else - if (profile != EEsProfile) + + if (!isEsProfile()) return; -#endif // for ES, if size isn't coming from an initializer, it has to be explicitly declared now, // with very few exceptions +#ifndef GLSLANG_WEB + // last member of ssbo block exception: if (qualifier.storage == EvqBuffer && lastMember) return; @@ -3770,27 +3773,27 @@ void TParseContext::arraySizesCheck(const TSourceLoc& loc, const TQualifier& qua switch (language) { case EShLangGeometry: if (qualifier.storage == EvqVaryingIn) - if ((profile == EEsProfile && version >= 320) || + if ((isEsProfile() && version >= 320) || extensionsTurnedOn(Num_AEP_geometry_shader, AEP_geometry_shader)) return; break; case EShLangTessControl: if ( qualifier.storage == EvqVaryingIn || (qualifier.storage == EvqVaryingOut && ! qualifier.patch)) - if ((profile == EEsProfile && version >= 320) || + if ((isEsProfile() && version >= 320) || extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader)) return; break; case EShLangTessEvaluation: if ((qualifier.storage == EvqVaryingIn && ! qualifier.patch) || qualifier.storage == EvqVaryingOut) - if ((profile == EEsProfile && version >= 320) || + if ((isEsProfile() && version >= 320) || extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader)) return; break; case EShLangMeshNV: if (qualifier.storage == EvqVaryingOut) - if ((profile == EEsProfile && version >= 320) || + if ((isEsProfile() && version >= 320) || extensionTurnedOn(E_GL_NV_mesh_shader)) return; break; @@ -3798,6 +3801,8 @@ void TParseContext::arraySizesCheck(const TSourceLoc& loc, const TQualifier& qua break; } +#endif + arraySizeRequiredCheck(loc, *arraySizes); } @@ -3995,7 +4000,7 @@ void TParseContext::checkAndResizeMeshViewDim(const TSourceLoc& loc, TType& type // source string number source-string-number. bool TParseContext::lineDirectiveShouldSetNextLine() const { - return profile == EEsProfile || version >= 330; + return isEsProfile() || version >= 330; } // @@ -4030,15 +4035,15 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS if (! builtInName(identifier) || symbolTable.atBuiltInLevel() || ! symbolTable.atGlobalLevel()) return nullptr; - bool nonEsRedecls = (profile != EEsProfile && (version >= 130 || identifier == "gl_TexCoord")); - bool esRedecls = (profile == EEsProfile && + bool nonEsRedecls = (!isEsProfile() && (version >= 130 || identifier == "gl_TexCoord")); + bool esRedecls = (isEsProfile() && (version >= 320 || extensionsTurnedOn(Num_AEP_shader_io_blocks, AEP_shader_io_blocks))); if (! esRedecls && ! nonEsRedecls) return nullptr; // Special case when using GL_ARB_separate_shader_objects bool ssoPre150 = false; // means the only reason this variable is redeclared is due to this combination - if (profile != EEsProfile && version <= 140 && extensionTurnedOn(E_GL_ARB_separate_shader_objects)) { + if (!isEsProfile() && version <= 140 && extensionTurnedOn(E_GL_ARB_separate_shader_objects)) { if (identifier == "gl_Position" || identifier == "gl_PointSize" || identifier == "gl_ClipVertex" || @@ -4722,18 +4727,18 @@ void TParseContext::finish() // about the stage itself. switch (language) { case EShLangGeometry: - if (profile == EEsProfile && version == 310) + if (isEsProfile() && version == 310) requireExtensions(getCurrentLoc(), Num_AEP_geometry_shader, AEP_geometry_shader, "geometry shaders"); break; case EShLangTessControl: case EShLangTessEvaluation: - if (profile == EEsProfile && version == 310) + if (isEsProfile() && version == 310) requireExtensions(getCurrentLoc(), Num_AEP_tessellation_shader, AEP_tessellation_shader, "tessellation shaders"); - else if (profile != EEsProfile && version < 400) + else if (!isEsProfile() && version < 400) requireExtensions(getCurrentLoc(), 1, &E_GL_ARB_tessellation_shader, "tessellation shaders"); break; case EShLangCompute: - if (profile != EEsProfile && version < 430) + if (!isEsProfile() && version < 430) requireExtensions(getCurrentLoc(), 1, &E_GL_ARB_compute_shader, "compute shaders"); break; case EShLangTaskNV: @@ -5672,18 +5677,22 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type) if (spvVersion.vulkan == 0 && lastBinding >= resources.maxCombinedTextureImageUnits) error(loc, "sampler binding not less than gl_MaxCombinedTextureImageUnits", "binding", type.isArray() ? "(using array)" : ""); } +#ifndef GLSLANG_WEB if (type.getBasicType() == EbtAtomicUint) { if (qualifier.layoutBinding >= (unsigned int)resources.maxAtomicCounterBindings) { error(loc, "atomic_uint binding is too large; see gl_MaxAtomicCounterBindings", "binding", ""); return; } } +#endif } else if (!intermediate.getAutoMapBindings()) { // some types require bindings +#ifndef GLSLANG_WEB // atomic_uint if (type.getBasicType() == EbtAtomicUint) error(loc, "layout(binding=X) is required", "atomic_uint", ""); +#endif // SPIR-V if (spvVersion.spv > 0) { @@ -5725,7 +5734,7 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type) if (type.getSampler().type == EbtUint && qualifier.getFormat() < ElfIntGuard) error(loc, "does not apply to unsigned integer images", TQualifier::getLayoutFormatString(qualifier.getFormat()), ""); - if (profile == EEsProfile) { + if (isEsProfile()) { // "Except for image variables qualified with the format qualifiers r32f, r32i, and r32ui, image variables must // specify either memory qualifier readonly or the memory qualifier writeonly." if (! (qualifier.getFormat() == ElfR32f || qualifier.getFormat() == ElfR32i || qualifier.getFormat() == ElfR32ui)) { @@ -5807,7 +5816,7 @@ void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier case EvqVaryingIn: { const char* feature = "location qualifier on input"; - if (profile == EEsProfile && version < 310) + if (isEsProfile() && version < 310) requireStage(loc, EShLangVertex, feature); else requireStage(loc, (EShLanguageMask)~EShLangComputeMask, feature); @@ -5824,7 +5833,7 @@ void TParseContext::layoutQualifierCheck(const TSourceLoc& loc, const TQualifier case EvqVaryingOut: { const char* feature = "location qualifier on output"; - if (profile == EEsProfile && version < 310) + if (isEsProfile() && version < 310) requireStage(loc, EShLangFragment, feature); else requireStage(loc, (EShLanguageMask)~EShLangComputeMask, feature); @@ -5954,6 +5963,7 @@ void TParseContext::checkNoShaderLayouts(const TSourceLoc& loc, const TShaderQua // Correct and/or advance an object's offset layout qualifier. void TParseContext::fixOffset(const TSourceLoc& loc, TSymbol& symbol) { +#ifndef GLSLANG_WEB const TQualifier& qualifier = symbol.getType().getQualifier(); if (symbol.getType().getBasicType() == EbtAtomicUint) { if (qualifier.hasBinding() && (int)qualifier.layoutBinding < resources.maxAtomicCounterBindings) { @@ -5984,6 +5994,7 @@ void TParseContext::fixOffset(const TSourceLoc& loc, TSymbol& symbol) atomicUintOffsets[qualifier.layoutBinding] = offset + numOffsets; } } +#endif } // @@ -6012,7 +6023,7 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& loc, const TFunct extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32) || extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64); - if (profile == EEsProfile || version < 120) + if (isEsProfile() || version < 120) function = findFunctionExact(loc, call, builtIn); else if (version < 400) function = findFunction120(loc, call, builtIn); @@ -6299,11 +6310,13 @@ const TFunction* TParseContext::findFunctionExplicitTypes(const TSourceLoc& loc, return bestMatch; } -// When a declaration includes a type, but not a variable name, it can be +// When a declaration includes a type, but not a variable name, it can be used // to establish defaults. void TParseContext::declareTypeDefaults(const TSourceLoc& loc, const TPublicType& publicType) { - if (publicType.basicType == EbtAtomicUint && publicType.qualifier.hasBinding() && publicType.qualifier.hasOffset()) { +#ifndef GLSLANG_WEB + if (publicType.basicType == EbtAtomicUint && publicType.qualifier.hasBinding() && + publicType.qualifier.hasOffset()) { if (publicType.qualifier.layoutBinding >= (unsigned int)resources.maxAtomicCounterBindings) { error(loc, "atomic_uint binding is too large", "binding", ""); return; @@ -6314,6 +6327,7 @@ void TParseContext::declareTypeDefaults(const TSourceLoc& loc, const TPublicType if (publicType.qualifier.hasLayout() && !publicType.qualifier.hasBufferReference()) warn(loc, "useless application of layout qualifier", "layout", ""); +#endif } // @@ -6510,7 +6524,7 @@ TIntermNode* TParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyp // TStorageQualifier qualifier = variable->getType().getQualifier().storage; if (! (qualifier == EvqTemporary || qualifier == EvqGlobal || qualifier == EvqConst || - (qualifier == EvqUniform && profile != EEsProfile && version >= 120))) { + (qualifier == EvqUniform && !isEsProfile() && version >= 120))) { error(loc, " cannot initialize this type of qualifier ", variable->getType().getStorageQualifierString(), ""); return nullptr; } @@ -6582,7 +6596,7 @@ TIntermNode* TParseContext::executeInitializer(const TSourceLoc& loc, TIntermTyp // qualifier any initializer must be a constant expression." if (symbolTable.atGlobalLevel() && ! initializer->getType().getQualifier().isConstant()) { const char* initFeature = "non-constant global initializer (needs GL_EXT_shader_non_constant_global_initializers)"; - if (profile == EEsProfile) { + if (isEsProfile()) { if (relaxedErrors() && ! extensionTurnedOn(E_GL_EXT_shader_non_constant_global_initializers)) warn(loc, "not allowed in this version", initFeature, ""); else @@ -7724,7 +7738,7 @@ void TParseContext::invariantCheck(const TSourceLoc& loc, const TQualifier& qual bool pipeOut = qualifier.isPipeOutput(); bool pipeIn = qualifier.isPipeInput(); - if (version >= 300 || (profile != EEsProfile && version >= 420)) { + if (version >= 300 || (!isEsProfile() && version >= 420)) { if (! pipeOut) error(loc, "can only apply to an output", "invariant", ""); } else { @@ -8080,7 +8094,7 @@ TIntermNode* TParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* expre // "it is an error to have no statement between a label and the end of the switch statement." // The specifications were updated to remove this (being ill-defined what a "statement" was), // so, this became a warning. However, 3.0 tests still check for the error. - if (profile == EEsProfile && version <= 300 && ! relaxedErrors()) + if (isEsProfile() && version <= 300 && ! relaxedErrors()) error(loc, "last case/default label not followed by statements", "switch", ""); else warn(loc, "last case/default label not followed by statements", "switch", ""); diff --git a/glslang/MachineIndependent/Scan.cpp b/glslang/MachineIndependent/Scan.cpp index ae7f75cb..ad0c12c9 100644 --- a/glslang/MachineIndependent/Scan.cpp +++ b/glslang/MachineIndependent/Scan.cpp @@ -904,8 +904,8 @@ int TScanContext::tokenizeIdentifier() case SWITCH: case DEFAULT: - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 130)) + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 130)) reservedWord(); return keyword; @@ -938,14 +938,14 @@ int TScanContext::tokenizeIdentifier() return keyword; case SMOOTH: - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 130)) + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 130)) return identifierOrType(); return keyword; case FLAT: - if (parseContext.profile == EEsProfile && parseContext.version < 300) + if (parseContext.isEsProfile() && parseContext.version < 300) reservedWord(); - else if (parseContext.profile != EEsProfile && parseContext.version < 130) + else if (!parseContext.isEsProfile() && parseContext.version < 130) return identifierOrType(); return keyword; case CENTROID: @@ -953,30 +953,30 @@ int TScanContext::tokenizeIdentifier() return identifierOrType(); return keyword; case INVARIANT: - if (parseContext.profile != EEsProfile && parseContext.version < 120) + if (!parseContext.isEsProfile() && parseContext.version < 120) return identifierOrType(); return keyword; case PACKED: - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 330)) + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 330)) return reservedWord(); return identifierOrType(); case RESOURCE: { - bool reserved = (parseContext.profile == EEsProfile && parseContext.version >= 300) || - (parseContext.profile != EEsProfile && parseContext.version >= 420); + bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) || + (!parseContext.isEsProfile() && parseContext.version >= 420); return identifierOrReserved(reserved); } case SUPERP: { - bool reserved = parseContext.profile == EEsProfile || parseContext.version >= 130; + bool reserved = parseContext.isEsProfile() || parseContext.version >= 130; return identifierOrReserved(reserved); } #ifndef GLSLANG_WEB case NOPERSPECTIVE: - if (parseContext.profile == EEsProfile && parseContext.version >= 300 && + if (parseContext.isEsProfile() && parseContext.version >= 300 && parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation)) return keyword; return es30ReservedFromGLSL(130); @@ -988,13 +988,13 @@ int TScanContext::tokenizeIdentifier() return identifierOrType(); case ATTRIBUTE: case VARYING: - if (parseContext.profile == EEsProfile && parseContext.version >= 300) + if (parseContext.isEsProfile() && parseContext.version >= 300) reservedWord(); return keyword; case BUFFER: afterBuffer = true; - if ((parseContext.profile == EEsProfile && parseContext.version < 310) || - (parseContext.profile != EEsProfile && parseContext.version < 430)) + if ((parseContext.isEsProfile() && parseContext.version < 310) || + (!parseContext.isEsProfile() && parseContext.version < 430)) return identifierOrType(); return keyword; case PAYLOADNV: @@ -1004,12 +1004,12 @@ int TScanContext::tokenizeIdentifier() case CALLDATAINNV: case ACCSTRUCTNV: if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && parseContext.version >= 460 + (!parseContext.isEsProfile() && parseContext.version >= 460 && parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))) return keyword; return identifierOrType(); case ATOMIC_UINT: - if ((parseContext.profile == EEsProfile && parseContext.version >= 310) || + if ((parseContext.isEsProfile() && parseContext.version >= 310) || parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters)) return keyword; return es30ReservedFromGLSL(420); @@ -1023,28 +1023,28 @@ int TScanContext::tokenizeIdentifier() case RESTRICT: case READONLY: case WRITEONLY: - if (parseContext.profile == EEsProfile && parseContext.version >= 310) + if (parseContext.isEsProfile() && parseContext.version >= 310) return keyword; return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420); case VOLATILE: - if (parseContext.profile == EEsProfile && parseContext.version >= 310) + if (parseContext.isEsProfile() && parseContext.version >= 310) return keyword; - if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.profile == EEsProfile || + if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() || (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store)))) reservedWord(); return keyword; case PATCH: if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile == EEsProfile && + (parseContext.isEsProfile() && (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) || - (parseContext.profile != EEsProfile && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader))) + (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader))) return keyword; return es30ReservedFromGLSL(400); case SAMPLE: - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation)) return keyword; return es30ReservedFromGLSL(400); @@ -1058,15 +1058,15 @@ int TScanContext::tokenizeIdentifier() const int numLayoutExts = 2; const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack, E_GL_ARB_explicit_attrib_location }; - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 140 && + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 140 && ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts))) return identifierOrType(); return keyword; } case SHARED: - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 140)) + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 140)) return identifierOrType(); return keyword; @@ -1118,7 +1118,7 @@ int TScanContext::tokenizeIdentifier() case IIMAGEBUFFER: case UIMAGEBUFFER: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer)) return keyword; return firstGenerationImage(false); @@ -1142,7 +1142,7 @@ int TScanContext::tokenizeIdentifier() case IIMAGECUBEARRAY: case UIMAGECUBEARRAY: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array)) return keyword; return secondGenerationImage(); @@ -1161,7 +1161,7 @@ int TScanContext::tokenizeIdentifier() case DVEC3: case DVEC4: afterType = true; - if (parseContext.profile == EEsProfile || parseContext.version < 400) + if (parseContext.isEsProfile() || parseContext.version < 400) reservedWord(); return keyword; @@ -1175,7 +1175,7 @@ int TScanContext::tokenizeIdentifier() case U64VEC4: afterType = true; if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && parseContext.version >= 450 && + (!parseContext.isEsProfile() && parseContext.version >= 450 && (parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64)))) @@ -1195,7 +1195,7 @@ int TScanContext::tokenizeIdentifier() ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8)) && - parseContext.profile != EEsProfile && parseContext.version >= 450)) + !parseContext.isEsProfile() && parseContext.version >= 450)) return keyword; return identifierOrType(); @@ -1209,7 +1209,7 @@ int TScanContext::tokenizeIdentifier() case U16VEC4: afterType = true; if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && parseContext.version >= 450 && + (!parseContext.isEsProfile() && parseContext.version >= 450 && (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) || parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || @@ -1228,7 +1228,7 @@ int TScanContext::tokenizeIdentifier() if (parseContext.symbolTable.atBuiltInLevel() || ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32)) && - parseContext.profile != EEsProfile && parseContext.version >= 450)) + !parseContext.isEsProfile() && parseContext.version >= 450)) return keyword; return identifierOrType(); case FLOAT32_T: @@ -1251,7 +1251,7 @@ int TScanContext::tokenizeIdentifier() if (parseContext.symbolTable.atBuiltInLevel() || ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32)) && - parseContext.profile != EEsProfile && parseContext.version >= 450)) + !parseContext.isEsProfile() && parseContext.version >= 450)) return keyword; return identifierOrType(); @@ -1275,7 +1275,7 @@ int TScanContext::tokenizeIdentifier() if (parseContext.symbolTable.atBuiltInLevel() || ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64)) && - parseContext.profile != EEsProfile && parseContext.version >= 450)) + !parseContext.isEsProfile() && parseContext.version >= 450)) return keyword; return identifierOrType(); @@ -1285,7 +1285,7 @@ int TScanContext::tokenizeIdentifier() case F16VEC4: afterType = true; if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && parseContext.version >= 450 && + (!parseContext.isEsProfile() && parseContext.version >= 450 && (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) || parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || @@ -1308,7 +1308,7 @@ int TScanContext::tokenizeIdentifier() case F16MAT4X4: afterType = true; if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && parseContext.version >= 450 && + (!parseContext.isEsProfile() && parseContext.version >= 450 && (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) || parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16)))) @@ -1322,10 +1322,10 @@ int TScanContext::tokenizeIdentifier() case ISAMPLERCUBEARRAY: case USAMPLERCUBEARRAY: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array)) return keyword; - if (parseContext.profile == EEsProfile || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array))) + if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array))) reservedWord(); return keyword; @@ -1349,7 +1349,7 @@ int TScanContext::tokenizeIdentifier() case SAMPLER3D: afterType = true; - if (parseContext.profile == EEsProfile && parseContext.version < 300) { + if (parseContext.isEsProfile() && parseContext.version < 300) { if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D)) reservedWord(); } @@ -1357,7 +1357,7 @@ int TScanContext::tokenizeIdentifier() case SAMPLER2DSHADOW: afterType = true; - if (parseContext.profile == EEsProfile && parseContext.version < 300) { + if (parseContext.isEsProfile() && parseContext.version < 300) { if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers)) reservedWord(); } @@ -1378,7 +1378,7 @@ int TScanContext::tokenizeIdentifier() case SAMPLERBUFFER: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer)) return keyword; return es30ReservedFromGLSL(130); @@ -1386,7 +1386,7 @@ int TScanContext::tokenizeIdentifier() case ISAMPLERBUFFER: case USAMPLERBUFFER: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer)) return keyword; return es30ReservedFromGLSL(140); @@ -1395,7 +1395,7 @@ int TScanContext::tokenizeIdentifier() case ISAMPLER2DMS: case USAMPLER2DMS: afterType = true; - if (parseContext.profile == EEsProfile && parseContext.version >= 310) + if (parseContext.isEsProfile() && parseContext.version >= 310) return keyword; return es30ReservedFromGLSL(150); @@ -1403,7 +1403,7 @@ int TScanContext::tokenizeIdentifier() case ISAMPLER2DMSARRAY: case USAMPLER2DMSARRAY: afterType = true; - if ((parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array)) return keyword; return es30ReservedFromGLSL(150); @@ -1411,14 +1411,14 @@ int TScanContext::tokenizeIdentifier() case SAMPLER1D: case SAMPLER1DSHADOW: afterType = true; - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) reservedWord(); return keyword; case SAMPLER2DRECT: case SAMPLER2DRECTSHADOW: afterType = true; - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) reservedWord(); else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) { if (parseContext.relaxedErrors()) @@ -1430,10 +1430,10 @@ int TScanContext::tokenizeIdentifier() case SAMPLER1DARRAY: afterType = true; - if (parseContext.profile == EEsProfile && parseContext.version == 300) + if (parseContext.isEsProfile() && parseContext.version == 300) reservedWord(); - else if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < 130)) + else if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < 130)) return identifierOrType(); return keyword; @@ -1551,29 +1551,29 @@ int TScanContext::tokenizeIdentifier() afterType = true; if (parseContext.symbolTable.atBuiltInLevel() || (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch) && - parseContext.profile != EEsProfile && parseContext.version >= 450)) + !parseContext.isEsProfile() && parseContext.version >= 450)) return keyword; return identifierOrType(); case EXPLICITINTERPAMD: - if (parseContext.profile != EEsProfile && parseContext.version >= 450 && + if (!parseContext.isEsProfile() && parseContext.version >= 450 && parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter)) return keyword; return identifierOrType(); case PERVERTEXNV: - if (((parseContext.profile != EEsProfile && parseContext.version >= 450) || - (parseContext.profile == EEsProfile && parseContext.version >= 320)) && + if (((!parseContext.isEsProfile() && parseContext.version >= 450) || + (parseContext.isEsProfile() && parseContext.version >= 320)) && parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric)) return keyword; return identifierOrType(); case PRECISE: - if ((parseContext.profile == EEsProfile && + if ((parseContext.isEsProfile() && (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) || - (parseContext.profile != EEsProfile && parseContext.version >= 400)) + (!parseContext.isEsProfile() && parseContext.version >= 400)) return keyword; - if (parseContext.profile == EEsProfile && parseContext.version == 310) { + if (parseContext.isEsProfile() && parseContext.version == 310) { reservedWord(); return keyword; } @@ -1582,8 +1582,8 @@ int TScanContext::tokenizeIdentifier() case PERPRIMITIVENV: case PERVIEWNV: case PERTASKNV: - if ((parseContext.profile != EEsProfile && parseContext.version >= 450) || - (parseContext.profile == EEsProfile && parseContext.version >= 320) || + if ((!parseContext.isEsProfile() && parseContext.version >= 450) || + (parseContext.isEsProfile() && parseContext.version >= 320) || parseContext.extensionTurnedOn(E_GL_NV_mesh_shader)) return keyword; return identifierOrType(); @@ -1662,13 +1662,13 @@ int TScanContext::es30ReservedFromGLSL(int version) if (parseContext.symbolTable.atBuiltInLevel()) return keyword; - if ((parseContext.profile == EEsProfile && parseContext.version < 300) || - (parseContext.profile != EEsProfile && parseContext.version < version)) { + if ((parseContext.isEsProfile() && parseContext.version < 300) || + (!parseContext.isEsProfile() && parseContext.version < version)) { if (parseContext.forwardCompatible) parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, ""); return identifierOrType(); - } else if (parseContext.profile == EEsProfile && parseContext.version >= 300) + } else if (parseContext.isEsProfile() && parseContext.version >= 300) reservedWord(); return keyword; @@ -1678,8 +1678,8 @@ int TScanContext::es30ReservedFromGLSL(int version) // showed up, both in an es version and a non-ES version. int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion) { - if ((parseContext.profile == EEsProfile && parseContext.version < esVersion) || - (parseContext.profile != EEsProfile && parseContext.version < nonEsVersion)) { + if ((parseContext.isEsProfile() && parseContext.version < esVersion) || + (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) { if (parseContext.forwardCompatible) parseContext.warn(loc, "using future keyword", tokenText, ""); @@ -1691,7 +1691,7 @@ int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion) int TScanContext::precisionKeyword() { - if (parseContext.profile == EEsProfile || parseContext.version >= 130) + if (parseContext.isEsProfile() || parseContext.version >= 130) return keyword; if (parseContext.forwardCompatible) @@ -1717,13 +1717,13 @@ int TScanContext::dMat() { afterType = true; - if (parseContext.profile == EEsProfile && parseContext.version >= 300) { + if (parseContext.isEsProfile() && parseContext.version >= 300) { reservedWord(); return keyword; } - if (parseContext.profile != EEsProfile && parseContext.version >= 400) + if (!parseContext.isEsProfile() && parseContext.version >= 400) return keyword; if (parseContext.forwardCompatible) @@ -1735,13 +1735,13 @@ int TScanContext::dMat() int TScanContext::firstGenerationImage(bool inEs310) { if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && (parseContext.version >= 420 || + (!parseContext.isEsProfile() && (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) || - (inEs310 && parseContext.profile == EEsProfile && parseContext.version >= 310)) + (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310)) return keyword; - if ((parseContext.profile == EEsProfile && parseContext.version >= 300) || - (parseContext.profile != EEsProfile && parseContext.version >= 130)) { + if ((parseContext.isEsProfile() && parseContext.version >= 300) || + (!parseContext.isEsProfile() && parseContext.version >= 130)) { reservedWord(); return keyword; @@ -1755,13 +1755,13 @@ int TScanContext::firstGenerationImage(bool inEs310) int TScanContext::secondGenerationImage() { - if (parseContext.profile == EEsProfile && parseContext.version >= 310) { + if (parseContext.isEsProfile() && parseContext.version >= 310) { reservedWord(); return keyword; } if (parseContext.symbolTable.atBuiltInLevel() || - (parseContext.profile != EEsProfile && + (!parseContext.isEsProfile() && (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store)))) return keyword; diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index b01cbe3a..bced5d72 100755 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -377,8 +377,6 @@ bool InitializeSymbolTables(TInfoSink& infoSink, TSymbolTable** commonTable, TS infoSink, commonTable, symbolTables); #endif - - return true; } diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 05ace4d2..e9c4c4da 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -306,7 +306,7 @@ void TParseVersions::initializeExtensionBehavior() // or needed by the preprocessor (which does not use a shared symbol table). void TParseVersions::getPreamble(std::string& preamble) { - if (profile == EEsProfile) { + if (isEsProfile()) { preamble = "#define GL_ES 1\n" "#define GL_FRAGMENT_PRECISION_HIGH 1\n" @@ -352,7 +352,7 @@ void TParseVersions::getPreamble(std::string& preamble) "#define GL_EXT_shader_non_constant_global_initializers 1\n" ; - if (profile == EEsProfile && version >= 300) { + if (isEsProfile() && version >= 300) { preamble += "#define GL_NV_shader_noperspective_interpolation 1\n"; } @@ -458,8 +458,8 @@ void TParseVersions::getPreamble(std::string& preamble) } #ifndef GLSLANG_WEB - if ((profile != EEsProfile && version >= 140) || - (profile == EEsProfile && version >= 310)) { + if ((!isEsProfile() && version >= 140) || + (isEsProfile() && version >= 310)) { preamble += "#define GL_EXT_device_group 1\n" "#define GL_EXT_multiview 1\n" diff --git a/glslang/MachineIndependent/glslang.m4 b/glslang/MachineIndependent/glslang.m4 index 1bc12d2b..d1ad04dd 100644 --- a/glslang/MachineIndependent/glslang.m4 +++ b/glslang/MachineIndependent/glslang.m4 @@ -3265,7 +3265,7 @@ struct_declaration if ($1.arraySizes) { parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes); } @@ -3287,7 +3287,7 @@ struct_declaration if ($2.arraySizes) { parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck($2.loc, *$2.arraySizes); } diff --git a/glslang/MachineIndependent/glslang.y b/glslang/MachineIndependent/glslang.y index bc32ade8..4055dcc4 100644 --- a/glslang/MachineIndependent/glslang.y +++ b/glslang/MachineIndependent/glslang.y @@ -3265,7 +3265,7 @@ struct_declaration if ($1.arraySizes) { parseContext.profileRequires($1.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes); } @@ -3287,7 +3287,7 @@ struct_declaration if ($2.arraySizes) { parseContext.profileRequires($2.loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires($2.loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck($2.loc, *$2.arraySizes); } diff --git a/glslang/MachineIndependent/glslang_tab.cpp b/glslang/MachineIndependent/glslang_tab.cpp index 499b20f3..3889132f 100644 --- a/glslang/MachineIndependent/glslang_tab.cpp +++ b/glslang/MachineIndependent/glslang_tab.cpp @@ -9319,7 +9319,7 @@ yyreduce: if ((yyvsp[-2].interm.type).arraySizes) { parseContext.profileRequires((yyvsp[-2].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires((yyvsp[-2].interm.type).loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes); } @@ -9346,7 +9346,7 @@ yyreduce: if ((yyvsp[-2].interm.type).arraySizes) { parseContext.profileRequires((yyvsp[-2].interm.type).loc, ENoProfile, 120, E_GL_3DL_array_objects, "arrayed type"); parseContext.profileRequires((yyvsp[-2].interm.type).loc, EEsProfile, 300, 0, "arrayed type"); - if (parseContext.profile == EEsProfile) + if (parseContext.isEsProfile()) parseContext.arraySizeRequiredCheck((yyvsp[-2].interm.type).loc, *(yyvsp[-2].interm.type).arraySizes); } diff --git a/glslang/MachineIndependent/linkValidate.cpp b/glslang/MachineIndependent/linkValidate.cpp index 12939232..b5b3cdb0 100644 --- a/glslang/MachineIndependent/linkValidate.cpp +++ b/glslang/MachineIndependent/linkValidate.cpp @@ -120,7 +120,7 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit) version = unit.version; requestedExtensions = unit.requestedExtensions; } else { - if ((profile == EEsProfile) != (unit.profile == EEsProfile)) + if ((isEsProfile()) != (unit.isEsProfile())) error(infoSink, "Cannot cross link ES and desktop profiles"); else if (unit.profile == ECompatibilityProfile) profile = ECompatibilityProfile; @@ -952,7 +952,7 @@ void TIntermediate::inOutLocationCheck(TInfoSink& infoSink) } } - if (profile == EEsProfile) { + if (isEsProfile()) { if (numFragOut > 1 && fragOutWithNoLocation) error(infoSink, "when more than one fragment shader output, all must have location qualifiers"); } @@ -1091,7 +1091,7 @@ int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& typ TIoRange range(locationRange, componentRange, type.getBasicType(), qualifier.hasIndex() ? qualifier.layoutIndex : 0); // check for collisions, except for vertex inputs on desktop targeting OpenGL - if (! (profile != EEsProfile && language == EShLangVertex && qualifier.isPipeInput()) || spvVersion.vulkan > 0) + if (! (!isEsProfile() && language == EShLangVertex && qualifier.isPipeInput()) || spvVersion.vulkan > 0) collision = checkLocationRange(set, range, type, typeCollision); if (collision < 0) diff --git a/glslang/MachineIndependent/localintermediate.h b/glslang/MachineIndependent/localintermediate.h index 2dcacff6..affab4b2 100644 --- a/glslang/MachineIndependent/localintermediate.h +++ b/glslang/MachineIndependent/localintermediate.h @@ -460,6 +460,7 @@ public: #ifdef GLSLANG_WEB void output(TInfoSink&, bool tree) { } + bool isEsProfile() const { return false; } bool getXfbMode() const { return false; } bool isMultiStream() const { return false; } TLayoutGeometry getOutputPrimitive() const { return ElgNone; } @@ -483,6 +484,8 @@ public: #else void output(TInfoSink&, bool tree); + bool isEsProfile() const { return profile == EEsProfile; } + void setShiftBinding(TResourceType res, unsigned int shift) { shiftBinding[res] = shift; diff --git a/glslang/MachineIndependent/parseVersions.h b/glslang/MachineIndependent/parseVersions.h index 8c964343..bd46c6d9 100755 --- a/glslang/MachineIndependent/parseVersions.h +++ b/glslang/MachineIndependent/parseVersions.h @@ -67,6 +67,7 @@ public: virtual void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc); virtual void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc); #ifdef GLSLANG_WEB + bool isEsProfile() const { return true; } virtual void initializeExtensionBehavior() { } virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc) { } virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc) { } @@ -92,6 +93,7 @@ public: virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false) { } virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false) { } #else + bool isEsProfile() const { return profile == EEsProfile; } virtual void initializeExtensionBehavior(); virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc); virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc); diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 68ccfdfa..fc23c047 100755 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -545,7 +545,7 @@ int TPpContext::evalToToken(int token, bool shortCircuit, int& res, bool& err, T case MacroExpandStarted: break; case MacroExpandUndef: - if (! shortCircuit && parseContext.profile == EEsProfile) { + if (! shortCircuit && parseContext.isEsProfile()) { const char* message = "undefined macro in expression not allowed in es profile"; if (parseContext.relaxedErrors()) parseContext.ppWarn(ppToken->loc, message, "preprocessor evaluation", ppToken->name);