diff options
| author | Lujin Wang <143145775+lujinwangnv@users.noreply.github.com> | 2025-06-04 22:55:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-05 05:55:11 +0000 |
| commit | 0c4c63b4a575f45f5dcf03f26b78becd36b0efca (patch) | |
| tree | e44bd4b5fc47b1f3b0b76d9a6ab27355fc02f6dd /source | |
| parent | 22ebf908f0efdabc0c2ebfad044f35677b6d6660 (diff) | |
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<SourceFile*> m_includedFileSet;
---------
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/compiler-core/slang-source-loc.h | 9 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 6 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 35 |
3 files changed, 45 insertions, 5 deletions
diff --git a/source/compiler-core/slang-source-loc.h b/source/compiler-core/slang-source-loc.h index 674ed2076..b52f2e50d 100644 --- a/source/compiler-core/slang-source-loc.h +++ b/source/compiler-core/slang-source-loc.h @@ -331,6 +331,12 @@ public: m_sourceMapKind = sourceMapKind; } + /// Set the source file as an included file + void setIncludedFile() { m_included = true; } + + /// Check if the source file is an included file + bool isIncludedFile() { return m_included; } + /// Ctor SourceFile(SourceManager* sourceManager, const PathInfo& pathInfo, size_t contentSize); /// Dtor @@ -360,6 +366,9 @@ protected: ComPtr<IBoxValue<SourceMap>> m_sourceMap; // What kind of source map it is (if there is one) SourceMapKind m_sourceMapKind = SourceMapKind::Normal; + + // Indicate if the source file is an included file + bool m_included = false; }; enum class SourceLocType diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 8f7f7d49a..861719aac 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1880,6 +1880,7 @@ public: { m_sourceArtifacts.clear(); m_sourceFiles.clear(); + m_includedFileSet.clear(); } /// Add a source artifact @@ -1888,6 +1889,8 @@ public: /// Add both the artifact and the sourceFile. void addSource(IArtifact* sourceArtifact, SourceFile* sourceFile); + void addIncludedSourceFileIfNotExist(SourceFile* sourceFile); + // The entry points associated with this translation unit List<RefPtr<EntryPoint>> const& getEntryPoints() { return module->getEntryPoints(); } @@ -1936,6 +1939,9 @@ protected: // NOTE! This member is generated lazily from m_sourceArtifacts // it is *necessary* to call requireSourceFiles to ensure it's in sync. List<SourceFile*> m_sourceFiles; + + // Track all the included source files added in m_sourceFiles + HashSet<SourceFile*> m_includedFileSet; }; enum class FloatingPointMode : SlangFloatingPointModeIntegral 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<IPathArtifactRepresentation>(artifact); @@ -2652,7 +2662,6 @@ void TranslationUnitRequest::_addSourceFile(SourceFile* sourceFile) List<SourceFile*> 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; |
