From 9f786fdf71e90339e20979ef3ba8f073657f5a98 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Fri, 17 May 2024 11:43:08 -0500 Subject: capture/relay: Add capture interface classes (#4177) * capture/relay: Add capture interface classes Add `ModuleCapture` class for capturing `IModule` - The `IModule` can only be created from -- `ISession::loadModule` -- `ISession::loadModuleFromIRBlob` -- `ISession::loadModuleFromSource` -- `ISession::loadModuleFromSourceString` so, we create the `ModuleCapture` at those methods in `SessionCapture` class. We use a hash map to store a map from `IModule` to `ModuleCapture` to avoid creating new `ModuleCapture` when there is already an old one. - In `SessionCapture::getLoadedModule`, we will assert on not finding a `ModuleCapture` instance. Add `EntryPointCapture` class for capturing `IEntryPoint`. - The `IEntryPoint` can only be created from: -- `IModule::findEntryPointByName` -- `IModule::findAndCheckEntryPoint` so, we create the `EntryPointCapture` at those methods in `ModuleCapture`. Similarly, we use a hash map to store a map from `IEntryPoint` to `EntryPointCapture`. - In `IModule::getDefinedEntryPoint`, we will assert on not finding a `EntryPointCapture` instance. Add `CompositeComponentTypeCapture` class for capturing CompositeComponentType, but since user is only exposed to `IComponentType`, so `CompositeComponentTypeCapture` just inherits from `IComponentType`. - `CompositeComponentType` can only be created from: -- ISession::createCompositeComponentType so create it here. Add `TypeConformanceCapture` class for capturing `ITypeConformance`. - The `ITypeConformance` can only be created from: -- `ISession::createTypeConformanceComponentType` so create it here. In addition, because `EntryPointCapture` and `ModuleCapture` share a some base class `IComponentType`, we generate the COM GUID for those two classes to differentiate them. * Fix the build issue * Add nullptr check for output parameter * define the SLANG_CAPTURE_ASSERT macro used in both debug and release build --- .../slang-composite-component-type.cpp | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 source/slang-capture-replay/slang-composite-component-type.cpp (limited to 'source/slang-capture-replay/slang-composite-component-type.cpp') diff --git a/source/slang-capture-replay/slang-composite-component-type.cpp b/source/slang-capture-replay/slang-composite-component-type.cpp new file mode 100644 index 000000000..09fcec357 --- /dev/null +++ b/source/slang-capture-replay/slang-composite-component-type.cpp @@ -0,0 +1,129 @@ +#include "capture_utility.h" +#include "slang-composite-component-type.h" + +namespace SlangCapture +{ + CompositeComponentTypeCapture::CompositeComponentTypeCapture(slang::IComponentType* componentType) + : m_actualCompositeComponentType(componentType) + { + SLANG_CAPTURE_ASSERT(m_actualCompositeComponentType != nullptr); + slangCaptureLog(LogLevel::Verbose, "%s: %p\n", __PRETTY_FUNCTION__, componentType); + } + + CompositeComponentTypeCapture::~CompositeComponentTypeCapture() + { + m_actualCompositeComponentType->release(); + } + + ISlangUnknown* CompositeComponentTypeCapture::getInterface(const Guid& guid) + { + if (guid == IComponentType::getTypeGuid()) + { + return static_cast(this); + } + return nullptr; + } + + SLANG_NO_THROW slang::ISession* CompositeComponentTypeCapture::getSession() + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + slang::ISession* res = m_actualCompositeComponentType->getSession(); + return res; + } + + SLANG_NO_THROW slang::ProgramLayout* CompositeComponentTypeCapture::getLayout( + SlangInt targetIndex, + slang::IBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + slang::ProgramLayout* res = m_actualCompositeComponentType->getLayout(targetIndex, outDiagnostics); + return res; + } + + SLANG_NO_THROW SlangInt CompositeComponentTypeCapture::getSpecializationParamCount() + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangInt res = m_actualCompositeComponentType->getSpecializationParamCount(); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::getEntryPointCode( + SlangInt entryPointIndex, + SlangInt targetIndex, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::getResultAsFileSystem( + SlangInt entryPointIndex, + SlangInt targetIndex, + ISlangMutableFileSystem** outFileSystem) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->getResultAsFileSystem(entryPointIndex, targetIndex, outFileSystem); + return res; + } + + SLANG_NO_THROW void CompositeComponentTypeCapture::getEntryPointHash( + SlangInt entryPointIndex, + SlangInt targetIndex, + slang::IBlob** outHash) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + m_actualCompositeComponentType->getEntryPointHash(entryPointIndex, targetIndex, outHash); + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::specialize( + slang::SpecializationArg const* specializationArgs, + SlangInt specializationArgCount, + slang::IComponentType** outSpecializedComponentType, + ISlangBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->specialize(specializationArgs, specializationArgCount, outSpecializedComponentType, outDiagnostics); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::link( + slang::IComponentType** outLinkedComponentType, + ISlangBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->link(outLinkedComponentType, outDiagnostics); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::getEntryPointHostCallable( + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary, + slang::IBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->getEntryPointHostCallable(entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::renameEntryPoint( + const char* newName, IComponentType** outEntryPoint) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->renameEntryPoint(newName, outEntryPoint); + return res; + } + + SLANG_NO_THROW SlangResult CompositeComponentTypeCapture::linkWithOptions( + IComponentType** outLinkedComponentType, + uint32_t compilerOptionEntryCount, + slang::CompilerOptionEntry* compilerOptionEntries, + ISlangBlob** outDiagnostics) + { + slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangResult res = m_actualCompositeComponentType->linkWithOptions(outLinkedComponentType, compilerOptionEntryCount, compilerOptionEntries, outDiagnostics); + return res; + } +} -- cgit v1.2.3