From 986256ffb92ab7c8fc7cf9f2c424919a439a824f Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:45:26 -0500 Subject: 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". --- .../record/slang-entrypoint.cpp | 313 +++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 source/slang-record-replay/record/slang-entrypoint.cpp (limited to 'source/slang-record-replay/record/slang-entrypoint.cpp') diff --git a/source/slang-record-replay/record/slang-entrypoint.cpp b/source/slang-record-replay/record/slang-entrypoint.cpp new file mode 100644 index 000000000..d3bf3b47e --- /dev/null +++ b/source/slang-record-replay/record/slang-entrypoint.cpp @@ -0,0 +1,313 @@ +#include "../util/record-utility.h" +#include "slang-entrypoint.h" + +namespace SlangRecord +{ + EntryPointRecorder::EntryPointRecorder(slang::IEntryPoint* entryPoint, RecordManager* recordManager) + : m_actualEntryPoint(entryPoint), + m_recordManager(recordManager) + { + SLANG_RECORD_ASSERT(m_actualEntryPoint != nullptr); + SLANG_RECORD_ASSERT(m_recordManager != nullptr); + + m_entryPointHandle = reinterpret_cast(m_actualEntryPoint.get()); + slangRecordLog(LogLevel::Verbose, "%s: %p\n", __PRETTY_FUNCTION__, entryPoint); + } + + EntryPointRecorder::~EntryPointRecorder() + { + m_actualEntryPoint->release(); + } + + ISlangUnknown* EntryPointRecorder::getInterface(const Guid& guid) + { + if(guid == EntryPointRecorder::getTypeGuid()) + return static_cast(this); + else + return nullptr; + } + + SLANG_NO_THROW slang::ISession* EntryPointRecorder::getSession() + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getSession, m_entryPointHandle); + recorder = m_recordManager->endMethodRecord(); + } + + slang::ISession* session = m_actualEntryPoint->getSession(); + + { + recorder->recordAddress(session); + m_recordManager->endMethodRecordAppendOutput(); + } + + return session; + } + + SLANG_NO_THROW slang::ProgramLayout* EntryPointRecorder::getLayout( + SlangInt targetIndex, + slang::IBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getLayout, m_entryPointHandle); + recorder->recordInt64(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + slang::ProgramLayout* programLayout = m_actualEntryPoint->getLayout(targetIndex, outDiagnostics); + + { + recorder->recordAddress(*outDiagnostics); + recorder->recordAddress(programLayout); + m_recordManager->endMethodRecordAppendOutput(); + } + + return programLayout; + } + + SLANG_NO_THROW SlangInt EntryPointRecorder::getSpecializationParamCount() + { + // No need to record this call as it is just a query. + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + SlangInt res = m_actualEntryPoint->getSpecializationParamCount(); + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::getEntryPointCode( + SlangInt entryPointIndex, + SlangInt targetIndex, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getEntryPointCode, m_entryPointHandle); + recorder->recordInt64(entryPointIndex); + recorder->recordInt64(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->getEntryPointCode(entryPointIndex, targetIndex, outCode, outDiagnostics); + + { + recorder->recordAddress(*outCode); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::getTargetCode( + SlangInt targetIndex, + slang::IBlob** outCode, + slang::IBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getTargetCode, m_entryPointHandle); + recorder->recordInt64(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->getTargetCode(targetIndex, outCode, outDiagnostics); + + { + recorder->recordAddress(*outCode); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::getResultAsFileSystem( + SlangInt entryPointIndex, + SlangInt targetIndex, + ISlangMutableFileSystem** outFileSystem) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getResultAsFileSystem, m_entryPointHandle); + recorder->recordInt64(entryPointIndex); + recorder->recordInt64(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->getResultAsFileSystem(entryPointIndex, targetIndex, outFileSystem); + + { + recorder->recordAddress(*outFileSystem); + } + + // TODO: We might need to wrap the file system object. + return res; + } + + SLANG_NO_THROW void EntryPointRecorder::getEntryPointHash( + SlangInt entryPointIndex, + SlangInt targetIndex, + slang::IBlob** outHash) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getEntryPointHash, m_entryPointHandle); + recorder->recordInt64(entryPointIndex); + recorder->recordInt64(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + m_actualEntryPoint->getEntryPointHash(entryPointIndex, targetIndex, outHash); + + { + recorder->recordAddress(*outHash); + m_recordManager->endMethodRecordAppendOutput(); + } + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::specialize( + slang::SpecializationArg const* specializationArgs, + SlangInt specializationArgCount, + slang::IComponentType** outSpecializedComponentType, + ISlangBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_specialize, m_entryPointHandle); + recorder->recordInt64(specializationArgCount); + recorder->recordStructArray(specializationArgs, specializationArgCount); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->specialize(specializationArgs, specializationArgCount, outSpecializedComponentType, outDiagnostics); + + { + recorder->recordAddress(*outSpecializedComponentType); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::link( + slang::IComponentType** outLinkedComponentType, + ISlangBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_link, m_entryPointHandle); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->link(outLinkedComponentType, outDiagnostics); + + { + recorder->recordAddress(*outLinkedComponentType); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::getEntryPointHostCallable( + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary, + slang::IBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_getEntryPointHostCallable, m_entryPointHandle); + recorder->recordInt32(entryPointIndex); + recorder->recordInt32(targetIndex); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->getEntryPointHostCallable(entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + + { + recorder->recordAddress(*outSharedLibrary); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::renameEntryPoint( + const char* newName, IComponentType** outEntryPoint) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_renameEntryPoint, m_entryPointHandle); + recorder->recordString(newName); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->renameEntryPoint(newName, outEntryPoint); + + { + recorder->recordAddress(*outEntryPoint); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW SlangResult EntryPointRecorder::linkWithOptions( + IComponentType** outLinkedComponentType, + uint32_t compilerOptionEntryCount, + slang::CompilerOptionEntry* compilerOptionEntries, + ISlangBlob** outDiagnostics) + { + slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__); + + ParameterRecorder* recorder {}; + { + recorder = m_recordManager->beginMethodRecord(ApiCallId::IEntryPoint_linkWithOptions, m_entryPointHandle); + recorder->recordUint32(compilerOptionEntryCount); + recorder->recordStructArray(compilerOptionEntries, compilerOptionEntryCount); + recorder = m_recordManager->endMethodRecord(); + } + + SlangResult res = m_actualEntryPoint->linkWithOptions(outLinkedComponentType, compilerOptionEntryCount, compilerOptionEntries, outDiagnostics); + + { + recorder->recordAddress(*outLinkedComponentType); + recorder->recordAddress(*outDiagnostics); + m_recordManager->endMethodRecordAppendOutput(); + } + + return res; + } + + SLANG_NO_THROW slang::FunctionReflection* EntryPointRecorder::getFunctionReflection() + { + return m_actualEntryPoint->getFunctionReflection(); + } + +} -- cgit v1.2.3