Skip to content

Commit 05903f7

Browse files
csyongheslangbot
andauthored
Embed core module in wasm build. (shader-slang#5569)
* Embed core module in wasm build. * format code * add uintptr_t case. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
1 parent f0bc464 commit 05903f7

18 files changed

+150
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ vkd3d-proton.cache.write
9494
.*.swp
9595
.*.swo
9696
/generators
97+
/tests/library/linked.spirv

CMakePresets.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"binaryDir": "${sourceDir}/build.em",
2323
"cacheVariables": {
2424
"SLANG_SLANG_LLVM_FLAVOR": "DISABLE",
25+
"SLANG_EMBED_CORE_MODULE": "ON",
2526
"CMAKE_C_FLAGS_INIT": "-fwasm-exceptions -Os",
2627
"CMAKE_CXX_FLAGS_INIT": "-fwasm-exceptions -Os",
2728
"CMAKE_EXE_LINKER_FLAGS": "-sASSERTIONS -sALLOW_MEMORY_GROWTH -fwasm-exceptions --export=__cpp_exception"
@@ -71,7 +72,8 @@
7172
"inherits": "default",
7273
"description": "Build the compile time generators used in building Slang",
7374
"cacheVariables": {
74-
"SLANG_SLANG_LLVM_FLAVOR": "DISABLE"
75+
"SLANG_SLANG_LLVM_FLAVOR": "DISABLE",
76+
"SLANG_ENABLE_SLANG_RHI": false
7577
}
7678
}
7779
],

source/compiler-core/slang-artifact-associated-impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class ArtifactPostEmitMetadata : public ComBaseObject, public IArtifactPostEmitM
189189
SLANG_OVERRIDE;
190190

191191
// IMetadata
192-
SLANG_NO_THROW virtual SlangResult SLANG_MCALL isParameterLocationUsed(
192+
SLANG_NO_THROW virtual SlangResult isParameterLocationUsed(
193193
SlangParameterCategory category, // is this a `t` register? `s` register?
194194
SlangUInt spaceIndex, // `space` for D3D12, `set` for Vulkan
195195
SlangUInt registerIndex, // `register` for D3D12, `binding` for Vulkan

source/slang-record-replay/record/slang-module.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class ModuleRecorder : public IModuleRecorder, public IComponentTypeRecorder
180180
outDiagnostics);
181181
}
182182

183-
virtual SLANG_NO_THROW slang::DeclReflection* getModuleReflection() override;
183+
virtual SLANG_NO_THROW slang::DeclReflection* SLANG_MCALL getModuleReflection() override;
184184

185185
slang::IModule* getActualModule() const { return m_actualModule; }
186186

source/slang/slang-ast-decl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ class GenericTypeParamDeclBase : public SimpleTypeDecl
552552
SLANG_AST_CLASS(GenericTypeParamDeclBase)
553553

554554
// The index of the generic parameter.
555-
Index parameterIndex = -1;
555+
int parameterIndex = -1;
556556
};
557557

558558
class GenericTypeParamDecl : public GenericTypeParamDeclBase
@@ -597,7 +597,7 @@ class GenericValueParamDecl : public VarDeclBase
597597
SLANG_AST_CLASS(GenericValueParamDecl)
598598

599599
// The index of the generic parameter.
600-
Index parameterIndex = 0;
600+
int parameterIndex = 0;
601601
};
602602

603603
// An empty declaration (which might still have modifiers attached).

source/slang/slang-ast-expr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class SwizzleExpr : public Expr
293293
{
294294
SLANG_AST_CLASS(SwizzleExpr)
295295
Expr* base = nullptr;
296-
ShortList<UInt, 4> elementIndices;
296+
ShortList<uint32_t, 4> elementIndices;
297297
SourceLoc memberOpLoc;
298298
};
299299

source/slang/slang-ast-modifier.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class HLSLPackOffsetSemantic : public HLSLLayoutSemantic
398398
{
399399
SLANG_AST_CLASS(HLSLPackOffsetSemantic)
400400

401-
Index uniformOffset = 0;
401+
int uniformOffset = 0;
402402
};
403403

404404

