Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legalize the Entry-point for WGSL #5498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/slang/slang-emit-c-like.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,11 @@ void CLikeSourceEmitter::emitSemanticsUsingVarLayout(IRVarLayout* varLayout)
}
}

void CLikeSourceEmitter::emitSemanticsPrefix(IRInst* inst)
{
emitSemanticsPrefixImpl(inst);
}

void CLikeSourceEmitter::emitSemantics(IRInst* inst, bool allowOffsetLayout)
{
emitSemanticsImpl(inst, allowOffsetLayout);
Expand Down Expand Up @@ -3869,6 +3874,7 @@ void CLikeSourceEmitter::emitStructDeclarationsBlock(
emitPackOffsetModifier(fieldKey, fieldType, packOffsetDecoration);
}
}
emitSemanticsPrefix(fieldKey);
emitStructFieldAttributes(structType, ff);
emitMemoryQualifiers(fieldKey);
emitType(fieldType, getName(fieldKey));
Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-emit-c-like.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class CLikeSourceEmitter : public SourceEmitterBase
void diagnoseUnhandledInst(IRInst* inst);
void emitInst(IRInst* inst);

void emitSemanticsPrefix(IRInst* inst);
void emitSemantics(IRInst* inst, bool allowOffsets = false);
void emitSemanticsUsingVarLayout(IRVarLayout* varLayout);

Expand Down Expand Up @@ -557,6 +558,7 @@ class CLikeSourceEmitter : public SourceEmitterBase
SLANG_UNUSED(rate);
SLANG_UNUSED(addressSpace);
}
virtual void emitSemanticsPrefixImpl(IRInst* inst) { SLANG_UNUSED(inst); }
virtual void emitSemanticsImpl(IRInst* inst, bool allowOffsetLayout)
{
SLANG_UNUSED(inst);
Expand Down
26 changes: 26 additions & 0 deletions source/slang/slang-emit-wgsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,32 @@ static bool isPowerOf2(const uint32_t n)
return (n != 0U) && ((n - 1U) & n) == 0U;
}

bool WGSLSourceEmitter::maybeEmitSystemSemantic(IRInst* inst)
{
if (auto sysSemanticDecor = inst->findDecoration<IRTargetSystemValueDecoration>())
{
m_writer->emit("@builtin(");
m_writer->emit(sysSemanticDecor->getSemantic());
m_writer->emit(")");
return true;
}
return false;
}

void WGSLSourceEmitter::emitSemanticsPrefixImpl(IRInst* inst)
{
if (!maybeEmitSystemSemantic(inst))
{
if (auto semanticDecoration = inst->findDecoration<IRSemanticDecoration>())
{
m_writer->emit("@location(");
m_writer->emit(semanticDecoration->getSemanticIndex());
m_writer->emit(")");
return;
}
}
}

void WGSLSourceEmitter::emitStructFieldAttributes(IRStructType* structType, IRStructField* field)
{
// Tint emits errors unless we explicitly spell out the layout in some cases, so emit
Expand Down
3 changes: 3 additions & 0 deletions source/slang/slang-emit-wgsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class WGSLSourceEmitter : public CLikeSourceEmitter
virtual void emitParamTypeImpl(IRType* type, const String& name) SLANG_OVERRIDE;
virtual void _emitType(IRType* type, DeclaratorInfo* declarator) SLANG_OVERRIDE;
virtual void emitFrontMatterImpl(TargetRequest* targetReq) SLANG_OVERRIDE;
virtual void emitSemanticsPrefixImpl(IRInst* inst) SLANG_OVERRIDE;
virtual void emitStructFieldAttributes(IRStructType* structType, IRStructField* field)
SLANG_OVERRIDE;
virtual void emitCallArg(IRInst* inst) SLANG_OVERRIDE;
Expand All @@ -57,6 +58,8 @@ class WGSLSourceEmitter : public CLikeSourceEmitter
void ensurePrelude(const char* preludeText);

private:
bool maybeEmitSystemSemantic(IRInst* inst);

// Emit the matrix type with 'rowCountWGSL' WGSL-rows and 'colCountWGSL' WGSL-columns
void emitMatrixType(
IRType* const elementType,
Expand Down
Loading
Loading