Skip to content

Commit

Permalink
Fix lowering logic around imported modules. (shader-slang#3668)
Browse files Browse the repository at this point in the history
* Fix lowering logic around imported modules.

* Use actual source loc when emitting SPIRV.
  • Loading branch information
csyonghe authored Mar 4, 2024
1 parent f8c5405 commit 16342f4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/slang/slang-lower-to-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,16 @@ bool isFromStdLib(Decl* decl)
return false;
}

bool isDeclInDifferentModule(IRGenContext* context, Decl* decl)
{
return getModuleDecl(decl) != context->getMainModuleDecl();
}

bool isForceInlineEarly(Decl* decl)
{
return decl->hasModifier<UnsafeForceInlineEarlyAttribute>();
}

bool isImportedDecl(IRGenContext* context, Decl* decl, bool& outIsExplicitExtern)
{
// If the declaration has the extern attribute then it must be imported
Expand Down Expand Up @@ -6295,7 +6305,10 @@ void maybeEmitDebugLine(IRGenContext* context, StmtLoweringVisitor& visitor, Stm
IRInst* debugSourceInst = nullptr;
if (context->shared->mapSourceFileToDebugSourceInst.tryGetValue(source, debugSourceInst))
{
auto humaneLoc = context->getLinkage()->getSourceManager()->getHumaneLoc(stmt->loc, SourceLocType::Emit);
// When working with RenderDoc, we need to use actual source loc instead of the nominal one,
// since RenderDoc has the builtin support to split a source file into multiple files based on
// line directives in the file.
auto humaneLoc = context->getLinkage()->getSourceManager()->getHumaneLoc(stmt->loc, SourceLocType::Actual);
visitor.startBlockIfNeeded(stmt);
context->irBuilder->emitDebugLine(debugSourceInst, humaneLoc.line, humaneLoc.line, humaneLoc.column, humaneLoc.column + 1);
}
Expand Down Expand Up @@ -9131,6 +9144,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
// In Slang we currently try not to support forward declarations
// (although we might have to give in eventually), so
// this case should really only occur for builtin declarations.
}
else if (isDeclInDifferentModule(context, decl) && !isForceInlineEarly(decl))
{

}
else if (emitBody)
{
Expand Down

0 comments on commit 16342f4

Please sign in to comment.