summaryrefslogtreecommitdiff
path: root/source/slang-capture-replay/slang-session.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-05-08 09:13:45 -0700
committerGitHub <noreply@github.com>2024-05-08 09:13:45 -0700
commit4f2330d059ab5943ddf33bfed37be6a0378d43a8 (patch)
tree9e3a0790deee6248343d49a644ab9f0be7909901 /source/slang-capture-replay/slang-session.cpp
parenteb3970897049269602cc18cee644e437c0aff928 (diff)
capture/replay: interface implementation 1 (#4122)
* capture/replay: interface implementation 1 - Add global session, filesystem, and session capture interface classes: GlobalSessionCapture for IGlobalSession FileSystemCapture for ISlangFileSystemExt SessionCapture for ISession - Add environment variables to enable it The 2 variables are SLANG_CAPTURE_LAYER and SLANG_CAPTURE_LOG_LEVEL SLANG_CAPTURE_LAYER: In slang_createGlobalSession(), after the compiling/loading stdlib, we will check the capture environment variable, if it's set to 1, we will create a GlobalSessionCapture object and return to user code. SLANG_CAPTURE_LOG_LEVEL: This is to set the log level, user can choose the loglevel to debug. (We can remove this when the feature is fully implemented). - Update premake file and cmake file to add the capture/replay source folder * Fix Windows build error Fix windows build error by adding the "SLANG_MCALL" keyword. Change to use Slang::ComPtr for those captured object pointers to simplify the resource management. Use __func__ macro to print the function name in the log.
Diffstat (limited to 'source/slang-capture-replay/slang-session.cpp')
-rw-r--r--source/slang-capture-replay/slang-session.cpp196
1 files changed, 196 insertions, 0 deletions
diff --git a/source/slang-capture-replay/slang-session.cpp b/source/slang-capture-replay/slang-session.cpp
new file mode 100644
index 000000000..3d96af6d7
--- /dev/null
+++ b/source/slang-capture-replay/slang-session.cpp
@@ -0,0 +1,196 @@
+#include "capture_utility.h"
+#include "slang-session.h"
+
+namespace SlangCapture
+{
+
+ SessionCapture::SessionCapture(slang::ISession* session)
+ : m_actualSession(session)
+ {
+ assert(m_actualSession);
+ slangCaptureLog(LogLevel::Verbose, "%s: %p\n", "Session", session);
+ }
+
+ SessionCapture::~SessionCapture()
+ {
+ m_actualSession->release();
+ }
+
+ ISlangUnknown* SessionCapture::getInterface(const Guid& guid)
+ {
+ if(guid == ISlangUnknown::getTypeGuid() || guid == ISession::getTypeGuid())
+ return asExternal(this);
+
+ return nullptr;
+ }
+
+ SLANG_NO_THROW slang::IGlobalSession* SessionCapture::getGlobalSession()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IGlobalSession* pGlobalSession = m_actualSession->getGlobalSession();
+ return pGlobalSession;
+ }
+
+ SLANG_NO_THROW slang::IModule* SessionCapture::loadModule(
+ const char* moduleName,
+ slang::IBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IModule* pModule = m_actualSession->loadModule(moduleName, outDiagnostics);
+ return pModule;
+ }
+
+ SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromIRBlob(
+ const char* moduleName,
+ const char* path,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IModule* pModule = m_actualSession->loadModuleFromIRBlob(moduleName, path, source, outDiagnostics);
+ return pModule;
+ }
+
+ SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromSource(
+ const char* moduleName,
+ const char* path,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IModule* pModule = m_actualSession->loadModuleFromSource(moduleName, path, source, outDiagnostics);
+ return pModule;
+ }
+
+ SLANG_NO_THROW slang::IModule* SessionCapture::loadModuleFromSourceString(
+ const char* moduleName,
+ const char* path,
+ const char* string,
+ slang::IBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IModule* pModule = m_actualSession->loadModuleFromSourceString(moduleName, path, string, outDiagnostics);
+ return pModule;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::createCompositeComponentType(
+ slang::IComponentType* const* componentTypes,
+ SlangInt componentTypeCount,
+ slang::IComponentType** outCompositeComponentType,
+ ISlangBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->createCompositeComponentType(componentTypes, componentTypeCount, outCompositeComponentType, outDiagnostics);
+ return result;
+ }
+
+ SLANG_NO_THROW slang::TypeReflection* SessionCapture::specializeType(
+ slang::TypeReflection* type,
+ slang::SpecializationArg const* specializationArgs,
+ SlangInt specializationArgCount,
+ ISlangBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::TypeReflection* pTypeReflection = m_actualSession->specializeType(type, specializationArgs, specializationArgCount, outDiagnostics);
+ return pTypeReflection;
+ }
+
+ SLANG_NO_THROW slang::TypeLayoutReflection* SessionCapture::getTypeLayout(
+ slang::TypeReflection* type,
+ SlangInt targetIndex,
+ slang::LayoutRules rules,
+ ISlangBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::TypeLayoutReflection* pTypeLayoutReflection = m_actualSession->getTypeLayout(type, targetIndex, rules, outDiagnostics);
+ return pTypeLayoutReflection;
+ }
+
+ SLANG_NO_THROW slang::TypeReflection* SessionCapture::getContainerType(
+ slang::TypeReflection* elementType,
+ slang::ContainerType containerType,
+ ISlangBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::TypeReflection* pTypeReflection = m_actualSession->getContainerType(elementType, containerType, outDiagnostics);
+ return pTypeReflection;
+ }
+
+ SLANG_NO_THROW slang::TypeReflection* SessionCapture::getDynamicType()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::TypeReflection* pTypeReflection = m_actualSession->getDynamicType();
+ return pTypeReflection;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::getTypeRTTIMangledName(
+ slang::TypeReflection* type,
+ ISlangBlob** outNameBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->getTypeRTTIMangledName(type, outNameBlob);
+ return result;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::getTypeConformanceWitnessMangledName(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ ISlangBlob** outNameBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->getTypeConformanceWitnessMangledName(type, interfaceType, outNameBlob);
+ return result;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::getTypeConformanceWitnessSequentialID(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ uint32_t* outId)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->getTypeConformanceWitnessSequentialID(type, interfaceType, outId);
+ return result;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::createTypeConformanceComponentType(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ slang::ITypeConformance** outConformance,
+ SlangInt conformanceIdOverride,
+ ISlangBlob** outDiagnostics)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->createTypeConformanceComponentType(type, interfaceType, outConformance, conformanceIdOverride, outDiagnostics);
+ return result;
+ }
+
+ SLANG_NO_THROW SlangResult SessionCapture::createCompileRequest(
+ SlangCompileRequest** outCompileRequest)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangResult result = m_actualSession->createCompileRequest(outCompileRequest);
+ return result;
+ }
+
+ SLANG_NO_THROW SlangInt SessionCapture::getLoadedModuleCount()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ SlangInt count = m_actualSession->getLoadedModuleCount();
+ return count;
+ }
+
+ SLANG_NO_THROW slang::IModule* SessionCapture::getLoadedModule(SlangInt index)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ slang::IModule* pModule = m_actualSession->getLoadedModule(index);
+ return pModule;
+ }
+
+ SLANG_NO_THROW bool SessionCapture::isBinaryModuleUpToDate(const char* modulePath, slang::IBlob* binaryModuleBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%s\n", __func__);
+ bool result = m_actualSession->isBinaryModuleUpToDate(modulePath, binaryModuleBlob);
+ return result;
+ }
+
+} // namespace SlangCapture