Explorar el Código

Updated glslang.

Бранимир Караџић hace 3 años
padre
commit
a710e11630

+ 10 - 0
3rdparty/glslang/SPIRV/GlslangToSpv.cpp

@@ -9078,15 +9078,19 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
                 break;
 #ifndef GLSLANG_WEB
             case glslang::EbtInt8:
+                builder.addCapability(spv::CapabilityInt8);
                 spvConsts.push_back(builder.makeInt8Constant(zero ? 0 : consts[nextConst].getI8Const()));
                 break;
             case glslang::EbtUint8:
+                builder.addCapability(spv::CapabilityInt8);
                 spvConsts.push_back(builder.makeUint8Constant(zero ? 0 : consts[nextConst].getU8Const()));
                 break;
             case glslang::EbtInt16:
+                builder.addCapability(spv::CapabilityInt16);
                 spvConsts.push_back(builder.makeInt16Constant(zero ? 0 : consts[nextConst].getI16Const()));
                 break;
             case glslang::EbtUint16:
+                builder.addCapability(spv::CapabilityInt16);
                 spvConsts.push_back(builder.makeUint16Constant(zero ? 0 : consts[nextConst].getU16Const()));
                 break;
             case glslang::EbtInt64:
@@ -9099,6 +9103,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
                 spvConsts.push_back(builder.makeDoubleConstant(zero ? 0.0 : consts[nextConst].getDConst()));
                 break;
             case glslang::EbtFloat16:
+                builder.addCapability(spv::CapabilityFloat16);
                 spvConsts.push_back(builder.makeFloat16Constant(zero ? 0.0F : (float)consts[nextConst].getDConst()));
                 break;
 #endif
@@ -9127,15 +9132,19 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
             break;
 #ifndef GLSLANG_WEB
         case glslang::EbtInt8:
+            builder.addCapability(spv::CapabilityInt8);
             scalar = builder.makeInt8Constant(zero ? 0 : consts[nextConst].getI8Const(), specConstant);
             break;
         case glslang::EbtUint8:
+            builder.addCapability(spv::CapabilityInt8);
             scalar = builder.makeUint8Constant(zero ? 0 : consts[nextConst].getU8Const(), specConstant);
             break;
         case glslang::EbtInt16:
+            builder.addCapability(spv::CapabilityInt16);
             scalar = builder.makeInt16Constant(zero ? 0 : consts[nextConst].getI16Const(), specConstant);
             break;
         case glslang::EbtUint16:
+            builder.addCapability(spv::CapabilityInt16);
             scalar = builder.makeUint16Constant(zero ? 0 : consts[nextConst].getU16Const(), specConstant);
             break;
         case glslang::EbtInt64:
@@ -9148,6 +9157,7 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
             scalar = builder.makeDoubleConstant(zero ? 0.0 : consts[nextConst].getDConst(), specConstant);
             break;
         case glslang::EbtFloat16:
+            builder.addCapability(spv::CapabilityFloat16);
             scalar = builder.makeFloat16Constant(zero ? 0.0F : (float)consts[nextConst].getDConst(), specConstant);
             break;
         case glslang::EbtReference:

+ 1 - 0
3rdparty/glslang/SPIRV/SpvTools.cpp

@@ -212,6 +212,7 @@ void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector
     optimizer.RegisterPass(spvtools::CreateInterpolateFixupPass());
     if (options->optimizeSize) {
         optimizer.RegisterPass(spvtools::CreateRedundancyEliminationPass());
+        optimizer.RegisterPass(spvtools::CreateEliminateDeadInputComponentsPass());
     }
     optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
     optimizer.RegisterPass(spvtools::CreateCFGCleanupPass());

+ 79 - 4
3rdparty/glslang/StandAlone/StandAlone.cpp

@@ -192,6 +192,9 @@ glslang::EShTargetClientVersion ClientVersion;       // not valid until Client i
 glslang::EShTargetLanguage TargetLanguage = glslang::EShTargetNone;
 glslang::EShTargetLanguageVersion TargetVersion;     // not valid until TargetLanguage is set
 
+// GLSL version
+int GlslVersion = 0; // GLSL version specified on CLI, overrides #version in shader source
+
 std::vector<std::string> Processes;                     // what should be recorded by OpModuleProcessed, or equivalent
 
 // Per descriptor-set binding base data
