From 16342f4a6baa2e50d390c8835879fc056497aa4c Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 4 Mar 2024 12:11:40 -0800 Subject: [PATCH] Fix lowering logic around imported modules. (#3668) * Fix lowering logic around imported modules. * Use actual source loc when emitting SPIRV. --- source/slang/slang-lower-to-ir.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 89fc000879..5e35bf1657 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -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(); +} + bool isImportedDecl(IRGenContext* context, Decl* decl, bool& outIsExplicitExtern) { // If the declaration has the extern attribute then it must be imported @@ -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); } @@ -9131,6 +9144,10 @@ struct DeclLoweringVisitor : DeclVisitor // 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) {