diff --git a/3rdparty/glslang/SPIRV/CMakeLists.txt b/3rdparty/glslang/SPIRV/CMakeLists.txt index 9d9d8033a..1e5513c73 100755 --- a/3rdparty/glslang/SPIRV/CMakeLists.txt +++ b/3rdparty/glslang/SPIRV/CMakeLists.txt @@ -43,6 +43,7 @@ endif(ENABLE_NV_EXTENSIONS) add_library(SPIRV ${LIB_TYPE} ${SOURCES} ${HEADERS}) set_property(TARGET SPIRV PROPERTY FOLDER glslang) set_property(TARGET SPIRV PROPERTY POSITION_INDEPENDENT_CODE ON) +target_include_directories(SPIRV PUBLIC ..) add_library(SPVRemapper ${LIB_TYPE} ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS}) set_property(TARGET SPVRemapper PROPERTY FOLDER glslang) diff --git a/3rdparty/glslang/SPIRV/GlslangToSpv.cpp b/3rdparty/glslang/SPIRV/GlslangToSpv.cpp index 36fb8a127..4838f20cb 100755 --- a/3rdparty/glslang/SPIRV/GlslangToSpv.cpp +++ b/3rdparty/glslang/SPIRV/GlslangToSpv.cpp @@ -190,7 +190,7 @@ protected: glslang::TBasicType typeProxy); spv::Id createConversion(glslang::TOperator op, OpDecorations&, spv::Id destTypeId, spv::Id operand, glslang::TBasicType typeProxy); - spv::Id createConversionOperation(glslang::TOperator op, spv::Id operand, int vectorSize); + spv::Id createIntWidthConversion(glslang::TOperator op, spv::Id operand, int vectorSize); spv::Id makeSmearedConstant(spv::Id constant, int vectorSize); spv::Id createAtomicOperation(glslang::TOperator op, spv::Decoration precision, spv::Id typeId, std::vector& operands, glslang::TBasicType typeProxy); spv::Id createInvocationsOperation(glslang::TOperator op, spv::Id typeId, std::vector& operands, glslang::TBasicType typeProxy); @@ -340,8 +340,10 @@ void TranslateMemoryDecoration(const glslang::TQualifier& qualifier, std::vector { if (qualifier.coherent) memory.push_back(spv::DecorationCoherent); - if (qualifier.volatil) + if (qualifier.volatil) { memory.push_back(spv::DecorationVolatile); + memory.push_back(spv::DecorationCoherent); + } if (qualifier.restrict) memory.push_back(spv::DecorationRestrict); if (qualifier.readonly) @@ -4828,109 +4830,45 @@ spv::Id TGlslangToSpvTraverser::createUnaryMatrixOperation(spv::Op op, OpDecorat return result; } -spv::Id TGlslangToSpvTraverser::createConversionOperation(glslang::TOperator op, spv::Id operand, int vectorSize) +// For converting integers where both the bitwidth and the signedness could +// change, but only do the width change here. The caller is still responsible +// for the signedness conversion. +spv::Id TGlslangToSpvTraverser::createIntWidthConversion(glslang::TOperator op, spv::Id operand, int vectorSize) { - spv::Op convOp = spv::OpNop; - spv::Id type = 0; - - spv::Id result = 0; - + // Get the result type width, based on the type to convert to. + int width = 32; switch(op) { + case glslang::EOpConvInt16ToUint8: + case glslang::EOpConvIntToUint8: + case glslang::EOpConvInt64ToUint8: + case glslang::EOpConvUint16ToInt8: + case glslang::EOpConvUintToInt8: + case glslang::EOpConvUint64ToInt8: + width = 8; + break; case glslang::EOpConvInt8ToUint16: - convOp = spv::OpSConvert; - type = builder.makeIntType(16); + case glslang::EOpConvIntToUint16: + case glslang::EOpConvInt64ToUint16: + case glslang::EOpConvUint8ToInt16: + case glslang::EOpConvUintToInt16: + case glslang::EOpConvUint64ToInt16: + width = 16; break; case glslang::EOpConvInt8ToUint: - convOp = spv::OpSConvert; - type = builder.makeIntType(32); + case glslang::EOpConvInt16ToUint: + case glslang::EOpConvInt64ToUint: + case glslang::EOpConvUint8ToInt: + case glslang::EOpConvUint16ToInt: + case glslang::EOpConvUint64ToInt: + width = 32; break; case glslang::EOpConvInt8ToUint64: - convOp = spv::OpSConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvInt16ToUint8: - convOp = spv::OpSConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvInt16ToUint: - convOp = spv::OpSConvert; - type = builder.makeIntType(32); - break; case glslang::EOpConvInt16ToUint64: - convOp = spv::OpSConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvIntToUint8: - convOp = spv::OpSConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvIntToUint16: - convOp = spv::OpSConvert; - type = builder.makeIntType(16); - break; case glslang::EOpConvIntToUint64: - convOp = spv::OpSConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvInt64ToUint8: - convOp = spv::OpSConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvInt64ToUint16: - convOp = spv::OpSConvert; - type = builder.makeIntType(16); - break; - case glslang::EOpConvInt64ToUint: - convOp = spv::OpSConvert; - type = builder.makeIntType(32); - break; - case glslang::EOpConvUint8ToInt16: - convOp = spv::OpUConvert; - type = builder.makeIntType(16); - break; - case glslang::EOpConvUint8ToInt: - convOp = spv::OpUConvert; - type = builder.makeIntType(32); - break; case glslang::EOpConvUint8ToInt64: - convOp = spv::OpUConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvUint16ToInt8: - convOp = spv::OpUConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvUint16ToInt: - convOp = spv::OpUConvert; - type = builder.makeIntType(32); - break; case glslang::EOpConvUint16ToInt64: - convOp = spv::OpUConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvUintToInt8: - convOp = spv::OpUConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvUintToInt16: - convOp = spv::OpUConvert; - type = builder.makeIntType(16); - break; case glslang::EOpConvUintToInt64: - convOp = spv::OpUConvert; - type = builder.makeIntType(64); - break; - case glslang::EOpConvUint64ToInt8: - convOp = spv::OpUConvert; - type = builder.makeIntType(8); - break; - case glslang::EOpConvUint64ToInt16: - convOp = spv::OpUConvert; - type = builder.makeIntType(16); - break; - case glslang::EOpConvUint64ToInt: - convOp = spv::OpUConvert; - type = builder.makeIntType(32); + width = 64; break; default: @@ -4938,11 +4876,36 @@ spv::Id TGlslangToSpvTraverser::createConversionOperation(glslang::TOperator op, break; } + // Get the conversion operation and result type, + // based on the target width, but the source type. + spv::Id type = spv::NoType; + spv::Op convOp = spv::OpNop; + switch(op) { + case glslang::EOpConvInt8ToUint16: + case glslang::EOpConvInt8ToUint: + case glslang::EOpConvInt8ToUint64: + case glslang::EOpConvInt16ToUint8: + case glslang::EOpConvInt16ToUint: + case glslang::EOpConvInt16ToUint64: + case glslang::EOpConvIntToUint8: + case glslang::EOpConvIntToUint16: + case glslang::EOpConvIntToUint64: + case glslang::EOpConvInt64ToUint8: + case glslang::EOpConvInt64ToUint16: + case glslang::EOpConvInt64ToUint: + convOp = spv::OpSConvert; + type = builder.makeIntType(width); + break; + default: + convOp = spv::OpUConvert; + type = builder.makeUintType(width); + break; + } + if (vectorSize > 0) type = builder.makeVectorType(type, vectorSize); - result = builder.createUnaryOp(convOp, type, operand); - return result; + return builder.createUnaryOp(convOp, type, operand); } spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, OpDecorations& decorations, spv::Id destType, @@ -5217,7 +5180,7 @@ spv::Id TGlslangToSpvTraverser::createConversion(glslang::TOperator op, OpDecora case glslang::EOpConvUint64ToInt16: case glslang::EOpConvUint64ToInt: // OpSConvert/OpUConvert + OpBitCast - operand = createConversionOperation(op, operand, vectorSize); + operand = createIntWidthConversion(op, operand, vectorSize); if (builder.isInSpecConstCodeGenMode()) { // Build zero scalar or vector for OpIAdd. @@ -6922,8 +6885,9 @@ int GetSpirvGeneratorVersion() // return 3; // change/correct barrier-instruction operands, to match memory model group decisions // return 4; // some deeper access chains: for dynamic vector component, and local Boolean component // return 5; // make OpArrayLength result type be an int with signedness of 0 - return 6; // revert version 5 change, which makes a different (new) kind of incorrect code, - // versions 4 and 6 each generate OpArrayLength as it has long been done + // return 6; // revert version 5 change, which makes a different (new) kind of incorrect code, + // versions 4 and 6 each generate OpArrayLength as it has long been done + return 7; // GLSL volatile keyword maps to both SPIR-V decorations Volatile and Coherent } // Write SPIR-V out to a binary file @@ -7024,18 +6988,16 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vectoroptimizeSize) { optimizer.RegisterPass(CreateRedundancyEliminationPass()); @@ -7043,6 +7005,7 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector 0.0 && (fabs(value) < 1e-5 || fabs(value) > 1e12)) format = "%-.13e"; - snprintf(buf, maxSize, format, value); + int len = snprintf(buf, maxSize, format, value); + assert(len < maxSize); // remove a leading zero in the 100s slot in exponent; it is not portable // pattern: XX...XXXe+0XX or XX...XXXe-0XX - int len = (int)strnlen(buf, maxSize); if (len > 5) { if (buf[len-5] == 'e' && (buf[len-4] == '+' || buf[len-4] == '-') && buf[len-3] == '0') { buf[len-3] = buf[len-2]; @@ -1131,7 +1131,7 @@ static void OutputDouble(TInfoSink& out, double value, TOutputTraverser::EExtraO { out.debug << " : "; long long b = *reinterpret_cast(&value); - for (int i = 0; i < 8 * sizeof(value); ++i, ++b) { + for (size_t i = 0; i < 8 * sizeof(value); ++i, ++b) { out.debug << ((b & 0x8000000000000000) != 0 ? "1" : "0"); b <<= 1; } diff --git a/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp b/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp index d8088e7d4..7dc2722ce 100755 --- a/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp +++ b/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp @@ -188,7 +188,7 @@ void TPpContext::TokenStream::putToken(int atom, TPpToken* ppToken) // save the numeric value if (SaveValue(atom)) { const char* n = reinterpret_cast(&ppToken->i64val); - for (int i = 0; i < sizeof(ppToken->i64val); ++i) + for (size_t i = 0; i < sizeof(ppToken->i64val); ++i) putSubtoken(*n++); } } @@ -238,7 +238,7 @@ int TPpContext::TokenStream::getToken(TParseContextBase& parseContext, TPpToken // get the numeric value if (SaveValue(atom)) { char* n = reinterpret_cast(&ppToken->i64val); - for (int i = 0; i < sizeof(ppToken->i64val); ++i) + for (size_t i = 0; i < sizeof(ppToken->i64val); ++i) *n++ = getSubtoken(); } diff --git a/3rdparty/glslang/known_good.json b/3rdparty/glslang/known_good.json index 3b202f6c3..66593490c 100644 --- a/3rdparty/glslang/known_good.json +++ b/3rdparty/glslang/known_good.json @@ -5,7 +5,7 @@ "site" : "github", "subrepo" : "KhronosGroup/SPIRV-Tools", "subdir" : "External/spirv-tools", - "commit" : "a579e720a8d7805ec9ebf657a4c6fa67ec268f7e" + "commit" : "f2c93c6e124836797311facb8449f9a0b76fefc2" }, { "name" : "spirv-tools/external/spirv-headers",