From 3192c53a1198fabf9cd83a5ca67183188c0a6df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 23 Mar 2018 18:45:33 -0700 Subject: [PATCH] Updated glslang. --- 3rdparty/glslang/SPIRV/SpvBuilder.cpp | 4 +- 3rdparty/glslang/StandAlone/StandAlone.cpp | 4 +- .../cppRelaxSkipTokensErrors.vert.out | 14 ++++ .../baseResults/spv.debugInfo.1.1.frag.out | 1 + .../Test/baseResults/spv.debugInfo.frag.out | 1 + 3rdparty/glslang/Test/cppBad.vert | 2 +- .../Test/cppRelaxSkipTokensErrors.vert | 14 ++++ 3rdparty/glslang/glslang/Include/revision.h | 2 +- .../MachineIndependent/ParseHelper.cpp | 4 +- .../glslang/MachineIndependent/iomapper.cpp | 9 ++- .../MachineIndependent/linkValidate.cpp | 30 ++++++++ .../MachineIndependent/localintermediate.h | 1 + .../preprocessor/PpScanner.cpp | 71 +++++++++++-------- 3rdparty/glslang/glslang/Public/ShaderLang.h | 8 ++- 3rdparty/glslang/gtests/AST.FromFile.cpp | 1 + 3rdparty/glslang/gtests/TestFixture.h | 4 +- 16 files changed, 126 insertions(+), 44 deletions(-) create mode 100755 3rdparty/glslang/Test/baseResults/cppRelaxSkipTokensErrors.vert.out create mode 100644 3rdparty/glslang/Test/cppRelaxSkipTokensErrors.vert diff --git a/3rdparty/glslang/SPIRV/SpvBuilder.cpp b/3rdparty/glslang/SPIRV/SpvBuilder.cpp index 6e78b7999..dfeae8715 100644 --- a/3rdparty/glslang/SPIRV/SpvBuilder.cpp +++ b/3rdparty/glslang/SPIRV/SpvBuilder.cpp @@ -859,12 +859,14 @@ Id Builder::makeFpConstant(Id type, double d, bool specConstant) return makeFloatConstant(d, specConstant); case 64: return makeDoubleConstant(d, specConstant); + default: + break; } assert(false); + return NoResult; } - Id Builder::findCompositeConstant(Op typeClass, const std::vector& comps) { Instruction* constant = 0; diff --git a/3rdparty/glslang/StandAlone/StandAlone.cpp b/3rdparty/glslang/StandAlone/StandAlone.cpp index 280ca7b0d..356e016e8 100644 --- a/3rdparty/glslang/StandAlone/StandAlone.cpp +++ b/3rdparty/glslang/StandAlone/StandAlone.cpp @@ -160,9 +160,9 @@ const char* variableName = nullptr; bool HlslEnable16BitTypes = false; std::vector IncludeDirectoryList; int ClientInputSemanticsVersion = 100; // maps to, say, #define VULKAN 100 -glslang::EshTargetClientVersion VulkanClientVersion = +glslang::EShTargetClientVersion VulkanClientVersion = glslang::EShTargetVulkan_1_0; // would map to, say, Vulkan 1.0 -glslang::EshTargetClientVersion OpenGLClientVersion = +glslang::EShTargetClientVersion OpenGLClientVersion = glslang::EShTargetOpenGL_450; // doesn't influence anything yet, but maps to OpenGL 4.50 glslang::EShTargetLanguageVersion TargetVersion = glslang::EShTargetSpv_1_0; // maps to, say, SPIR-V 1.0 diff --git a/3rdparty/glslang/Test/baseResults/cppRelaxSkipTokensErrors.vert.out b/3rdparty/glslang/Test/baseResults/cppRelaxSkipTokensErrors.vert.out new file mode 100755 index 000000000..e9b4b1b7a --- /dev/null +++ b/3rdparty/glslang/Test/baseResults/cppRelaxSkipTokensErrors.vert.out @@ -0,0 +1,14 @@ +cppRelaxSkipTokensErrors.vert +Shader version: 110 +0:? Sequence +0:? Linker Objects + + +Linked vertex stage: + +ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point + +Shader version: 110 +0:? Sequence +0:? Linker Objects + diff --git a/3rdparty/glslang/Test/baseResults/spv.debugInfo.1.1.frag.out b/3rdparty/glslang/Test/baseResults/spv.debugInfo.1.1.frag.out index b73037625..9bd14910b 100644 --- a/3rdparty/glslang/Test/baseResults/spv.debugInfo.1.1.frag.out +++ b/3rdparty/glslang/Test/baseResults/spv.debugInfo.1.1.frag.out @@ -94,6 +94,7 @@ void main() MemberDecorate 54(ubuf) 0 Offset 0 Decorate 54(ubuf) Block Decorate 56 DescriptorSet 3 + Decorate 69(s2d) Location 0 Decorate 69(s2d) DescriptorSet 3 3: TypeVoid 4: TypeFunction 3 diff --git a/3rdparty/glslang/Test/baseResults/spv.debugInfo.frag.out b/3rdparty/glslang/Test/baseResults/spv.debugInfo.frag.out index de5441512..0bb266bde 100644 --- a/3rdparty/glslang/Test/baseResults/spv.debugInfo.frag.out +++ b/3rdparty/glslang/Test/baseResults/spv.debugInfo.frag.out @@ -97,6 +97,7 @@ void main() Decorate 54(ubuf) Block Decorate 56 DescriptorSet 3 Decorate 56 Binding 0 + Decorate 69(s2d) Location 0 Decorate 69(s2d) DescriptorSet 3 Decorate 69(s2d) Binding 1 3: TypeVoid diff --git a/3rdparty/glslang/Test/cppBad.vert b/3rdparty/glslang/Test/cppBad.vert index 49600f916..0044c44fc 100644 --- a/3rdparty/glslang/Test/cppBad.vert +++ b/3rdparty/glslang/Test/cppBad.vert @@ -1,5 +1,5 @@ #define m#0# #if m - +#endif #define n() int n" \ No newline at end of file diff --git a/3rdparty/glslang/Test/cppRelaxSkipTokensErrors.vert b/3rdparty/glslang/Test/cppRelaxSkipTokensErrors.vert new file mode 100644 index 000000000..b30af0c9f --- /dev/null +++ b/3rdparty/glslang/Test/cppRelaxSkipTokensErrors.vert @@ -0,0 +1,14 @@ +#version 110 + +#if 0 +3.5L +3.5h +2034h +1.#INF +0x1234567812345L +12323394203923879234L +0123s; +123s; +0123456712345671234L +"string" +#endif diff --git a/3rdparty/glslang/glslang/Include/revision.h b/3rdparty/glslang/glslang/Include/revision.h index 05060fd36..0a3b29172 100644 --- a/3rdparty/glslang/glslang/Include/revision.h +++ b/3rdparty/glslang/glslang/Include/revision.h @@ -1,3 +1,3 @@ // This header is generated by the make-revision script. -#define GLSLANG_PATCH_LEVEL 2629 +#define GLSLANG_PATCH_LEVEL 2637 diff --git a/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp b/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp index f189558cb..5ced1b0bf 100644 --- a/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp +++ b/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp @@ -2778,8 +2778,8 @@ void TParseContext::globalQualifierTypeCheck(const TSourceLoc& loc, const TQuali error(loc, "can't use auxiliary qualifier on a fragment output", "centroid/sample/patch", ""); if (qualifier.isInterpolation()) error(loc, "can't use interpolation qualifier on a fragment output", "flat/smooth/noperspective", ""); - if (publicType.basicType == EbtDouble) - error(loc, "cannot contain a double", GetStorageQualifierString(qualifier.storage), ""); + if (publicType.basicType == EbtDouble || publicType.basicType == EbtInt64 || publicType.basicType == EbtUint64) + error(loc, "cannot contain a double, int64, or uint64", GetStorageQualifierString(qualifier.storage), ""); break; case EShLangCompute: diff --git a/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp b/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp index a7deb9d50..68172538d 100644 --- a/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp +++ b/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp @@ -431,7 +431,8 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver // no locations added if already present, a built-in variable, a block, or an opaque if (type.getQualifier().hasLocation() || type.isBuiltIn() || - type.getBasicType() == EbtBlock || type.containsOpaque()) + type.getBasicType() == EbtBlock || + (type.containsOpaque() && intermediate.getSpv().openGl == 0)) return -1; // no locations on blocks of built-in variables @@ -442,7 +443,11 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver return -1; } - return nextUniformLocation++; + int location = nextUniformLocation; + + nextUniformLocation += TIntermediate::computeTypeUniformLocationSize(type); + + return location; } bool validateInOut(EShLanguage /*stage*/, const char* /*name*/, const TType& /*type*/, bool /*is_live*/) override { diff --git a/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp b/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp index 9aba27922..aa9c5121b 100644 --- a/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp +++ b/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp @@ -962,6 +962,36 @@ int TIntermediate::computeTypeLocationSize(const TType& type, EShLanguage stage) return 1; } +// Same as computeTypeLocationSize but for uniforms +int TIntermediate::computeTypeUniformLocationSize(const TType& type) +{ + // "Individual elements of a uniform array are assigned + // consecutive locations with the first element taking location + // location." + if (type.isArray()) { + // TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness + TType elementType(type, 0); + if (type.isImplicitlySizedArray()) { + // TODO: are there valid cases of having an implicitly-sized array with a location? If so, running this code too early. + return computeTypeUniformLocationSize(elementType); + } else + return type.getOuterArraySize() * computeTypeUniformLocationSize(elementType); + } + + // "Each subsequent inner-most member or element gets incremental + // locations for the entire structure or array." + if (type.isStruct()) { + int size = 0; + for (int member = 0; member < (int)type.getStruct()->size(); ++member) { + TType memberType(type, member); + size += computeTypeUniformLocationSize(memberType); + } + return size; + } + + return 1; +} + // Accumulate xfb buffer ranges and check for collisions as the accumulation is done. // // Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value. diff --git a/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h b/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h index d6ecbe340..d6f13ae4e 100644 --- a/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h +++ b/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h @@ -590,6 +590,7 @@ public: int addUsedOffsets(int binding, int offset, int numOffsets); bool addUsedConstantId(int id); static int computeTypeLocationSize(const TType&, EShLanguage); + static int computeTypeUniformLocationSize(const TType&); bool setXfbBufferStride(int buffer, unsigned stride) { diff --git a/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 61bf027fa..f4eaf57d3 100644 --- a/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -118,7 +118,7 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) ch = getChar(); // 1.#INF or -1.#INF - if (parseContext.intermediate.getSource() == EShSourceHlsl && ch == '#') { + if (ch == '#' && (ifdepth > 0 || parseContext.intermediate.getSource() == EShSourceHlsl)) { if ((len < 2) || (len == 2 && ppToken->name[0] != '1') || (len == 3 && ppToken->name[1] != '1' && !(ppToken->name[0] == '-' || ppToken->name[0] == '+')) || @@ -174,9 +174,9 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) // Suffix: bool isFloat16 = false; if (ch == 'l' || ch == 'L') { - if (parseContext.intermediate.getSource() == EShSourceGlsl) + if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl) parseContext.doubleCheck(ppToken->loc, "double floating-point suffix"); - if (! HasDecimalOrExponent) + if (ifdepth == 0 && !HasDecimalOrExponent) parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); if (parseContext.intermediate.getSource() == EShSourceGlsl) { int ch2 = getChar(); @@ -193,9 +193,9 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) isDouble = 1; } } else if (ch == 'h' || ch == 'H') { - if (parseContext.intermediate.getSource() == EShSourceGlsl) + if (ifdepth == 0 && parseContext.intermediate.getSource() == EShSourceGlsl) parseContext.float16Check(ppToken->loc, "half floating-point suffix"); - if (!HasDecimalOrExponent) + if (ifdepth == 0 && !HasDecimalOrExponent) parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); if (parseContext.intermediate.getSource() == EShSourceGlsl) { int ch2 = getChar(); @@ -212,10 +212,11 @@ int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) isFloat16 = true; } } else if (ch == 'f' || ch == 'F') { - parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix"); - if (! parseContext.relaxedErrors()) + if (ifdepth == 0) + parseContext.profileRequires(ppToken->loc, EEsProfile, 300, nullptr, "floating-point suffix"); + if (ifdepth == 0 && !parseContext.relaxedErrors()) parseContext.profileRequires(ppToken->loc, ~EEsProfile, 120, nullptr, "floating-point suffix"); - if (! HasDecimalOrExponent) + if (ifdepth == 0 && !HasDecimalOrExponent) parseContext.ppError(ppToken->loc, "float literal needs a decimal point or exponent", "", ""); saveName(ch); } else @@ -483,18 +484,22 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ppToken->name[len] = '\0'; if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { - pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, + if (pp->ifdepth == 0) { + pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, "64-bit hexadecimal literal"); - pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, - Num_Int64_Extensions, Int64_Extensions, "64-bit hexadecimal literal"); + pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, + Num_Int64_Extensions, Int64_Extensions, "64-bit hexadecimal literal"); + } ppToken->i64val = ival; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; } else if (isInt16) { - if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { - pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, - "16-bit hexadecimal literal"); - pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, - Num_Int16_Extensions, Int16_Extensions, "16-bit hexadecimal literal"); + if (pp->ifdepth == 0) { + if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { + pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, + "16-bit hexadecimal literal"); + pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, + Num_Int16_Extensions, Int16_Extensions, "16-bit hexadecimal literal"); + } } ppToken->ival = (int)ival; return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16; @@ -595,18 +600,22 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) pp->parseContext.ppError(ppToken->loc, "octal literal too big", "", ""); if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { - pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, + if (pp->ifdepth == 0) { + pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, "64-bit octal literal"); - pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, - Num_Int64_Extensions, Int64_Extensions, "64-bit octal literal"); + pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, + Num_Int64_Extensions, Int64_Extensions, "64-bit octal literal"); + } ppToken->i64val = ival; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; } else if (isInt16) { - if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { - pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, - "16-bit octal literal"); - pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, - Num_Int16_Extensions, Int16_Extensions, "16-bit octal literal"); + if (pp->ifdepth == 0) { + if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { + pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, + "16-bit octal literal"); + pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, + Num_Int16_Extensions, Int16_Extensions, "16-bit octal literal"); + } } ppToken->ival = (int)ival; return isUnsigned ? PpAtomConstUint16 : PpAtomConstInt16; @@ -700,16 +709,18 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) } if (isInt64 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { - pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, + if (pp->ifdepth == 0) { + pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, "64-bit literal"); - pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, - Num_Int64_Extensions, Int64_Extensions, "64-bit literal"); + pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, + Num_Int64_Extensions, Int64_Extensions, "64-bit literal"); + } ppToken->i64val = ival; return isUnsigned ? PpAtomConstUint64 : PpAtomConstInt64; } else if (isInt16) { - if (pp->parseContext.intermediate.getSource() == EShSourceGlsl) { + if (pp->ifdepth == 0 && pp->parseContext.intermediate.getSource() == EShSourceGlsl) { pp->parseContext.requireProfile(ppToken->loc, ~EEsProfile, - "16-bit literal"); + "16-bit literal"); pp->parseContext.profileRequires(ppToken->loc, ~EEsProfile, 0, Num_Int16_Extensions, Int16_Extensions, "16-bit literal"); } @@ -972,7 +983,7 @@ int TPpContext::tokenize(TPpToken& ppToken) continue; break; case PpAtomConstString: - if (parseContext.intermediate.getSource() != EShSourceHlsl) { + if (ifdepth == 0 && parseContext.intermediate.getSource() != EShSourceHlsl) { // HLSL allows string literals. parseContext.ppError(ppToken.loc, "string literals not supported", "\"\"", ""); continue; diff --git a/3rdparty/glslang/glslang/Public/ShaderLang.h b/3rdparty/glslang/glslang/Public/ShaderLang.h index 6400ecf01..ef6c07458 100644 --- a/3rdparty/glslang/glslang/Public/ShaderLang.h +++ b/3rdparty/glslang/glslang/Public/ShaderLang.h @@ -132,7 +132,9 @@ typedef enum { EShTargetVulkan_1_0 = (1 << 22), EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), EShTargetOpenGL_450 = 450, -} EshTargetClientVersion; +} EShTargetClientVersion; + +typedef EShTargetClientVersion EshTargetClientVersion; typedef enum { EShTargetSpv_1_0 = (1 << 16), @@ -148,7 +150,7 @@ struct TInputLanguage { struct TClient { EShClient client; - EshTargetClientVersion version; // version of client itself (not the client's input dialect) + EShTargetClientVersion version; // version of client itself (not the client's input dialect) }; struct TTarget { @@ -411,7 +413,7 @@ public: environment.input.dialect = client; environment.input.dialectVersion = version; } - void setEnvClient(EShClient client, EshTargetClientVersion version) + void setEnvClient(EShClient client, EShTargetClientVersion version) { environment.client.client = client; environment.client.version = version; diff --git a/3rdparty/glslang/gtests/AST.FromFile.cpp b/3rdparty/glslang/gtests/AST.FromFile.cpp index fea758633..061c86c30 100644 --- a/3rdparty/glslang/gtests/AST.FromFile.cpp +++ b/3rdparty/glslang/gtests/AST.FromFile.cpp @@ -99,6 +99,7 @@ INSTANTIATE_TEST_CASE_P( "cppComplexExpr.vert", "cppDeepNest.frag", "cppPassMacroName.frag", + "cppRelaxSkipTokensErrors.vert", "badChars.frag", "pointCoord.frag", "array.frag", diff --git a/3rdparty/glslang/gtests/TestFixture.h b/3rdparty/glslang/gtests/TestFixture.h index 5af96d97b..0e984d4e5 100644 --- a/3rdparty/glslang/gtests/TestFixture.h +++ b/3rdparty/glslang/gtests/TestFixture.h @@ -197,7 +197,7 @@ public: GlslangResult compileAndLink( const std::string shaderName, const std::string& code, const std::string& entryPointName, EShMessages controls, - glslang::EshTargetClientVersion clientTargetVersion, + glslang::EShTargetClientVersion clientTargetVersion, bool flattenUniformArrays = false, EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep, bool disableOptimizer = true, @@ -407,7 +407,7 @@ public: const std::string& testName, Source source, Semantics semantics, - glslang::EshTargetClientVersion clientTargetVersion, + glslang::EShTargetClientVersion clientTargetVersion, Target target, bool automap = true, const std::string& entryPointName="",