From 5e97be2b28cb0d9684094b191b0a6a6270a87290 Mon Sep 17 00:00:00 2001 From: danginsburg Date: Tue, 11 Aug 2020 09:39:43 -0400 Subject: [PATCH] Fix compile errors and assert when using latest glslang: * Compile fixes for TType::isRuntimeSizedArray() being removed and computeTypeLocationSize() requiring the stage. * TType::getStruct() was changed to assert(isStruct()) which meant several places causing getStruct() would assert in debug builds. Add getStructIfIsStruct() and use that or isStruct() in places where checking for nullptr was used. --- Frontends/glslang/GlslangToTopVisitor.cpp | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Frontends/glslang/GlslangToTopVisitor.cpp b/Frontends/glslang/GlslangToTopVisitor.cpp index ef90c965..af4b9dfb 100644 --- a/Frontends/glslang/GlslangToTopVisitor.cpp +++ b/Frontends/glslang/GlslangToTopVisitor.cpp @@ -131,6 +131,8 @@ class TGlslangToTopTraverser : public glslang::TIntermTraverser { void setOutputMetadata(glslang::TIntermSymbol* node, llvm::Value*, int slot, int numSlots); llvm::MDNode* makeInputMetadata(glslang::TIntermSymbol* node, llvm::Value*, int slot); + const glslang::TTypeList* getStructIfIsStruct(const glslang::TType& type) const { return type.isStruct() ? type.getStruct() : nullptr; } + gla::Manager& manager; llvm::LLVMContext &context; llvm::BasicBlock* globalInitializerInsertPoint; // the last block of the global initializers, which start at beginning of the entry point @@ -179,7 +181,7 @@ gla::EMdInputOutput GetMdInputOutput(const glslang::TType& type) mdQualifier = gla::EMioPipeOutBlock; break; case glslang::EvqBuffer: - if (type.getStruct()->back().type->isRuntimeSizedArray()) + if (type.getStruct()->back().type->isArray() && type.getStruct()->back().type->getOuterArraySize() == glslang::UnsizedArraySize && type.getStruct()->back().type->getQualifier().storage == glslang::EvqBuffer) mdQualifier = gla::EMioBufferBlockMemberArrayed; else mdQualifier = gla::EMioBufferBlockMember; @@ -826,7 +828,7 @@ bool TGlslangToTopTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T // If this dereference results in a runtime-sized array, it's a pointer // we don't want in the middle of an access chain, but rather the base // of a new one. - if (node->getType().isRuntimeSizedArray()) + if (node->getType().isArray() && node->getType().getOuterArraySize() == glslang::UnsizedArraySize && node->getType().getQualifier().storage == glslang::EvqBuffer) glaBuilder->accessChainEvolveToRuntimeArrayBase(); } return false; @@ -1733,10 +1735,10 @@ llvm::Type* TGlslangToTopTraverser::convertGlslangToGlaType(const glslang::TType } if (type.isArray()) { - if (type.isImplicitlySizedArray()) { + if (type.isArray() && type.getOuterArraySize() == glslang::UnsizedArraySize && type.getQualifier().storage != glslang::EvqBuffer) { gla::UnsupportedFunctionality("implicitly-sized array", gla::EATContinue); glaType = llvm::ArrayType::get(glaType, UnknownArraySize); - } if (type.isRuntimeSizedArray()) { + } if (type.isArray() && type.getOuterArraySize() == glslang::UnsizedArraySize && type.getQualifier().storage == glslang::EvqBuffer) { // // Runtime array design. // @@ -3002,7 +3004,7 @@ void TGlslangToTopTraverser::createPipelineSubread(const glslang::TType& type, l } if (gepChain.size() == 1) gepChain.pop_back(); - } else if (const glslang::TTypeList* typeList = type.getStruct()) { + } else if (const glslang::TTypeList* typeList = getStructIfIsStruct(type)) { if (gepChain.size() == 0) gepChain.push_back(gla::MakeIntConstant(context, 0)); for (int field = 0; field < (int)typeList->size(); ++field) { @@ -3069,9 +3071,9 @@ int TGlslangToTopTraverser::assignSlot(glslang::TIntermSymbol* node, bool input, //numSlots = glslangIntermediate->computeTypeLocationSize(elementType); if (! glaBuilder->useLogicalIo()) gla::UnsupportedFunctionality("arrayed IO in physical IO mode (use logical IO instead)", gla::EATContinue); - numSlots = glslangIntermediate->computeTypeLocationSize(type); + numSlots = glslangIntermediate->computeTypeLocationSize(type, glslangIntermediate->getStage()); } else - numSlots = glslangIntermediate->computeTypeLocationSize(type); + numSlots = glslangIntermediate->computeTypeLocationSize(type, glslangIntermediate->getStage()); } else { numSlots = 1; if (type.isArray() && ! type.getQualifier().isArrayedIo(glslangIntermediate->getStage())) @@ -3142,7 +3144,7 @@ llvm::Constant* TGlslangToTopTraverser::createLLVMConstant(const glslang::TType& glslang::TType vectorType(glslangType, 0); for (int col = 0; col < glslangType.getMatrixCols(); ++col) llvmConsts.push_back(llvm::dyn_cast(createLLVMConstant(vectorType, consts, nextConst))); - } else if (glslangType.getStruct()) { + } else if (glslangType.isStruct()) { glslang::TVector::const_iterator iter; for (iter = glslangType.getStruct()->begin(); iter != glslangType.getStruct()->end(); ++iter) llvmConsts.push_back(llvm::dyn_cast(createLLVMConstant(*iter->type, consts, nextConst))); @@ -3226,7 +3228,7 @@ llvm::MDNode* TGlslangToTopTraverser::declareMdType(const glslang::TType& type, std::vector mdArgs; // name of aggregate, if an aggregate (struct or block) - if (type.getStruct()) + if (type.isStruct()) mdArgs.push_back(llvm::MDString::get(context, type.getTypeName().c_str())); else mdArgs.push_back(llvm::MDString::get(context, "")); @@ -3235,7 +3237,7 @@ llvm::MDNode* TGlslangToTopTraverser::declareMdType(const glslang::TType& type, mdArgs.push_back(metadata.makeMdTypeLayout(GetMdTypeLayout(type, inheritMatrix), GetMdPrecision(type), GetMdSlotLocation(type), samplerMd, -1, GetMdBuiltIn(type), GetMdBinding(type), GetMdQualifiers(type), GetMdOffset(type, useUniformOffsets))); - const glslang::TTypeList* typeList = type.getStruct(); + const glslang::TTypeList* typeList = getStructIfIsStruct(type); if (typeList) { for (int t = 0; t < (int)typeList->size(); ++t) { const glslang::TType* fieldType = (*typeList)[t].type; @@ -3329,7 +3331,7 @@ llvm::MDNode* TGlslangToTopTraverser::declareMdIo(llvm::StringRef instanceName, // and should then stay the same while visiting the substructure of that member. void TGlslangToTopTraverser::declareChildMdIo(const glslang::TType& type, llvm::Type* proxyType, llvm::SmallVector& members, gla::EMdTypeLayout inheritMatrix) { - const glslang::TTypeList* typeList = type.getStruct(); + const glslang::TTypeList* typeList = getStructIfIsStruct(type); if (typeList) { // Get the llvm type of the struct holding the members (bypassing arrays and pointers) llvm::Type* structType = proxyType;