From 05903f708856a70d68bf41bbfb2b06620508dee0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 15 Nov 2024 00:37:58 -0800 Subject: Embed core module in wasm build. (#5569) * Embed core module in wasm build. * format code * add uintptr_t case. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .gitignore | 1 + CMakePresets.json | 4 +- .../compiler-core/slang-artifact-associated-impl.h | 2 +- source/slang-record-replay/record/slang-module.h | 2 +- source/slang/slang-ast-decl.h | 4 +- source/slang/slang-ast-expr.h | 2 +- source/slang/slang-ast-modifier.h | 2 +- source/slang/slang-ast-support-types.h | 2 +- source/slang/slang-ast-type.cpp | 2 +- source/slang/slang-ast-val.cpp | 2 +- source/slang/slang-check-decl.cpp | 4 +- source/slang/slang-check-expr.cpp | 8 +-- source/slang/slang-compiler.h | 2 +- source/slang/slang-ir-insts.h | 29 +++++++++-- source/slang/slang-ir.cpp | 58 ++++++++++++++++++++-- source/slang/slang-lower-to-ir.cpp | 12 ++--- tools/slang-cpp-extractor/diagnostic-defs.h | 5 ++ tools/slang-cpp-extractor/parser.cpp | 40 ++++++++++++++- 18 files changed, 150 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 803fcbe14..45987f804 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ vkd3d-proton.cache.write .*.swp .*.swo /generators +/tests/library/linked.spirv diff --git a/CMakePresets.json b/CMakePresets.json index a92440eee..34a1c15df 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -22,6 +22,7 @@ "binaryDir": "${sourceDir}/build.em", "cacheVariables": { "SLANG_SLANG_LLVM_FLAVOR": "DISABLE", + "SLANG_EMBED_CORE_MODULE": "ON", "CMAKE_C_FLAGS_INIT": "-fwasm-exceptions -Os", "CMAKE_CXX_FLAGS_INIT": "-fwasm-exceptions -Os", "CMAKE_EXE_LINKER_FLAGS": "-sASSERTIONS -sALLOW_MEMORY_GROWTH -fwasm-exceptions --export=__cpp_exception" @@ -71,7 +72,8 @@ "inherits": "default", "description": "Build the compile time generators used in building Slang", "cacheVariables": { - "SLANG_SLANG_LLVM_FLAVOR": "DISABLE" + "SLANG_SLANG_LLVM_FLAVOR": "DISABLE", + "SLANG_ENABLE_SLANG_RHI": false } } ], diff --git a/source/compiler-core/slang-artifact-associated-impl.h b/source/compiler-core/slang-artifact-associated-impl.h index ff8f03163..8a89f865b 100644 --- a/source/compiler-core/slang-artifact-associated-impl.h +++ b/source/compiler-core/slang-artifact-associated-impl.h @@ -189,7 +189,7 @@ public: SLANG_OVERRIDE; // IMetadata - SLANG_NO_THROW virtual SlangResult SLANG_MCALL isParameterLocationUsed( + SLANG_NO_THROW virtual SlangResult isParameterLocationUsed( SlangParameterCategory category, // is this a `t` register? `s` register? SlangUInt spaceIndex, // `space` for D3D12, `set` for Vulkan SlangUInt registerIndex, // `register` for D3D12, `binding` for Vulkan diff --git a/source/slang-record-replay/record/slang-module.h b/source/slang-record-replay/record/slang-module.h index 5cf3126f7..7608ac52d 100644 --- a/source/slang-record-replay/record/slang-module.h +++ b/source/slang-record-replay/record/slang-module.h @@ -180,7 +180,7 @@ public: outDiagnostics); } - virtual SLANG_NO_THROW slang::DeclReflection* getModuleReflection() override; + virtual SLANG_NO_THROW slang::DeclReflection* SLANG_MCALL getModuleReflection() override; slang::IModule* getActualModule() const { return m_actualModule; } diff --git a/source/slang/slang-ast-decl.h b/source/slang/slang-ast-decl.h index 400a9635a..e8886a59a 100644 --- a/source/slang/slang-ast-decl.h +++ b/source/slang/slang-ast-decl.h @@ -552,7 +552,7 @@ class GenericTypeParamDeclBase : public SimpleTypeDecl SLANG_AST_CLASS(GenericTypeParamDeclBase) // The index of the generic parameter. - Index parameterIndex = -1; + int parameterIndex = -1; }; class GenericTypeParamDecl : public GenericTypeParamDeclBase @@ -597,7 +597,7 @@ class GenericValueParamDecl : public VarDeclBase SLANG_AST_CLASS(GenericValueParamDecl) // The index of the generic parameter. - Index parameterIndex = 0; + int parameterIndex = 0; }; // An empty declaration (which might still have modifiers attached). diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index 1f44e31c2..409909b16 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -293,7 +293,7 @@ class SwizzleExpr : public Expr { SLANG_AST_CLASS(SwizzleExpr) Expr* base = nullptr; - ShortList elementIndices; + ShortList elementIndices; SourceLoc memberOpLoc; }; diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index 956704b4c..ee9b55334 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -398,7 +398,7 @@ class HLSLPackOffsetSemantic : public HLSLLayoutSemantic { SLANG_AST_CLASS(HLSLPackOffsetSemantic) - Index uniformOffset = 0; + int uniformOffset = 0; }; diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index 0a2dbe78d..4bbd51f93 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -689,7 +689,7 @@ struct SubstitutionSet // `T` is a type pack, then packExpansionIndex will have a value starting from 0 // to the count of the type pack during expansion of the `expand` type when we // substitute `each T` with the element of `T` at index `packExpansionIndex`. - Index packExpansionIndex = -1; + int packExpansionIndex = -1; SubstitutionSet() = default; SubstitutionSet(DeclRefBase* declRefBase) diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 7e4777a76..23d89957a 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -706,7 +706,7 @@ Val* ExpandType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet ShortList expandedTypes; SLANG_ASSERT(capturedPacks.getCount() != 0); - for (Index i = 0; i < concreteTypePacks[0]->getTypeCount(); i++) + for (int i = 0; i < (int)concreteTypePacks[0]->getTypeCount(); i++) { subst.packExpansionIndex = i; auto substElementType = getPatternType()->substituteImpl(astBuilder, subst, &diff); diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index fdb7e6990..98135ef16 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -364,7 +364,7 @@ Val* ExpandSubtypeWitness::_substituteImplOverride( // If sub is substituted into a concrete type pack, we should return a // TypePackSubtypeWitness. ShortList newWitnesses; - for (Index i = 0; i < subTypePack->getTypeCount(); i++) + for (int i = 0; i < (int)subTypePack->getTypeCount(); i++) { auto elementType = subTypePack->getElementType(i); subst.packExpansionIndex = i; diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 663a2186e..fb27614d0 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -2817,7 +2817,7 @@ void SemanticsDeclHeaderVisitor::visitGenericDecl(GenericDecl* genericDecl) // // Accessing the members via index side steps the issue. - Index parameterIndex = 0; + int parameterIndex = 0; const auto& members = genericDecl->members; for (Index i = 0; i < members.getCount(); ++i) { @@ -4392,7 +4392,7 @@ void SemanticsVisitor::addRequiredParamsToSynthesizedDecl( auto elementType = typePack->getElementType(i); auto synMemberExpr = m_astBuilder->create(); synMemberExpr->base = synArg; - synMemberExpr->elementIndices.add((UInt)i); + synMemberExpr->elementIndices.add((uint32_t)i); synMemberExpr->type = elementType; synArgs.add(synMemberExpr); } diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 44e399e79..2840cdd39 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4308,7 +4308,7 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType* auto span = swizzleText.getUnownedSlice(); Index pos = 0; - ShortList elementCoords; + ShortList elementCoords; bool anyDuplicates = false; @@ -4316,7 +4316,7 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType* // Every update to cursor corresponds to a check against 0-termination while (pos < span.getLength()) { - UInt elementCoord; + uint32_t elementCoord; // Check for the preceding underscore if (span[pos] != '_') @@ -4341,7 +4341,7 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType* // member lookup. return checkGeneralMemberLookupExpr(memberExpr, baseTupleType); } - elementCoord = (UInt)StringUtil::parseIntAndAdvancePos(span, pos); + elementCoord = (uint32_t)StringUtil::parseIntAndAdvancePos(span, pos); if (elementCoord >= tupleElementCount) { @@ -4400,7 +4400,7 @@ Expr* SemanticsVisitor::CheckSwizzleExpr( swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc; IntegerLiteralValue limitElement = baseElementCount; - ShortList elementIndices; + ShortList elementIndices; bool anyDuplicates = false; bool anyError = false; diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 9fea93b7c..e0df18a8c 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1622,7 +1622,7 @@ public: virtual void buildHash(DigestBuilder& builder) SLANG_OVERRIDE; - virtual slang::DeclReflection* getModuleReflection() SLANG_OVERRIDE; + virtual slang::DeclReflection* SLANG_MCALL getModuleReflection() SLANG_OVERRIDE; void setDigest(SHA1::Digest const& digest) { m_digest = digest; } SHA1::Digest computeDigest(); diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 9ccfce51c..97989e9ce 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -4253,7 +4253,17 @@ public: UInt elementCount, IRInst* const* elementIndices); - IRInst* emitSwizzle(IRType* type, IRInst* base, UInt elementCount, UInt const* elementIndices); + IRInst* emitSwizzle( + IRType* type, + IRInst* base, + UInt elementCount, + uint64_t const* elementIndices); + + IRInst* emitSwizzle( + IRType* type, + IRInst* base, + UInt elementCount, + uint32_t const* elementIndices); IRInst* emitSwizzleSet( IRType* type, @@ -4267,7 +4277,14 @@ public: IRInst* base, IRInst* source, UInt elementCount, - UInt const* elementIndices); + uint64_t const* elementIndices); + + IRInst* emitSwizzleSet( + IRType* type, + IRInst* base, + IRInst* source, + UInt elementCount, + uint32_t const* elementIndices); IRInst* emitSwizzledStore( IRInst* dest, @@ -4279,7 +4296,13 @@ public: IRInst* dest, IRInst* source, UInt elementCount, - UInt const* elementIndices); + uint32_t const* elementIndices); + + IRInst* emitSwizzledStore( + IRInst* dest, + IRInst* source, + UInt elementCount, + uint64_t const* elementIndices); IRInst* emitReturn(IRInst* val); diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 5e4db43b2..e7f82f5ad 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -5311,7 +5311,24 @@ IRInst* IRBuilder::emitSwizzle( IRType* type, IRInst* base, UInt elementCount, - UInt const* elementIndices) + uint64_t const* elementIndices) +{ + auto intType = getBasicType(BaseType::Int); + + IRInst* irElementIndices[4]; + for (UInt ii = 0; ii < elementCount; ++ii) + { + irElementIndices[ii] = getIntValue(intType, elementIndices[ii]); + } + + return emitSwizzle(type, base, elementCount, irElementIndices); +} + +IRInst* IRBuilder::emitSwizzle( + IRType* type, + IRInst* base, + UInt elementCount, + uint32_t const* elementIndices) { auto intType = getBasicType(BaseType::Int); @@ -5380,7 +5397,25 @@ IRInst* IRBuilder::emitSwizzleSet( IRInst* base, IRInst* source, UInt elementCount, - UInt const* elementIndices) + uint32_t const* elementIndices) +{ + auto intType = getBasicType(BaseType::Int); + + IRInst* irElementIndices[4]; + for (UInt ii = 0; ii < elementCount; ++ii) + { + irElementIndices[ii] = getIntValue(intType, elementIndices[ii]); + } + + return emitSwizzleSet(type, base, source, elementCount, irElementIndices); +} + +IRInst* IRBuilder::emitSwizzleSet( + IRType* type, + IRInst* base, + IRInst* source, + UInt elementCount, + uint64_t const* elementIndices) { auto intType = getBasicType(BaseType::Int); @@ -5419,7 +5454,24 @@ IRInst* IRBuilder::emitSwizzledStore( IRInst* dest, IRInst* source, UInt elementCount, - UInt const* elementIndices) + uint32_t const* elementIndices) +{ + auto intType = getBasicType(BaseType::Int); + + IRInst* irElementIndices[4]; + for (UInt ii = 0; ii < elementCount; ++ii) + { + irElementIndices[ii] = getIntValue(intType, elementIndices[ii]); + } + + return emitSwizzledStore(dest, source, elementCount, irElementIndices); +} + +IRInst* IRBuilder::emitSwizzledStore( + IRInst* dest, + IRInst* source, + UInt elementCount, + uint64_t const* elementIndices) { auto intType = getBasicType(BaseType::Int); diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index b98218c5a..92c442433 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -333,8 +333,8 @@ struct SwizzledLValueInfo : ExtendedValueInfo // The base expression (this should be an l-value) LoweredValInfo base; - // THe indices for the elements being swizzled - ShortList elementIndices; + // The indices for the elements being swizzled + ShortList elementIndices; }; // Represents the result of a matrix swizzle operation in an l-value context. @@ -5495,7 +5495,7 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase swizzledLValue = new SwizzledLValueInfo; swizzledLValue->type = irType; swizzledLValue->base = baseSwizzleInfo->base; - swizzledLValue->elementIndices = elementCount; + swizzledLValue->elementIndices.add((uint32_t)elementCount); // Take the swizzle element of the "outer" swizzle, as it was // written by the user. In our running example of `foo[i].zw.y` @@ -7146,7 +7146,7 @@ void assign(IRGenContext* context, LoweredValInfo const& inLeft, LoweredValInfo // If there's a single element, just emit a regular store, otherwise // proceed with a swizzle store auto swizzledStore = - [builder](IRInst* dest, IRInst* source, UInt elementCount, UInt const* elementIndices) + [builder](IRInst* dest, IRInst* source, UInt elementCount, uint32_t const* elementIndices) { if (elementCount == 1) { @@ -7272,14 +7272,14 @@ top: // The number of element writes in each row UInt rowSizes[maxRowIndex] = {}; // The columns being written to in each row - UInt rowWrites[maxRowIndex][maxCols]; + uint32_t rowWrites[maxRowIndex][maxCols]; // The RHS element indices being written in each row UInt rowIndices[maxRowIndex][maxCols]; for (UInt i = 0; i < swizzleInfo->elementCount; ++i) { const auto& c = swizzleInfo->elementCoords[i]; auto& rowSize = rowSizes[c.row]; - rowWrites[c.row][rowSize] = c.col; + rowWrites[c.row][rowSize] = (uint32_t)c.col; rowIndices[c.row][rowSize] = i; ++rowSize; } diff --git a/tools/slang-cpp-extractor/diagnostic-defs.h b/tools/slang-cpp-extractor/diagnostic-defs.h index 290036a23..03ba88dd3 100644 --- a/tools/slang-cpp-extractor/diagnostic-defs.h +++ b/tools/slang-cpp-extractor/diagnostic-defs.h @@ -75,6 +75,11 @@ DIAGNOSTIC( destructorNameDoesntMatch, "Destructor name doesn't match class name '$0'"); DIAGNOSTIC(100023, Error, cannotParseCallable, "Cannot parse callable"); +DIAGNOSTIC( + 100024, + Error, + cannoseUseArchDependentType, + "Cannot use architecture dependent type '$0' for serializable data.") // Command line errors 100100 diff --git a/tools/slang-cpp-extractor/parser.cpp b/tools/slang-cpp-extractor/parser.cpp index 070aea297..3a4891829 100644 --- a/tools/slang-cpp-extractor/parser.cpp +++ b/tools/slang-cpp-extractor/parser.cpp @@ -1524,6 +1524,11 @@ bool Parser::_isCtor() return isCtor; } +bool isAlphaNumeric(char c) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); +} + SlangResult Parser::_maybeParseContained(Node** outNode) { *outNode = nullptr; @@ -1833,7 +1838,37 @@ SlangResult Parser::_maybeParseContained(Node** outNode) fieldNode->m_name = nameToken; fieldNode->m_reflectionType = m_currentScope->getContainedReflectionType(); fieldNode->m_isStatic = isStatic; - + if (fieldNode->m_reflectionType == ReflectionType::Reflected) + { + static const char* illegalTypes[] = { + "size_t", + "Int", + "UInt", + "Index", + "Count", + "UIndex", + "UCount", + "PtrInt", + "intptr_t", + "uintptr_t"}; + for (const auto& illegalType : illegalTypes) + { + int index = typeName.indexOf(UnownedStringSlice(illegalType)); + if (index != -1) + { + index += UnownedStringSlice(illegalType).getLength(); + if (index >= typeName.getLength() || !isAlphaNumeric(typeName[index])) + { + // Cannot use this type in a field (as it's arch dependent + m_sink->diagnose( + nameToken, + CPPDiagnostics::cannoseUseArchDependentType, + illegalType); + return SLANG_FAIL; + } + } + } + } m_currentScope->addChild(fieldNode); *outNode = fieldNode; @@ -2187,7 +2222,8 @@ SlangResult Parser::parse(SourceOrigin* sourceOrigin, const Options* options) m_sink->diagnose(m_reader.peekToken(), CPPDiagnostics::braceOpenAtEndOfFile); return SLANG_FAIL; } - + if (m_sink->getErrorCount()) + return SLANG_FAIL; return SLANG_OK; } case TokenType::Pound: -- cgit v1.2.3