diff options
| author | jarcherNV <jarcher@nvidia.com> | 2025-06-12 19:14:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-12 19:14:49 -0700 |
| commit | 9c8fab83a53c43e345566c35f87c16fe7b815e01 (patch) | |
| tree | d7d487050656b927a48de9bd6473cf757c6dc94d | |
| parent | 60b66c309075e91824aef69a153e304561ca6041 (diff) | |
Fix API changes from separate debugging support (#7397)
Recent separate debugging support added two new functions which broke
backwards compatibility. This change restores the old API and moves the
new functions to an IComponentType2 interface which can be used if
separate debug files are needed.
| -rw-r--r-- | include/slang.h | 39 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-component-type.cpp | 26 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-component-type.h | 9 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-entrypoint.h | 21 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-module.h | 21 | ||||
| -rw-r--r-- | source/slang-record-replay/record/slang-type-conformance.h | 21 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 24 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 84 | ||||
| -rw-r--r-- | tools/slang-unit-test/unit-test-separate-debug.cpp | 7 |
9 files changed, 92 insertions, 160 deletions
diff --git a/include/slang.h b/include/slang.h index 9797ea00c..b9fe732c0 100644 --- a/include/slang.h +++ b/include/slang.h @@ -4408,16 +4408,6 @@ struct IComponentType : public ISlangUnknown SlangInt targetIndex, IMetadata** outMetadata, IBlob** outDiagnostics = nullptr) = 0; - - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - ICompileResult** outCompileResult, - IBlob** outDiagnostics = nullptr) = 0; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - ICompileResult** outCompileResult, - IBlob** outDiagnostics = nullptr) = 0; }; #define SLANG_UUID_IComponentType IComponentType::getTypeGuid() @@ -4436,6 +4426,35 @@ struct ITypeConformance : public IComponentType }; #define SLANG_UUID_ITypeConformance ITypeConformance::getTypeGuid() +/** IComponentType2 is a component type used for getting separate debug data. + +This interface is used for getting separate debug data, introduced here to +avoid breaking backwards compatibility of the IComponentType interface. + +The `getTargetCompileResult` and `getEntryPointCompileResult` functions +are used to get the base and debug spirv, and metadata containing the +debug build identifier. +*/ +struct IComponentType2 : public ISlangUnknown +{ + SLANG_COM_INTERFACE( + 0x9c2a4b3d, + 0x7f68, + 0x4e91, + {0xa5, 0x2c, 0x8b, 0x19, 0x3e, 0x45, 0x7a, 0x9f}) + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( + SlangInt targetIndex, + ICompileResult** outCompileResult, + IBlob** outDiagnostics = nullptr) = 0; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( + SlangInt entryPointIndex, + SlangInt targetIndex, + ICompileResult** outCompileResult, + IBlob** outDiagnostics = nullptr) = 0; +}; + #define SLANG_UUID_IComponentType2 IComponentType2::getTypeGuid() + /** A module is the granularity of shader code compilation and loading. In most cases a module corresponds to a single compile "translation unit." diff --git a/source/slang-record-replay/record/slang-component-type.cpp b/source/slang-record-replay/record/slang-component-type.cpp index 732721aa4..05fd68691 100644 --- a/source/slang-record-replay/record/slang-component-type.cpp +++ b/source/slang-record-replay/record/slang-component-type.cpp @@ -157,32 +157,6 @@ SLANG_NO_THROW SlangResult SLANG_MCALL IComponentTypeRecorder::getTargetMetadata return m_actualComponentType->getTargetMetadata(targetIndex, outMetadata, outDiagnostics); } -SLANG_NO_THROW SlangResult SLANG_MCALL IComponentTypeRecorder::getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) -{ - // No need to record this call. - return m_actualComponentType->getEntryPointCompileResult( - entryPointIndex, - targetIndex, - outCompileResult, - outDiagnostics); -} - -SLANG_NO_THROW SlangResult SLANG_MCALL IComponentTypeRecorder::getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) -{ - // No need to record this call. - return m_actualComponentType->getTargetCompileResult( - targetIndex, - outCompileResult, - outDiagnostics); -} - SLANG_NO_THROW SlangResult IComponentTypeRecorder::getResultAsFileSystem( SlangInt entryPointIndex, SlangInt targetIndex, diff --git a/source/slang-record-replay/record/slang-component-type.h b/source/slang-record-replay/record/slang-component-type.h index da9749d90..2c854ee33 100644 --- a/source/slang-record-replay/record/slang-component-type.h +++ b/source/slang-record-replay/record/slang-component-type.h @@ -71,15 +71,6 @@ public: SlangInt targetIndex, slang::IMetadata** outMetadata, slang::IBlob** outDiagnostics = nullptr) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics = nullptr) override; protected: virtual ApiClassId getClassId() = 0; diff --git a/source/slang-record-replay/record/slang-entrypoint.h b/source/slang-record-replay/record/slang-entrypoint.h index 93da5557a..f9906f3a2 100644 --- a/source/slang-record-replay/record/slang-entrypoint.h +++ b/source/slang-record-replay/record/slang-entrypoint.h @@ -96,27 +96,6 @@ public: return Super::getTargetMetadata(targetIndex, outMetadata, outDiagnostics); } - SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getEntryPointCompileResult( - entryPointIndex, - targetIndex, - outCompileResult, - outDiagnostics); - } - - SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getTargetCompileResult(targetIndex, outCompileResult, outDiagnostics); - } - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem( SlangInt entryPointIndex, SlangInt targetIndex, diff --git a/source/slang-record-replay/record/slang-module.h b/source/slang-record-replay/record/slang-module.h index fc2a790ed..d9c83576d 100644 --- a/source/slang-record-replay/record/slang-module.h +++ b/source/slang-record-replay/record/slang-module.h @@ -114,27 +114,6 @@ public: return Super::getTargetMetadata(targetIndex, outMetadata, outDiagnostics); } - SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getEntryPointCompileResult( - entryPointIndex, - targetIndex, - outCompileResult, - outDiagnostics); - } - - SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getTargetCompileResult(targetIndex, outCompileResult, outDiagnostics); - } - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem( SlangInt entryPointIndex, SlangInt targetIndex, diff --git a/source/slang-record-replay/record/slang-type-conformance.h b/source/slang-record-replay/record/slang-type-conformance.h index f43131b92..12a0e4021 100644 --- a/source/slang-record-replay/record/slang-type-conformance.h +++ b/source/slang-record-replay/record/slang-type-conformance.h @@ -93,27 +93,6 @@ public: return Super::getTargetMetadata(targetIndex, outMetadata, outDiagnostics); } - SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getEntryPointCompileResult( - entryPointIndex, - targetIndex, - outCompileResult, - outDiagnostics); - } - - SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE - { - return Super::getTargetCompileResult(targetIndex, outCompileResult, outDiagnostics); - } - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem( SlangInt entryPointIndex, SlangInt targetIndex, diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 24ddd00cc..43b51b231 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -285,6 +285,7 @@ class ComponentTypeVisitor; /// class ComponentType : public RefObject, public slang::IComponentType, + public slang::IComponentType2, public slang::IModulePrecompileService_Experimental { public: @@ -324,16 +325,6 @@ public: slang::IMetadata** outMetadata, slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; - SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( - SlangInt entryPointIndex, - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) SLANG_OVERRIDE; - SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( - SlangInt targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; - SLANG_NO_THROW SlangResult SLANG_MCALL getResultAsFileSystem( SlangInt entryPointIndex, SlangInt targetIndex, @@ -369,6 +360,19 @@ public: slang::CompilerOptionEntry* entries, ISlangBlob** outDiagnostics) override; + // + // slang::IComponentType2 interface + // + + SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCompileResult( + SlangInt entryPointIndex, + SlangInt targetIndex, + slang::ICompileResult** outCompileResult, + slang::IBlob** outDiagnostics) SLANG_OVERRIDE; + SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCompileResult( + SlangInt targetIndex, + slang::ICompileResult** outCompileResult, + slang::IBlob** outDiagnostics = nullptr) SLANG_OVERRIDE; // // slang::IModulePrecompileService interface diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index daebddeae..6ee50251a 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -5322,6 +5322,8 @@ ISlangUnknown* ComponentType::getInterface(Guid const& guid) } if (guid == IModulePrecompileService_Experimental::getTypeGuid()) return static_cast<slang::IModulePrecompileService_Experimental*>(this); + if (guid == IComponentType2::getTypeGuid()) + return static_cast<slang::IComponentType2*>(this); return nullptr; } @@ -5568,33 +5570,6 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointMetadata( return SLANG_OK; } -SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointCompileResult( - SlangInt entryPointIndex, - Int targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) -{ - auto linkage = getLinkage(); - if (targetIndex < 0 || targetIndex >= linkage->targets.getCount()) - return SLANG_E_INVALID_ARG; - auto target = linkage->targets[targetIndex]; - - auto targetProgram = getTargetProgram(target); - - DiagnosticSink sink(linkage->getSourceManager(), Lexer::sourceLocationLexer); - applySettingsToDiagnosticSink(&sink, &sink, linkage->m_optionSet); - applySettingsToDiagnosticSink(&sink, &sink, m_optionSet); - - IArtifact* artifact = targetProgram->getOrCreateEntryPointResult(entryPointIndex, &sink); - sink.getBlobIfNeeded(outDiagnostics); - if (artifact == nullptr) - return SLANG_E_NOT_AVAILABLE; - - *outCompileResult = static_cast<slang::ICompileResult*>(artifact); - (*outCompileResult)->addRef(); - return SLANG_OK; -} - RefPtr<ComponentType> ComponentType::specialize( SpecializationArg const* inSpecializationArgs, SlangInt specializationArgCount, @@ -5737,6 +5712,47 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::linkWithOptions( return SLANG_OK; } +SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointCompileResult( + SlangInt entryPointIndex, + Int targetIndex, + slang::ICompileResult** outCompileResult, + slang::IBlob** outDiagnostics) +{ + auto linkage = getLinkage(); + if (targetIndex < 0 || targetIndex >= linkage->targets.getCount()) + return SLANG_E_INVALID_ARG; + auto target = linkage->targets[targetIndex]; + + auto targetProgram = getTargetProgram(target); + + DiagnosticSink sink(linkage->getSourceManager(), Lexer::sourceLocationLexer); + applySettingsToDiagnosticSink(&sink, &sink, linkage->m_optionSet); + applySettingsToDiagnosticSink(&sink, &sink, m_optionSet); + + IArtifact* artifact = targetProgram->getOrCreateEntryPointResult(entryPointIndex, &sink); + sink.getBlobIfNeeded(outDiagnostics); + if (artifact == nullptr) + return SLANG_E_NOT_AVAILABLE; + + *outCompileResult = static_cast<slang::ICompileResult*>(artifact); + (*outCompileResult)->addRef(); + return SLANG_OK; +} + +SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getTargetCompileResult( + Int targetIndex, + slang::ICompileResult** outCompileResult, + slang::IBlob** outDiagnostics) +{ + IArtifact* artifact = getTargetArtifact(targetIndex, outDiagnostics); + if (artifact == nullptr) + return SLANG_E_NOT_AVAILABLE; + + *outCompileResult = static_cast<slang::ICompileResult*>(artifact); + (*outCompileResult)->addRef(); + return SLANG_OK; +} + /// Visitor used by `ComponentType::enumerateModules` struct EnumerateModulesVisitor : ComponentTypeVisitor { @@ -5930,20 +5946,6 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getTargetMetadata( return SLANG_OK; } -SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getTargetCompileResult( - Int targetIndex, - slang::ICompileResult** outCompileResult, - slang::IBlob** outDiagnostics) -{ - IArtifact* artifact = getTargetArtifact(targetIndex, outDiagnostics); - if (artifact == nullptr) - return SLANG_E_NOT_AVAILABLE; - - *outCompileResult = static_cast<slang::ICompileResult*>(artifact); - //(*outCompileResult)->addRef(); // TODO: Needed if using a ComPtr. - return SLANG_OK; -} - // // CompositeComponentType // diff --git a/tools/slang-unit-test/unit-test-separate-debug.cpp b/tools/slang-unit-test/unit-test-separate-debug.cpp index 42ada97a5..6ce849b0d 100644 --- a/tools/slang-unit-test/unit-test-separate-debug.cpp +++ b/tools/slang-unit-test/unit-test-separate-debug.cpp @@ -106,8 +106,13 @@ SLANG_UNIT_TEST(separateDebug) ComPtr<slang::IMetadata> metadata; const char* debugBuildIdentifier = nullptr; + // IComponentType2 is a separate interface from IComponentType, so we need + // to query for it, and then use it to get the results. ComPtr<slang::ICompileResult> compileResult; - auto result = linkedProgram->getEntryPointCompileResult( + ComPtr<slang::IComponentType2> linkedProgram2; + SLANG_CHECK( + linkedProgram->queryInterface(SLANG_IID_PPV_ARGS(linkedProgram2.writeRef())) == SLANG_OK); + auto result = linkedProgram2->getEntryPointCompileResult( 0, 0, compileResult.writeRef(), |
