diff options
21 files changed, 3070 insertions, 354 deletions
diff --git a/source/slang-record-replay/record/record-manager.cpp b/source/slang-record-replay/record/record-manager.cpp index f10d2c704..0979a170f 100644 --- a/source/slang-record-replay/record/record-manager.cpp +++ b/source/slang-record-replay/record/record-manager.cpp @@ -4,6 +4,7 @@ #include <thread> #include "../util/record-utility.h" #include "record-manager.h" +#include "../../core/slang-io.h" namespace SlangRecord { @@ -15,7 +16,8 @@ namespace SlangRecord m_recordFileDirectory = m_recordFileDirectory / "slang-record"; - if (!std::filesystem::exists(m_recordFileDirectory)) + Slang::String recordFileDirectory {m_recordFileDirectory.string().c_str()}; + if (!Slang::File::exists(recordFileDirectory)) { std::error_code ec; if (!std::filesystem::create_directory(m_recordFileDirectory, ec)) @@ -78,7 +80,7 @@ namespace SlangRecord return &m_recorder; } - void RecordManager::endMethodRecordAppendOutput() + void RecordManager::apendOutput() { FunctionTailer* pTailer = const_cast<FunctionTailer*>( reinterpret_cast<const FunctionTailer*>(m_memoryStream.getData())); diff --git a/source/slang-record-replay/record/record-manager.h b/source/slang-record-replay/record/record-manager.h index 40992e8ad..da8b30324 100644 --- a/source/slang-record-replay/record/record-manager.h +++ b/source/slang-record-replay/record/record-manager.h @@ -16,9 +16,9 @@ namespace SlangRecord ParameterRecorder* beginMethodRecord(const ApiCallId& callId, uint64_t handleId); ParameterRecorder* endMethodRecord(); - // endMethodRecordAppendOutput is an optional call that can be used to append output to + // apendOutput is an optional call that can be used to append output to // the end of the record. It has to start with a FunctionTailer - void endMethodRecordAppendOutput(); + void apendOutput(); std::filesystem::path const& getRecordFileDirectory() const { return m_recordFileDirectory; } diff --git a/source/slang-record-replay/record/slang-composite-component-type.cpp b/source/slang-record-replay/record/slang-composite-component-type.cpp index ef594a893..e3c339adb 100644 --- a/source/slang-record-replay/record/slang-composite-component-type.cpp +++ b/source/slang-record-replay/record/slang-composite-component-type.cpp @@ -43,7 +43,7 @@ namespace SlangRecord { recorder->recordAddress(res); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -67,7 +67,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(programLayout); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return programLayout; @@ -102,7 +102,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -127,7 +127,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -177,7 +177,7 @@ namespace SlangRecord { recorder->recordAddress(*outHash); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -202,7 +202,7 @@ namespace SlangRecord { recorder->recordAddress(*outSpecializedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -225,7 +225,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -252,7 +252,7 @@ namespace SlangRecord { recorder->recordAddress(*outSharedLibrary); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -274,7 +274,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -301,7 +301,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; diff --git a/source/slang-record-replay/record/slang-entrypoint.cpp b/source/slang-record-replay/record/slang-entrypoint.cpp index d3bf3b47e..e5c76a5af 100644 --- a/source/slang-record-replay/record/slang-entrypoint.cpp +++ b/source/slang-record-replay/record/slang-entrypoint.cpp @@ -41,7 +41,7 @@ namespace SlangRecord { recorder->recordAddress(session); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return session; @@ -65,7 +65,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(programLayout); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return programLayout; @@ -100,7 +100,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -125,7 +125,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -175,7 +175,7 @@ namespace SlangRecord { recorder->recordAddress(*outHash); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -200,7 +200,7 @@ namespace SlangRecord { recorder->recordAddress(*outSpecializedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -223,7 +223,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -250,7 +250,7 @@ namespace SlangRecord { recorder->recordAddress(*outSharedLibrary); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -272,7 +272,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -299,7 +299,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; diff --git a/source/slang-record-replay/record/slang-filesystem.cpp b/source/slang-record-replay/record/slang-filesystem.cpp index 1187a9aa6..d07b575e1 100644 --- a/source/slang-record-replay/record/slang-filesystem.cpp +++ b/source/slang-record-replay/record/slang-filesystem.cpp @@ -1,6 +1,9 @@ +#include <stdlib.h> + #include "slang-filesystem.h" #include "../util/record-utility.h" #include "output-stream.h" +#include "../../core/slang-io.h" namespace SlangRecord { @@ -52,6 +55,21 @@ namespace SlangRecord std::filesystem::path filePath = m_recordManager->getRecordFileDirectory(); filePath = filePath / path; + if (!File::exists(filePath.parent_path().string().c_str())) + { + slangRecordLog(LogLevel::Debug, "Create directory: %s to save captured shader file: %s\n", + filePath.parent_path().string().c_str(), filePath.filename().string().c_str()); + + std::error_code ec; + // std::filesystem::create_directories can create the directory recursively. + if (!std::filesystem::create_directories(filePath.parent_path(), ec)) + { + slangRecordLog(LogLevel::Error, "Fail to create directory: %s, error (%d): %s\n", + filePath.parent_path().string().c_str(), ec.value(), ec.message().c_str()); + return SLANG_FAIL; + } + } + FileOutputStream fileStream(filePath.string().c_str()); fileStream.write((*outBlob)->getBufferPointer(), (*outBlob)->getBufferSize()); diff --git a/source/slang-record-replay/record/slang-global-session.cpp b/source/slang-record-replay/record/slang-global-session.cpp index 78fa8aaa2..f8fe6c65b 100644 --- a/source/slang-record-replay/record/slang-global-session.cpp +++ b/source/slang-record-replay/record/slang-global-session.cpp @@ -18,9 +18,15 @@ namespace SlangRecord // We will use the address of the global session as the filename for the record manager // to make it unique for each global session. // record slang::createGlobalSession - ParameterRecorder* recorder = m_recordManager->beginMethodRecord(ApiCallId::CreateGlobalSession, g_globalFunctionHandle); + + ParameterRecorder* recorder{}; + { + m_recordManager->beginMethodRecord(ApiCallId::CreateGlobalSession, g_globalFunctionHandle); + recorder = m_recordManager->endMethodRecord(); + } + recorder->recordAddress(m_actualGlobalSession); - m_recordManager->endMethodRecord(); + m_recordManager->apendOutput(); } GlobalSessionRecorder::~GlobalSessionRecorder() @@ -65,7 +71,7 @@ namespace SlangRecord { // record output recorder->recordAddress(actualSession); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (actualSession != nullptr) @@ -147,7 +153,7 @@ namespace SlangRecord { recorder->recordAddress(*outPrelude); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -221,7 +227,7 @@ namespace SlangRecord { recorder->recordAddress(*outPrelude); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -239,7 +245,7 @@ namespace SlangRecord { recorder->recordAddress(*outCompileRequest); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -282,7 +288,7 @@ namespace SlangRecord { recorder->recordAddress(loader); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return loader; } @@ -348,7 +354,7 @@ namespace SlangRecord { recorder->recordAddress(*outBlob); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; } @@ -425,7 +431,7 @@ namespace SlangRecord { recorder->recordAddress(outSessionDesc); recorder->recordAddress(*outAllocation); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; } @@ -445,7 +451,7 @@ namespace SlangRecord { recorder->recordAddress(*outBlob); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; } diff --git a/source/slang-record-replay/record/slang-module.cpp b/source/slang-record-replay/record/slang-module.cpp index 1457e7cf1..b59aaa18b 100644 --- a/source/slang-record-replay/record/slang-module.cpp +++ b/source/slang-record-replay/record/slang-module.cpp @@ -52,7 +52,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (SLANG_OK == res) @@ -88,7 +88,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (*outEntryPoint) @@ -120,7 +120,7 @@ namespace SlangRecord { recorder->recordAddress(*outSerializedBlob); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -186,7 +186,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (SLANG_OK == res) @@ -240,7 +240,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(programLayout); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return programLayout; @@ -275,7 +275,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -300,7 +300,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -325,7 +325,7 @@ namespace SlangRecord { recorder->recordAddress(*outFileSystem); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } // TODO: We might need to wrap the file system object. @@ -351,7 +351,7 @@ namespace SlangRecord { recorder->recordAddress(*outHash); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -376,7 +376,7 @@ namespace SlangRecord { recorder->recordAddress(*outSpecializedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -399,7 +399,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -426,7 +426,7 @@ namespace SlangRecord { recorder->recordAddress(*outSharedLibrary); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -448,7 +448,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -475,7 +475,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; diff --git a/source/slang-record-replay/record/slang-session.cpp b/source/slang-record-replay/record/slang-session.cpp index 82c7a7479..7c0ccd2e1 100644 --- a/source/slang-record-replay/record/slang-session.cpp +++ b/source/slang-record-replay/record/slang-session.cpp @@ -56,7 +56,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pModule); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } ModuleRecorder* pModuleRecorder = getModuleRecorder(pModule); @@ -85,7 +85,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pModule); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } ModuleRecorder* pModuleRecorder = getModuleRecorder(pModule); @@ -114,7 +114,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pModule); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } ModuleRecorder* pModuleRecorder = getModuleRecorder(pModule); @@ -144,7 +144,7 @@ namespace SlangRecord // TODO: Not sure if we need to record the diagnostics blob. recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pModule); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } ModuleRecorder* pModuleRecorder = getModuleRecorder(pModule); @@ -180,7 +180,7 @@ namespace SlangRecord { recorder->recordAddress(*outCompositeComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (SLANG_OK == result) @@ -215,7 +215,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pTypeReflection); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return pTypeReflection; @@ -243,7 +243,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pTypeLayoutReflection); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return pTypeLayoutReflection; @@ -269,7 +269,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(pTypeReflection); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return pTypeReflection; @@ -289,7 +289,7 @@ namespace SlangRecord { recorder->recordAddress(pTypeReflection); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return pTypeReflection; @@ -312,7 +312,7 @@ namespace SlangRecord { recorder->recordAddress(outNameBlob); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return result; @@ -337,7 +337,7 @@ namespace SlangRecord { recorder->recordAddress(outNameBlob); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return result; @@ -387,7 +387,7 @@ namespace SlangRecord { recorder->recordAddress(*outConformance); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (SLANG_OK != result) @@ -415,7 +415,7 @@ namespace SlangRecord { recorder->recordAddress(*outCompileRequest); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return result; @@ -444,7 +444,7 @@ namespace SlangRecord { recorder->recordAddress(pModule); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } if (pModule) diff --git a/source/slang-record-replay/record/slang-type-conformance.cpp b/source/slang-record-replay/record/slang-type-conformance.cpp index b9b652e9e..91f108786 100644 --- a/source/slang-record-replay/record/slang-type-conformance.cpp +++ b/source/slang-record-replay/record/slang-type-conformance.cpp @@ -45,7 +45,7 @@ namespace SlangRecord { recorder->recordAddress(res); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -69,7 +69,7 @@ namespace SlangRecord { recorder->recordAddress(*outDiagnostics); recorder->recordAddress(programLayout); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return programLayout; @@ -103,7 +103,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -128,7 +128,7 @@ namespace SlangRecord { recorder->recordAddress(*outCode); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -178,7 +178,7 @@ namespace SlangRecord { recorder->recordAddress(*outHash); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } } @@ -203,7 +203,7 @@ namespace SlangRecord { recorder->recordAddress(*outSpecializedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -226,7 +226,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -253,7 +253,7 @@ namespace SlangRecord { recorder->recordAddress(*outSharedLibrary); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -275,7 +275,7 @@ namespace SlangRecord { recorder->recordAddress(*outEntryPoint); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; @@ -302,7 +302,7 @@ namespace SlangRecord { recorder->recordAddress(*outLinkedComponentType); recorder->recordAddress(*outDiagnostics); - m_recordManager->endMethodRecordAppendOutput(); + m_recordManager->apendOutput(); } return res; diff --git a/source/slang-record-replay/replay/decoder-consumer.h b/source/slang-record-replay/replay/decoder-consumer.h index f79d9aa5e..aa3883cc0 100644 --- a/source/slang-record-replay/replay/decoder-consumer.h +++ b/source/slang-record-replay/replay/decoder-consumer.h @@ -2,15 +2,16 @@ #define DECODER_CONSUMER_H #include "slang.h" -// #include "../../slang/slang-compiler.h" +#include "../../core/slang-stream.h" #include "../util/record-format.h" +#include "../util/record-utility.h" namespace SlangRecord { class IDecoderConsumer { public: - virtual void CreateGlobalSession(ObjectID objectId, const uint8_t* parameterBuffer, int64_t bufferSize) = 0; + virtual void CreateGlobalSession(ObjectID outGlobalSessionId) = 0; virtual void IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) = 0; virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name) = 0; virtual void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) = 0; @@ -106,8 +107,8 @@ namespace SlangRecord virtual void IModule_getSpecializationParamCount(ObjectID objectId) { (void) objectId; } - virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; + virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; + virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; virtual void IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; virtual void IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; virtual void IModule_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, @@ -124,8 +125,8 @@ namespace SlangRecord virtual void IEntryPoint_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; + virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; + virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; virtual void IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; virtual void IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; virtual void IEntryPoint_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, @@ -142,8 +143,8 @@ namespace SlangRecord virtual void ICompositeComponentType_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; + virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; + virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; virtual void ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; virtual void ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; virtual void ICompositeComponentType_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, @@ -160,8 +161,8 @@ namespace SlangRecord virtual void ITypeConformance_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; + virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; + virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) = 0; virtual void ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; virtual void ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; virtual void ITypeConformance_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, diff --git a/source/slang-record-replay/replay/json-consumer.cpp b/source/slang-record-replay/replay/json-consumer.cpp index a3ea0c31f..182776139 100644 --- a/source/slang-record-replay/replay/json-consumer.cpp +++ b/source/slang-record-replay/replay/json-consumer.cpp @@ -1,174 +1,1248 @@ +#include <filesystem> + +#include "slang.h" #include "json-consumer.h" +#include "../util/record-utility.h" +#include "../util/emum-to-string.h" +#include "../../core/slang-string-util.h" +#include "../../core/slang-io.h" namespace SlangRecord { - void JsonConsumer::CreateGlobalSession(ObjectID objectId, const uint8_t* parameterBuffer, int64_t bufferSize) +#define SANITY_CHECK() if (!m_isFileValid) return + + static inline void _writeIndent(Slang::StringBuilder& builder, int indent) { + for (int i = 0; i < indent; i++) + { + builder << " "; + } } - void JsonConsumer::IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) + template <typename T> + static inline void _writeString(Slang::StringBuilder& builder, int indent, T const& str) + { + _writeIndent(builder, indent); + builder << str; + } + + template <typename T, typename U> + static inline void _writePair(Slang::StringBuilder& builder, int indent, T const& name, U const& value) + { + _writeIndent(builder, indent); + builder << name << ": " << value << ",\n"; + } + + template <typename T, typename U> + static inline void _writePairNoComma(Slang::StringBuilder& builder, int indent, T const& name, U const& value) + { + _writeIndent(builder, indent); + builder << name << ": " << value << "\n"; + } + + class ScopeWritterForKey + { + public: + ScopeWritterForKey(Slang::StringBuilder* pBuilder, int* pIndent, Slang::String const& keyName, bool isOutterScope = true) + : m_pBuilder(pBuilder) + , m_pIndent(pIndent) + , m_isOutterScope(isOutterScope) + { + _writeString((*m_pBuilder), (*m_pIndent), keyName + ": {\n"); + (*m_pIndent)++; + } + + ~ScopeWritterForKey() + { + (*m_pIndent)--; + + if (m_isOutterScope) + _writeString((*m_pBuilder), (*m_pIndent), "}\n"); + else + _writeString((*m_pBuilder), (*m_pIndent), "},\n"); + + } + private: + Slang::StringBuilder* m_pBuilder; + int* m_pIndent; + bool m_isOutterScope; + }; + + void CommonInterfaceWriter::getSession(ObjectID objectId, ObjectID outSessionId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getSession"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "retSession", Slang::StringUtil::makeStringWithFormat("0x%X", outSessionId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getLayout"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePair(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + _writePairNoComma(builder, indent, "retProgramLayout", Slang::StringUtil::makeStringWithFormat("0x%X", retProgramLayoutId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getEntryPointCode"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "entryPointIndex", entryPointIndex); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePair(builder, indent, "outCode", Slang::StringUtil::makeStringWithFormat("0x%X", outCodeId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getTargetCode"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePair(builder, indent, "outCode", Slang::StringUtil::makeStringWithFormat("0x%X", outCodeId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getResultAsFileSystem"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "entryPointIndex", entryPointIndex); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePairNoComma(builder, indent, "outFileSystem", Slang::StringUtil::makeStringWithFormat("0x%X", outFileSystemId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getEntryPointHash"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "entryPointIndex", entryPointIndex); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePairNoComma(builder, indent, "outHash", Slang::StringUtil::makeStringWithFormat("0x%X", outHashId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::specialize"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + if (specializationArgCount) + { + ScopeWritterForKey scopeWritterForArgs(&builder, &indent, "specializationArgs", false); + for(int i = 0; i < specializationArgCount; i++) + { + bool isLastField = (i == specializationArgCount - 1); + ScopeWritterForKey scopeWritterForArg(&builder, &indent, Slang::StringUtil::makeStringWithFormat("[%d]\n", i), isLastField); + { + _writePair(builder, indent, "kind", SpecializationArgKindToString(specializationArgs[i].kind)); + _writePairNoComma(builder, indent, "type", Slang::StringUtil::makeStringWithFormat("0x%X", specializationArgs[i].type)); + } + } + } + else + { + _writePair(builder, indent, "specializationArgs", "nullptr"); + } + _writePair(builder, indent, "specializationArgCount", specializationArgCount); + _writePair(builder, indent, "outSpecializedComponentType", Slang::StringUtil::makeStringWithFormat("0x%X", outSpecializedComponentTypeId)); + _writePairNoComma(builder, indent, "outSpecializedComponentType", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::link"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "outLinkedComponentType", Slang::StringUtil::makeStringWithFormat("0x%X", outLinkedComponentTypeId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); } + void CommonInterfaceWriter::getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibraryId, + ObjectID outDiagnosticsId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::getEntryPointHostCallable"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "entryPointIndex", entryPointIndex); + _writePair(builder, indent, "targetIndex", targetIndex); + _writePair(builder, indent, "outSharedLibrary", Slang::StringUtil::makeStringWithFormat("0x%X", outSharedLibraryId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) + { + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::renameEntryPoint"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "newName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + newName != nullptr ? newName : "nullptr")); + _writePairNoComma(builder, indent, "outEntryPoint", Slang::StringUtil::makeStringWithFormat("0x%X", outEntryPointId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + void CommonInterfaceWriter::linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) + { + + Slang::StringBuilder builder; + int indent = 0; + + Slang::String functionName = m_className; + functionName = functionName + "::linkWithOptions"; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, functionName); + { + + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "compilerOptionEntryCount", compilerOptionEntryCount); + + JsonConsumer::_writeCompilerOptionEntryHelper(builder, indent, compilerOptionEntries, compilerOptionEntryCount); + + _writePair(builder, indent, "outLinkedComponentType", Slang::StringUtil::makeStringWithFormat("0x%X", outLinkedComponentTypeId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + } + + m_fileStream.write(builder.begin(), builder.getLength()); + m_fileStream.flush(); + } + + + JsonConsumer::JsonConsumer(const std::string& filePath) + { + std::filesystem::path jsonFileDir(filePath); + jsonFileDir = std::filesystem::absolute(jsonFileDir); + + if (!Slang::File::exists(jsonFileDir.parent_path().string().c_str())) + { + slangRecordLog(LogLevel::Error, "Directory for json file does not exist: %s\n", filePath.c_str()); + } + + Slang::String path(filePath.c_str()); + Slang::FileMode fileMode = Slang::FileMode::Create; + Slang::FileAccess fileAccess = Slang::FileAccess::Write; + Slang::FileShare fileShare = Slang::FileShare::None; + + SlangResult res = m_fileStream.init(path, fileMode, fileAccess, fileShare); + + if (res != SLANG_OK) + { + slangRecordLog(LogLevel::Error, "Failed to open file %s\n", filePath.c_str()); + } + + m_isFileValid = true; + } + + void JsonConsumer::_writeCompilerOptionEntryHelper(Slang::StringBuilder& builder, int indent, slang::CompilerOptionEntry* compilerOptionEntries, uint32_t compilerOptionEntryCount, bool isLastField) + { + if (compilerOptionEntryCount) + { + ScopeWritterForKey scopeWritterForCompilerOptionEntries(&builder, &indent, "compilerOptionEntries", isLastField); + + for (uint32_t j = 0; j < compilerOptionEntryCount; j++) + { + ScopeWritterForKey scopeWritterForCompileOptionElement(&builder, &indent, Slang::StringUtil::makeStringWithFormat("[%d]\n", j)); + { + _writePair(builder, indent, "name", CompilerOptionNameToString(compilerOptionEntries[j].name)); + + bool isLastEntry = (j == compilerOptionEntryCount - 1); + ScopeWritterForKey scopeWritterValue(&builder, &indent, "value", isLastEntry); + { + _writePair(builder, indent, "kind", CompilerOptionValueKindToString(compilerOptionEntries[j].value.kind)); + _writePair(builder, indent, "intValue0", compilerOptionEntries[j].value.intValue0); + _writePair(builder, indent, "intValue1", compilerOptionEntries[j].value.intValue1); + _writePair(builder, indent, "stringValue0", compilerOptionEntries[j].value.stringValue0); + _writePairNoComma(builder, indent, "stringValue1", compilerOptionEntries[j].value.stringValue1); + } + } + } + } + else + { + _writePairNoComma(builder, indent, "compilerOptionEntries", "nullptr"); + } + } + + void JsonConsumer::_writeSessionDescHelper(Slang::StringBuilder& builder, int indent, slang::SessionDesc const& desc, Slang::String keyName, bool isLastField) + { + ScopeWritterForKey scopeWritterForSessionDesc(&builder, &indent, keyName); + { + _writePair(builder, indent, "structureSize", (uint32_t)desc.structureSize); + + if (desc.targetCount) + { + ScopeWritterForKey scopeWritterForTarget(&builder, &indent, Slang::StringUtil::makeStringWithFormat("targets (0x%X)", desc.targets), isLastField); + { + for (int i = 0; i < desc.targetCount; i++) + { + bool isLastEntry = (i == desc.targetCount - 1); + ScopeWritterForKey scopeWritterForTargetElement(&builder, &indent, Slang::StringUtil::makeStringWithFormat("[%d]", i), isLastEntry); + { + _writePair(builder, indent, "structureSize", (uint32_t)desc.targets[i].structureSize); + _writePair(builder, indent, "format", SlangCompileTargetToString(desc.targets[i].format)); + _writePair(builder, indent, "profile", SlangProfileIDToString(desc.targets[i].profile)); + _writePair(builder, indent, "flags", SlangTargetFlagsToString(desc.targets[i].flags)); + _writePair(builder, indent, "floatingPointMode", SlangFloatingPointModeToString(desc.targets[i].floatingPointMode)); + _writePair(builder, indent, "lineDirectiveMode", SlangLineDirectiveModeToString(desc.targets[i].lineDirectiveMode)); + _writePair(builder, indent, "forceGLSLScalarBufferLayout", (desc.targets[i].floatingPointMode ? "true" : "false")); + + _writeCompilerOptionEntryHelper(builder, indent, desc.targets[i].compilerOptionEntries, desc.targets[i].compilerOptionEntryCount); + } + } + } + } + else + { + _writePair(builder, indent, "targets", "nullptr"); + } + + _writePair(builder, indent, "targetCount", desc.targetCount); + _writePair(builder, indent, "flags", SessionFlagsToString(desc.flags)); + _writePair(builder, indent, "defaultMatrixLayoutMode", SlangMatrixLayoutModeToString(desc.defaultMatrixLayoutMode)); + + if (desc.searchPathCount) + { + ScopeWritterForKey scopeWritterForSearchPath(&builder, &indent, "searchPaths", false); + for (int i = 0; i < desc.searchPathCount; i++) + { + Slang::String searchPath(desc.searchPaths[i]); + searchPath = searchPath + ",\n"; + _writeString(builder, indent, searchPath); + } + } + else + { + _writePair(builder, indent, "searchPaths", "nullptr"); + } + _writePair(builder, indent, "searchPathCount", desc.searchPathCount); + + if (desc.preprocessorMacroCount) + { + ScopeWritterForKey scopeWritterForMacro(&builder, &indent, "preprocessorMacros", false); + for (int i = 0; i < desc.preprocessorMacroCount; i++) + { + bool isLastField = (i == desc.preprocessorMacroCount - 1); + ScopeWritterForKey scopeWritterForMacroElement(&builder, &indent, Slang::StringUtil::makeStringWithFormat("[%d]", i), isLastField); + + _writePair(builder, indent, "name", Slang::StringUtil::makeStringWithFormat("\"%s\"", + desc.preprocessorMacros[i].name != nullptr ? desc.preprocessorMacros[i].name : "nullptr")); + + _writePair(builder, indent, "value", Slang::StringUtil::makeStringWithFormat("\"%s\"", + desc.preprocessorMacros[i].value != nullptr ? desc.preprocessorMacros[i].value : "nullptr")); + } + } + else + { + _writePair(builder, indent, "preprocessorMacros", "nullptr"); + } + _writePair(builder, indent, "preprocessorMacroCount", desc.preprocessorMacroCount); + + AddressFormat address = reinterpret_cast<AddressFormat>(desc.fileSystem); + _writePair(builder, indent, "fileSystem", Slang::StringUtil::makeStringWithFormat("0x%X", address)); + _writePair(builder, indent, "enableEffectAnnotations", (desc.enableEffectAnnotations ? "true" : "false")); + _writePair(builder, indent, "allowGLSLSyntax", (desc.allowGLSLSyntax ? "true" : "false")); + _writePair(builder, indent, "compilerOptionEntryCount", desc.compilerOptionEntryCount); + _writeCompilerOptionEntryHelper(builder, indent, desc.compilerOptionEntries, desc.compilerOptionEntryCount); + } + + } + + void JsonConsumer::CreateGlobalSession(ObjectID outGlobalSessionId) + { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "GlobalFunction::createGlobalSession: {\n"); + { + indent++; + _writePairNoComma(builder, indent, "outGlobalSession", Slang::StringUtil::makeStringWithFormat("0x%X", outGlobalSessionId)); + indent--; + } + _writeString(builder, indent, "}\n"); + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } + + void JsonConsumer::IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) + { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "IGlobalSession::createSession: {\n"); + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::createSession"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + + _writeSessionDescHelper(builder, indent, desc, "inDesc"); + + _writePairNoComma(builder, indent, "outSession", Slang::StringUtil::makeStringWithFormat("0x%X", outSessionId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } void JsonConsumer::IGlobalSession_findProfile(ObjectID objectId, char const* name) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::findProfile"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "name", Slang::StringUtil::makeStringWithFormat("\"%s\"", + name != nullptr ? name : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setDownstreamCompilerPath"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "passThrough", SlangPassThroughToString(passThrough)); + _writePairNoComma(builder, indent, "path", Slang::StringUtil::makeStringWithFormat("\"%s\"", + path != nullptr ? path : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setDownstreamCompilerPrelude"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "passThrough", SlangPassThroughToString(inPassThrough)); + _writePairNoComma(builder, indent, "preludeText", Slang::StringUtil::makeStringWithFormat("\"%s\"", + prelude != nullptr ? prelude : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getDownstreamCompilerPrelude"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "passThrough", SlangPassThroughToString(inPassThrough)); + _writePairNoComma(builder, indent, "outPrelude", Slang::StringUtil::makeStringWithFormat("0x%X", outPreludeId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setDefaultDownstreamCompiler"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "sourceLanguage", SlangSourceLanguageToString(sourceLanguage)); + _writePairNoComma(builder, indent, "defaultCompiler", SlangPassThroughToString(defaultCompiler)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getDefaultDownstreamCompiler"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "sourceLanguage", SlangSourceLanguageToString(sourceLanguage)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "IGlobalSession::setLanguagePrelude: {\n"); + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setLanguagePrelude"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "sourceLanguage", SlangSourceLanguageToString(inSourceLanguage)); + _writePairNoComma(builder, indent, "preludeText", (prelude != nullptr ? prelude : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getLanguagePrelude"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "sourceLanguage", SlangSourceLanguageToString(inSourceLanguage)); + _writePairNoComma(builder, indent, "outPrelude", Slang::StringUtil::makeStringWithFormat("0x%X", outPreludeId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "IGlobalSession::createCompileRequest: {\n"); + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::createCompileRequest"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "outCompileRequest", Slang::StringUtil::makeStringWithFormat("0x%X", outCompileRequest)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "IGlobalSession::addBuiltins: {\n"); + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::addBuiltins"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "sourcePath", Slang::StringUtil::makeStringWithFormat("\"%s\"", + sourcePath != nullptr ? sourcePath : "nullptr")); + _writePairNoComma(builder, indent, "sourceString", Slang::StringUtil::makeStringWithFormat("\"%s\"", + sourceString != nullptr ? sourceString : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setSharedLibraryLoader"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "loader", Slang::StringUtil::makeStringWithFormat("0x%X", loaderId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getSharedLibraryLoader"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "retLoader", Slang::StringUtil::makeStringWithFormat("0x%X", outLoaderId)); + } + } + + _writeString(builder, indent, "}\n"); + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::checkCompileTargetSupport"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "target", SlangCompileTargetToString(target)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::checkPassThroughSupport"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "passThrough", SlangPassThroughToString(passThrough)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::compileStdLib"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "flags", CompileStdLibFlagsToString(flags)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes) { - } + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + _writeString(builder, indent, "IGlobalSession::loadStdLib: {\n"); + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::loadStdLib"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "stdLib-Ignore-Data", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "stdLibSizeInBytes", (uint32_t)stdLibSizeInBytes); + } + } + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } void JsonConsumer::IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::saveStdLib"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "archiveType", SlangArchiveTypeToString(archiveType)); + _writePairNoComma(builder, indent, "outBlobId", Slang::StringUtil::makeStringWithFormat("0x%X", outBlobId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_findCapability(ObjectID objectId, char const* name) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::findCapability"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "name", Slang::StringUtil::makeStringWithFormat("\"%s\"", + name != nullptr ? name : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setDownstreamCompilerForTransition"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "source", SlangCompileTargetToString(source)); + _writePair(builder, indent, "target", SlangCompileTargetToString(target)); + _writePairNoComma(builder, indent, "compiler", SlangPassThroughToString(compiler)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getDownstreamCompilerForTransition"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "source", SlangCompileTargetToString(source)); + _writePairNoComma(builder, indent, "target", SlangCompileTargetToString(target)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::setSPIRVCoreGrammar"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "jsonPath", Slang::StringUtil::makeStringWithFormat("\"%s\"", + jsonPath != nullptr ? jsonPath : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::parseCommandLineArguments"); + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "argc", argc); + + if (argv) + { + _writeString(builder, indent, "argv: {\n"); + ScopeWritterForKey scopeWritteriForArgv(&builder, &indent, "argv"); + for (int i = 0; i < argc; i++) + { + if (i == (argc -1)) + _writePairNoComma(builder, indent, Slang::StringUtil::makeStringWithFormat("[%d]", i), argv[i]); + else + _writePair(builder, indent, Slang::StringUtil::makeStringWithFormat("[%d]", i), argv[i]); + } + } + else + { + _writePair(builder, indent, "argv", "nullptr"); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId) { - } + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IGlobalSession::getSessionDescDigest"); + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + if (sessionDesc) + { + _writeSessionDescHelper(builder, indent, *sessionDesc, Slang::StringUtil::makeStringWithFormat("sessionDesc (0x%X)\n", sessionDesc)); + } + else + { + _writePair(builder, indent, "sessionDesc", "nullptr"); + } + _writePair(builder, indent, "outBlob", Slang::StringUtil::makeStringWithFormat("0x%X", outBlobId)); + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } // ISession void JsonConsumer::ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::getGlobalSession"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "retGlobalSession", Slang::StringUtil::makeStringWithFormat("0x%X", outGlobalSessionId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::loadModule"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "moduleName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + moduleName != nullptr ? moduleName : "nullptr")); + _writePair(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "retIModule", Slang::StringUtil::makeStringWithFormat("0x%X", outModuleId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_loadModuleFromIRBlob(ObjectID objectId, const char* moduleName, const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::loadModuleFromIRBlob"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "moduleName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + moduleName != nullptr ? moduleName : "nullptr")); + _writePair(builder, indent, "path", Slang::StringUtil::makeStringWithFormat("\"%s\"", + path != nullptr ? path : "nullptr")); + if (source) + { + void const* bufPtr = source->getBufferPointer(); + size_t bufSize = source->getBufferSize(); + + ScopeWritterForKey scopeWritterForSource(&builder, &indent, Slang::StringUtil::makeStringWithFormat("source (0x%X): {\n", source), false); + { + _writePair(builder, indent, "bufferPointer", Slang::StringUtil::makeStringWithFormat("0x%X", bufPtr)); + _writePairNoComma(builder, indent, "bufferSize", (uint32_t)bufSize); + } + } + else + { + _writePair(builder, indent, "source", "nullptr"); + } + + _writePair(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + _writePairNoComma(builder, indent, "retIModule", Slang::StringUtil::makeStringWithFormat("0x%X", outModuleId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_loadModuleFromSource(ObjectID objectId, const char* moduleName, const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::loadModuleFromSource"); + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "moduleName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + moduleName != nullptr ? moduleName : "nullptr")); + _writePair(builder, indent, "path", Slang::StringUtil::makeStringWithFormat("\"%s\"", + path != nullptr ? path : "nullptr")); + if (source) + { + void const* bufPtr = source->getBufferPointer(); + size_t bufSize = source->getBufferSize(); + ScopeWritterForKey scopeWritterForSource(&builder, &indent, Slang::StringUtil::makeStringWithFormat("source (0x%X): {\n", source), false); + { + _writePair(builder, indent, "bufferPointer", Slang::StringUtil::makeStringWithFormat("0x%X", bufPtr)); + _writePairNoComma(builder, indent, "bufferSize", (uint32_t)bufSize); + } + } + else + { + _writePair(builder, indent, "source", "nullptr"); + } + + _writePair(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + _writePairNoComma(builder, indent, "retIModule", Slang::StringUtil::makeStringWithFormat("0x%X", outModuleId)); + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_loadModuleFromSourceString(ObjectID objectId, const char* moduleName, const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::loadModuleFromSourceString"); + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "moduleName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + moduleName != nullptr ? moduleName : "nullptr")); + + _writePair(builder, indent, "path", Slang::StringUtil::makeStringWithFormat("\"%s\"", + path != nullptr ? path : "nullptr")); + + _writePair(builder, indent, "string", Slang::StringUtil::makeStringWithFormat("\"%s\"", + string != nullptr ? string : "nullptr")); + + _writePair(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + _writePairNoComma(builder, indent, "retIModule", Slang::StringUtil::makeStringWithFormat("0x%X", outModuleId)); + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_createCompositeComponentType(ObjectID objectId, ObjectID* componentTypeIds, SlangInt componentTypeCount, ObjectID outCompositeComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::createCompositeComponentType"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + if (componentTypeCount) + { + ScopeWritterForKey scopeWritterForComponentTypes(&builder, &indent, "componentTypes", false); + for (int i = 0; i < componentTypeCount; i++) + { + if (i != componentTypeCount - 1) + { + _writeString(builder, indent, Slang::StringUtil::makeStringWithFormat("[%d]: 0x%X,\n", i, componentTypeIds[i])); + } + else + { + _writeString(builder, indent, Slang::StringUtil::makeStringWithFormat("[%d]: 0x%X\n", i, componentTypeIds[i])); + } + } + } + else + { + _writePair(builder, indent, "componentTypes", "nullptr"); + } + } + _writePair(builder, indent, "componentTypeCount", componentTypeCount); + _writePair(builder, indent, "outCompositeComponentType", Slang::StringUtil::makeStringWithFormat("0x%X", outCompositeComponentTypeId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnosticsId)); + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_specializeType(ObjectID objectId, ObjectID typeId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::specializeType"); + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "type", Slang::StringUtil::makeStringWithFormat("0x%X", typeId)); + + if (specializationArgCount) + { + ScopeWritterForKey scopeWritterForArgs(&builder, &indent, "specializationArgs", false); + for(int i = 0; i < specializationArgCount; i++) + { + ScopeWritterForKey scopeWritterForArg(&builder, &indent, Slang::StringUtil::makeStringWithFormat("[%d]\n", i), false); + { + _writePair(builder, indent, "kind", SpecializationArgKindToString(specializationArgs[i].kind)); + _writePairNoComma(builder, indent, "type", Slang::StringUtil::makeStringWithFormat("0x%X", specializationArgs[i].type)); + } + } + } + else + { + _writePair(builder, indent, "specializationArgs", "nullptr"); + } + + _writePair(builder, indent, "specializationArgCount", specializationArgCount); + _writePair(builder, indent, "outDiagnostics", outDiagnosticsId); + _writePairNoComma(builder, indent, "retTypeReflectionId", outTypeReflectionId); + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_getTypeLayout(ObjectID objectId, ObjectID typeId, SlangInt targetIndex, - slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection) + slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflectionId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::getTypeLayout"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "type", Slang::StringUtil::makeStringWithFormat("0x%X", typeId)); + _writePair(builder, indent, "rules", LayoutRulesToString(rules)); + _writePair(builder, indent, "outDiagnostics", outDiagnosticsId); + _writePair(builder, indent, "retTypeReflectionId", outTypeLayoutReflectionId); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_getContainerType(ObjectID objectId, ObjectID elementType, @@ -204,155 +1278,301 @@ namespace SlangRecord void JsonConsumer::ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::createCompileRequest"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "outCompileRequest", outCompileRequestId); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId) { - } + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + { + ScopeWritterForKey scopeWritter(&builder, &indent, "ISession::getLoadedModule"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "index", index); + _writePairNoComma(builder, indent, "retModule", Slang::StringUtil::makeStringWithFormat("0x%X", outModuleId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } // IModule void JsonConsumer::IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IModule::findEntryPointByName"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "name", Slang::StringUtil::makeStringWithFormat("\"%s\"", + name != nullptr ? name : "nullptr")); + + _writePairNoComma(builder, indent, "outEntryPoint", Slang::StringUtil::makeStringWithFormat("0x%X", outEntryPointId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IModule::getDefinedEntryPoint"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "index", index); + _writePairNoComma(builder, indent, "outEntryPoint", Slang::StringUtil::makeStringWithFormat("0x%X", outEntryPointId)); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IModule::serialize"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "outSerializedBlob", outSerializedBlobId); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IModule_writeToFile(ObjectID objectId, char const* fileName) { + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IModule::writeToFile"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePairNoComma(builder, indent, "fileName", Slang::StringUtil::makeStringWithFormat("\"%s\"", + fileName != nullptr ? fileName : "nullptr")); + } + } + + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); } void JsonConsumer::IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics) { - } + SANITY_CHECK(); + Slang::StringBuilder builder; + int indent = 0; + { + ScopeWritterForKey scopeWritter(&builder, &indent, "IModule::findAndCheckEntryPoint"); + { + _writePair(builder, indent, "this", Slang::StringUtil::makeStringWithFormat("0x%X", objectId)); + _writePair(builder, indent, "name", Slang::StringUtil::makeStringWithFormat("\"%s\"", + name != nullptr ? name : "nullptr")); + _writePair(builder, indent, "stage", SlangStageToString(stage)); + _writePair(builder, indent, "outEntryPoint", Slang::StringUtil::makeStringWithFormat("0x%X", outEntryPointId)); + _writePairNoComma(builder, indent, "outDiagnostics", Slang::StringUtil::makeStringWithFormat("0x%X", outDiagnostics)); + } + } + m_fileStream.write(builder.produceString().begin(), builder.produceString().getLength()); + m_fileStream.flush(); + } void JsonConsumer::IModule_getSession(ObjectID objectId, ObjectID outSessionId) { + SANITY_CHECK(); + m_moduleHelper.getSession(objectId, outSessionId); } - void JsonConsumer::IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SANITY_CHECK(); + m_moduleHelper.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); } - void JsonConsumer::IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCodeId, outDiagnosticsId); } - void JsonConsumer::IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.getTargetCode(objectId, targetIndex, outCodeId, outDiagnosticsId); } - void JsonConsumer::IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) + void JsonConsumer::IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId) { + SANITY_CHECK(); + m_moduleHelper.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystemId); } void JsonConsumer::IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SANITY_CHECK(); + m_moduleHelper.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); } void JsonConsumer::IModule_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.specialize(objectId, specializationArgs, specializationArgCount, outSpecializedComponentTypeId, outDiagnosticsId); } void JsonConsumer::IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); } - void JsonConsumer::IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) + void JsonConsumer::IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibraryId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibraryId, outDiagnosticsId); } void JsonConsumer::IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SANITY_CHECK(); + m_moduleHelper.renameEntryPoint(objectId, newName, outEntryPointId); } void JsonConsumer::IModule_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_moduleHelper.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); } - - // IEntryPoint void JsonConsumer::IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId) { + SANITY_CHECK(); + m_entryPointHelper.getSession(objectId, outSessionId); } void JsonConsumer::IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SANITY_CHECK(); + m_entryPointHelper.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); } - void JsonConsumer::IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_entryPointHelper.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCodeId, outDiagnosticsId); } - void JsonConsumer::IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_entryPointHelper.getTargetCode(objectId, targetIndex, outCodeId, outDiagnosticsId); } void JsonConsumer::IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SANITY_CHECK(); + m_entryPointHelper.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); } void JsonConsumer::IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SANITY_CHECK(); + m_entryPointHelper.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); } void JsonConsumer::IEntryPoint_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_entryPointHelper.specialize(objectId, specializationArgs, specializationArgCount, outSpecializedComponentTypeId, outDiagnosticsId); } void JsonConsumer::IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_entryPointHelper.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); } void JsonConsumer::IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SANITY_CHECK(); + m_entryPointHelper.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); } void JsonConsumer::IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SANITY_CHECK(); + m_entryPointHelper.renameEntryPoint(objectId, newName, outEntryPointId); } void JsonConsumer::IEntryPoint_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_entryPointHelper.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); } @@ -360,58 +1580,80 @@ namespace SlangRecord // ICompositeComponentType void JsonConsumer::ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getSession(objectId, outSessionId); } void JsonConsumer::ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); } - void JsonConsumer::ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCodeId, outDiagnosticsId); } - void JsonConsumer::ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getTargetCode(objectId, targetIndex, outCodeId, outDiagnosticsId); } void JsonConsumer::ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); } void JsonConsumer::ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); } void JsonConsumer::ICompositeComponentType_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.specialize(objectId, specializationArgs, specializationArgCount, outSpecializedComponentTypeId, outDiagnosticsId); } void JsonConsumer::ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); } void JsonConsumer::ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); } void JsonConsumer::ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.renameEntryPoint(objectId, newName, outEntryPointId); } void JsonConsumer::ICompositeComponentType_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_compositeComponentTypeHelper.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); } @@ -419,59 +1661,79 @@ namespace SlangRecord // ITypeConformance void JsonConsumer::ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId) { + SANITY_CHECK(); + m_typeConformanceHelper.getSession(objectId, outSessionId); } void JsonConsumer::ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SANITY_CHECK(); + m_typeConformanceHelper.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); } - void JsonConsumer::ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_typeConformanceHelper.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCodeId, outDiagnosticsId); } - void JsonConsumer::ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void JsonConsumer::ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_typeConformanceHelper.getTargetCode(objectId, targetIndex, outCodeId, outDiagnosticsId); } void JsonConsumer::ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SANITY_CHECK(); + m_typeConformanceHelper.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); } void JsonConsumer::ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SANITY_CHECK(); + m_typeConformanceHelper.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); } void JsonConsumer::ITypeConformance_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_typeConformanceHelper.specialize(objectId, specializationArgs, specializationArgCount, outSpecializedComponentTypeId, outDiagnosticsId); } void JsonConsumer::ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_typeConformanceHelper.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); } void JsonConsumer::ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SANITY_CHECK(); + m_typeConformanceHelper.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); } void JsonConsumer::ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SANITY_CHECK(); + m_typeConformanceHelper.renameEntryPoint(objectId, newName, outEntryPointId); } void JsonConsumer::ITypeConformance_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SANITY_CHECK(); + m_typeConformanceHelper.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); } - - }; // namespace SlangRecord diff --git a/source/slang-record-replay/replay/json-consumer.h b/source/slang-record-replay/replay/json-consumer.h index e638a833b..09b51980e 100644 --- a/source/slang-record-replay/replay/json-consumer.h +++ b/source/slang-record-replay/replay/json-consumer.h @@ -2,173 +2,235 @@ #define JSON_CONSUMER_H #include "decoder-consumer.h" +#include "../../core/slang-stream.h" +#include "../util/record-utility.h" +#include "../util/record-format.h" namespace SlangRecord { + class CommonInterfaceWriter + { + public: + CommonInterfaceWriter(ApiClassId classId, Slang::FileStream& fileStream) + : m_fileStream(fileStream) + { + switch(classId) + { + case ApiClassId::Class_IModule: + m_className = "IModule"; + break; + case ApiClassId::Class_IEntryPoint: + m_className = "IEntryPoint"; + break; + case ApiClassId::Class_ICompositeComponentType: + m_className = "ICompositeComponentType"; + break; + case ApiClassId::Class_ITypeConformance: + m_className = "ITypeConformance"; + break; + default: + slangRecordLog(LogLevel::Error, "Invalid classNo %u\n", classId); + break; + } + } + CommonInterfaceWriter() = delete; + void getSession(ObjectID objectId, ObjectID outSessionId); + void getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); + void getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + void getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + void getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId); + void getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); + void specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId); + void link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + void getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibraryId, + ObjectID outDiagnosticsId); + void renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); + void linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); + protected: + Slang::String m_className; + Slang::FileStream& m_fileStream; + }; + class JsonConsumer : public IDecoderConsumer { public: - virtual void CreateGlobalSession(ObjectID objectId, const uint8_t* parameterBuffer, int64_t bufferSize) = 0; - virtual void IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) = 0; - virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name) = 0; - virtual void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) = 0; - virtual void IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude) = 0; - virtual void IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId) = 0; + JsonConsumer(const std::string& filePath); + + virtual void CreateGlobalSession(ObjectID outGlobalSessionId); + virtual void IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId); + virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name); + virtual void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path); + virtual void IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude); + virtual void IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId); virtual void IGlobalSession_getBuildTagString(ObjectID objectId) { (void) objectId; } - virtual void IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) = 0; - virtual void IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage) = 0; - virtual void IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude) = 0; - virtual void IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId) = 0; - virtual void IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest) = 0; - virtual void IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString) = 0; - virtual void IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId) = 0; - virtual void IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId) = 0; - virtual void IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target) = 0; - virtual void IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough) = 0; - virtual void IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags) = 0; - virtual void IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes) = 0; - virtual void IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId) = 0; - virtual void IGlobalSession_findCapability(ObjectID objectId, char const* name) = 0; - virtual void IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) = 0; - virtual void IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target) = 0; + virtual void IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler); + virtual void IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage); + virtual void IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude); + virtual void IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId); + virtual void IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest); + virtual void IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString); + virtual void IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId); + virtual void IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId); + virtual void IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target); + virtual void IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough); + virtual void IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags); + virtual void IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes); + virtual void IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId); + virtual void IGlobalSession_findCapability(ObjectID objectId, char const* name); + virtual void IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler); + virtual void IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target); virtual void IGlobalSession_getCompilerElapsedTime(ObjectID objectId) { (void) objectId; } - virtual void IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath) = 0; - virtual void IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId) = 0; - virtual void IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId) = 0; + virtual void IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath); + virtual void IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId); + virtual void IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId); // ISession - virtual void ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) = 0; - virtual void ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId) = 0; + virtual void ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId); + virtual void ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId); virtual void ISession_loadModuleFromIRBlob(ObjectID objectId, const char* moduleName, - const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId); virtual void ISession_loadModuleFromSource(ObjectID objectId, const char* moduleName, - const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId); virtual void ISession_loadModuleFromSourceString(ObjectID objectId, const char* moduleName, - const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId); virtual void ISession_createCompositeComponentType(ObjectID objectId, ObjectID* componentTypeIds, - SlangInt componentTypeCount, ObjectID outCompositeComponentTypeIds, ObjectID outDiagnosticsId) = 0; + SlangInt componentTypeCount, ObjectID outCompositeComponentTypeIds, ObjectID outDiagnosticsId); virtual void ISession_specializeType(ObjectID objectId, ObjectID typeId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) = 0; + SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId); virtual void ISession_getTypeLayout(ObjectID objectId, ObjectID typeId, SlangInt targetIndex, - slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection) = 0; + slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection); virtual void ISession_getContainerType(ObjectID objectId, ObjectID elementType, - slang::ContainerType containerType, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) = 0; + slang::ContainerType containerType, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId); - virtual void ISession_getDynamicType(ObjectID objectId, ObjectID outTypeReflectionId) = 0; + virtual void ISession_getDynamicType(ObjectID objectId, ObjectID outTypeReflectionId); - virtual void ISession_getTypeRTTIMangledName(ObjectID objectId, ObjectID typeId, ObjectID outNameBlobId) = 0; + virtual void ISession_getTypeRTTIMangledName(ObjectID objectId, ObjectID typeId, ObjectID outNameBlobId); virtual void ISession_getTypeConformanceWitnessMangledName(ObjectID objectId, ObjectID typeId, - ObjectID interfaceTypeId, ObjectID outNameBlobId) = 0; + ObjectID interfaceTypeId, ObjectID outNameBlobId); virtual void ISession_getTypeConformanceWitnessSequentialID(ObjectID objectId, ObjectID typeId, - ObjectID interfaceTypeId, uint32_t outId) = 0; + ObjectID interfaceTypeId, uint32_t outId); virtual void ISession_createTypeConformanceComponentType(ObjectID objectId, ObjectID typeId, ObjectID interfaceTypeId, ObjectID outConformanceId, - SlangInt conformanceIdOverride, ObjectID outDiagnosticsId) = 0; + SlangInt conformanceIdOverride, ObjectID outDiagnosticsId); - virtual void ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId) = 0; + virtual void ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId); virtual void ISession_getLoadedModuleCount(ObjectID objectId) { (void) objectId; } - virtual void ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId) = 0; + virtual void ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId); virtual void ISession_isBinaryModuleUpToDate(ObjectID objectId) { (void) objectId; } // IModule - virtual void IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId) = 0; + virtual void IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId); virtual void IModule_getDefinedEntryPointCount(ObjectID objectId) { (void) objectId; } - virtual void IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId) = 0; - virtual void IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) = 0; - virtual void IModule_writeToFile(ObjectID objectId, char const* fileName) = 0; + virtual void IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId); + virtual void IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId); + virtual void IModule_writeToFile(ObjectID objectId, char const* fileName); virtual void IModule_getName(ObjectID objectId) { (void) objectId; } virtual void IModule_getFilePath(ObjectID objectId) { (void) objectId; } virtual void IModule_getUniqueIdentity(ObjectID objectId) { (void) objectId; } - virtual void IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics) = 0; + virtual void IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics); - virtual void IModule_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void IModule_getSession(ObjectID objectId, ObjectID outSessionId); + virtual void IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); virtual void IModule_getSpecializationParamCount(ObjectID objectId) { (void) objectId; } - virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem); + virtual void IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); virtual void IModule_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId); + virtual void IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + virtual void IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics); + virtual void IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); virtual void IModule_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); // IEntryPoint - virtual void IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId); + virtual void IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); virtual void IEntryPoint_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem); + virtual void IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); virtual void IEntryPoint_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId); + virtual void IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + virtual void IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics); + virtual void IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); virtual void IEntryPoint_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); // ICompositeComponentType - virtual void ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId); + virtual void ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); virtual void ICompositeComponentType_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnostics); + virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnostics); + virtual void ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem); + virtual void ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); virtual void ICompositeComponentType_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId); + virtual void ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + virtual void ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics); + virtual void ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); virtual void ICompositeComponentType_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); // ITypeConformance - virtual void ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId); + virtual void ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); virtual void ITypeConformance_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; - virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + virtual void ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem); + virtual void ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); virtual void ITypeConformance_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId); + virtual void ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + virtual void ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics); + virtual void ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); virtual void ITypeConformance_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); + + static void _writeCompilerOptionEntryHelper(Slang::StringBuilder& builder, int indent, slang::CompilerOptionEntry* compilerOptionEntries, uint32_t compilerOptionEntryCount, bool isLast = false); + static void _writeSessionDescHelper(Slang::StringBuilder& builder, int indent, slang::SessionDesc const& sessionDesc, Slang::String keyName, bool isLast = false); + + private: + Slang::FileStream m_fileStream; + bool m_isFileValid = false; + CommonInterfaceWriter m_moduleHelper {ApiClassId::Class_IModule, m_fileStream}; + CommonInterfaceWriter m_entryPointHelper {ApiClassId::Class_IEntryPoint, m_fileStream}; + CommonInterfaceWriter m_compositeComponentTypeHelper {ApiClassId::Class_ICompositeComponentType, m_fileStream}; + CommonInterfaceWriter m_typeConformanceHelper {ApiClassId::Class_ITypeConformance, m_fileStream}; + }; } #endif // JSON_CONSUMER_H diff --git a/source/slang-record-replay/replay/recordFile-processor.cpp b/source/slang-record-replay/replay/recordFile-processor.cpp index bf9cec435..bf3ea874b 100644 --- a/source/slang-record-replay/replay/recordFile-processor.cpp +++ b/source/slang-record-replay/replay/recordFile-processor.cpp @@ -1,24 +1,26 @@ #include "recordFile-processor.h" -#include "../util/record-utility.h" +#include "../util/record-format.h" #include "parameter-decoder.h" namespace SlangRecord { - RecordFileProcessor::RecordFileProcessor(const std::string& filename) + RecordFileProcessor::RecordFileProcessor(const Slang::String& filePath) { - Slang::String path(filename.c_str()); Slang::FileMode fileMode = Slang::FileMode::Open; Slang::FileAccess fileAccess = Slang::FileAccess::Read; Slang::FileShare fileShare = Slang::FileShare::None; // Open the record file with read-only access - SlangResult res = m_inputStream.init(path, fileMode, fileAccess, fileShare); + SlangResult res = m_inputStream.init(filePath, fileMode, fileAccess, fileShare); if (res != SLANG_OK) { - SlangRecord::slangRecordLog(SlangRecord::LogLevel::Error, "Failed to open file %s\n", filename.c_str()); + SlangRecord::slangRecordLog(SlangRecord::LogLevel::Error, "Failed to open file %s\n", filePath.begin()); std::abort(); } + + // Enable log system + setLogLevel(); } bool RecordFileProcessor::processNextBlock() @@ -48,7 +50,7 @@ namespace SlangRecord } FunctionTailer tailer {}; - if (!processTailer(tailer)) + if (processTailer(tailer) == ERROR_BLOCK) { return false; } @@ -71,16 +73,17 @@ namespace SlangRecord paramBlock.outputBuffer = m_outputBuffer.getBuffer(); paramBlock.outputBufferSize = tailer.dataSizeInBytes; - if (classId == GlobalFunction) + if (classId == ApiClassId::GlobalFunction) { - ret = m_decoder.processFunctionCall(header, paramBlock); + ret = m_decoder->processFunctionCall(header, paramBlock); } else { - ret = m_decoder.processMethodCall(header, paramBlock); + ret = m_decoder->processMethodCall(header, paramBlock); } m_parameterBuffer.clear(); + m_outputBuffer.clear(); return ret; } @@ -102,22 +105,33 @@ namespace SlangRecord return true; } - bool RecordFileProcessor::processTailer(FunctionTailer& tailer) + RecordFileResultCode RecordFileProcessor::processTailer(FunctionTailer& tailer) { size_t readBytes = 0; SlangResult res = m_inputStream.read(&tailer, sizeof(FunctionTailer), readBytes); if (res != SLANG_OK || readBytes != sizeof(FunctionTailer)) { - return false; + return ERROR_BLOCK; + } + + // If we don't read a valid tailer, but the magic is bit is a header, it indicates that + // there is no tailer for this block, but it's still a valid block. + if (tailer.magic == MAGIC_HEADER) + { + // revert back to last read position, and clear tailer + int64_t offset = -(int64_t)sizeof(FunctionTailer); + m_inputStream.seek(Slang::SeekOrigin::Current, offset); + memset(&tailer, 0, sizeof(FunctionTailer)); + return NOT_EXSIT; } if (tailer.magic != MAGIC_TAILER) { - return false; + return ERROR_BLOCK; } - return true; + return RESULT_OK; } bool RecordFileProcessor::processMethod(FunctionHeader const& header, const uint8_t* parameterBuffer, int64_t bufferSize) diff --git a/source/slang-record-replay/replay/recordFile-processor.h b/source/slang-record-replay/replay/recordFile-processor.h index b9570a259..6530d956c 100644 --- a/source/slang-record-replay/replay/recordFile-processor.h +++ b/source/slang-record-replay/replay/recordFile-processor.h @@ -1,20 +1,41 @@ #ifndef FILE_PROCESSOR_H #define FILE_PROCESSOR_H +#include <cstdlib> #include <string> #include "../../core/slang-stream.h" -#include "../util/record-format.h" +#include "../util/record-utility.h" #include "slang-decoder.h" namespace SlangRecord { + + enum RecordFileResultCode + { + RESULT_OK = 0x00, + NOT_EXSIT = 0x01, + ERROR_BLOCK = 0x02 + }; + class RecordFileProcessor { public: - RecordFileProcessor(const std::string& filePath); + RecordFileProcessor(const Slang::String& filePath); + + bool addDecoder(SlangDecoder* pDecoder) + { + if (pDecoder == nullptr) + { + slangRecordLog(LogLevel::Error, "Decoder is nullptr\n"); + return false; + } + m_decoder = pDecoder; + return true; + } + bool processNextBlock(); bool processHeader(FunctionHeader& header); - bool processTailer(FunctionTailer& tailer); + RecordFileResultCode processTailer(FunctionTailer& tailer); bool processMethod(FunctionHeader const& header, const uint8_t* buffer, int64_t bufferSize); bool processFunction(FunctionHeader const& header, const uint8_t* buffer, int64_t bufferSize); private: @@ -22,7 +43,7 @@ namespace SlangRecord Slang::List<uint8_t> m_parameterBuffer; Slang::List<uint8_t> m_outputBuffer; - SlangDecoder m_decoder; + SlangDecoder* m_decoder = nullptr; }; } // namespace SlangRecord; diff --git a/source/slang-record-replay/replay/replay-consumer.cpp b/source/slang-record-replay/replay/replay-consumer.cpp index 51aa2d1b1..cb1117bc0 100644 --- a/source/slang-record-replay/replay/replay-consumer.cpp +++ b/source/slang-record-replay/replay/replay-consumer.cpp @@ -1,128 +1,571 @@ #include "replay-consumer.h" +#include "../../core/slang-string-util.h" namespace SlangRecord { - void ReplayConsumer::CreateGlobalSession(ObjectID objectId, const uint8_t* parameterBuffer, int64_t bufferSize) + +#define OutputObjectSanityCheck(objId) \ + do { \ + if(m_objectMap.tryGetValue((objId))) { \ + slangRecordLog(LogLevel::Error, "Output object 0x%X already exists! %s:%d\n", objId, __PRETTY_FUNCTION__, __LINE__); \ + std::abort(); \ + } \ + } while(0) + +#define InputObjectSanityCheck(objId) \ + do { \ + if(!m_objectMap.tryGetValue((objId))) { \ + slangRecordLog(LogLevel::Error, "Input object 0x%X has not been allocated yet! %s:%d\n", objId, __PRETTY_FUNCTION__, __LINE__); \ + std::abort(); \ + } \ + } while(0) + +#define FAIL_WITH_LOG(funcName) \ + do { \ + if (SLANG_FAILED(res)) { \ + slangRecordLog(LogLevel::Error, #funcName" fails, ret: 0x%X, this: 0x%X\n", res, objectId); \ + } \ + } while (0) + + SlangResult CommonInterfaceReplayer::getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IBlob* outDiagnostics {}; + slang::ProgramLayout* outProgramLayout {}; + + SlangResult res = SLANG_OK; + outProgramLayout = pObj->getLayout(targetIndex, &outDiagnostics); + + if (outProgramLayout) + { + m_objectMap.addIfNotExists(retProgramLayoutId, outProgramLayout); + } + else + { + res = SLANG_FAIL; + } + return res; + } + + SlangResult CommonInterfaceReplayer::getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IBlob* outCode {}; + slang::IBlob* outDiagnostics {}; + + SlangResult res = pObj->getEntryPointCode(entryPointIndex, targetIndex, &outCode, &outDiagnostics); + + if (outCode && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outCodeId, outCode); + } + + ReplayConsumer::printDiagnosticMessage(outDiagnostics); + return res; + } + + SlangResult CommonInterfaceReplayer::getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IBlob* outCode {}; + slang::IBlob* outDiagnostics {}; + + SlangResult res = pObj->getTargetCode(targetIndex, &outCode, &outDiagnostics); + + if (outCode && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outCodeId, outCode); + } + + ReplayConsumer::printDiagnosticMessage(outDiagnostics); + return res; + } + + SlangResult CommonInterfaceReplayer::getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId) + { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outFileSystemId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + ISlangMutableFileSystem* outFileSystem {}; + SlangResult res = pObj->getResultAsFileSystem(entryPointIndex, targetIndex, &outFileSystem); + + if (outFileSystem && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outFileSystemId, outFileSystem); + } + return res; + } + + SlangResult CommonInterfaceReplayer::getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) + { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outHashId); + + SlangResult res = SLANG_OK; + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IBlob* outHash {}; + pObj->getEntryPointHash(entryPointIndex, targetIndex, &outHash); + + if (outHash) + { + m_objectMap.add(outHashId, outHash); + if (outHash->getBufferSize()) + { + uint8_t* buffer = (uint8_t*)outHash->getBufferPointer(); + Slang::StringBuilder strBuilder; + for (size_t i = 0; i < outHash->getBufferSize(); i++) + { + strBuilder<<Slang::StringUtil::makeStringWithFormat("%.2X ", buffer[i]); + } + slangRecordLog(LogLevel::Verbose, "getEntryPointHash: %s\n", strBuilder.begin()); + } + else + { + res = SLANG_FAIL; + } + } + else + { + res = SLANG_FAIL; + } + return res; + } + + + SlangResult CommonInterfaceReplayer::link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IComponentType* outLinkedComponentType {}; + slang::IBlob* outDiagnostics {}; + + SlangResult res = pObj->link(&outLinkedComponentType, &outDiagnostics); + + if (outLinkedComponentType && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outLinkedComponentTypeId, outLinkedComponentType); + } + + ReplayConsumer::printDiagnosticMessage(outDiagnostics); + return res; + } + + SlangResult CommonInterfaceReplayer::getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibraryId, + ObjectID outDiagnosticsId) { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + ISlangSharedLibrary* outSharedLib {}; + slang::IBlob* outDiagnosticsBlob {}; + + SlangResult res = pObj->getEntryPointHostCallable(entryPointIndex, targetIndex, &outSharedLib, &outDiagnosticsBlob); + + if (outSharedLib && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outSharedLibraryId, outSharedLib); + } + + ReplayConsumer::printDiagnosticMessage(outDiagnosticsBlob); + return res; + } + + SlangResult CommonInterfaceReplayer::renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IComponentType* outEntryPoint {}; + SlangResult res = pObj->renameEntryPoint(newName, &outEntryPoint); + + if (outEntryPoint && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outEntryPointId, outEntryPoint); + } + return res; + } + + SlangResult CommonInterfaceReplayer::linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) + { + InputObjectSanityCheck(objectId); + + slang::IComponentType* pObj = getObjectPointer(objectId); + slang::IComponentType* outLinkedComponentType {}; + slang::IBlob* outDiagnostics {}; + + SlangResult res = pObj->linkWithOptions(&outLinkedComponentType, compilerOptionEntryCount, compilerOptionEntries, &outDiagnostics); + + if (outLinkedComponentType && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outLinkedComponentTypeId, outLinkedComponentType); + } + + ReplayConsumer::printDiagnosticMessage(outDiagnostics); + return res; + } + + + void ReplayConsumer::printDiagnosticMessage(slang::IBlob* diagnosticsBlob) + { + if (diagnosticsBlob) + { + const char* diagnostics = (const char*)diagnosticsBlob->getBufferPointer(); + slangRecordLog(LogLevel::Error, "Replayer: %s\n", diagnostics); + } + } + + void ReplayConsumer::CreateGlobalSession(ObjectID outGlobalSessionId) + { + OutputObjectSanityCheck(outGlobalSessionId); + + slang::IGlobalSession* outGlobalSession {}; + slang::createGlobalSession(&outGlobalSession); + + if (outGlobalSession) + { + m_objectMap.add(outGlobalSessionId, outGlobalSession); + slangRecordLog(LogLevel::Verbose, "createGlobalSession, capture: 0x%X, new: 0x%X\n", + outGlobalSessionId, reinterpret_cast<AddressFormat>(outGlobalSession)); + } + else + { + slangRecordLog(LogLevel::Error, "createGlobalSession fails, outGlobalSessionId: 0x%X\n", outGlobalSessionId); + } } void ReplayConsumer::IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outSessionId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + slang::ISession* outSession {}; + SlangResult res = globalSession->createSession(desc, &outSession); + + if (outSession && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outSessionId, outSession); + } + else + { + slangRecordLog(LogLevel::Error, "IGlobalSession::createSession fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_findProfile(ObjectID objectId, char const* name) { + InputObjectSanityCheck(objectId); + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->findProfile(name); } void ReplayConsumer::IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) { + InputObjectSanityCheck(objectId); + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->setDownstreamCompilerPath(passThrough, path); } void ReplayConsumer::IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude) { + InputObjectSanityCheck(objectId); + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->setDownstreamCompilerPrelude(inPassThrough, prelude); } void ReplayConsumer::IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outPreludeId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + + ISlangBlob* outPrelude {}; + globalSession->getDownstreamCompilerPrelude(inPassThrough, &outPrelude); + if (outPrelude) + { + m_objectMap.add(outPreludeId, outPrelude); + } } void ReplayConsumer::IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->setDefaultDownstreamCompiler(sourceLanguage, defaultCompiler); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::setDefaultDownstreamCompiler fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->getDefaultDownstreamCompiler(sourceLanguage); } void ReplayConsumer::IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->setLanguagePrelude(inSourceLanguage, prelude); } void ReplayConsumer::IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outPreludeId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + + ISlangBlob* outPrelude {}; + globalSession->getLanguagePrelude(inSourceLanguage, &outPrelude); + if (outPrelude) + { + m_objectMap.add(outPreludeId, outPrelude); + } } void ReplayConsumer::IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outCompileRequest); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + slang::ICompileRequest* outRequest {}; + SlangResult res = globalSession->createCompileRequest(&outRequest); + + if (outRequest && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outCompileRequest, outRequest); + } + else + { + slangRecordLog(LogLevel::Error, "IGlobalSession::createCompileRequest fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->addBuiltins(sourcePath, sourceString); } void ReplayConsumer::IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId) { + InputObjectSanityCheck(objectId); + InputObjectSanityCheck(loaderId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + ISlangSharedLibraryLoader* loader = getObjectPointer<ISlangSharedLibraryLoader>(loaderId); + globalSession->setSharedLibraryLoader(loader); } void ReplayConsumer::IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outLoaderId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + ISlangSharedLibraryLoader* loader = globalSession->getSharedLibraryLoader(); + if (loader) + { + m_objectMap.add(outLoaderId, loader); + } + else + { + slangRecordLog(LogLevel::Error, "IGlobalSession::getSharedLibraryLoader fails, this: 0x%X\n", objectId); + } } void ReplayConsumer::IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->checkCompileTargetSupport(target); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::checkCompileTargetSupport fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->checkPassThroughSupport(passThrough); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::checkPassThroughSupport fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->compileStdLib(flags); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::compileStdLib fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->loadStdLib(stdLib, stdLibSizeInBytes); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::loadStdLib fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outBlobId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + ISlangBlob* outBlob {}; + SlangResult res = globalSession->saveStdLib(archiveType, &outBlob); + + if (outBlob && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outBlobId, outBlob); + } + else + { + slangRecordLog(LogLevel::Error, "IGlobalSession::saveStdLib fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_findCapability(ObjectID objectId, char const* name) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->findCapability(name); } void ReplayConsumer::IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->setDownstreamCompilerForTransition(source, target, compiler); } void ReplayConsumer::IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + globalSession->getDownstreamCompilerForTransition(source, target); } void ReplayConsumer::IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath) { + InputObjectSanityCheck(objectId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + SlangResult res = globalSession->setSPIRVCoreGrammar(jsonPath); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IGlobalSession::setSPIRVCoreGrammar fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outAllocationId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + slang::SessionDesc sessionDesc {}; + ISlangUnknown* allocation {}; + + // Note: we don't save the sessionDesc here, because it's an output to user, but we do need to save the allocation, because + // it holds the auxiliary data for the sessionDesc. So if use provide the same sessionDesc to slang, we won't hit any segfault. + SlangResult res = globalSession->parseCommandLineArguments(argc, argv, &sessionDesc, &allocation); + + if (SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outAllocationId, allocation); + } + else + { + slangRecordLog(LogLevel::Debug, "IGlobalSession::parseCommandLineArguments fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outBlobId); + + slang::IGlobalSession* globalSession = getObjectPointer<slang::IGlobalSession>(objectId); + ISlangBlob* outBlob {}; + SlangResult res = globalSession->getSessionDescDigest(sessionDesc, &outBlob); + + if (outBlob && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outBlobId, outBlob); + } + else + { + slangRecordLog(LogLevel::Error, "IGlobalSession::getSessionDescDigest fails, ret:0x%X, this: 0x%X\n", res, objectId); + } } @@ -130,45 +573,150 @@ namespace SlangRecord // ISession void ReplayConsumer::ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) { + // No need to replay this function } - void ReplayConsumer::ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId) + void ReplayConsumer::ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnosticsId, ObjectID outModuleId) { + InputObjectSanityCheck(objectId); + + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::IModule* outModule {}; + slang::IBlob* outDiagnostics {}; + + // loadModule could return a new module or an existing module, so can't use OutputObjectSanityCheck here + outModule = session->loadModule(moduleName, &outDiagnostics); + + if (outModule) + { + // Save the module if it's not being tracked + m_objectMap.addIfNotExists(outModuleId, outModule); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::loadModule returns nullptr, this: 0x%X\n", objectId); + } + + printDiagnosticMessage(outDiagnostics); } void ReplayConsumer::ISession_loadModuleFromIRBlob(ObjectID objectId, const char* moduleName, const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) { + InputObjectSanityCheck(objectId); + + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::IModule* outModule {}; + slang::IBlob* outDiagnostics {}; + + outModule = session->loadModuleFromIRBlob(moduleName, path, source, &outDiagnostics); + + if (outModule) + { + // Save the module if it's not being tracked + m_objectMap.addIfNotExists(outModuleId, outModule); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::loadModule returns nullptr, this: 0x%X\n", objectId); + } + + printDiagnosticMessage(outDiagnostics); } void ReplayConsumer::ISession_loadModuleFromSource(ObjectID objectId, const char* moduleName, const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) { + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::IModule* outModule {}; + slang::IBlob* outDiagnostics {}; + + outModule = session->loadModuleFromSource(moduleName, path, source, &outDiagnostics); + + if (outModule) + { + // Save the module if it's not being tracked + m_objectMap.addIfNotExists(outModuleId, outModule); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::loadModule returns nullptr, this: 0x%X\n", objectId); + } + + printDiagnosticMessage(outDiagnostics); } void ReplayConsumer::ISession_loadModuleFromSourceString(ObjectID objectId, const char* moduleName, const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId) { + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::IModule* outModule {}; + slang::IBlob* outDiagnostics {}; + + outModule = session->loadModuleFromSourceString(moduleName, path, string, &outDiagnostics); + + if (outModule) + { + // Save the module if it's not being tracked + m_objectMap.addIfNotExists(outModuleId, outModule); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::loadModule returns nullptr, this: 0x%X\n", objectId); + } + + printDiagnosticMessage(outDiagnostics); } void ReplayConsumer::ISession_createCompositeComponentType(ObjectID objectId, ObjectID* componentTypeIds, SlangInt componentTypeCount, ObjectID outCompositeComponentTypeId, ObjectID outDiagnosticsId) { - } + InputObjectSanityCheck(objectId); + for (SlangInt i = 0; i < componentTypeCount; i++) + { + InputObjectSanityCheck(componentTypeIds[i]); + } + + OutputObjectSanityCheck(outCompositeComponentTypeId); + + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + + Slang::List<slang::IComponentType*> componentTypes; + componentTypes.reserve(componentTypeCount); + + for (SlangInt i = 0; i < componentTypeCount; i++) + { + componentTypes.add(getObjectPointer<slang::IComponentType>(componentTypeIds[i])); + } + + slang::IComponentType* outCompositeComponentType {}; + slang::IBlob* outDiagnostics {}; + SlangResult res = session->createCompositeComponentType(componentTypes.getBuffer(), componentTypeCount, &outCompositeComponentType, &outDiagnostics); + if (outCompositeComponentType && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outCompositeComponentTypeId, outCompositeComponentType); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::createCompositeComponentType fails, ret: 0x%X, this: 0x%X\n", objectId); + } + + printDiagnosticMessage(outDiagnostics); + } + + // TODO: implement those functions related to TypeReflection void ReplayConsumer::ISession_specializeType(ObjectID objectId, ObjectID typeId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) { } - - void ReplayConsumer::ISession_getTypeLayout(ObjectID objectId, ObjectID typeId, SlangInt targetIndex, slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection) { @@ -203,101 +751,221 @@ namespace SlangRecord SlangInt conformanceIdOverride, ObjectID outDiagnosticsId) { } + // End of TODO void ReplayConsumer::ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outCompileRequestId); + + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::ICompileRequest* outRequest {}; + SlangResult res = session->createCompileRequest(&outRequest); + + if (outRequest && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outCompileRequestId, outRequest); + } + else + { + slangRecordLog(LogLevel::Error, "ISession::createCompileRequest fails, ret:0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId) { - } + InputObjectSanityCheck(objectId); + slang::ISession* session = getObjectPointer<slang::ISession>(objectId); + slang::IModule* outModule = session->getLoadedModule(index); + + if (!m_objectMap.tryGetValue(outModuleId)) + { + // This module should already be tracked during loadModule() call, if not this should be a bug in the replayer or record. + slangRecordLog(LogLevel::Error, "ISession::getLoadedModule: this: 0x%X, module 0x%X is not tracked \n", objectId, outModuleId); + m_objectMap.add(outModuleId, outModule); + } + + if (!outModule) + { + slangRecordLog(LogLevel::Error, "ISession::getLoadedModule returns nullptr, this: 0x%X\n", objectId); + } + } // IModule void ReplayConsumer::IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId) { + InputObjectSanityCheck(objectId); + + slang::IModule* module = getObjectPointer<slang::IModule>(objectId); + slang::IEntryPoint* outEntryPoint {}; + SlangResult res = module->findEntryPointByName(name, &outEntryPoint); + + if (outEntryPoint && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outEntryPointId, outEntryPoint); + } + else + { + slangRecordLog(LogLevel::Error, "IModule::findEntryPointByName fails, ret: 0x%X, this: 0x%X\n", objectId); + } } void ReplayConsumer::IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId) { + InputObjectSanityCheck(objectId); + + slang::IModule* module = getObjectPointer<slang::IModule>(objectId); + slang::IEntryPoint* outEntryPoint {}; + SlangResult res = module->getDefinedEntryPoint(index, &outEntryPoint); + + if (outEntryPoint && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outEntryPointId, outEntryPoint); + } + else + { + slangRecordLog(LogLevel::Error, "IModule::getDefinedEntryPoint returns nullptr, this: 0x%X\n", objectId); + } } void ReplayConsumer::IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) { + InputObjectSanityCheck(objectId); + OutputObjectSanityCheck(outSerializedBlobId); + + slang::IModule* module = getObjectPointer<slang::IModule>(objectId); + slang::IBlob* outBlob {}; + SlangResult res = module->serialize(&outBlob); + + if (outBlob && SLANG_SUCCEEDED(res)) + { + m_objectMap.add(outSerializedBlobId, outBlob); + } + else + { + slangRecordLog(LogLevel::Error, "IModule::serialize fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } void ReplayConsumer::IModule_writeToFile(ObjectID objectId, char const* fileName) { + InputObjectSanityCheck(objectId); + + slang::IModule* module = getObjectPointer<slang::IModule>(objectId); + SlangResult res = module->writeToFile(fileName); + + if (SLANG_FAILED(res)) + { + slangRecordLog(LogLevel::Error, "IModule::writeToFile fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } } - void ReplayConsumer::IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics) + void ReplayConsumer::IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnosticsId) { - } + InputObjectSanityCheck(objectId); + + slang::IModule* module = getObjectPointer<slang::IModule>(objectId); + slang::IEntryPoint* outEntryPoint {}; + slang::IBlob* outDiagnostics {}; + SlangResult res = module->findAndCheckEntryPoint(name, stage, &outEntryPoint, &outDiagnostics); + + if (outEntryPoint && SLANG_SUCCEEDED(res)) + { + m_objectMap.addIfNotExists(outEntryPointId, outEntryPoint); + } + else + { + slangRecordLog(LogLevel::Error, "IModule::findAndCheckEntryPoint fails, ret: 0x%X, this: 0x%X\n", res, objectId); + } + + printDiagnosticMessage(outDiagnostics); + } void ReplayConsumer::IModule_getSession(ObjectID objectId, ObjectID outSessionId) { + // No need to replay this function } - void ReplayConsumer::IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SlangResult res = m_commonReplayer.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); + FAIL_WITH_LOG(IModule::getLayout); } - void ReplayConsumer::IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void ReplayConsumer::IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCodeId, outDiagnosticsId); + FAIL_WITH_LOG(IModule::getEntryPointCode); } - void ReplayConsumer::IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) + void ReplayConsumer::IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.getTargetCode(objectId, targetIndex, outCodeId, outDiagnosticsId); + FAIL_WITH_LOG(IModule::getTargetCode); } - void ReplayConsumer::IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) + void ReplayConsumer::IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId) { + SlangResult res = m_commonReplayer.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystemId); + FAIL_WITH_LOG(IModule::getResultAsFileSystem); } void ReplayConsumer::IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SlangResult res = m_commonReplayer.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); + FAIL_WITH_LOG(IModule::getEntryPointHash); } void ReplayConsumer::IModule_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + // TODO: Cannot replay this function because of the TypeReflection is not recorded. } + void ReplayConsumer::IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); + FAIL_WITH_LOG(IModule::link); } void ReplayConsumer::IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + FAIL_WITH_LOG(IModule::getEntryPointHostCallable); } void ReplayConsumer::IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SlangResult res = m_commonReplayer.renameEntryPoint(objectId, newName, outEntryPointId); + FAIL_WITH_LOG(IModule::renameEntryPoint); } void ReplayConsumer::IModule_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); + FAIL_WITH_LOG(IModule::linkWithOptions); } @@ -310,53 +978,72 @@ namespace SlangRecord void ReplayConsumer::IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SlangResult res = m_commonReplayer.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); + FAIL_WITH_LOG(IEntryPoint::getLayout); } void ReplayConsumer::IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(IEntryPoint::getEntryPointCode); } void ReplayConsumer::IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getTargetCode(objectId, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(IEntryPoint::getTargetCode); } void ReplayConsumer::IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SlangResult res = m_commonReplayer.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); + FAIL_WITH_LOG(IEntryPoint::getResultAsFileSystem); } void ReplayConsumer::IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SlangResult res = m_commonReplayer.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); + FAIL_WITH_LOG(IEntryPoint::getEntryPointHash); } void ReplayConsumer::IEntryPoint_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) { + } void ReplayConsumer::IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); + FAIL_WITH_LOG(IEntryPoint::link); } void ReplayConsumer::IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + FAIL_WITH_LOG(IEntryPoint::getEntryPointHostCallable); } void ReplayConsumer::IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SlangResult res = m_commonReplayer.renameEntryPoint(objectId, newName, outEntryPointId); + FAIL_WITH_LOG(IEntryPoint::renameEntryPoint); } void ReplayConsumer::IEntryPoint_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); + FAIL_WITH_LOG(IEntryPoint::linkWithOptions); } @@ -369,26 +1056,36 @@ namespace SlangRecord void ReplayConsumer::ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SlangResult res = m_commonReplayer.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); + FAIL_WITH_LOG(ICompositeComponentType::getLayout); } void ReplayConsumer::ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(ICompositeComponentType::getEntryPointCode); } void ReplayConsumer::ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getTargetCode(objectId, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(ICompositeComponentType::getTargetCode); } void ReplayConsumer::ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SlangResult res = m_commonReplayer.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); + FAIL_WITH_LOG(ICompositeComponentType::getResultAsFileSystem); } void ReplayConsumer::ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SlangResult res = m_commonReplayer.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); + FAIL_WITH_LOG(ICompositeComponentType::getEntryPointHash); } @@ -400,22 +1097,30 @@ namespace SlangRecord void ReplayConsumer::ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); + FAIL_WITH_LOG(ICompositeComponentType::link); } void ReplayConsumer::ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + FAIL_WITH_LOG(ICompositeComponentType::getEntryPointHostCallable); } void ReplayConsumer::ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SlangResult res = m_commonReplayer.renameEntryPoint(objectId, newName, outEntryPointId); + FAIL_WITH_LOG(ICompositeComponentType::renameEntryPoint); } void ReplayConsumer::ICompositeComponentType_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); + FAIL_WITH_LOG(ICompositeComponentType::linkWithOptions); } @@ -428,26 +1133,36 @@ namespace SlangRecord void ReplayConsumer::ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) { + SlangResult res = m_commonReplayer.getLayout(objectId, targetIndex, outDiagnosticsId, retProgramLayoutId); + FAIL_WITH_LOG(ITypeConformance::getLayout); } void ReplayConsumer::ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointCode(objectId, entryPointIndex, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(ITypeConformance::getEntryPointCode); } void ReplayConsumer::ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getTargetCode(objectId, targetIndex, outCode, outDiagnostics); + FAIL_WITH_LOG(ITypeConformance::getTargetCode); } void ReplayConsumer::ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) { + SlangResult res = m_commonReplayer.getResultAsFileSystem(objectId, entryPointIndex, targetIndex, outFileSystem); + FAIL_WITH_LOG(ITypeConformance::getResultAsFileSystem); } void ReplayConsumer::ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) { + SlangResult res = m_commonReplayer.getEntryPointHash(objectId, entryPointIndex, targetIndex, outHashId); + FAIL_WITH_LOG(ITypeConformance::getEntryPointHash); } @@ -459,22 +1174,30 @@ namespace SlangRecord void ReplayConsumer::ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.link(objectId, outLinkedComponentTypeId, outDiagnosticsId); + FAIL_WITH_LOG(ITypeConformance::link); } void ReplayConsumer::ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) { + SlangResult res = m_commonReplayer.getEntryPointHostCallable(objectId, entryPointIndex, targetIndex, outSharedLibrary, outDiagnostics); + FAIL_WITH_LOG(ITypeConformance::getEntryPointHostCallable); } void ReplayConsumer::ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) { + SlangResult res = m_commonReplayer.renameEntryPoint(objectId, newName, outEntryPointId); + FAIL_WITH_LOG(ITypeConformance::renameEntryPoint); } void ReplayConsumer::ITypeConformance_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) { + SlangResult res = m_commonReplayer.linkWithOptions(objectId, outLinkedComponentTypeId, compilerOptionEntryCount, compilerOptionEntries, outDiagnosticsId); + FAIL_WITH_LOG(ITypeConformance::linkWithOptions); } diff --git a/source/slang-record-replay/replay/replay-consumer.h b/source/slang-record-replay/replay/replay-consumer.h index 6ac733f90..8a38d6202 100644 --- a/source/slang-record-replay/replay/replay-consumer.h +++ b/source/slang-record-replay/replay/replay-consumer.h @@ -2,195 +2,247 @@ #define REPLAY_CONSUMER_H #include <unordered_map> +#include "../../core/slang-stream.h" #include "../util/record-format.h" +#include "../util/record-utility.h" #include "decoder-consumer.h" namespace SlangRecord { + // class CommonInterfaceReplayer; + + class CommonInterfaceReplayer + { + public: + CommonInterfaceReplayer(Slang::Dictionary<ObjectID, void*>& pObjectMap) + : m_objectMap(pObjectMap) + {} + virtual ~CommonInterfaceReplayer() = default; + + SlangResult getSession(ObjectID objectId, ObjectID outSessionId) { return SLANG_FAIL; } + + SlangResult getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId); + SlangResult getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + SlangResult getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId); + SlangResult getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystemId); + SlangResult getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId); + SlangResult specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) + {return SLANG_FAIL;} + SlangResult link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId); + SlangResult getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibraryId, + ObjectID outDiagnosticsId); + SlangResult renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId); + SlangResult linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId); + private: + inline slang::IComponentType* getObjectPointer(ObjectID objectId) + { + void* objPtr = nullptr; + + // If the object is not found, there must be something wrong with the record/replay + // logic, so report an error. + if (!m_objectMap.tryGetValue(objectId, objPtr)) + { + slangRecordLog(LogLevel::Error, "Object not found in the object map: %d\n", objectId); + std::abort(); + } + + return static_cast<slang::IComponentType*>(objPtr); + } + + Slang::Dictionary<ObjectID, void*>& m_objectMap; + }; + class ReplayConsumer : public IDecoderConsumer { public: - virtual void CreateGlobalSession(ObjectID objectId, const uint8_t* parameterBuffer, int64_t bufferSize) = 0; - virtual void IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) = 0; - virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name) = 0; - virtual void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) = 0; - virtual void IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude) = 0; - virtual void IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId) = 0; - - virtual void IGlobalSession_getBuildTagString(ObjectID objectId) { (void) objectId; } - - virtual void IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) = 0; - virtual void IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage) = 0; - virtual void IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude) = 0; - virtual void IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId) = 0; - virtual void IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest) = 0; - virtual void IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString) = 0; - virtual void IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId) = 0; - virtual void IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId) = 0; - virtual void IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target) = 0; - virtual void IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough) = 0; - virtual void IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags) = 0; - virtual void IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes) = 0; - virtual void IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId) = 0; - virtual void IGlobalSession_findCapability(ObjectID objectId, char const* name) = 0; - virtual void IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) = 0; - virtual void IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target) = 0; - - virtual void IGlobalSession_getCompilerElapsedTime(ObjectID objectId) { (void) objectId; } - - virtual void IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath) = 0; - virtual void IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId) = 0; - virtual void IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId) = 0; + virtual void CreateGlobalSession(ObjectID outGlobalSessionId) override; + virtual void IGlobalSession_createSession(ObjectID objectId, slang::SessionDesc const& desc, ObjectID outSessionId) override; + virtual void IGlobalSession_findProfile(ObjectID objectId, char const* name) override; + virtual void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, SlangPassThrough passThrough, char const* path) override; + virtual void IGlobalSession_setDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, char const* prelude) override; + virtual void IGlobalSession_getDownstreamCompilerPrelude(ObjectID objectId, SlangPassThrough inPassThrough, ObjectID outPreludeId) override; + + virtual void IGlobalSession_getBuildTagString(ObjectID objectId) override { (void) objectId; } + + virtual void IGlobalSession_setDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) override; + virtual void IGlobalSession_getDefaultDownstreamCompiler(ObjectID objectId, SlangSourceLanguage sourceLanguage) override; + virtual void IGlobalSession_setLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, char const* prelude) override; + virtual void IGlobalSession_getLanguagePrelude(ObjectID objectId, SlangSourceLanguage inSourceLanguage, ObjectID outPreludeId) override; + virtual void IGlobalSession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequest) override; + virtual void IGlobalSession_addBuiltins(ObjectID objectId, char const* sourcePath, char const* sourceString) override; + virtual void IGlobalSession_setSharedLibraryLoader(ObjectID objectId, ObjectID loaderId) override; + virtual void IGlobalSession_getSharedLibraryLoader(ObjectID objectId, ObjectID outLoaderId) override; + virtual void IGlobalSession_checkCompileTargetSupport(ObjectID objectId, SlangCompileTarget target) override; + virtual void IGlobalSession_checkPassThroughSupport(ObjectID objectId, SlangPassThrough passThrough) override; + virtual void IGlobalSession_compileStdLib(ObjectID objectId, slang::CompileStdLibFlags flags) override; + virtual void IGlobalSession_loadStdLib(ObjectID objectId, const void* stdLib, size_t stdLibSizeInBytes) override; + virtual void IGlobalSession_saveStdLib(ObjectID objectId, SlangArchiveType archiveType, ObjectID outBlobId) override; + virtual void IGlobalSession_findCapability(ObjectID objectId, char const* name) override; + virtual void IGlobalSession_setDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) override; + virtual void IGlobalSession_getDownstreamCompilerForTransition(ObjectID objectId, SlangCompileTarget source, SlangCompileTarget target) override; + + virtual void IGlobalSession_getCompilerElapsedTime(ObjectID objectId) override { (void) objectId; } + + virtual void IGlobalSession_setSPIRVCoreGrammar(ObjectID objectId, char const* jsonPath) override; + virtual void IGlobalSession_parseCommandLineArguments(ObjectID objectId, int argc, const char* const* argv, ObjectID outSessionDescId, ObjectID outAllocationId) override; + virtual void IGlobalSession_getSessionDescDigest(ObjectID objectId, slang::SessionDesc* sessionDesc, ObjectID outBlobId) override; // ISession - virtual void ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) = 0; - virtual void ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId) = 0; + virtual void ISession_getGlobalSession(ObjectID objectId, ObjectID outGlobalSessionId) override; + virtual void ISession_loadModule(ObjectID objectId, const char* moduleName, ObjectID outDiagnostics, ObjectID outModuleId) override; virtual void ISession_loadModuleFromIRBlob(ObjectID objectId, const char* moduleName, - const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) override; virtual void ISession_loadModuleFromSource(ObjectID objectId, const char* moduleName, - const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, slang::IBlob* source, ObjectID outDiagnosticsId, ObjectID outModuleId) override; virtual void ISession_loadModuleFromSourceString(ObjectID objectId, const char* moduleName, - const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId) = 0; + const char* path, const char* string, ObjectID outDiagnosticsId, ObjectID outModuleId) override; virtual void ISession_createCompositeComponentType(ObjectID objectId, ObjectID* componentTypeIds, - SlangInt componentTypeCount, ObjectID outCompositeComponentTypeIds, ObjectID outDiagnosticsId) = 0; + SlangInt componentTypeCount, ObjectID outCompositeComponentTypeIds, ObjectID outDiagnosticsId) override; virtual void ISession_specializeType(ObjectID objectId, ObjectID typeId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) = 0; + SlangInt specializationArgCount, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) override; virtual void ISession_getTypeLayout(ObjectID objectId, ObjectID typeId, SlangInt targetIndex, - slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection) = 0; + slang::LayoutRules rules, ObjectID outDiagnosticsId, ObjectID outTypeLayoutReflection) override; virtual void ISession_getContainerType(ObjectID objectId, ObjectID elementType, - slang::ContainerType containerType, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) = 0; + slang::ContainerType containerType, ObjectID outDiagnosticsId, ObjectID outTypeReflectionId) override; - virtual void ISession_getDynamicType(ObjectID objectId, ObjectID outTypeReflectionId) = 0; + virtual void ISession_getDynamicType(ObjectID objectId, ObjectID outTypeReflectionId) override; - virtual void ISession_getTypeRTTIMangledName(ObjectID objectId, ObjectID typeId, ObjectID outNameBlobId) = 0; + virtual void ISession_getTypeRTTIMangledName(ObjectID objectId, ObjectID typeId, ObjectID outNameBlobId) override; virtual void ISession_getTypeConformanceWitnessMangledName(ObjectID objectId, ObjectID typeId, - ObjectID interfaceTypeId, ObjectID outNameBlobId) = 0; + ObjectID interfaceTypeId, ObjectID outNameBlobId) override; virtual void ISession_getTypeConformanceWitnessSequentialID(ObjectID objectId, ObjectID typeId, - ObjectID interfaceTypeId, uint32_t outId) = 0; + ObjectID interfaceTypeId, uint32_t outId) override; virtual void ISession_createTypeConformanceComponentType(ObjectID objectId, ObjectID typeId, ObjectID interfaceTypeId, ObjectID outConformanceId, - SlangInt conformanceIdOverride, ObjectID outDiagnosticsId) = 0; + SlangInt conformanceIdOverride, ObjectID outDiagnosticsId) override; - virtual void ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId) = 0; + virtual void ISession_createCompileRequest(ObjectID objectId, ObjectID outCompileRequestId) override; - virtual void ISession_getLoadedModuleCount(ObjectID objectId) { (void) objectId; } + virtual void ISession_getLoadedModuleCount(ObjectID objectId) override { (void) objectId; } - virtual void ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId) = 0; + virtual void ISession_getLoadedModule(ObjectID objectId, SlangInt index, ObjectID outModuleId) override; - virtual void ISession_isBinaryModuleUpToDate(ObjectID objectId) { (void) objectId; } + virtual void ISession_isBinaryModuleUpToDate(ObjectID objectId) override { (void) objectId; } // IModule - virtual void IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId) = 0; + virtual void IModule_findEntryPointByName(ObjectID objectId, char const* name, ObjectID outEntryPointId) override; - virtual void IModule_getDefinedEntryPointCount(ObjectID objectId) { (void) objectId; } + virtual void IModule_getDefinedEntryPointCount(ObjectID objectId) override { (void) objectId; } - virtual void IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId) = 0; - virtual void IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) = 0; - virtual void IModule_writeToFile(ObjectID objectId, char const* fileName) = 0; + virtual void IModule_getDefinedEntryPoint(ObjectID objectId, SlangInt32 index, ObjectID outEntryPointId) override; + virtual void IModule_serialize(ObjectID objectId, ObjectID outSerializedBlobId) override; + virtual void IModule_writeToFile(ObjectID objectId, char const* fileName) override; - virtual void IModule_getName(ObjectID objectId) { (void) objectId; } - virtual void IModule_getFilePath(ObjectID objectId) { (void) objectId; } - virtual void IModule_getUniqueIdentity(ObjectID objectId) { (void) objectId; } + virtual void IModule_getName(ObjectID objectId) override { (void) objectId; } + virtual void IModule_getFilePath(ObjectID objectId) override { (void) objectId; } + virtual void IModule_getUniqueIdentity(ObjectID objectId) override { (void) objectId; } - virtual void IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics) = 0; + virtual void IModule_findAndCheckEntryPoint(ObjectID objectId, char const* name, SlangStage stage, ObjectID outEntryPointId, ObjectID outDiagnostics) override; - virtual void IModule_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void IModule_getSession(ObjectID objectId, ObjectID outSessionId) override; + virtual void IModule_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) override; - virtual void IModule_getSpecializationParamCount(ObjectID objectId) { (void) objectId; } + virtual void IModule_getSpecializationParamCount(ObjectID objectId) override { (void) objectId; } - virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void IModule_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void IModule_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void IModule_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) override; + virtual void IModule_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) override; virtual void IModule_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void IModule_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void IModule_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) override; + virtual void IModule_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) override; virtual void IModule_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) override; // IEntryPoint - virtual void IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void IEntryPoint_getSession(ObjectID objectId, ObjectID outSessionId) override; + virtual void IEntryPoint_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) override; - virtual void IEntryPoint_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; + virtual void IEntryPoint_getSpecializationParamCount(ObjectID objectId) override { (void) objectId; }; - virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void IEntryPoint_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void IEntryPoint_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void IEntryPoint_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) override; + virtual void IEntryPoint_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) override; virtual void IEntryPoint_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void IEntryPoint_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void IEntryPoint_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) override; + virtual void IEntryPoint_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) override; virtual void IEntryPoint_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) override; // ICompositeComponentType - virtual void ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void ICompositeComponentType_getSession(ObjectID objectId, ObjectID outSessionId) override; + virtual void ICompositeComponentType_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) override; - virtual void ICompositeComponentType_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; + virtual void ICompositeComponentType_getSpecializationParamCount(ObjectID objectId) override { (void) objectId; }; - virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void ICompositeComponentType_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void ICompositeComponentType_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void ICompositeComponentType_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) override; + virtual void ICompositeComponentType_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) override; virtual void ICompositeComponentType_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void ICompositeComponentType_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void ICompositeComponentType_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) override; + virtual void ICompositeComponentType_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) override; virtual void ICompositeComponentType_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) override; // ITypeConformance - virtual void ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId) = 0; - virtual void ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) = 0; + virtual void ITypeConformance_getSession(ObjectID objectId, ObjectID outSessionId) override; + virtual void ITypeConformance_getLayout(ObjectID objectId, SlangInt targetIndex, ObjectID outDiagnosticsId, ObjectID retProgramLayoutId) override; - virtual void ITypeConformance_getSpecializationParamCount(ObjectID objectId) { (void) objectId; }; + virtual void ITypeConformance_getSpecializationParamCount(ObjectID objectId) override { (void) objectId; }; - virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCode, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) = 0; - virtual void ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) = 0; + virtual void ITypeConformance_getEntryPointCode(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void ITypeConformance_getTargetCode(ObjectID objectId, SlangInt targetIndex, ObjectID outCodeId, ObjectID outDiagnosticsId) override; + virtual void ITypeConformance_getResultAsFileSystem(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outFileSystem) override; + virtual void ITypeConformance_getEntryPointHash(ObjectID objectId, SlangInt entryPointIndex, SlangInt targetIndex, ObjectID outHashId) override; virtual void ITypeConformance_specialize(ObjectID objectId, slang::SpecializationArg const* specializationArgs, - SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) = 0; - virtual void ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) = 0; - virtual void ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) = 0; + SlangInt specializationArgCount, ObjectID outSpecializedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void ITypeConformance_link(ObjectID objectId, ObjectID outLinkedComponentTypeId, ObjectID outDiagnosticsId) override; + virtual void ITypeConformance_getEntryPointHostCallable(ObjectID objectId, int entryPointIndex, int targetIndex, ObjectID outSharedLibrary, ObjectID outDiagnostics) override; + virtual void ITypeConformance_renameEntryPoint(ObjectID objectId, const char* newName, ObjectID outEntryPointId) override; virtual void ITypeConformance_linkWithOptions(ObjectID objectId, ObjectID outLinkedComponentTypeId, - uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) = 0; + uint32_t compilerOptionEntryCount, slang::CompilerOptionEntry* compilerOptionEntries, ObjectID outDiagnosticsId) override; + + static void printDiagnosticMessage(slang::IBlob* diagnosticsBlob); private: // Map of the address of the object allocated by slang during record to // the address of the object allocated by the replay. // We need to have this map because we never save the content of the object - // allocated by slang, because those are just opaque objects or handles, we + // allocated by slang. Because those are just opaque objects or handles, we // only need to provide them to the corresponding replay function or call the // methods on the correct object. - std::unordered_map<ObjectID, void*> m_objectMap; - - inline void* getObjectPointer(ObjectID objectId) - { - if (m_objectMap.find(objectId) == m_objectMap.end()) - { - return nullptr; - } - else - { - return m_objectMap[objectId]; - } - } + Slang::Dictionary<ObjectID, void*> m_objectMap; + + template<typename T> + inline T* getObjectPointer(ObjectID objectId) + { + void* objPtr = nullptr; + if (!m_objectMap.tryGetValue(objectId, objPtr)) + { + slangRecordLog(LogLevel::Error, "Object not found in the object map: %d\n", objectId); + std::abort(); + } + + return static_cast<T*>(objPtr); + } + + CommonInterfaceReplayer m_commonReplayer {m_objectMap}; }; } #endif // REPLAY_CONSUMER_H diff --git a/source/slang-record-replay/replay/slang-decoder.cpp b/source/slang-record-replay/replay/slang-decoder.cpp index 561a2c9e3..e30bd4584 100644 --- a/source/slang-record-replay/replay/slang-decoder.cpp +++ b/source/slang-record-replay/replay/slang-decoder.cpp @@ -43,9 +43,6 @@ namespace SlangRecord default: slangRecordLog(LogLevel::Error, "Unhandled Slang API call: %d\n", callId); break; - case ApiCallId::CreateGlobalSession: - CreateGlobalSession(objectId, parameterBlock); - break; case ApiCallId::IGlobalSession_createSession: IGlobalSession_createSession(objectId, parameterBlock); break; @@ -411,13 +408,29 @@ namespace SlangRecord bool SlangDecoder::processFunctionCall(FunctionHeader const& header, ParameterBlock const& parameterBlock) { - return false; + switch(header.callId) + { + default: + slangRecordLog(LogLevel::Error, "Unhandled Slang API call: %d\n", header.callId); + return false; + case ApiCallId::CreateGlobalSession: + CreateGlobalSession(parameterBlock); + break; + } + return true; } - bool SlangDecoder::CreateGlobalSession(ObjectID objectId, ParameterBlock const& parameterBlock) + bool SlangDecoder::CreateGlobalSession(ParameterBlock const& parameterBlock) { - return false; + ObjectID outGlobalSessionId = 0; + ParameterDecoder::decodeAddress(parameterBlock.outputBuffer, parameterBlock.outputBufferSize, outGlobalSessionId); + + for (auto consumer: m_consumers) + { + consumer->CreateGlobalSession(outGlobalSessionId); + } + return true; } bool SlangDecoder::IGlobalSession_createSession(ObjectID objectId, ParameterBlock const& parameterBlock) diff --git a/source/slang-record-replay/replay/slang-decoder.h b/source/slang-record-replay/replay/slang-decoder.h index f127ebc85..78c3128ba 100644 --- a/source/slang-record-replay/replay/slang-decoder.h +++ b/source/slang-record-replay/replay/slang-decoder.h @@ -28,6 +28,8 @@ namespace SlangRecord SlangDecoder() {}; ~SlangDecoder() {}; + void addConsumer(IDecoderConsumer* consumer) { m_consumers.add(consumer); } + bool processMethodCall(FunctionHeader const& header, ParameterBlock const& parameterBlock); bool processFunctionCall(FunctionHeader const& header, ParameterBlock const& parameterBlock); @@ -38,7 +40,7 @@ namespace SlangRecord bool processICompositeComponentTypeMethods(ApiCallId callId, ObjectID objectId, ParameterBlock const& parameterBlock); bool processITypeConformanceMethods(ApiCallId callId, ObjectID objectId, ParameterBlock const& parameterBlock); - bool CreateGlobalSession(ObjectID objectId, ParameterBlock const& parameterBlock); + bool CreateGlobalSession(ParameterBlock const& parameterBlock); bool IGlobalSession_createSession(ObjectID objectId, ParameterBlock const& parameterBlock); void IGlobalSession_findProfile(ObjectID objectId, ParameterBlock const& parameterBlock); void IGlobalSession_setDownstreamCompilerPath(ObjectID objectId, ParameterBlock const& parameterBlock); diff --git a/source/slang-record-replay/util/emum-to-string.h b/source/slang-record-replay/util/emum-to-string.h new file mode 100644 index 000000000..f06631719 --- /dev/null +++ b/source/slang-record-replay/util/emum-to-string.h @@ -0,0 +1,437 @@ +#include "slang.h" + +namespace SlangRecord +{ + static Slang::String SlangCompileTargetToString(const SlangCompileTarget target) + { +#define CASE(x) case x: return #x + + switch(target) + { + CASE(SLANG_TARGET_UNKNOWN); + CASE(SLANG_GLSL); + CASE(SLANG_GLSL_VULKAN_DEPRECATED); + CASE(SLANG_GLSL_VULKAN_ONE_DESC_DEPRECATED); + CASE(SLANG_HLSL); + CASE(SLANG_SPIRV); + CASE(SLANG_SPIRV_ASM); + CASE(SLANG_DXBC); + CASE(SLANG_DXIL); + CASE(SLANG_DXIL_ASM); + CASE(SLANG_C_SOURCE); + CASE(SLANG_CPP_SOURCE); + CASE(SLANG_HOST_EXECUTABLE); + CASE(SLANG_SHADER_SHARED_LIBRARY); + CASE(SLANG_SHADER_HOST_CALLABLE); + CASE(SLANG_CUDA_SOURCE); + CASE(SLANG_PTX); + CASE(SLANG_CUDA_OBJECT_CODE); + CASE(SLANG_OBJECT_CODE); + CASE(SLANG_HOST_CPP_SOURCE); + CASE(SLANG_HOST_HOST_CALLABLE); + CASE(SLANG_CPP_PYTORCH_BINDING); + CASE(SLANG_METAL); + CASE(SLANG_METAL_LIB); + CASE(SLANG_METAL_LIB_ASM); + CASE(SLANG_HOST_SHARED_LIBRARY); + CASE(SLANG_TARGET_COUNT_OF); + default: + Slang::StringBuilder str; + str << "Unknown SlangCompileTarget: " << static_cast<uint32_t>(target); + return str.toString(); + } +#undef CASE + } + + static Slang::String SlangProfileIDToString(const SlangProfileID profile) + { + switch(profile) + { + case SLANG_PROFILE_UNKNOWN: + return "SLANG_PROFILE_UNKNOWN"; + default: + Slang::StringBuilder str; + str << "Unknown SlangProfileID: " << static_cast<uint32_t>(profile); + return str.toString(); + } + } + + static Slang::String SlangTargetFlagsToString(const SlangTargetFlags flags) + { + switch(flags) + { + case SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES: + return "SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES"; + case SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM: + return "SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM"; + case SLANG_TARGET_FLAG_DUMP_IR: + return "SLANG_TARGET_FLAG_DUMP_IR"; + case SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY: + return "SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY"; + default: + Slang::StringBuilder str; + str << "Unknown SlangTargetFlags: " << static_cast<uint32_t>(flags); + return str.toString(); + } + } + + static Slang::String SlangFloatingPointModeToString(const SlangFloatingPointMode mode) + { + switch(mode) + { + case SLANG_FLOATING_POINT_MODE_DEFAULT: + return "SLANG_FLOATING_POINT_MODE_DEFAULT"; + case SLANG_FLOATING_POINT_MODE_FAST: + return "SLANG_FLOATING_POINT_MODE_FAST"; + case SLANG_FLOATING_POINT_MODE_PRECISE: + return "SLANG_FLOATING_POINT_MODE_PRECISE"; + default: + Slang::StringBuilder str; + str << "Unknown SlangFloatingPointMode: " << static_cast<uint32_t>(mode); + return str.toString(); + } + } + + static Slang::String SlangLineDirectiveModeToString(const SlangLineDirectiveMode mode) + { + switch(mode) + { + case SLANG_LINE_DIRECTIVE_MODE_DEFAULT: + return "SLANG_LINE_DIRECTIVE_MODE_DEFAULT"; + case SLANG_LINE_DIRECTIVE_MODE_NONE: + return "SLANG_LINE_DIRECTIVE_MODE_NONE"; + case SLANG_LINE_DIRECTIVE_MODE_STANDARD: + return "SLANG_LINE_DIRECTIVE_MODE_STANDARD"; + case SLANG_LINE_DIRECTIVE_MODE_GLSL: + return "SLANG_LINE_DIRECTIVE_MODE_GLSL"; + case SLANG_LINE_DIRECTIVE_MODE_SOURCE_MAP: + return "SLANG_LINE_DIRECTIVE_MODE_SOURCE_MAP"; + default: + Slang::StringBuilder str; + str << "Unknown SlangLineDirectiveMode: " << static_cast<uint32_t>(mode); + return str.toString(); + } + } + + static Slang::String CompilerOptionNameToString(const slang::CompilerOptionName name) + { +#define CASE(x) case CompilerOptionName::x: return #x + + using namespace slang; + switch(name) + { + CASE(MacroDefine); + CASE(DepFile); + CASE(EntryPointName); + CASE(Specialize); + CASE(Help); + CASE(HelpStyle); + CASE(Include); + CASE(Language); + CASE(MatrixLayoutColumn); + CASE(MatrixLayoutRow); + CASE(ZeroInitialize); + CASE(IgnoreCapabilities); + CASE(RestrictiveCapabilityCheck); + CASE(ModuleName); + CASE(Output); + CASE(Profile); + CASE(Stage); + CASE(Target); + CASE(Version); + CASE(WarningsAsErrors); + CASE(DisableWarnings); + CASE(EnableWarning); + CASE(DisableWarning); + CASE(DumpWarningDiagnostics); + CASE(InputFilesRemain); + CASE(EmitIr); + CASE(ReportDownstreamTime); + CASE(ReportPerfBenchmark); + CASE(SkipSPIRVValidation); + CASE(SourceEmbedStyle); + CASE(SourceEmbedName); + CASE(SourceEmbedLanguage); + CASE(DisableShortCircuit); + CASE(MinimumSlangOptimization); + CASE(DisableNonEssentialValidations); + CASE(DisableSourceMap); + CASE(UnscopedEnum); + CASE(PreserveParameters); + CASE(Capability); + CASE(DefaultImageFormatUnknown); + CASE(DisableDynamicDispatch); + CASE(DisableSpecialization); + CASE(FloatingPointMode); + CASE(DebugInformation); + CASE(LineDirectiveMode); + CASE(Optimization); + CASE(Obfuscate); + CASE(VulkanBindShift); + CASE(VulkanBindGlobals); + CASE(VulkanInvertY); + CASE(VulkanUseDxPositionW); + CASE(VulkanUseEntryPointName); + CASE(VulkanUseGLLayout); + CASE(VulkanEmitReflection); + CASE(GLSLForceScalarLayout); + CASE(EnableEffectAnnotations); + CASE(EmitSpirvViaGLSL); + CASE(EmitSpirvDirectly); + CASE(SPIRVCoreGrammarJSON); + CASE(IncompleteLibrary); + CASE(CompilerPath); + CASE(DefaultDownstreamCompiler); + CASE(DownstreamArgs); + CASE(PassThrough); + CASE(DumpRepro); + CASE(DumpReproOnError); + CASE(ExtractRepro); + CASE(LoadRepro); + CASE(LoadReproDirectory); + CASE(ReproFallbackDirectory); + CASE(DumpAst); + CASE(DumpIntermediatePrefix); + CASE(DumpIntermediates); + CASE(DumpIr); + CASE(DumpIrIds); + CASE(PreprocessorOutput); + CASE(OutputIncludes); + CASE(ReproFileSystem); + CASE(SerialIr); + CASE(SkipCodeGen); + CASE(ValidateIr); + CASE(VerbosePaths); + CASE(VerifyDebugSerialIr); + CASE(NoCodeGen); + CASE(FileSystem); + CASE(Heterogeneous); + CASE(NoMangle); + CASE(NoHLSLBinding); + CASE(NoHLSLPackConstantBufferElements); + CASE(ValidateUniformity); + CASE(AllowGLSL); + CASE(ArchiveType); + CASE(CompileStdLib); + CASE(Doc); + CASE(IrCompression); + CASE(LoadStdLib); + CASE(ReferenceModule); + CASE(SaveStdLib); + CASE(SaveStdLibBinSource); + CASE(TrackLiveness); + CASE(LoopInversion); + CASE(CountOfParsableOptions); + CASE(DebugInformationFormat); + CASE(VulkanBindShiftAll); + CASE(GenerateWholeProgram); + CASE(UseUpToDateBinaryModule); + CASE(CountOf); + default: + Slang::StringBuilder str; + str << "Unknown CompilerOptionName: " << static_cast<uint32_t>(name); + return str.toString(); + } +#undef CASE + } + + static Slang::String CompilerOptionValueKindToString(const slang::CompilerOptionValueKind kind) + { + using namespace slang; + switch(kind) + { + case CompilerOptionValueKind::Int: + return "Int"; + case CompilerOptionValueKind::String: + return "String"; + default: + Slang::StringBuilder str; + str << "Unknown CompilerOptionValueKind: " << static_cast<uint32_t>(kind); + return str.toString(); + } + } + + static Slang::String SessionFlagsToString(const slang::SessionFlags flags) + { + using namespace slang; + switch(flags) + { + case kSessionFlags_None: return "kSessionFlags_None"; + default: + Slang::StringBuilder str; + str << "Unknown SessionFlags: " << static_cast<uint32_t>(flags); + return str.toString(); + } + } + + static Slang::String SlangMatrixLayoutModeToString(const SlangMatrixLayoutMode mode) + { + switch(mode) + { + case SLANG_MATRIX_LAYOUT_MODE_UNKNOWN: return "SLANG_MATRIX_LAYOUT_MODE_UNKNOWN"; + case SLANG_MATRIX_LAYOUT_ROW_MAJOR: return "SLANG_MATRIX_LAYOUT_ROW_MAJOR"; + case SLANG_MATRIX_LAYOUT_COLUMN_MAJOR: return "SLANG_MATRIX_LAYOUT_COLUMN_MAJOR"; + default: + Slang::StringBuilder str; + str << "Unknown SlangMatrixLayoutMode: " << static_cast<uint32_t>(mode); + return str.toString(); + } + } + + static Slang::String SlangPassThroughToString(const SlangPassThrough passThrough) + { +#define CASE(x) case x: return #x + + switch(passThrough) + { + CASE(SLANG_PASS_THROUGH_NONE); + CASE(SLANG_PASS_THROUGH_FXC); + CASE(SLANG_PASS_THROUGH_DXC); + CASE(SLANG_PASS_THROUGH_GLSLANG); + CASE(SLANG_PASS_THROUGH_SPIRV_DIS); + CASE(SLANG_PASS_THROUGH_CLANG); + CASE(SLANG_PASS_THROUGH_VISUAL_STUDIO); + CASE(SLANG_PASS_THROUGH_GCC); + CASE(SLANG_PASS_THROUGH_GENERIC_C_CPP); + CASE(SLANG_PASS_THROUGH_NVRTC); + CASE(SLANG_PASS_THROUGH_LLVM); + CASE(SLANG_PASS_THROUGH_SPIRV_OPT); + CASE(SLANG_PASS_THROUGH_METAL); + CASE(SLANG_PASS_THROUGH_COUNT_OF); + default: + Slang::StringBuilder str; + str << "Unknown SlangPassThrough: " << static_cast<uint32_t>(passThrough); + return str.toString(); + } +#undef CASE + } + + static Slang::String SlangSourceLanguageToString(const SlangSourceLanguage language) + { +#define CASE(x) case x: return #x + + switch(language) + { + CASE(SLANG_SOURCE_LANGUAGE_UNKNOWN); + CASE(SLANG_SOURCE_LANGUAGE_SLANG); + CASE(SLANG_SOURCE_LANGUAGE_HLSL); + CASE(SLANG_SOURCE_LANGUAGE_GLSL); + CASE(SLANG_SOURCE_LANGUAGE_C); + CASE(SLANG_SOURCE_LANGUAGE_CPP); + CASE(SLANG_SOURCE_LANGUAGE_CUDA); + CASE(SLANG_SOURCE_LANGUAGE_SPIRV); + CASE(SLANG_SOURCE_LANGUAGE_METAL); + CASE(SLANG_SOURCE_LANGUAGE_COUNT_OF); + default: + Slang::StringBuilder str; + str << "Unknown SlangSourceLanguage: " << static_cast<uint32_t>(language); + return str.toString(); + } + } + + static Slang::String CompileStdLibFlagsToString(const slang::CompileStdLibFlags flags) + { + using namespace slang; + switch(flags) + { + case CompileStdLibFlag::WriteDocumentation: return "WriteDocumentation"; + default: + Slang::StringBuilder str; + str << "Unknown CompileStdLibFlags: " << static_cast<uint32_t>(flags); + return str.toString(); + } + } + + static Slang::String SlangArchiveTypeToString(const SlangArchiveType type) + { +#define CASE(x) case x: return #x + switch(type) + { + CASE(SLANG_ARCHIVE_TYPE_UNDEFINED); + CASE(SLANG_ARCHIVE_TYPE_ZIP); + CASE(SLANG_ARCHIVE_TYPE_RIFF); + CASE(SLANG_ARCHIVE_TYPE_RIFF_DEFLATE); + CASE(SLANG_ARCHIVE_TYPE_RIFF_LZ4); + CASE(SLANG_ARCHIVE_TYPE_COUNT_OF); + default: + Slang::StringBuilder str; + str << "Unknown SlangArchiveType: " << static_cast<uint32_t>(type); + return str.toString(); + } + } + + static Slang::String SpecializationArgKindToString(const slang::SpecializationArg::Kind kind) + { + using namespace slang; + switch(kind) + { + case SpecializationArg::Kind::Unknown: return "Unknown"; + case SpecializationArg::Kind::Type: return "Type"; + default: + Slang::StringBuilder str; + str << "Unknown SpecializationArg::Kind: " << static_cast<uint32_t>(kind); + return str.toString(); + } + } + + static Slang::String LayoutRulesToString(const slang::LayoutRules rules) + { + using namespace slang; + switch(rules) + { + case LayoutRules::Default: return "Default"; + case LayoutRules::MetalArgumentBufferTier2: return "MetalArgumentBufferTier2"; + default: + Slang::StringBuilder str; + str << "Unknown LayoutRules: " << static_cast<uint32_t>(rules); + return str.toString(); + } + } + // enum SlangStage : SlangStageIntegral + // { + // SLANG_STAGE_NONE, + // SLANG_STAGE_VERTEX, + // SLANG_STAGE_HULL, + // SLANG_STAGE_DOMAIN, + // SLANG_STAGE_GEOMETRY, + // SLANG_STAGE_FRAGMENT, + // SLANG_STAGE_COMPUTE, + // SLANG_STAGE_RAY_GENERATION, + // SLANG_STAGE_INTERSECTION, + // SLANG_STAGE_ANY_HIT, + // SLANG_STAGE_CLOSEST_HIT, + // SLANG_STAGE_MISS, + // SLANG_STAGE_CALLABLE, + // SLANG_STAGE_MESH, + // SLANG_STAGE_AMPLIFICATION, + // }; + + static Slang::String SlangStageToString(const SlangStage stage) + { +#define CASE(x) case x: return #x + + switch(stage) + { + CASE(SLANG_STAGE_NONE); + CASE(SLANG_STAGE_VERTEX); + CASE(SLANG_STAGE_HULL); + CASE(SLANG_STAGE_DOMAIN); + CASE(SLANG_STAGE_GEOMETRY); + CASE(SLANG_STAGE_FRAGMENT); + CASE(SLANG_STAGE_COMPUTE); + CASE(SLANG_STAGE_RAY_GENERATION); + CASE(SLANG_STAGE_INTERSECTION); + CASE(SLANG_STAGE_ANY_HIT); + CASE(SLANG_STAGE_CLOSEST_HIT); + CASE(SLANG_STAGE_MISS); + CASE(SLANG_STAGE_CALLABLE); + CASE(SLANG_STAGE_MESH); + CASE(SLANG_STAGE_AMPLIFICATION); + default: + Slang::StringBuilder str; + str << "Unknown SlangStage: " << static_cast<uint32_t>(stage); + return str.toString(); + } +#undef CASE + } +} diff --git a/source/slang-record-replay/util/record-utility.cpp b/source/slang-record-replay/util/record-utility.cpp index 8bf89ea67..ea7618e81 100644 --- a/source/slang-record-replay/util/record-utility.cpp +++ b/source/slang-record-replay/util/record-utility.cpp @@ -6,6 +6,7 @@ #include <mutex> #include "record-utility.h" +#include "../../core/slang-string-util.h" constexpr const char* kRecordLayerEnvVar = "SLANG_RECORD_LAYER"; constexpr const char* kRecordLayerLogLevel = "SLANG_RECORD_LOG_LEVEL"; @@ -74,9 +75,13 @@ namespace SlangRecord return; } + Slang::StringBuilder builder; + va_list args; va_start(args, fmt); - vfprintf(stdout, fmt, args); + Slang::StringUtil::append(fmt, args, builder); va_end(args); + + fprintf(stdout, "[slang-record-replay]: %s", builder.begin()); } } diff --git a/tools/slang-replay/main.cpp b/tools/slang-replay/main.cpp index 7f042f91b..adce34c56 100644 --- a/tools/slang-replay/main.cpp +++ b/tools/slang-replay/main.cpp @@ -1,10 +1,108 @@ #include <stdio.h> +#include <filesystem> + #include <replay/recordFile-processor.h> -#include <replay/decoder-consumer.h> +#include <replay/json-consumer.h> +#include <replay/replay-consumer.h> +#include <replay/slang-decoder.h> + +struct Options +{ + bool convertToJson {false}; + Slang::String recordFileName; +}; + +void printUsage() +{ + printf("Usage: slang-replay [options] <record-file>\n"); + printf("Options:\n"); + printf(" --convert-json, -cj: Convert the record file to a JSON file in the same directory with record file.\n\ + When this option is set, it won't replay the record file.\n"); +} + +Options parseOption(int argc, char *argv[]) +{ + Options option; + char const* arg {}; + if (argc <= 1) + { + printUsage(); + exit(1); + } + + int argIndex = 1; + while(argIndex < argc) + { + arg = argv[argIndex]; + + // For anything not starting with a '-', it is a file name + if (arg[0] != '-') + { + option.recordFileName = arg; + argIndex++; + } + else if ( (strcmp("--convert-json", arg) == 0) || + (strcmp("-cj", arg) == 0) ) + { + option.convertToJson = true; + argIndex++; + } + else if ( (strcmp("--help", arg) == 0) || + (strcmp("-h", arg) == 0) ) + { + printUsage(); + exit(0); + } + else + { + // Unknown option + printf("Unknown option: %s\n", arg); + printUsage(); + exit(1); + } + } + + if (option.recordFileName.getLength() == 0) + { + printUsage(); + exit(1); + } + + return option; +} int main(int argc, char *argv[]) { - // TODO: This is just a place holder binary - SlangRecord::RecordFileProcessor recordFileProcessor("input.capture"); + Options options = parseOption(argc, argv); + + SlangRecord::RecordFileProcessor recordFileProcessor(options.recordFileName); + + + std::filesystem::path jsonPath = options.recordFileName.begin(); + jsonPath.replace_extension(".json"); + + SlangRecord::JsonConsumer jsonConsumer(jsonPath.string()); + SlangRecord::ReplayConsumer replayConsumer; + + SlangRecord::SlangDecoder decoder; + + if (options.convertToJson) + { + decoder.addConsumer(&jsonConsumer); + } + else + { + decoder.addConsumer(&replayConsumer); + } + + recordFileProcessor.addDecoder(&decoder); + + while(true) + { + if(!recordFileProcessor.processNextBlock()) + { + break; + } + } return 0; } |
