Ver código fonte

Updated glslang.

Бранимир Караџић 4 anos atrás
pai
commit
dbc8a2c62a

+ 12 - 6
3rdparty/glslang/SPIRV/SPVRemapper.cpp

@@ -297,15 +297,21 @@ namespace spv {
     std::string spirvbin_t::literalString(unsigned word) const
     std::string spirvbin_t::literalString(unsigned word) const
     {
     {
         std::string literal;
         std::string literal;
+        const spirword_t * pos = spv.data() + word;
 
 
         literal.reserve(16);
         literal.reserve(16);
 
 
-        const char* bytes = reinterpret_cast<const char*>(spv.data() + word);
-
-        while (bytes && *bytes)
-            literal += *bytes++;
-
-        return literal;
+        do {
+            spirword_t word = *pos;
+            for (int i = 0; i < 4; i++) {
+                char c = word & 0xff;
+                if (c == '\0')
+                    return literal;
+                literal += c;
+                word >>= 8;
+            }
+            pos++;
+        } while (true);
     }
     }
 
 
     void spirvbin_t::applyMap()
     void spirvbin_t::applyMap()

+ 3 - 3
3rdparty/glslang/SPIRV/SpvBuilder.cpp

@@ -433,11 +433,11 @@ Id Builder::makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& opera
     Instruction* type;
     Instruction* type;
     for (int t = 0; t < (int)groupedTypes[opcode].size(); ++t) {
     for (int t = 0; t < (int)groupedTypes[opcode].size(); ++t) {
         type = groupedTypes[opcode][t];
         type = groupedTypes[opcode][t];
-        if (type->getNumOperands() != operands.size())
+        if (static_cast<size_t>(type->getNumOperands()) != operands.size())
             continue; // Number mismatch, find next
             continue; // Number mismatch, find next
 
 
         bool match = true;
         bool match = true;
-        for (int op = 0; match && op < operands.size(); ++op) {
+        for (size_t op = 0; match && op < operands.size(); ++op) {
             match = (operands[op].isId ? type->getIdOperand(op) : type->getImmediateOperand(op)) == operands[op].word;
             match = (operands[op].isId ? type->getIdOperand(op) : type->getImmediateOperand(op)) == operands[op].word;
         }
         }
         if (match)
         if (match)
@@ -446,7 +446,7 @@ Id Builder::makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& opera
 
 
     // not found, make it
     // not found, make it
     type = new Instruction(getUniqueId(), NoType, opcode);
     type = new Instruction(getUniqueId(), NoType, opcode);
-    for (int op = 0; op < operands.size(); ++op) {
+    for (size_t op = 0; op < operands.size(); ++op) {
         if (operands[op].isId)
         if (operands[op].isId)
             type->addIdOperand(operands[op].word);
             type->addIdOperand(operands[op].word);
         else
         else

+ 31 - 16
3rdparty/glslang/SPIRV/disassemble.cpp

@@ -43,6 +43,7 @@
 #include <stack>
 #include <stack>
 #include <sstream>
 #include <sstream>
 #include <cstring>
 #include <cstring>
+#include <utility>
 
 
 #include "disassemble.h"
 #include "disassemble.h"
 #include "doc.h"
 #include "doc.h"
@@ -100,6 +101,7 @@ protected:
     void outputMask(OperandClass operandClass, unsigned mask);
     void outputMask(OperandClass operandClass, unsigned mask);
     void disassembleImmediates(int numOperands);
     void disassembleImmediates(int numOperands);
     void disassembleIds(int numOperands);
     void disassembleIds(int numOperands);
+    std::pair<int, std::string> decodeString();
     int disassembleString();
     int disassembleString();
     void disassembleInstruction(Id resultId, Id typeId, Op opCode, int numOperands);
     void disassembleInstruction(Id resultId, Id typeId, Op opCode, int numOperands);
 
 
@@ -290,31 +292,44 @@ void SpirvStream::disassembleIds(int numOperands)
     }
     }
 }
 }
 
 
-// return the number of operands consumed by the string
-int SpirvStream::disassembleString()
+// decode string from words at current position (non-consuming)
+std::pair<int, std::string> SpirvStream::decodeString()
 {
 {
-    int startWord = word;
-
-    out << " \"";
-
-    const char* wordString;
+    std::string res;
+    int wordPos = word;
+    char c;
     bool done = false;
     bool done = false;
+
     do {
     do {
-        unsigned int content = stream[word];
-        wordString = (const char*)&content;
+        unsigned int content = stream[wordPos];
         for (int charCount = 0; charCount < 4; ++charCount) {
         for (int charCount = 0; charCount < 4; ++charCount) {
-            if (*wordString == 0) {
+            c = content & 0xff;
+            content >>= 8;
+            if (c == '\0') {
                 done = true;
                 done = true;
                 break;
                 break;
             }
             }
-            out << *(wordString++);
+            res += c;
         }
         }
-        ++word;
-    } while (! done);
+        ++wordPos;
+    } while(! done);
+
+    return std::make_pair(wordPos - word, res);
+}
+
+// return the number of operands consumed by the string
+int SpirvStream::disassembleString()
+{
+    out << " \"";
 
 
+    std::pair<int, std::string> decoderes = decodeString();
+
+    out << decoderes.second;
     out << "\"";
     out << "\"";
 
 
-    return word - startWord;
+    word += decoderes.first;
+
+    return decoderes.first;
 }
 }
 
 
 void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, int numOperands)
 void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, int numOperands)
