Ver Fonte

Updated glslang.

Бранимир Караџић há 3 anos atrás
pai
commit
a883ee37c3

+ 21 - 5
3rdparty/glslang/SPIRV/SPVRemapper.cpp

@@ -160,15 +160,29 @@ namespace spv {
     }
 
     // Is this an opcode we should remove when using --strip?
-    bool spirvbin_t::isStripOp(spv::Op opCode) const
+    bool spirvbin_t::isStripOp(spv::Op opCode, unsigned start) const
     {
         switch (opCode) {
         case spv::OpSource:
         case spv::OpSourceExtension:
         case spv::OpName:
         case spv::OpMemberName:
-        case spv::OpLine:           return true;
-        default:                    return false;
+        case spv::OpLine :
+        {
+            const std::string name = literalString(start + 2);
+
+            std::vector<std::string>::const_iterator it;
+            for (it = stripWhiteList.begin(); it < stripWhiteList.end(); it++)
+            {
+                if (name.find(*it) != std::string::npos) {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+        default :
+            return false;
         }
     }
 
@@ -372,7 +386,7 @@ namespace spv {
         process(
             [&](spv::Op opCode, unsigned start) {
                 // remember opcodes we want to strip later
-                if (isStripOp(opCode))
+                if (isStripOp(opCode, start))
                     stripInst(start);
                 return true;
             },
@@ -1494,8 +1508,10 @@ namespace spv {
     }
 
     // remap from a memory image
-    void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, std::uint32_t opts)
+    void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, const std::vector<std::string>& whiteListStrings,
+                           std::uint32_t opts)
     {
+        stripWhiteList = whiteListStrings;
         spv.swap(in_spv);
         remap(opts);
         spv.swap(in_spv);

+ 6 - 1
3rdparty/glslang/SPIRV/SPVRemapper.h

@@ -118,7 +118,8 @@ public:
    virtual ~spirvbin_t() { }
 
    // remap on an existing binary in memory
-   void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
+   void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
+              std::uint32_t opts = DO_EVERYTHING);
 
    // Type for error/log handler functions
    typedef std::function<void(const std::string&)> errorfn_t;
@@ -180,6 +181,8 @@ private:
    unsigned typeSizeInWords(spv::Id id)    const;
    unsigned idTypeSizeInWords(spv::Id id)  const;
 
+   bool isStripOp(spv::Op opCode, unsigned start) const;
+
    spv::Id&        asId(unsigned word)                { return spv[word]; }
    const spv::Id&  asId(unsigned word)          const { return spv[word]; }
    spv::Op         asOpCode(unsigned word)      const { return opOpCode(spv[word]); }
@@ -249,6 +252,8 @@ private:
 
    std::vector<spirword_t> spv;      // SPIR words
 
+   std::vector<std::string> stripWhiteList;
+
    namemap_t               nameMap;  // ID names from OpName
 
    // Since we want to also do binary ops, we can't use std::vector<bool>.  we could use

+ 40 - 6
3rdparty/glslang/StandAlone/spirv-remap.cpp

@@ -105,6 +105,32 @@ namespace {
         }
     }
 
+    // Read strings from a file
+    void read(std::vector<std::string>& strings, const std::string& inFilename, int verbosity)
+    {
+        std::ifstream fp;
+
+        if (verbosity > 0)
+            logHandler(std::string("  reading: ") + inFilename);
+
+        strings.clear();
+        fp.open(inFilename, std::fstream::in);
+
+        if (fp.fail())
+            errHandler("error opening file for read: ");
+
+        std::string line;
+        while (std::getline(fp, line))
+        {
+            // Ignore empty lines and lines starting with the comment marker '#'.
+            if (line.length() == 0 || line[0] == '#') {
+                continue;
+            }
+
+            strings.push_back(line);
+        }
+    }
+
     void write(std::vector<SpvWord>& spv, const std::string& outFile, int verbosity)
     {
         if (outFile.empty())
@@ -144,6 +170,7 @@ namespace {
             << " [--dce (all|types|funcs)]"
             << " [--opt (all|loadstore)]"
             << " [--strip-all | --strip all | -s]"
+            << " [--strip-white-list]"
             << " [--do-everything]"
             << " --input | -i file1 [file2...] --output|-o DESTDIR"
             << std::endl;
@@ -156,16 +183,18 @@ namespace {
 
     // grind through each SPIR in turn
     void execute(const std::vector<std::string>& inputFile, const std::string& outputDir,
-        int opts, int verbosity)
+                 const std::string& whiteListFile, int opts, int verbosity)
     {
+        std::vector<std::string> whiteListStrings;
+        if(!whiteListFile.empty())
+            read(whiteListStrings, whiteListFile, verbosity);
+
         for (auto it = inputFile.cbegin(); it != inputFile.cend(); ++it) {
             const std::string &filename = *it;
             std::vector<SpvWord> spv;
             read(spv, filename, verbosity);
-            spv::spirvbin_t(verbosity).remap(spv, opts);
-
+            spv::spirvbin_t(verbosity).remap(spv, whiteListStrings, opts);
             const std::string outfile = outputDir + path_sep_char() + basename(filename);
-
             write(spv, outfile, verbosity);
         }
 
@@ -176,6 +205,7 @@ namespace {
     // Parse command line options
     void parseCmdLine(int argc, char** argv, std::vector<std::string>& inputFile,
         std::string& outputDir,
+        std::string& stripWhiteListFile,
         int& options,
         int& verbosity)
     {
@@ -245,6 +275,9 @@ namespace {
                     options = options | spv::spirvbin_t::STRIP;
                     ++a;
                 }
+            } else if (arg == "--strip-white-list") {
+                ++a;
+                stripWhiteListFile = argv[a++];
             } else if (arg == "--dce") {
                 // Parse comma (or colon, etc) separated list of things to dce
                 ++a;
@@ -315,6 +348,7 @@ int main(int argc, char** argv)
 {
     std::vector<std::string> inputFile;
     std::string              outputDir;
+    std::string              whiteListFile;
     int                      opts;
     int                      verbosity;
 
@@ -329,13 +363,13 @@ int main(int argc, char** argv)
     if (argc < 2)
         usage(argv[0]);
 
-    parseCmdLine(argc, argv, inputFile, outputDir, opts, verbosity);
+    parseCmdLine(argc, argv, inputFile, outputDir, whiteListFile, opts, verbosity);
 
     if (outputDir.empty())
         usage(argv[0], "Output directory required");
 
     // Main operations: read, remap, and write.
-    execute(inputFile, outputDir, opts, verbosity);
+    execute(inputFile, outputDir, whiteListFile, opts, verbosity);
 
     // If we get here, everything went OK!  Nothing more to be done.
 }

+ 1 - 1
3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp

@@ -642,7 +642,7 @@ void TIntermediate::mergeBlockDefinitions(TInfoSink& infoSink, TIntermSymbol* bl
         }
         TMergeBlockTraverser(const TIntermSymbol* newSym, const glslang::TType* unitType, glslang::TIntermediate* unit,
                              const std::map<unsigned int, unsigned int>* memberIdxUpdates)
-            : newSymbol(newSym), unitType(unitType), unit(unit), memberIndexUpdates(memberIdxUpdates)
+            : TIntermTraverser(false, true), newSymbol(newSym), unitType(unitType), unit(unit), memberIndexUpdates(memberIdxUpdates)
         {
         }
         virtual ~TMergeBlockTraverser() {}