source/slang/slang-ast-support-types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ struct SubstitutionSet
689689
// `T` is a type pack, then packExpansionIndex will have a value starting from 0
690690
// to the count of the type pack during expansion of the `expand` type when we
691691
// substitute `each T` with the element of `T` at index `packExpansionIndex`.
692-
Index packExpansionIndex = -1;
692+
int packExpansionIndex = -1;
693693

694694
SubstitutionSet() = default;
695695
SubstitutionSet(DeclRefBase* declRefBase)

source/slang/slang-ast-type.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ Val* ExpandType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet
706706
ShortList<Type*> expandedTypes;
707707
SLANG_ASSERT(capturedPacks.getCount() != 0);
708708

709-
for (Index i = 0; i < concreteTypePacks[0]->getTypeCount(); i++)
709+
for (int i = 0; i < (int)concreteTypePacks[0]->getTypeCount(); i++)
710710
{
711711
subst.packExpansionIndex = i;
712712
auto substElementType = getPatternType()->substituteImpl(astBuilder, subst, &diff);

source/slang/slang-ast-val.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Val* ExpandSubtypeWitness::_substituteImplOverride(
364364
// If sub is substituted into a concrete type pack, we should return a
365365
// TypePackSubtypeWitness.
366366
ShortList<SubtypeWitness*> newWitnesses;
367-
for (Index i = 0; i < subTypePack->getTypeCount(); i++)
367+
for (int i = 0; i < (int)subTypePack->getTypeCount(); i++)
368368
{
369369
auto elementType = subTypePack->getElementType(i);
370370
subst.packExpansionIndex = i;

source/slang/slang-check-decl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,7 @@ void SemanticsDeclHeaderVisitor::visitGenericDecl(GenericDecl* genericDecl)
28172817
//
28182818
// Accessing the members via index side steps the issue.
28192819

2820-
Index parameterIndex = 0;
2820+
int parameterIndex = 0;
28212821
const auto& members = genericDecl->members;
28222822
for (Index i = 0; i < members.getCount(); ++i)
28232823
{
@@ -4392,7 +4392,7 @@ void SemanticsVisitor::addRequiredParamsToSynthesizedDecl(
43924392
auto elementType = typePack->getElementType(i);
43934393
auto synMemberExpr = m_astBuilder->create<SwizzleExpr>();
43944394
synMemberExpr->base = synArg;
4395-
synMemberExpr->elementIndices.add((UInt)i);
4395+
synMemberExpr->elementIndices.add((uint32_t)i);
43964396
synMemberExpr->type = elementType;
43974397
synArgs.add(synMemberExpr);
43984398
}

source/slang/slang-check-expr.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4308,15 +4308,15 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType*
43084308
auto span = swizzleText.getUnownedSlice();
43094309
Index pos = 0;
43104310

4311-
ShortList<UInt> elementCoords;
4311+
ShortList<uint32_t> elementCoords;
43124312

43134313
bool anyDuplicates = false;
43144314

43154315
// The contents of the string are 0-terminated
43164316
// Every update to cursor corresponds to a check against 0-termination
43174317
while (pos < span.getLength())
43184318
{
4319-
UInt elementCoord;
4319+
uint32_t elementCoord;
43204320

43214321
// Check for the preceding underscore
43224322
if (span[pos] != '_')
@@ -4341,7 +4341,7 @@ Expr* SemanticsVisitor::checkTupleSwizzleExpr(MemberExpr* memberExpr, TupleType*
43414341
// member lookup.
43424342
return checkGeneralMemberLookupExpr(memberExpr, baseTupleType);
43434343
}
4344-
elementCoord = (UInt)StringUtil::parseIntAndAdvancePos(span, pos);
4344+
elementCoord = (uint32_t)StringUtil::parseIntAndAdvancePos(span, pos);
43454345

43464346
if (elementCoord >= tupleElementCount)
43474347
{
@@ -4400,7 +4400,7 @@ Expr* SemanticsVisitor::CheckSwizzleExpr(
44004400
swizExpr->memberOpLoc = memberRefExpr->memberOperatorLoc;
44014401
IntegerLiteralValue limitElement = baseElementCount;
44024402

4403-
ShortList<UInt, 4> elementIndices;
4403+
ShortList<uint32_t, 4> elementIndices;
44044404

44054405
bool anyDuplicates = false;
44064406
bool anyError = false;

source/slang/slang-compiler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ class Module : public ComponentType, public slang::IModule
16221622

16231623
virtual void buildHash(DigestBuilder<SHA1>& builder) SLANG_OVERRIDE;
16241624

1625-
virtual slang::DeclReflection* getModuleReflection() SLANG_OVERRIDE;
1625+
virtual slang::DeclReflection* SLANG_MCALL getModuleReflection() SLANG_OVERRIDE;
16261626

16271627
void setDigest(SHA1::Digest const& digest) { m_digest = digest; }
16281628
SHA1::Digest computeDigest();

source/slang/slang-ir-insts.h

+26-3
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,17 @@ struct IRBuilder
42534253
UInt elementCount,
42544254
IRInst* const* elementIndices);
42554255

4256-
IRInst* emitSwizzle(IRType* type, IRInst* base, UInt elementCount, UInt const* elementIndices);
4256+
IRInst* emitSwizzle(
4257+
IRType* type,
4258+
IRInst* base,
4259+
UInt elementCount,
4260+
uint64_t const* elementIndices);
4261+
4262+
IRInst* emitSwizzle(
4263+
IRType* type,
4264+
IRInst* base,
4265+
UInt elementCount,
4266+
uint32_t const* elementIndices);
42574267

42584268
IRInst* emitSwizzleSet(
42594269
IRType* type,
@@ -4267,7 +4277,14 @@ struct IRBuilder
42674277
IRInst* base,
42684278
IRInst* source,
42694279
UInt elementCount,
4270-
UInt const* elementIndices);
4280+
uint64_t const* elementIndices);
4281+
4282+
IRInst* emitSwizzleSet(
4283+
IRType* type,
4284+
IRInst* base,
4285+
IRInst* source,
4286+
UInt elementCount,
4287+
uint32_t const* elementIndices);
42714288

42724289
IRInst* emitSwizzledStore(
42734290
IRInst* dest,
@@ -4279,7 +4296,13 @@ struct IRBuilder
42794296
IRInst* dest,
42804297
IRInst* source,
42814298
UInt elementCount,
4282-
UInt const* elementIndices);
4299+
uint32_t const* elementIndices);
4300+
4301+
IRInst* emitSwizzledStore(
4302+
IRInst* dest,
4303+
IRInst* source,
4304+
UInt elementCount,
4305+
uint64_t const* elementIndices);
42834306

42844307

42854308
IRInst* emitReturn(IRInst* val);

source/slang/slang-ir.cpp

+55-3
Original file line numberDiff line numberDiff line change
@@ -5311,7 +5311,24 @@ IRInst* IRBuilder::emitSwizzle(
53115311
IRType* type,
53125312
IRInst* base,
53135313
UInt elementCount,
5314-
UInt const* elementIndices)
5314+
uint64_t const* elementIndices)
5315+
{
5316+
auto intType = getBasicType(BaseType::Int);
5317+
5318+
IRInst* irElementIndices[4];
5319+
for (UInt ii = 0; ii < elementCount; ++ii)
5320+
{
5321+
irElementIndices[ii] = getIntValue(intType, elementIndices[ii]);
5322+
}
5323+
5324+
return emitSwizzle(type, base, elementCount, irElementIndices);
5325+
}
5326+
5327+
IRInst* IRBuilder::emitSwizzle(
5328+
IRType* type,
5329+
IRInst* base,
5330+
UInt elementCount,
5331+
uint32_t const* elementIndices)
53155332
{
53165333
auto intType = getBasicType(BaseType::Int);
53175334

@@ -5380,7 +5397,25 @@ IRInst* IRBuilder::emitSwizzleSet(
53805397
IRInst* base,
53815398
IRInst* source,
53825399
UInt elementCount,
5383-
UInt const* elementIndices)
5400+
uint32_t const* elementIndices)
5401+
{
5402+
auto intType = getBasicType(BaseType::Int);
5403+
5404+
IRInst* irElementIndices[4];
5405+
for (UInt ii = 0; ii < elementCount; ++ii)
5406+
{
5407+
irElementIndices[ii] = getIntValue(intType, elementIndices[ii]);
5408+
}
5409+
5410+
return emitSwizzleSet(type, base, source, elementCount, irElementIndices);
5411+
}
5412+
5413+
IRInst* IRBuilder::emitSwizzleSet(
5414+
IRType* type,
5415+
IRInst* base,
5416+
IRInst* source,
5417+
UInt elementCount,
5418+
uint64_t const* elementIndices)
53845419
{
53855420
auto intType = getBasicType(BaseType::Int);
53865421

@@ -5419,7 +5454,24 @@ IRInst* IRBuilder::emitSwizzledStore(
54195454
IRInst* dest,
54205455
IRInst* source,
54215456
UInt elementCount,
5422-
UInt const* elementIndices)
5457+
uint32_t const* elementIndices)
5458+
{
5459+
auto intType = getBasicType(BaseType::Int);
5460+
5461+
IRInst* irElementIndices[4];
5462+
for (UInt ii = 0; ii < elementCount; ++ii)
5463+
{
5464+
irElementIndices[ii] = getIntValue(intType, elementIndices[ii]);
5465+
}
5466+
5467+
return emitSwizzledStore(dest, source, elementCount, irElementIndices);
5468+
}
5469+
5470+
IRInst* IRBuilder::emitSwizzledStore(
5471+
IRInst* dest,
5472+
IRInst* source,
5473+
UInt elementCount,
5474+
uint64_t const* elementIndices)
54235475
{
54245476
auto intType = getBasicType(BaseType::Int);
54255477

source/slang/slang-lower-to-ir.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ struct SwizzledLValueInfo : ExtendedValueInfo
333333
// The base expression (this should be an l-value)
334334
LoweredValInfo base;
335335

336-
// THe indices for the elements being swizzled
337-
ShortList<UInt, 4> elementIndices;
336+
// The indices for the elements being swizzled
337+
ShortList<uint32_t, 4> elementIndices;
338338
};
339339

340340
// Represents the result of a matrix swizzle operation in an l-value context.
@@ -5495,7 +5495,7 @@ struct LValueExprLoweringVisitor : ExprLoweringVisitorBase<LValueExprLoweringVis
54955495
RefPtr<SwizzledLValueInfo> swizzledLValue = new SwizzledLValueInfo;
54965496
swizzledLValue->type = irType;
54975497
swizzledLValue->base = baseSwizzleInfo->base;
5498-
swizzledLValue->elementIndices = elementCount;
5498+
swizzledLValue->elementIndices.add((uint32_t)elementCount);
54995499

55005500
// Take the swizzle element of the "outer" swizzle, as it was
55015501
// 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
71467146
// If there's a single element, just emit a regular store, otherwise
71477147
// proceed with a swizzle store
71487148
auto swizzledStore =
7149-
[builder](IRInst* dest, IRInst* source, UInt elementCount, UInt const* elementIndices)
7149+
[builder](IRInst* dest, IRInst* source, UInt elementCount, uint32_t const* elementIndices)
71507150
{
71517151
if (elementCount == 1)
71527152
{
@@ -7272,14 +7272,14 @@ void assign(IRGenContext* context, LoweredValInfo const& inLeft, LoweredValInfo
72727272
// The number of element writes in each row
72737273
UInt rowSizes[maxRowIndex] = {};
72747274
// The columns being written to in each row
7275-
UInt rowWrites[maxRowIndex][maxCols];
7275+
uint32_t rowWrites[maxRowIndex][maxCols];
72767276
// The RHS element indices being written in each row
72777277
UInt rowIndices[maxRowIndex][maxCols];
72787278
for (UInt i = 0; i < swizzleInfo->elementCount; ++i)
72797279
{
72807280
const auto& c = swizzleInfo->elementCoords[i];
72817281
auto& rowSize = rowSizes[c.row];
7282-
rowWrites[c.row][rowSize] = c.col;
7282+
rowWrites[c.row][rowSize] = (uint32_t)c.col;
72837283
rowIndices[c.row][rowSize] = i;
72847284
++rowSize;
72857285
}

tools/slang-cpp-extractor/diagnostic-defs.h

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ DIAGNOSTIC(
7575
destructorNameDoesntMatch,
7676
"Destructor name doesn't match class name '$0'");
7777
DIAGNOSTIC(100023, Error, cannotParseCallable, "Cannot parse callable");
78+
DIAGNOSTIC(
79+
100024,
80+
Error,
81+
cannoseUseArchDependentType,
82+
"Cannot use architecture dependent type '$0' for serializable data.")
7883

7984
// Command line errors 100100
8085

0 commit comments

Comments
 (0)