From 0c4c63b4a575f45f5dcf03f26b78becd36b0efca Mon Sep 17 00:00:00 2001 From: Lujin Wang <143145775+lujinwangnv@users.noreply.github.com> Date: Wed, 4 Jun 2025 22:55:11 -0700 Subject: Fix missing debug info for the included slang file (#7281) * Fix missing debug info in the included slang file Issue: https://github.com/shader-slang/slang/issues/7271 Debug info including DebugFunction, DebugLocation, and DebugValue are missing in IR for "#included" Slang shader file. The included shader file was not added to TranslationUnit's source file list, therefore mapSourceFileToDebugSourceInst.add() was not called for the source in generateIRForTranslationUnit(), and later mapSourceFileToDebugSourceInst.tryGetValue() could not get value for the source to add DebugLocationDecoration, which led to missing DebugFunction, DebugLocation and other debug info for the included file in IR. Adding the include file in TranslationUnit's source file list fixes the issue. * Add source file using PreprocessorHandler Call _addSourceFile from FrontEndPreprocessorHandler::handleFileDependency. * Just use FrontEndPreprocessorHandler * Make _addSourceFile public * format code * Distingush the included source file * Add m_includedFileSet to avoid adding dup file HashSet m_includedFileSet; --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 065b9de93..912cd2e10 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -2540,6 +2540,16 @@ void TranslationUnitRequest::addSource(IArtifact* sourceArtifact, SourceFile* so _addSourceFile(sourceFile); } +void TranslationUnitRequest::addIncludedSourceFileIfNotExist(SourceFile* sourceFile) +{ + if (m_includedFileSet.contains(sourceFile)) + return; + + sourceFile->setIncludedFile(); + m_sourceFiles.add(sourceFile); + m_includedFileSet.add(sourceFile); +} + PathInfo TranslationUnitRequest::_findSourcePathInfo(IArtifact* artifact) { auto pathRep = findRepresentation(artifact); @@ -2652,7 +2662,6 @@ void TranslationUnitRequest::_addSourceFile(SourceFile* sourceFile) List const& TranslationUnitRequest::getSourceFiles() { - SLANG_ASSERT(m_sourceArtifacts.getCount() == m_sourceFiles.getCount()); return m_sourceFiles; } @@ -3072,8 +3081,15 @@ FrontEndCompileRequest::FrontEndCompileRequest( struct FrontEndPreprocessorHandler : PreprocessorHandler { public: - FrontEndPreprocessorHandler(Module* module, ASTBuilder* astBuilder, DiagnosticSink* sink) - : m_module(module), m_astBuilder(astBuilder), m_sink(sink) + FrontEndPreprocessorHandler( + Module* module, + ASTBuilder* astBuilder, + DiagnosticSink* sink, + TranslationUnitRequest* translationUnit) + : m_module(module) + , m_astBuilder(astBuilder) + , m_sink(sink) + , m_translationUnit(translationUnit) { } @@ -3081,6 +3097,7 @@ protected: Module* m_module; ASTBuilder* m_astBuilder; DiagnosticSink* m_sink; + TranslationUnitRequest* m_translationUnit = nullptr; // The first task that this handler tries to deal with is // capturing all the files on which a module is dependent. @@ -3092,6 +3109,7 @@ protected: void handleFileDependency(SourceFile* sourceFile) SLANG_OVERRIDE { m_module->addFileDependency(sourceFile); + m_translationUnit->addIncludedSourceFileIfNotExist(sourceFile); } // The second task that this handler deals with is detecting @@ -3358,6 +3376,9 @@ static void _outputIncludes( // For all the source files for (SourceFile* sourceFile : sourceFiles) { + if (sourceFile->isIncludedFile()) + continue; + // Find an initial view (this is the view of this file, that doesn't have an initiating loc) SourceView* sourceView = _findInitialSourceView(sourceFile); if (!sourceView) @@ -3429,7 +3450,7 @@ void FrontEndCompileRequest::parseTranslationUnit(TranslationUnitRequest* transl // preprocessoing can be communicated to later phases of // compilation. // - FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink()); + FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink(), translationUnit); for (auto sourceFile : translationUnit->getSourceFiles()) { @@ -4950,7 +4971,11 @@ Linkage::IncludeResult Linkage::findAndIncludeFile( fileDecl->parentDecl = module->getModuleDecl(); module->getIncludedSourceFileMap().add(sourceFile, fileDecl); - FrontEndPreprocessorHandler preprocessorHandler(module, module->getASTBuilder(), sink); + FrontEndPreprocessorHandler preprocessorHandler( + module, + module->getASTBuilder(), + sink, + translationUnit); auto combinedPreprocessorDefinitions = translationUnit->getCombinedPreprocessorDefinitions(); SourceLanguage sourceLanguage = translationUnit->sourceLanguage; SlangLanguageVersion slangLanguageVersion = module->getModuleDecl()->languageVersion; -- cgit v1.2.3