@@ -654,6 +657,48 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
                                lowerword == "flatten-uniform-array"  ||
                                lowerword == "fua") {
                         Options |= EOptionFlattenUniformArrays;
+                    } else if (lowerword == "glsl-version") {
+                        if (argc > 1) {
+                            if (strcmp(argv[1], "100") == 0) {
+                                GlslVersion = 100;
+                            } else if (strcmp(argv[1], "110") == 0) {
+                                GlslVersion = 110;
+                            } else if (strcmp(argv[1], "120") == 0) {
+                                GlslVersion = 120;
+                            } else if (strcmp(argv[1], "130") == 0) {
+                                GlslVersion = 130;
+                            } else if (strcmp(argv[1], "140") == 0) {
+                                GlslVersion = 140;
+                            } else if (strcmp(argv[1], "150") == 0) {
+                                GlslVersion = 150;
+                            } else if (strcmp(argv[1], "300es") == 0) {
+                                GlslVersion = 300;
+                            } else if (strcmp(argv[1], "310es") == 0) {
+                                GlslVersion = 310;
+                            } else if (strcmp(argv[1], "320es") == 0) {
+                                GlslVersion = 320;
+                            } else if (strcmp(argv[1], "330") == 0) {
+                                GlslVersion = 330;
+                            } else if (strcmp(argv[1], "400") == 0) {
+                                GlslVersion = 400;
+                            } else if (strcmp(argv[1], "410") == 0) {
+                                GlslVersion = 410;
+                            } else if (strcmp(argv[1], "420") == 0) {
+                                GlslVersion = 420;
+                            } else if (strcmp(argv[1], "430") == 0) {
+                                GlslVersion = 430;
+                            } else if (strcmp(argv[1], "440") == 0) {
+                                GlslVersion = 440;
+                            } else if (strcmp(argv[1], "450") == 0) {
+                                GlslVersion = 450;
+                            } else if (strcmp(argv[1], "460") == 0) {
+                                GlslVersion = 460;
+                            } else
+                                Error("--glsl-version expected one of: 100, 110, 120, 130, 140, 150,\n"
+                                      "300es, 310es, 320es, 330\n"
+                                      "400, 410, 420, 430, 440, 450, 460");
+                        }
+                        bumpArg();
                     } else if (lowerword == "hlsl-offsets") {
                         Options |= EOptionHlslOffsets;
                     } else if (lowerword == "hlsl-iomap" ||
@@ -1168,6 +1213,27 @@ struct ShaderCompUnit {
     }
 };
 
+// Writes a string into a depfile, escaping some special characters following the Makefile rules.
+static void writeEscapedDepString(std::ofstream& file, const std::string& str)
+{
+    for (char c : str) {
+        switch (c) {
+        case ' ':
+        case ':':
+        case '#':
+        case '[':
+        case ']':
+        case '\\':
+            file << '\\';
+            break;
+        case '$':
+            file << '$';
+            break;
+        }
+        file << c;
+    }
+}
+
 // Writes a depfile similar to gcc -MMD foo.c
 bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, const std::vector<std::string>& sources)
 {
@@ -1175,10 +1241,12 @@ bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, co
     if (file.fail())
         return false;
 
-    for (auto it = binaryFiles.begin(); it != binaryFiles.end(); it++) {
-        file << *it << ":";
-        for (auto it = sources.begin(); it != sources.end(); it++) {
-            file << " " << *it;
+    for (auto binaryFile = binaryFiles.begin(); binaryFile != binaryFiles.end(); binaryFile++) {
+        writeEscapedDepString(file, *binaryFile);
+        file << ":";
+        for (auto sourceFile = sources.begin(); sourceFile != sources.end(); sourceFile++) {
+            file << " ";
+            writeEscapedDepString(file, *sourceFile);
         }
         file << std::endl;
     }
@@ -1228,6 +1296,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
             shader->setSourceEntryPoint(sourceEntryPointName);
         }
 
+        shader->setOverrideVersion(GlslVersion);
+
         std::string intrinsicString = getIntrinsic(compUnit.text, compUnit.count);
 
         PreambleString = "";
@@ -1865,6 +1935,11 @@ void usage()
            "  -dumpfullversion | -dumpversion   print bare major.minor.patchlevel\n"
            "  --flatten-uniform-arrays | --fua  flatten uniform texture/sampler arrays to\n"
            "                                    scalars\n"
+           "  --glsl-version {100 | 110 | 120 | 130 | 140 | 150 |\n"
+           "                300es | 310es | 320es | 330\n"
+           "                400 | 410 | 420 | 430 | 440 | 450 | 460}\n"
+           "                                    set GLSL version, overrides #version\n"
+           "                                    in shader sourcen\n"
            "  --hlsl-offsets                    allow block offsets to follow HLSL rules\n"
            "                                    works independently of source language\n"
            "  --hlsl-iomap                      perform IO mapping in HLSL register space\n"

+ 4 - 0
3rdparty/glslang/glslang/CInterface/glslang_c_interface.cpp

@@ -375,7 +375,11 @@ GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int opt
     if (options & GLSLANG_SHADER_VULKAN_RULES_RELAXED) {
         shader->shader->setEnvInputVulkanRulesRelaxed();
     }
+}
 
+GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version)
+{
+    shader->shader->setOverrideVersion(version);
 }
 
 GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader)