@@ -331,7 +346,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
             nextNestedControl = 0;
             nextNestedControl = 0;
         }
         }
     } else if (opCode == OpExtInstImport) {
     } else if (opCode == OpExtInstImport) {
-        idDescriptor[resultId] = (const char*)(&stream[word]);
+        idDescriptor[resultId] = decodeString().second;
     }
     }
     else {
     else {
         if (resultId != 0 && idDescriptor[resultId].size() == 0) {
         if (resultId != 0 && idDescriptor[resultId].size() == 0) {
@@ -428,7 +443,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
             --numOperands;
             --numOperands;
             // Get names for printing "(XXX)" for readability, *after* this id
             // Get names for printing "(XXX)" for readability, *after* this id
             if (opCode == OpName)
             if (opCode == OpName)
-                idDescriptor[stream[word - 1]] = (const char*)(&stream[word]);
+                idDescriptor[stream[word - 1]] = decodeString().second;
             break;
             break;
         case OperandVariableIds:
         case OperandVariableIds:
             disassembleIds(numOperands);
             disassembleIds(numOperands);

+ 9 - 13
3rdparty/glslang/SPIRV/spvIR.h

@@ -111,27 +111,23 @@ public:
 
 
     void addStringOperand(const char* str)
     void addStringOperand(const char* str)
     {
     {
-        unsigned int word;
-        char* wordString = (char*)&word;
-        char* wordPtr = wordString;
-        int charCount = 0;
+        unsigned int word = 0;
+        unsigned int shiftAmount = 0;
         char c;
         char c;
+
         do {
         do {
             c = *(str++);
             c = *(str++);
-            *(wordPtr++) = c;
-            ++charCount;
-            if (charCount == 4) {
+            word |= ((unsigned int)c) << shiftAmount;
+            shiftAmount += 8;
+            if (shiftAmount == 32) {
                 addImmediateOperand(word);
                 addImmediateOperand(word);
-                wordPtr = wordString;
-                charCount = 0;
+                word = 0;
+                shiftAmount = 0;
             }
             }
         } while (c != 0);
         } while (c != 0);
 
 
         // deal with partial last word
         // deal with partial last word
-        if (charCount > 0) {
-            // pad with 0s
-            for (; charCount < 4; ++charCount)
-                *(wordPtr++) = 0;
+        if (shiftAmount > 0) {
             addImmediateOperand(word);
             addImmediateOperand(word);
         }
         }
     }
     }

+ 5 - 2
3rdparty/glslang/glslang/Include/Types.h

@@ -2446,11 +2446,15 @@ public:
     //
     //
     bool sameStructType(const TType& right) const
     bool sameStructType(const TType& right) const
     {
     {
+        // TODO: Why return true when neither types are structures?
         // Most commonly, they are both nullptr, or the same pointer to the same actual structure
         // Most commonly, they are both nullptr, or the same pointer to the same actual structure
         if ((!isStruct() && !right.isStruct()) ||
         if ((!isStruct() && !right.isStruct()) ||
             (isStruct() && right.isStruct() && structure == right.structure))
             (isStruct() && right.isStruct() && structure == right.structure))
             return true;
             return true;
 
 
+        if (!isStruct() || !right.isStruct())
+            return false;
+
         // Structure names have to match
         // Structure names have to match
         if (*typeName != *right.typeName)
         if (*typeName != *right.typeName)
             return false;
             return false;
@@ -2460,8 +2464,7 @@ public:
         bool isGLPerVertex = *typeName == "gl_PerVertex";
         bool isGLPerVertex = *typeName == "gl_PerVertex";
 
 
         // Both being nullptr was caught above, now they both have to be structures of the same number of elements
         // Both being nullptr was caught above, now they both have to be structures of the same number of elements
-        if (!isStruct() || !right.isStruct() ||
-            (structure->size() != right.structure->size() && !isGLPerVertex))
+        if (structure->size() != right.structure->size() && !isGLPerVertex)
             return false;
             return false;
 
 
         // Compare the names and types of all the members, which have to match
         // Compare the names and types of all the members, which have to match

+ 5 - 4
3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp

@@ -8353,10 +8353,11 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
         }
         }
 
 
         if (profile != EEsProfile && version < 330 ) {
         if (profile != EEsProfile && version < 330 ) {
-            symbolTable.setFunctionExtensions("floatBitsToInt", 1, &E_GL_ARB_shader_bit_encoding);
-            symbolTable.setFunctionExtensions("floatBitsToUint", 1, &E_GL_ARB_shader_bit_encoding);
-            symbolTable.setFunctionExtensions("intBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
-            symbolTable.setFunctionExtensions("uintBitsToFloat", 1, &E_GL_ARB_shader_bit_encoding);
+            const char* bitsConvertExt[2] = {E_GL_ARB_shader_bit_encoding, E_GL_ARB_gpu_shader5};
+            symbolTable.setFunctionExtensions("floatBitsToInt", 2, bitsConvertExt);
+            symbolTable.setFunctionExtensions("floatBitsToUint", 2, bitsConvertExt);
+            symbolTable.setFunctionExtensions("intBitsToFloat", 2, bitsConvertExt);
+            symbolTable.setFunctionExtensions("uintBitsToFloat", 2, bitsConvertExt);
         }
         }
 
 
         if (profile != EEsProfile && version < 430 ) {
         if (profile != EEsProfile && version < 430 ) {

+ 7 - 5
3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp

@@ -1321,7 +1321,7 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
         // Find it in the symbol table.
         // Find it in the symbol table.
         //
         //
         const TFunction* fnCandidate;
         const TFunction* fnCandidate;
-        bool builtIn;
+        bool builtIn {false};
         fnCandidate = findFunction(loc, *function, builtIn);
         fnCandidate = findFunction(loc, *function, builtIn);
         if (fnCandidate) {
         if (fnCandidate) {
             // This is a declared function that might map to
             // This is a declared function that might map to
@@ -6210,11 +6210,13 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
 
 
 #ifndef GLSLANG_WEB
 #ifndef GLSLANG_WEB
     if (qualifier.hasXfbOffset() && qualifier.hasXfbBuffer()) {
     if (qualifier.hasXfbOffset() && qualifier.hasXfbBuffer()) {
-        int repeated = intermediate.addXfbBufferOffset(type);
-        if (repeated >= 0)
-            error(loc, "overlapping offsets at", "xfb_offset", "offset %d in buffer %d", repeated, qualifier.layoutXfbBuffer);
-        if (type.isUnsizedArray())
+        if (type.isUnsizedArray()) {
             error(loc, "unsized array", "xfb_offset", "in buffer %d", qualifier.layoutXfbBuffer);
             error(loc, "unsized array", "xfb_offset", "in buffer %d", qualifier.layoutXfbBuffer);
+        } else {
+            int repeated = intermediate.addXfbBufferOffset(type);
+            if (repeated >= 0)
+                error(loc, "overlapping offsets at", "xfb_offset", "offset %d in buffer %d", repeated, qualifier.layoutXfbBuffer);
+        }
 
 
         // "The offset must be a multiple of the size of the first component of the first
         // "The offset must be a multiple of the size of the first component of the first
         // qualified variable or block member, or a compile-time error results. Further, if applied to an aggregate
         // qualified variable or block member, or a compile-time error results. Further, if applied to an aggregate

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

@@ -1802,7 +1802,7 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
         return size;
         return size;
     }
     }
 
 
-    int numComponents;
+    int numComponents {0};
     if (type.isScalar())
     if (type.isScalar())
         numComponents = 1;
         numComponents = 1;
     else if (type.isVector())
     else if (type.isVector())