Skip to content

Commit

Permalink
Embed core module in wasm build. (#5569)
Browse files Browse the repository at this point in the history
* Embed core module in wasm build.

* format code

* add uintptr_t case.

---------

Co-authored-by: slangbot <[email protected]>
  • Loading branch information
csyonghe and slangbot authored Nov 15, 2024
1 parent f0bc464 commit 05903f7
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ vkd3d-proton.cache.write
.*.swp
.*.swo
/generators
/tests/library/linked.spirv
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion source/compiler-core/slang-artifact-associated-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ArtifactPostEmitMetadata : public ComBaseObject, public IArtifactPostEmitM
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
Expand Down
2 changes: 1 addition & 1 deletion source/slang-record-replay/record/slang-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ModuleRecorder : public IModuleRecorder, public IComponentTypeRecorder
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; }

Expand Down
4 changes: 2 additions & 2 deletions source/slang/slang-ast-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class SwizzleExpr : public Expr
{
SLANG_AST_CLASS(SwizzleExpr)
Expr* base = nullptr;
ShortList<UInt, 4> elementIndices;
ShortList<uint32_t, 4> elementIndices;
SourceLoc memberOpLoc;
};

Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class HLSLPackOffsetSemantic : public HLSLLayoutSemantic
{
SLANG_AST_CLASS(HLSLPackOffsetSemantic)

Index uniformOffset = 0;
int uniformOffset = 0;
};


Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-support-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ Val* ExpandType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet
ShortList<Type*> 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);
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ast-val.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Val* ExpandSubtypeWitness::_substituteImplOverride(
// If sub is substituted into a concrete type pack, we should return a
// TypePackSubtypeWitness.
ShortList<SubtypeWitness*> 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;
Expand Down
4 changes: 2 additions & 2 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -4392,7 +4392,7 @@ void SemanticsVisitor::addRequiredParamsToSynthesizedDecl(
auto elementType = typePack->getElementType(i);
auto synMemberExpr = m_astBuilder->create<SwizzleExpr>();
synMemberExpr->base = synArg;
synMemberExpr->elementIndices.add((UInt)i);
synMemberExpr->elementIndices.add((uint32_t)i);
synMemberExpr->type = elementType;
synArgs.add(synMemberExpr);
}
Expand Down
8 changes: 4 additions & 4 deletions source/slang/slang-check-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4308,15 +4308,15 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType*
auto span = swizzleText.getUnownedSlice();
Index pos = 0;

ShortList<UInt> elementCoords;
ShortList<uint32_t> elementCoords;

bool anyDuplicates = false;

// The contents of the string are 0-terminated
// 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] != '_')
Expand All @@ -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)
{
Expand Down Expand Up @@ -4400,7 +4400,7 @@ Expr* SemanticsVisitor::CheckSwizzleExpr(
swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc;
IntegerLiteralValue limitElement = baseElementCount;

ShortList<UInt, 4> elementIndices;
ShortList<uint32_t, 4> elementIndices;

bool anyDuplicates = false;
bool anyError = false;
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ class Module : public ComponentType, public slang::IModule

virtual void buildHash(DigestBuilder<SHA1>& 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();
Expand Down
29 changes: 26 additions & 3 deletions source/slang/slang-ir-insts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4253,7 +4253,17 @@ struct IRBuilder
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,
Expand All @@ -4267,7 +4277,14 @@ struct IRBuilder
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,
Expand All @@ -4279,7 +4296,13 @@ struct IRBuilder
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);
Expand Down
58 changes: 55 additions & 3 deletions source/slang/slang-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions source/slang/slang-lower-to-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt, 4> elementIndices;
// The indices for the elements being swizzled
ShortList<uint32_t, 4> elementIndices;
};

// Represents the result of a matrix swizzle operation in an l-value context.
Expand Down Expand Up @@ -5495,7 +5495,7 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis
RefPtr<SwizzledLValueInfo> 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`
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -7272,14 +7272,14 @@ void assign(IRGenContext* context, LoweredValInfo const& inLeft, LoweredValInfo
// 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;
}
Expand Down
5 changes: 5 additions & 0 deletions tools/slang-cpp-extractor/diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 05903f7

Please sign in to comment.