summaryrefslogtreecommitdiff
path: root/source/slang-capture-replay/slang-session.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-07-23 10:45:26 -0500
committerGitHub <noreply@github.com>2024-07-23 08:45:26 -0700
commit986256ffb92ab7c8fc7cf9f2c424919a439a824f (patch)
tree260e37bd439275e3398d16fe238b20cd00d08cb7 /source/slang-capture-replay/slang-session.cpp
parentc28d8b6aec721fa3350fc52647f1572a353f6151 (diff)
Feature/capture (#4625)
* Add decoder * Add a replay executable to consume the decoded content Add file-processor.cpp/h where we implement the logic to process the captured file block by block. Each block is: function header + parameter buffer + function tailer + function output[optional]. After reading one block, the block of data is sent to decoder module to dispatch the corresponding API. Add slang-decoder.cpp/h where we implement the logic to dispatch the slang API according to the input block data. - Rename api_callId.h to capture-format.h - Renmae capture_utility.cpp to capture-utility.cpp - Renmae capture_utility.h to capture-utility.h - Change the #include file name accordingly. * Reorganize source files structure Move all the capture logic code into `capture` directory. - the capture code will be build with slang dll. Move all the replay logic code into `relay` directoy. - the replay code is not part of slang dll, it will be built as a stand alone binary and link against slang dll. Change the #include file names accordingly. Add tools/slang-replay/main.cpp for the slang-replay stand alone binary place holder. Will implement it later. Update premake5.lua accordingly. * Update cmake files Update cmake files to change the build process for capture and relay system. - capture component should be build with slang dll, so we should not include replay component. - replay component should be a separate executable tool, which should not include capture component. - In order to easy use our current cmake infrastructure, move the shared files to a `util` folder - change the header include path * Redesgin the interfaces of consumers Fix some issues in capture Finish implementing all slang-decoder functions * Fix the AppleClang build issue * Address few comments - Fix the weird indent issues. - Correct the function name for CreateGlobalSession() - Rename file-processor to captureFile-processor to be more specific. - Use Slang::List instead of std::vector * record/replay: name refactor change Refactor the naming. Change the name "encoder/capture" to "record".
Diffstat (limited to 'source/slang-capture-replay/slang-session.cpp')
-rw-r--r--source/slang-capture-replay/slang-session.cpp517
1 files changed, 0 insertions, 517 deletions
diff --git a/source/slang-capture-replay/slang-session.cpp b/source/slang-capture-replay/slang-session.cpp
deleted file mode 100644
index ee9fd9549..000000000
--- a/source/slang-capture-replay/slang-session.cpp
+++ /dev/null
@@ -1,517 +0,0 @@
-#include "capture_utility.h"
-#include "slang-session.h"
-#include "slang-entrypoint.h"
-#include "slang-composite-component-type.h"
-#include "slang-type-conformance.h"
-
-namespace SlangCapture
-{
-
- SessionCapture::SessionCapture(slang::ISession* session, CaptureManager* captureManager)
- : m_actualSession(session),
- m_captureManager(captureManager)
- {
- SLANG_CAPTURE_ASSERT(m_actualSession);
- SLANG_CAPTURE_ASSERT(m_captureManager);
- m_sessionHandle = reinterpret_cast<uint64_t>(m_actualSession.get());
- slangCaptureLog(LogLevel::Verbose, "%s: %p\n", "SessionCapture create:", session);
- }
-
- SessionCapture::~SessionCapture()
- {
- m_actualSession->release();
- }
-
- ISlangUnknown* SessionCapture::getInterface(const Guid& guid)
- {
- if(guid == ISlangUnknown::getTypeGuid() || guid == ISession::getTypeGuid())
- return asExternal(this);
-
- return nullptr;
- }
-
- SLANG_NO_THROW slang::IGlobalSession* SessionCapture::getGlobalSession()
- {
- // No need to capture this function.
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
- slang::IGlobalSession* pGlobalSession = m_actualSession->getGlobalSession();
- return pGlobalSession;
- }
-
- SLANG_NO_THROW slang::IModule* SessionCapture::loadModule(
- const char* moduleName,
- slang::IBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_loadModule, m_sessionHandle);
- encoder->encodeString(moduleName);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::IModule* pModule = m_actualSession->loadModule(moduleName, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pModule);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- ModuleCapture* pModuleCapture = getModuleCapture(pModule);
- return static_cast<slang::IModule*>(pModuleCapture);
- }
-
- SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromIRBlob(
- const char* moduleName,
- const char* path,
- slang::IBlob* source,
- slang::IBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_loadModuleFromIRBlob, m_sessionHandle);
- encoder->encodeString(moduleName);
- encoder->encodeString(path);
- encoder->encodePointer(source);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::IModule* pModule = m_actualSession->loadModuleFromIRBlob(moduleName, path, source, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pModule);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- ModuleCapture* pModuleCapture = getModuleCapture(pModule);
- return static_cast<slang::IModule*>(pModuleCapture);
- }
-
- SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromSource(
- const char* moduleName,
- const char* path,
- slang::IBlob* source,
- slang::IBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_loadModuleFromSource, m_sessionHandle);
- encoder->encodeString(moduleName);
- encoder->encodeString(path);
- encoder->encodePointer(source);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::IModule* pModule = m_actualSession->loadModuleFromSource(moduleName, path, source, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pModule);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- ModuleCapture* pModuleCapture = getModuleCapture(pModule);
- return static_cast<slang::IModule*>(pModuleCapture);
- }
-
- SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromSourceString(
- const char* moduleName,
- const char* path,
- const char* string,
- slang::IBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_loadModuleFromSourceString, m_sessionHandle);
- encoder->encodeString(moduleName);
- encoder->encodeString(path);
- encoder->encodeString(string);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::IModule* pModule = m_actualSession->loadModuleFromSourceString(moduleName, path, string, outDiagnostics);
-
- {
- // TODO: Not sure if we need to capture the diagnostics blob.
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pModule);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- ModuleCapture* pModuleCapture = getModuleCapture(pModule);
- return static_cast<slang::IModule*>(pModuleCapture);
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::createCompositeComponentType(
- slang::IComponentType* const* componentTypes,
- SlangInt componentTypeCount,
- slang::IComponentType** outCompositeComponentType,
- ISlangBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- Slang::List<slang::IComponentType*> componentTypeList;
-
- // get the actual component types from our capture wrappers
- if(SLANG_OK != getActualComponentTypes(componentTypes, componentTypeCount, componentTypeList))
- {
- SLANG_CAPTURE_ASSERT(!"Failed to get actual component types");
- }
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_createCompositeComponentType, m_sessionHandle);
- encoder->encodeAddressArray(componentTypeList.getBuffer(), componentTypeCount);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->createCompositeComponentType(
- componentTypeList.getBuffer(), componentTypeCount, outCompositeComponentType, outDiagnostics);
-
- {
- encoder->encodeAddress(*outCompositeComponentType);
- encoder->encodeAddress(*outDiagnostics);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- if (SLANG_OK == result)
- {
- CompositeComponentTypeCapture* compositeComponentTypeCapture =
- new CompositeComponentTypeCapture(*outCompositeComponentType, m_captureManager);
- Slang::ComPtr<CompositeComponentTypeCapture> resultCapture(compositeComponentTypeCapture);
- *outCompositeComponentType = resultCapture.detach();
- }
-
- return result;
- }
-
- SLANG_NO_THROW slang::TypeReflection* SessionCapture::specializeType(
- slang::TypeReflection* type,
- slang::SpecializationArg const* specializationArgs,
- SlangInt specializationArgCount,
- ISlangBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_specializeType, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder->encodeStructArray(specializationArgs, specializationArgCount);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::TypeReflection* pTypeReflection = m_actualSession->specializeType(type, specializationArgs, specializationArgCount, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pTypeReflection);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return pTypeReflection;
- }
-
- SLANG_NO_THROW slang::TypeLayoutReflection* SessionCapture::getTypeLayout(
- slang::TypeReflection* type,
- SlangInt targetIndex,
- slang::LayoutRules rules,
- ISlangBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getTypeLayout, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder->encodeInt64(targetIndex);
- encoder->encodeEnumValue(rules);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::TypeLayoutReflection* pTypeLayoutReflection = m_actualSession->getTypeLayout(type, targetIndex, rules, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pTypeLayoutReflection);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return pTypeLayoutReflection;
- }
-
- SLANG_NO_THROW slang::TypeReflection* SessionCapture::getContainerType(
- slang::TypeReflection* elementType,
- slang::ContainerType containerType,
- ISlangBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getContainerType, m_sessionHandle);
- encoder->encodeAddress(elementType);
- encoder->encodeEnumValue(containerType);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::TypeReflection* pTypeReflection = m_actualSession->getContainerType(elementType, containerType, outDiagnostics);
-
- {
- encoder->encodeAddress(*outDiagnostics);
- encoder->encodeAddress(pTypeReflection);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return pTypeReflection;
- }
-
- SLANG_NO_THROW slang::TypeReflection* SessionCapture::getDynamicType()
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getDynamicType, m_sessionHandle);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::TypeReflection* pTypeReflection = m_actualSession->getDynamicType();
-
- {
- encoder->encodeAddress(pTypeReflection);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return pTypeReflection;
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::getTypeRTTIMangledName(
- slang::TypeReflection* type,
- ISlangBlob** outNameBlob)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getTypeRTTIMangledName, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->getTypeRTTIMangledName(type, outNameBlob);
-
- {
- encoder->encodeAddress(outNameBlob);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return result;
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::getTypeConformanceWitnessMangledName(
- slang::TypeReflection* type,
- slang::TypeReflection* interfaceType,
- ISlangBlob** outNameBlob)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getTypeConformanceWitnessMangledName, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder->encodeAddress(interfaceType);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->getTypeConformanceWitnessMangledName(type, interfaceType, outNameBlob);
-
- {
- encoder->encodeAddress(outNameBlob);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return result;
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::getTypeConformanceWitnessSequentialID(
- slang::TypeReflection* type,
- slang::TypeReflection* interfaceType,
- uint32_t* outId)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getTypeConformanceWitnessSequentialID, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder->encodeAddress(interfaceType);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->getTypeConformanceWitnessSequentialID(type, interfaceType, outId);
-
- // No need to capture outId, it's not slang allocation
- return result;
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::createTypeConformanceComponentType(
- slang::TypeReflection* type,
- slang::TypeReflection* interfaceType,
- slang::ITypeConformance** outConformance,
- SlangInt conformanceIdOverride,
- ISlangBlob** outDiagnostics)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_createTypeConformanceComponentType, m_sessionHandle);
- encoder->encodeAddress(type);
- encoder->encodeAddress(interfaceType);
- encoder->encodeInt64(conformanceIdOverride);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->createTypeConformanceComponentType(type, interfaceType, outConformance, conformanceIdOverride, outDiagnostics);
-
- {
- encoder->encodeAddress(*outConformance);
- encoder->encodeAddress(*outDiagnostics);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- if (SLANG_OK != result)
- {
- TypeConformanceCapture* conformanceCapture = new TypeConformanceCapture(*outConformance, m_captureManager);
- Slang::ComPtr<TypeConformanceCapture> resultCapture(conformanceCapture);
- *outConformance = resultCapture.detach();
- }
-
- return result;
- }
-
- SLANG_NO_THROW SlangResult SessionCapture::createCompileRequest(
- SlangCompileRequest** outCompileRequest)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_createCompileRequest, m_sessionHandle);
- encoder = m_captureManager->endMethodCapture();
- }
-
- SlangResult result = m_actualSession->createCompileRequest(outCompileRequest);
-
- {
- encoder->encodeAddress(*outCompileRequest);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- return result;
- }
-
- SLANG_NO_THROW SlangInt SessionCapture::getLoadedModuleCount()
- {
- // No need to capture this function, it's just a query.
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
- SlangInt count = m_actualSession->getLoadedModuleCount();
- return count;
- }
-
- SLANG_NO_THROW slang::IModule* SessionCapture::getLoadedModule(SlangInt index)
- {
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
-
- ParameterEncoder* encoder {};
- {
- encoder = m_captureManager->beginMethodCapture(ApiCallId::ISession_getLoadedModule, m_sessionHandle);
- encoder->encodeInt64(index);
- encoder = m_captureManager->endMethodCapture();
- }
-
- slang::IModule* pModule = m_actualSession->getLoadedModule(index);
-
- {
- encoder->encodeAddress(pModule);
- m_captureManager->endMethodCaptureAppendOutput();
- }
-
- if (pModule)
- {
- ModuleCapture* moduleCapture = m_mapModuleToCapture.tryGetValue(pModule);
- if (!moduleCapture)
- {
- SLANG_CAPTURE_ASSERT(!"Module not found in mapModuleToCapture");
- }
- return static_cast<slang::IModule*>(moduleCapture);
- }
-
- return pModule;
- }
-
- SLANG_NO_THROW bool SessionCapture::isBinaryModuleUpToDate(const char* modulePath, slang::IBlob* binaryModuleBlob)
- {
- // No need to capture this function, it's a query function and doesn't impact slang internal state.
- slangCaptureLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
- bool result = m_actualSession->isBinaryModuleUpToDate(modulePath, binaryModuleBlob);
- return result;
- }
-
- ModuleCapture* SessionCapture::getModuleCapture(slang::IModule* module)
- {
- ModuleCapture* moduleCapture = nullptr;
- moduleCapture = m_mapModuleToCapture.tryGetValue(module);
- if (!moduleCapture)
- {
- moduleCapture = new ModuleCapture(module, m_captureManager);
- Slang::ComPtr<ModuleCapture> result(moduleCapture);
- m_mapModuleToCapture.add(module, *result.detach());
- }
- return moduleCapture;
- }
-
- SlangResult SessionCapture::getActualComponentTypes(
- slang::IComponentType* const* componentTypes,
- SlangInt componentTypeCount,
- List<slang::IComponentType*>& outActualComponentTypes)
- {
- for (SlangInt i = 0; i < componentTypeCount; i++)
- {
- slang::IComponentType* const& componentType = componentTypes[i];
- void* outObj = nullptr;
-
- if (componentType->queryInterface(ModuleCapture::getTypeGuid(), &outObj) == SLANG_OK)
- {
- ModuleCapture* moduleCapture = static_cast<ModuleCapture*>(outObj);
- outActualComponentTypes.add(moduleCapture->getActualModule());
- }
- else if (componentType->queryInterface(EntryPointCapture::getTypeGuid(), &outObj) == SLANG_OK)
- {
- EntryPointCapture* entrypointCapture = static_cast<EntryPointCapture*>(outObj);
- outActualComponentTypes.add(entrypointCapture->getActualEntryPoint());
- }
- // will fall back to the actual component type, it means that we didn't capture this type.
- else
- {
- outActualComponentTypes.add(componentType);
- }
- }
-
- if (componentTypeCount == outActualComponentTypes.getCount())
- {
- return SLANG_OK;
- }
- return SLANG_FAIL;
- }
-} // namespace SlangCapture