+ 1 - 0
3rdparty/glslang/glslang/Include/glslang_c_interface.h

@@ -227,6 +227,7 @@ GLSLANG_EXPORT void glslang_shader_delete(glslang_shader_t* shader);
 GLSLANG_EXPORT void glslang_shader_shift_binding(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base);
 GLSLANG_EXPORT void glslang_shader_shift_binding_for_set(glslang_shader_t* shader, glslang_resource_type_t res, unsigned int base, unsigned int set);
 GLSLANG_EXPORT void glslang_shader_set_options(glslang_shader_t* shader, int options); // glslang_shader_options_t
+GLSLANG_EXPORT void glslang_shader_set_glsl_version(glslang_shader_t* shader, int version);
 GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
 GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
 GLSLANG_EXPORT const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);

+ 3 - 1
3rdparty/glslang/glslang/Include/glslang_c_shader_types.h

@@ -121,7 +121,9 @@ typedef enum {
 /* EShExecutable counterpart */
 typedef enum { GLSLANG_EX_VERTEX_FRAGMENT, GLSLANG_EX_FRAGMENT } glslang_executable_t;
 
-/* EShOptimizationLevel counterpart  */
+// EShOptimizationLevel counterpart
+// This enum is not used in the current C interface, but could be added at a later date.
+// GLSLANG_OPT_NONE is the current default.
 typedef enum {
     GLSLANG_OPT_NO_GENERATION,
     GLSLANG_OPT_NONE,

+ 10 - 3
3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp

@@ -4680,7 +4680,7 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS
                 symbolQualifier.storage != qualifier.storage)
                 error(loc, "cannot change qualification of", "redeclaration", symbol->getName().c_str());
         } else if (identifier == "gl_FragCoord") {
-            if (intermediate.inIoAccessed("gl_FragCoord"))
+            if (!intermediate.getTexCoordRedeclared() && intermediate.inIoAccessed("gl_FragCoord"))
                 error(loc, "cannot redeclare after use", "gl_FragCoord", "");
             if (qualifier.nopersp != symbolQualifier.nopersp || qualifier.flat != symbolQualifier.flat ||
                 qualifier.isMemory() || qualifier.isAuxiliary())
@@ -4690,6 +4690,9 @@ TSymbol* TParseContext::redeclareBuiltinVariable(const TSourceLoc& loc, const TS
             if (! builtIn && (publicType.pixelCenterInteger != intermediate.getPixelCenterInteger() ||
                               publicType.originUpperLeft != intermediate.getOriginUpperLeft()))
                 error(loc, "cannot redeclare with different qualification:", "redeclaration", symbol->getName().c_str());
+
+
+            intermediate.setTexCoordRedeclared();
             if (publicType.pixelCenterInteger)
                 intermediate.setPixelCenterInteger();
             if (publicType.originUpperLeft)
@@ -6365,8 +6368,12 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
         profileRequires(loc, ECoreProfile | ECompatibilityProfile, 0, E_GL_EXT_shader_image_load_formatted, explanation);
     }
 
-    if (qualifier.isPushConstant() && type.getBasicType() != EbtBlock)
-        error(loc, "can only be used with a block", "push_constant", "");
+    if (qualifier.isPushConstant()) {
+        if (type.getBasicType() != EbtBlock)
+            error(loc, "can only be used with a block", "push_constant", "");
+        if (type.isArray())
+            error(loc, "Push constants blocks can't be an array", "push_constant", "");
+    }
 
     if (qualifier.hasBufferReference() && type.getBasicType() != EbtBlock)
         error(loc, "can only be used with a block", "buffer_reference", "");

+ 17 - 6
3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp

@@ -813,6 +813,7 @@ bool ProcessDeferred(
     // set version/profile to defaultVersion/defaultProfile regardless of the #version
     // directive in the source code
     bool forceDefaultVersionAndProfile,
+    int overrideVersion, // overrides version specified by #verison or default version
     bool forwardCompatible,     // give errors for use of deprecated features
     EShMessages messages,       // warnings/errors/AST; things to print out
     TIntermediate& intermediate, // returned tree, etc.
@@ -900,6 +901,9 @@ bool ProcessDeferred(
         version = defaultVersion;
         profile = defaultProfile;
     }
+    if (source == EShSourceGlsl && overrideVersion != 0) {
+        version = overrideVersion;
+    }
 
     bool goodVersion = DeduceVersionProfile(compiler->infoSink, stage,
                                             versionNotFirst, defaultVersion, source, version, profile, spvVersion);
@@ -1275,6 +1279,7 @@ bool PreprocessDeferred(
     int defaultVersion,         // use 100 for ES environment, 110 for desktop
     EProfile defaultProfile,
     bool forceDefaultVersionAndProfile,
+    int overrideVersion,        // use 0 if not overriding GLSL version
     bool forwardCompatible,     // give errors for use of deprecated features
     EShMessages messages,       // warnings/errors/AST; things to print out
     TShader::Includer& includer,
@@ -1285,7 +1290,7 @@ bool PreprocessDeferred(
     DoPreprocessing parser(outputString);
     return ProcessDeferred(compiler, shaderStrings, numStrings, inputLengths, stringNames,
                            preamble, optLevel, resources, defaultVersion,
-                           defaultProfile, forceDefaultVersionAndProfile,
+                           defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
                            forwardCompatible, messages, intermediate, parser,
                            false, includer, "", environment);
 }
@@ -1314,6 +1319,7 @@ bool CompileDeferred(
     int defaultVersion,         // use 100 for ES environment, 110 for desktop
     EProfile defaultProfile,
     bool forceDefaultVersionAndProfile,
+    int overrideVersion,        // use 0 if not overriding GLSL version
     bool forwardCompatible,     // give errors for use of deprecated features
     EShMessages messages,       // warnings/errors/AST; things to print out
     TIntermediate& intermediate,// returned tree, etc.
@@ -1324,7 +1330,7 @@ bool CompileDeferred(
     DoFullParse parser;
     return ProcessDeferred(compiler, shaderStrings, numStrings, inputLengths, stringNames,
                            preamble, optLevel, resources, defaultVersion,
-                           defaultProfile, forceDefaultVersionAndProfile,
+                           defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
                            forwardCompatible, messages, intermediate, parser,
                            true, includer, sourceEntryPointName, environment);
 }
@@ -1498,7 +1504,7 @@ int ShCompile(
     TIntermediate intermediate(compiler->getLanguage());
     TShader::ForbidIncluder includer;
     bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, nullptr,
-                                   "", optLevel, resources, defaultVersion, ENoProfile, false,
+                                   "", optLevel, resources, defaultVersion, ENoProfile, false, 0,
                                    forwardCompatible, messages, intermediate, includer);
 
     //
@@ -1759,7 +1765,7 @@ public:
 };
 
 TShader::TShader(EShLanguage s)
-    : stage(s), lengths(nullptr), stringNames(nullptr), preamble("")
+    : stage(s), lengths(nullptr), stringNames(nullptr), preamble(""), overrideVersion(0)
 {
     pool = new TPoolAllocator;
     infoSink = new TInfoSink;
@@ -1828,6 +1834,11 @@ void  TShader::setUniqueId(unsigned long long id)
     intermediate->setUniqueId(id);
 }
 
+void TShader::setOverrideVersion(int version)
+{
+    overrideVersion = version;
+}
+
 void TShader::setInvertY(bool invert)                   { intermediate->setInvertY(invert); }
 void TShader::setDxPositionW(bool invert)               { intermediate->setDxPositionW(invert); }
 void TShader::setEnhancedMsgs()                         { intermediate->setEnhancedMsgs(); }
@@ -1910,7 +1921,7 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion
 
     return CompileDeferred(compiler, strings, numStrings, lengths, stringNames,
                            preamble, EShOptNone, builtInResources, defaultVersion,
-                           defaultProfile, forceDefaultVersionAndProfile,
+                           defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
                            forwardCompatible, messages, *intermediate, includer, sourceEntryPointName,
                            &environment);
 }
@@ -1937,7 +1948,7 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources,
 
     return PreprocessDeferred(compiler, strings, numStrings, lengths, stringNames, preamble,
                               EShOptNone, builtInResources, defaultVersion,
-                              defaultProfile, forceDefaultVersionAndProfile,
+                              defaultProfile, forceDefaultVersionAndProfile, overrideVersion,
                               forwardCompatible, message, includer, *intermediate, output_string,
                               &environment);
 }

+ 5 - 1
3rdparty/glslang/glslang/MachineIndependent/localintermediate.h

@@ -309,7 +309,7 @@ public:
         useVulkanMemoryModel(false),
         invocations(TQualifier::layoutNotSet), vertices(TQualifier::layoutNotSet),
         inputPrimitive(ElgNone), outputPrimitive(ElgNone),
-        pixelCenterInteger(false), originUpperLeft(false),
+        pixelCenterInteger(false), originUpperLeft(false),texCoordBuiltinRedeclared(false),
         vertexSpacing(EvsNone), vertexOrder(EvoNone), interlockOrdering(EioNone), pointMode(false), earlyFragmentTests(false),
         postDepthCoverage(false), depthLayout(EldNone),
         hlslFunctionality1(false),
@@ -834,6 +834,8 @@ public:
     bool getOriginUpperLeft() const { return originUpperLeft; }
     void setPixelCenterInteger() { pixelCenterInteger = true; }
     bool getPixelCenterInteger() const { return pixelCenterInteger; }
+    void setTexCoordRedeclared() { texCoordBuiltinRedeclared = true; }
+    bool getTexCoordRedeclared() const { return texCoordBuiltinRedeclared; }
     void addBlendEquation(TBlendEquationShift b) { blendEquations |= (1 << b); }
     unsigned int getBlendEquations() const { return blendEquations; }
     bool setXfbBufferStride(int buffer, unsigned stride)
@@ -1122,6 +1124,7 @@ protected:
     TLayoutGeometry outputPrimitive;
     bool pixelCenterInteger;
     bool originUpperLeft;
+    bool texCoordBuiltinRedeclared;
     TVertexSpacing vertexSpacing;
     TVertexOrder vertexOrder;
     TInterlockOrdering interlockOrdering;
@@ -1182,6 +1185,7 @@ protected:
                                             // for callableData/callableDataIn
     // set of names of statically read/written I/O that might need extra checking
     std::set<TString> ioAccessed;
+
     // source code of shader, useful as part of debug information
     std::string sourceFile;
     std::string sourceText;

+ 4 - 0
3rdparty/glslang/glslang/Public/ShaderLang.h

@@ -471,6 +471,7 @@ public:
     GLSLANG_EXPORT void setSourceEntryPoint(const char* sourceEntryPointName);
     GLSLANG_EXPORT void addProcesses(const std::vector<std::string>&);
     GLSLANG_EXPORT void setUniqueId(unsigned long long id);
+    GLSLANG_EXPORT void setOverrideVersion(int version);
 
     // IO resolver binding data: see comments in ShaderLang.cpp
     GLSLANG_EXPORT void setShiftBinding(TResourceType res, unsigned int base);
@@ -711,6 +712,9 @@ protected:
     // a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
     std::string sourceEntryPointName;
 
+    // overrides #version in shader source or default version if #version isn't present
+    int overrideVersion;
+
     TEnvironment environment;
 
     friend class TProgram;