summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--build/visual-studio/slang/slang.vcxproj10
-rw-r--r--build/visual-studio/slang/slang.vcxproj.filters30
-rw-r--r--premake5.lua3
-rw-r--r--source/slang-capture-replay/capture_utility.cpp82
-rw-r--r--source/slang-capture-replay/capture_utility.h18
-rw-r--r--source/slang-capture-replay/slang-filesystem.cpp100
-rw-r--r--source/slang-capture-replay/slang-filesystem.h69
-rw-r--r--source/slang-capture-replay/slang-global-session.cpp222
-rw-r--r--source/slang-capture-replay/slang-global-session.h71
-rw-r--r--source/slang-capture-replay/slang-session.cpp196
-rw-r--r--source/slang-capture-replay/slang-session.h99
-rw-r--r--source/slang/CMakeLists.txt5
-rw-r--r--source/slang/slang-api.cpp15
13 files changed, 911 insertions, 9 deletions
diff --git a/build/visual-studio/slang/slang.vcxproj b/build/visual-studio/slang/slang.vcxproj
index ee281252d..1c4761507 100644
--- a/build/visual-studio/slang/slang.vcxproj
+++ b/build/visual-studio/slang/slang.vcxproj
@@ -308,6 +308,10 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\slang.h" />
+ <ClInclude Include="..\..\..\source\slang-capture-replay\capture_utility.h" />
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-filesystem.h" />
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-global-session.h" />
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-session.h" />
<ClInclude Include="..\..\..\source\slang\slang-artifact-output-util.h" />
<ClInclude Include="..\..\..\source\slang\slang-ast-all.h" />
<ClInclude Include="..\..\..\source\slang\slang-ast-base.h" />
@@ -348,8 +352,6 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
<ClInclude Include="..\..\..\source\slang\slang-emit-spirv-ops-debug-info-ext.h" />
<ClInclude Include="..\..\..\source\slang\slang-emit-spirv-ops.h" />
<ClInclude Include="..\..\..\source\slang\slang-emit-torch.h" />
- <ClInclude Include="..\..\..\source\slang\slang-generated-capability-defs-impl.h" />
- <ClInclude Include="..\..\..\source\slang\slang-generated-capability-defs.h" />
<ClInclude Include="..\..\..\source\slang\slang-glsl-extension-tracker.h" />
<ClInclude Include="..\..\..\source\slang\slang-hlsl-to-vulkan-layout-options.h" />
<ClInclude Include="..\..\..\source\slang\slang-image-format-defs.h" />
@@ -539,6 +541,10 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
<ClCompile Include="..\..\..\prelude\slang-cuda-prelude.h.cpp" />
<ClCompile Include="..\..\..\prelude\slang-hlsl-prelude.h.cpp" />
<ClCompile Include="..\..\..\prelude\slang-torch-prelude.h.cpp" />
+ <ClCompile Include="..\..\..\source\slang-capture-replay\capture_utility.cpp" />
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-filesystem.cpp" />
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-global-session.cpp" />
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-session.cpp" />
<ClCompile Include="..\..\..\source\slang\slang-api.cpp" />
<ClCompile Include="..\..\..\source\slang\slang-artifact-output-util.cpp" />
<ClCompile Include="..\..\..\source\slang\slang-ast-base.cpp" />
diff --git a/build/visual-studio/slang/slang.vcxproj.filters b/build/visual-studio/slang/slang.vcxproj.filters
index f87a64ab1..b6789b77e 100644
--- a/build/visual-studio/slang/slang.vcxproj.filters
+++ b/build/visual-studio/slang/slang.vcxproj.filters
@@ -12,6 +12,18 @@
<ClInclude Include="..\..\..\slang.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\source\slang-capture-replay\capture_utility.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-filesystem.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-global-session.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\source\slang-capture-replay\slang-session.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\..\..\source\slang\slang-artifact-output-util.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -132,12 +144,6 @@
<ClInclude Include="..\..\..\source\slang\slang-emit-torch.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\source\slang\slang-generated-capability-defs-impl.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\..\source\slang\slang-generated-capability-defs.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\source\slang\slang-glsl-extension-tracker.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -701,6 +707,18 @@
<ClCompile Include="..\..\..\prelude\slang-torch-prelude.h.cpp">
<Filter>Header Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\..\source\slang-capture-replay\capture_utility.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-filesystem.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-global-session.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\source\slang-capture-replay\slang-session.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="..\..\..\source\slang\slang-api.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/premake5.lua b/premake5.lua
index b14844c8e..28dacf6b5 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -1609,6 +1609,8 @@ if enableEmbedStdLib then
"source/slang/slang-lookup-glslstd450.cpp",
"source/slang/slang-lookup-capability-defs.cpp"
}
+ addSourceDir("source/slang-capture-replay")
+
if not targetInfo.isWindows then
links { "pthread" }
end
@@ -1732,6 +1734,7 @@ standardProject("slang", "source/slang")
"source/slang/slang-generated-capability-defs-impl.h",
}
+ addSourceDir("source/slang-capture-replay")
--
-- The most challenging part of building `slang` is that we need
-- to invoke generators such as slang-cpp-extractor and slang-generate
diff --git a/source/slang-capture-replay/capture_utility.cpp b/source/slang-capture-replay/capture_utility.cpp
new file mode 100644
index 000000000..550edb64f
--- /dev/null
+++ b/source/slang-capture-replay/capture_utility.cpp
@@ -0,0 +1,82 @@
+
+#include <cstring>
+#include <string>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <mutex>
+
+#include "capture_utility.h"
+
+constexpr const char* kCaptureLayerEnvVar = "SLANG_CAPTURE_LAYER";
+constexpr const char* kCaptureLayerLogLevel = "SLANG_CAPTURE_LOG_LEVEL";
+
+namespace SlangCapture
+{
+ static thread_local unsigned int g_logLevel = LogLevel::Silent;
+
+ static bool getEnvironmentVariable(const char* name, std::string& out)
+ {
+#ifdef _WIN32
+ char* envVar = nullptr;
+ size_t sz = 0;
+ if (_dupenv_s(&envVar, &sz, name) == 0 && envVar != nullptr)
+ {
+ out = envVar;
+ free(envVar);
+ }
+#else
+ if (const char* envVar = std::getenv(name))
+ {
+ out = envVar;
+ }
+#endif
+ return out.empty() == false;
+ }
+
+ bool isCaptureLayerEnabled()
+ {
+ std::string envVarStr;
+ if(getEnvironmentVariable(kCaptureLayerEnvVar, envVarStr))
+ {
+ if (envVarStr == "1")
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void setLogLevel()
+ {
+ // We only want to set the log level once
+ if (g_logLevel != LogLevel::Silent)
+ {
+ return;
+ }
+
+ std::string envVarStr;
+ if (getEnvironmentVariable(kCaptureLayerLogLevel, envVarStr))
+ {
+ char* end = nullptr;
+ unsigned int logLevel = std::strtol(envVarStr.c_str(), &end, 10);
+ if (end && (*end == 0))
+ {
+ g_logLevel = std::min((unsigned int)(LogLevel::Verbose), logLevel);
+ return;
+ }
+ }
+ }
+
+ void slangCaptureLog(LogLevel logLevel, const char* fmt, ...)
+ {
+ if (logLevel > g_logLevel)
+ {
+ return;
+ }
+
+ va_list args;
+ va_start(args, fmt);
+ vfprintf(stdout, fmt, args);
+ va_end(args);
+ }
+}
diff --git a/source/slang-capture-replay/capture_utility.h b/source/slang-capture-replay/capture_utility.h
new file mode 100644
index 000000000..db2939894
--- /dev/null
+++ b/source/slang-capture-replay/capture_utility.h
@@ -0,0 +1,18 @@
+#ifndef CAPTURE_UTILITY_H
+#define CAPTURE_UTILITY_H
+
+namespace SlangCapture
+{
+ enum LogLevel: unsigned int
+ {
+ Silent = 0,
+ Error = 1,
+ Debug = 2,
+ Verbose = 3,
+ };
+
+ bool isCaptureLayerEnabled();
+ void slangCaptureLog(LogLevel logLevel, const char* fmt, ...);
+ void setLogLevel();
+}
+#endif // CAPTURE_UTILITY_H
diff --git a/source/slang-capture-replay/slang-filesystem.cpp b/source/slang-capture-replay/slang-filesystem.cpp
new file mode 100644
index 000000000..10afbdf10
--- /dev/null
+++ b/source/slang-capture-replay/slang-filesystem.cpp
@@ -0,0 +1,100 @@
+#include "slang-filesystem.h"
+#include "capture_utility.h"
+
+namespace SlangCapture
+{
+ FileSystemCapture::FileSystemCapture(ISlangFileSystemExt* fileSystem)
+ : m_actualFileSystem(fileSystem)
+ {
+ assert(m_actualFileSystem);
+ slangCaptureLog(LogLevel::Verbose, "%s: %p\n", __func__, m_actualFileSystem.get());
+ }
+
+ FileSystemCapture::~FileSystemCapture()
+ {
+ m_actualFileSystem->release();
+ }
+
+ void* FileSystemCapture::castAs(const Slang::Guid& guid)
+ {
+ return getInterface(guid);
+ }
+
+ ISlangUnknown* FileSystemCapture::getInterface(const Slang::Guid& guid)
+ {
+ if(guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid())
+ return static_cast<ISlangFileSystem*>(this);
+ return nullptr;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::loadFile(
+ char const* path,
+ ISlangBlob** outBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->loadFile(path, outBlob);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getFileUniqueIdentity(
+ const char* path,
+ ISlangBlob** outUniqueIdentity)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s :\"%s\"\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getFileUniqueIdentity(path, outUniqueIdentity);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::calcCombinedPath(
+ SlangPathType fromPathType,
+ const char* fromPath,
+ const char* path,
+ ISlangBlob** pathOut)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->calcCombinedPath(fromPathType, fromPath, path, pathOut);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getPathType(
+ const char* path,
+ SlangPathType* pathTypeOut)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getPathType(path, pathTypeOut);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getPath(
+ PathKind kind,
+ const char* path,
+ ISlangBlob** outPath)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getPath(kind, path, outPath);
+ return res;
+ }
+
+ SLANG_NO_THROW void FileSystemCapture::clearCache()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __func__);
+ m_actualFileSystem->clearCache();
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::enumeratePathContents(
+ const char* path,
+ FileSystemContentsCallBack callback,
+ void* userData)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->enumeratePathContents(path, callback, userData);
+ return res;
+ }
+
+ SLANG_NO_THROW OSPathKind FileSystemCapture::getOSPathKind()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __func__);
+ OSPathKind pathKind = m_actualFileSystem->getOSPathKind();
+ return pathKind;
+ }
+}
diff --git a/source/slang-capture-replay/slang-filesystem.h b/source/slang-capture-replay/slang-filesystem.h
new file mode 100644
index 000000000..1d0d8be3e
--- /dev/null
+++ b/source/slang-capture-replay/slang-filesystem.h
@@ -0,0 +1,69 @@
+#ifndef SLANG_FILE_SYSTEM_H
+#define SLANG_FILE_SYSTEM_H
+
+#include "../core/slang-com-object.h"
+#include "../../slang-com-helper.h"
+#include "../../slang-com-ptr.h"
+
+namespace SlangCapture
+{
+
+ using namespace Slang;
+
+ // slang always requires ISlangFileSystemExt interface, even if user only provides ISlangFileSystem,
+ // slang will still wrap it with ISlangFileSystemExt. So we have to capture ISlangFileSystemExt, even
+ // though we only need to record loadFile() function.
+ class FileSystemCapture : public RefObject, public ISlangFileSystemExt
+ {
+ public:
+ explicit FileSystemCapture(ISlangFileSystemExt* fileSystem);
+ ~FileSystemCapture();
+
+ // ISlangUnknown
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+
+ ISlangUnknown* getInterface(const Slang::Guid& guid);
+
+ // ISlangCastable
+ virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Slang::Guid& guid) override;
+
+ // ISlangFileSystem
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(
+ char const* path,
+ ISlangBlob** outBlob) override;
+
+ // ISlangFileSystemExt
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getFileUniqueIdentity(
+ const char* path,
+ ISlangBlob** outUniqueIdentity) override;
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcCombinedPath(
+ SlangPathType fromPathType,
+ const char* fromPath,
+ const char* path,
+ ISlangBlob** pathOut) override;
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType(
+ const char* path,
+ SlangPathType* pathTypeOut) override;
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPath(
+ PathKind kind,
+ const char* path,
+ ISlangBlob** outPath) override;
+
+ virtual SLANG_NO_THROW void SLANG_MCALL clearCache() override;
+
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL enumeratePathContents(
+ const char* path,
+ FileSystemContentsCallBack callback,
+ void* userData) override;
+
+ virtual SLANG_NO_THROW OSPathKind SLANG_MCALL getOSPathKind() override;
+ private:
+ Slang::ComPtr<ISlangFileSystemExt> m_actualFileSystem;
+};
+
+}
+#endif
+
diff --git a/source/slang-capture-replay/slang-global-session.cpp b/source/slang-capture-replay/slang-global-session.cpp
new file mode 100644
index 000000000..e4754b9d2
--- /dev/null
+++ b/source/slang-capture-replay/slang-global-session.cpp
@@ -0,0 +1,222 @@
+
+#include <vector>
+#include "slang-global-session.h"
+#include "capture_utility.h"
+#include "slang-session.h"
+#include "slang-filesystem.h"
+#include "../slang/slang-compiler.h"
+
+namespace SlangCapture
+{
+ GlobalSessionCapture::GlobalSessionCapture(slang::IGlobalSession* session):
+ m_actualGlobalSession(session)
+ {
+ assert(m_actualGlobalSession != nullptr);
+ }
+
+ GlobalSessionCapture::~GlobalSessionCapture()
+ {
+ m_actualGlobalSession->release();
+ }
+
+ ISlangUnknown* GlobalSessionCapture::getInterface(const Guid& guid)
+ {
+ if(guid == ISlangUnknown::getTypeGuid() || guid == IGlobalSession::getTypeGuid())
+ return asExternal(this);
+ return nullptr;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::createSession(slang::SessionDesc const& desc, slang::ISession** outSession)
+ {
+ setLogLevel();
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+
+ slang::ISession* actualSession = nullptr;
+ SlangResult res = m_actualGlobalSession->createSession(desc, &actualSession);
+
+ if (actualSession != nullptr)
+ {
+ // reset the file system to our capture file system. After createSession() call,
+ // the Linkage will set to user provided file system or slang default file system.
+ // We need to reset it to our capture file system
+ Slang::Linkage* linkage = static_cast<Linkage*>(actualSession);
+ FileSystemCapture* fileSystemCapture = new FileSystemCapture(linkage->getFileSystemExt());
+
+ Slang::ComPtr<FileSystemCapture> resultFileSystemCapture(fileSystemCapture);
+ linkage->setFileSystem(resultFileSystemCapture.detach());
+
+ SessionCapture* sessionCapture = new SessionCapture(actualSession);
+ Slang::ComPtr<SessionCapture> result(sessionCapture);
+ *outSession = result.detach();
+ }
+
+ return res;
+ }
+
+ SLANG_NO_THROW SlangProfileID SLANG_MCALL GlobalSessionCapture::findProfile(char const* name)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangProfileID profileId = m_actualGlobalSession->findProfile(name);
+ return profileId;
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::setDownstreamCompilerPath(SlangPassThrough passThrough, char const* path)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->setDownstreamCompilerPath(passThrough, path);
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::setDownstreamCompilerPrelude(SlangPassThrough inPassThrough, char const* prelude)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->setDownstreamCompilerPrelude(inPassThrough, prelude);
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::getDownstreamCompilerPrelude(SlangPassThrough inPassThrough, ISlangBlob** outPrelude)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->getDownstreamCompilerPrelude(inPassThrough, outPrelude);
+ }
+
+ SLANG_NO_THROW const char* SLANG_MCALL GlobalSessionCapture::getBuildTagString()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ const char* resStr = m_actualGlobalSession->getBuildTagString();
+ return resStr;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::setDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->setDefaultDownstreamCompiler(sourceLanguage, defaultCompiler);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangPassThrough SLANG_MCALL GlobalSessionCapture::getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangPassThrough passThrough = m_actualGlobalSession->getDefaultDownstreamCompiler(sourceLanguage);
+ return passThrough;
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->setLanguagePrelude(inSourceLanguage, prelude);
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->getLanguagePrelude(inSourceLanguage, outPrelude);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::createCompileRequest(slang::ICompileRequest** outCompileRequest)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->createCompileRequest(outCompileRequest);
+ return res;
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::addBuiltins(char const* sourcePath, char const* sourceString)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->addBuiltins(sourcePath, sourceString);
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::setSharedLibraryLoader(ISlangSharedLibraryLoader* loader)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->setSharedLibraryLoader(loader);
+ }
+
+ SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL GlobalSessionCapture::getSharedLibraryLoader()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ ISlangSharedLibraryLoader* loader = m_actualGlobalSession->getSharedLibraryLoader();
+ return loader;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::checkCompileTargetSupport(SlangCompileTarget target)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->checkCompileTargetSupport(target);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::checkPassThroughSupport(SlangPassThrough passThrough)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->checkPassThroughSupport(passThrough);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::compileStdLib(slang::CompileStdLibFlags flags)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->compileStdLib(flags);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::loadStdLib(const void* stdLib, size_t stdLibSizeInBytes)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->loadStdLib(stdLib, stdLibSizeInBytes);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::saveStdLib(SlangArchiveType archiveType, ISlangBlob** outBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->saveStdLib(archiveType, outBlob);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangCapabilityID SLANG_MCALL GlobalSessionCapture::findCapability(char const* name)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangCapabilityID capId = m_actualGlobalSession->findCapability(name);
+ return capId;
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::setDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->setDownstreamCompilerForTransition(source, target, compiler);
+ }
+
+ SLANG_NO_THROW SlangPassThrough SLANG_MCALL GlobalSessionCapture::getDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangPassThrough passThrough = m_actualGlobalSession->getDownstreamCompilerForTransition(source, target);
+ return passThrough;
+ }
+
+ SLANG_NO_THROW void SLANG_MCALL GlobalSessionCapture::getCompilerElapsedTime(double* outTotalTime, double* outDownstreamTime)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ m_actualGlobalSession->getCompilerElapsedTime(outTotalTime, outDownstreamTime);
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::setSPIRVCoreGrammar(char const* jsonPath)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->setSPIRVCoreGrammar(jsonPath);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::parseCommandLineArguments(
+ int argc, const char* const* argv, slang::SessionDesc* outSessionDesc, ISlangUnknown** outAllocation)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->parseCommandLineArguments(argc, argv, outSessionDesc, outAllocation);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL GlobalSessionCapture::getSessionDescDigest(slang::SessionDesc* sessionDesc, ISlangBlob** outBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualGlobalSession.get(), __func__);
+ SlangResult res = m_actualGlobalSession->getSessionDescDigest(sessionDesc, outBlob);
+ return res;
+ }
+}
diff --git a/source/slang-capture-replay/slang-global-session.h b/source/slang-capture-replay/slang-global-session.h
new file mode 100644
index 000000000..52260ba21
--- /dev/null
+++ b/source/slang-capture-replay/slang-global-session.h
@@ -0,0 +1,71 @@
+#ifndef SLANG_GLOBAL_SESSION_H
+#define SLANG_GLOBAL_SESSION_H
+
+#include "../../slang-com-ptr.h"
+#include "../../slang.h"
+#include "../../slang-com-helper.h"
+#include "../core/slang-smart-pointer.h"
+
+namespace SlangCapture
+{
+ using namespace Slang;
+
+ class GlobalSessionCapture : public RefObject, public slang::IGlobalSession
+ {
+ public:
+ explicit GlobalSessionCapture(slang::IGlobalSession* session);
+ virtual ~GlobalSessionCapture();
+
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ // slang::IGlobalSession
+ SLANG_NO_THROW SlangResult SLANG_MCALL createSession(slang::SessionDesc const& desc, slang::ISession** outSession) override;
+ SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile(char const* name) override;
+ SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPath(SlangPassThrough passThrough, char const* path) override;
+ SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPrelude(SlangPassThrough inPassThrough, char const* prelude) override;
+ SLANG_NO_THROW void SLANG_MCALL getDownstreamCompilerPrelude(SlangPassThrough inPassThrough, ISlangBlob** outPrelude) override;
+ SLANG_NO_THROW const char* SLANG_MCALL getBuildTagString() override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL setDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) override;
+ SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override;
+
+ SLANG_NO_THROW void SLANG_MCALL setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude) override;
+ SLANG_NO_THROW void SLANG_MCALL getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude) override;
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL createCompileRequest(slang::ICompileRequest** outCompileRequest) override;
+
+ SLANG_NO_THROW void SLANG_MCALL addBuiltins(char const* sourcePath, char const* sourceString) override;
+ SLANG_NO_THROW void SLANG_MCALL setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) override;
+ SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL getSharedLibraryLoader() override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL checkCompileTargetSupport(SlangCompileTarget target) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL checkPassThroughSupport(SlangPassThrough passThrough) override;
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL compileStdLib(slang::CompileStdLibFlags flags) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL loadStdLib(const void* stdLib, size_t stdLibSizeInBytes) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL saveStdLib(SlangArchiveType archiveType, ISlangBlob** outBlob) override;
+
+ SLANG_NO_THROW SlangCapabilityID SLANG_MCALL findCapability(char const* name) override;
+
+ SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target, SlangPassThrough compiler) override;
+ SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDownstreamCompilerForTransition(SlangCompileTarget source, SlangCompileTarget target) override;
+ SLANG_NO_THROW void SLANG_MCALL getCompilerElapsedTime(double* outTotalTime, double* outDownstreamTime) override;
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL setSPIRVCoreGrammar(char const* jsonPath) override;
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL parseCommandLineArguments(
+ int argc, const char* const* argv, slang::SessionDesc* outSessionDesc, ISlangUnknown** outAllocation) override;
+
+ SLANG_NO_THROW SlangResult SLANG_MCALL getSessionDescDigest(slang::SessionDesc* sessionDesc, ISlangBlob** outBlob) override;
+
+ private:
+ SLANG_FORCE_INLINE slang::IGlobalSession* asExternal(GlobalSessionCapture* session)
+ {
+ return static_cast<slang::IGlobalSession*>(session);
+ }
+
+ Slang::ComPtr<slang::IGlobalSession> m_actualGlobalSession;
+ };
+} // namespace Slang
+
+#endif
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
diff --git a/source/slang-capture-replay/slang-session.h b/source/slang-capture-replay/slang-session.h
new file mode 100644
index 000000000..24903a1b2
--- /dev/null
+++ b/source/slang-capture-replay/slang-session.h
@@ -0,0 +1,99 @@
+#ifndef SLANG_SESSION_H
+#define SLANG_SESSION_H
+
+#include "../../slang-com-ptr.h"
+#include "../../slang.h"
+#include "../../slang-com-helper.h"
+#include "../core/slang-smart-pointer.h"
+#include "../slang/slang-compiler.h"
+
+namespace SlangCapture
+{
+ using namespace Slang;
+ class SessionCapture: public RefObject, public slang::ISession
+ {
+ public:
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ explicit SessionCapture(slang::ISession* session);
+ ~SessionCapture();
+
+ SLANG_NO_THROW slang::IGlobalSession* SLANG_MCALL getGlobalSession() override;
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModule(
+ const char* moduleName,
+ slang::IBlob** outDiagnostics = nullptr) override;
+ slang::IModule* SLANG_MCALL loadModuleFromBlob(
+ const char* moduleName,
+ const char* path,
+ slang::IBlob* source,
+ ModuleBlobType blobType,
+ slang::IBlob** outDiagnostics = nullptr);
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromIRBlob(
+ const char* moduleName,
+ const char* path,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromSource(
+ const char* moduleName,
+ const char* path,
+ slang::IBlob* source,
+ slang::IBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL loadModuleFromSourceString(
+ const char* moduleName,
+ const char* path,
+ const char* string,
+ slang::IBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL createCompositeComponentType(
+ slang::IComponentType* const* componentTypes,
+ SlangInt componentTypeCount,
+ slang::IComponentType** outCompositeComponentType,
+ ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL specializeType(
+ slang::TypeReflection* type,
+ slang::SpecializationArg const* specializationArgs,
+ SlangInt specializationArgCount,
+ ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL getTypeLayout(
+ slang::TypeReflection* type,
+ SlangInt targetIndex = 0,
+ slang::LayoutRules rules = slang::LayoutRules::Default,
+ ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL getContainerType(
+ slang::TypeReflection* elementType,
+ slang::ContainerType containerType,
+ ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL getDynamicType() override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL getTypeRTTIMangledName(
+ slang::TypeReflection* type,
+ ISlangBlob** outNameBlob) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessMangledName(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ ISlangBlob** outNameBlob) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessSequentialID(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ uint32_t* outId) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL createTypeConformanceComponentType(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ slang::ITypeConformance** outConformance,
+ SlangInt conformanceIdOverride,
+ ISlangBlob** outDiagnostics) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL createCompileRequest(
+ SlangCompileRequest** outCompileRequest) override;
+ SLANG_NO_THROW SlangInt SLANG_MCALL getLoadedModuleCount() override;
+ SLANG_NO_THROW slang::IModule* SLANG_MCALL getLoadedModule(SlangInt index) override;
+ SLANG_NO_THROW bool SLANG_MCALL isBinaryModuleUpToDate(const char* modulePath, slang::IBlob* binaryModuleBlob) override;
+
+ private:
+ SLANG_FORCE_INLINE slang::ISession* asExternal(SessionCapture* session)
+ {
+ return static_cast<slang::ISession*>(session);
+ }
+ Slang::ComPtr<slang::ISession> m_actualSession;
+ };
+}
+
+#endif // SLANG_SESSION_H
diff --git a/source/slang/CMakeLists.txt b/source/slang/CMakeLists.txt
index 320cd0ce9..558c1558a 100644
--- a/source/slang/CMakeLists.txt
+++ b/source/slang/CMakeLists.txt
@@ -159,6 +159,9 @@ set(SLANG_LOOKUP_GENERATOR_OUTPUT_DIR
set(SLANG_LOOKUP_GENERATED_SOURCE
"${SLANG_LOOKUP_GENERATOR_OUTPUT_DIR}/slang-lookup-GLSLstd450.cpp"
)
+set(SLANG_CAPATURE_REPLAY_SYSTEM
+ "${slang_SOURCE_DIR}/source/slang-capture-replay"
+)
add_custom_command(
OUTPUT ${SLANG_LOOKUP_GENERATED_SOURCE}
COMMAND
@@ -192,6 +195,7 @@ slang_add_target(
.
OBJECT
TARGET_NAME slang-no-embedded-stdlib
+ EXTRA_SOURCE_DIRS ${SLANG_CAPATURE_REPLAY_SYSTEM}
EXCLUDE_FROM_ALL
EXTRA_COMPILE_DEFINITIONS_PUBLIC SLANG_STATIC
LINK_WITH_PRIVATE
@@ -244,6 +248,7 @@ target_include_directories(
slang_add_target(
.
${SLANG_LIB_TYPE}
+ EXTRA_SOURCE_DIRS ${SLANG_CAPATURE_REPLAY_SYSTEM}
LINK_WITH_PRIVATE
core
compiler-core
diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp
index 7284f2468..ff37d6398 100644
--- a/source/slang/slang-api.cpp
+++ b/source/slang/slang-api.cpp
@@ -5,6 +5,8 @@
#include "slang-repro.h"
#include "../core/slang-shared-library.h"
+#include "../slang-capture-replay/slang-global-session.h"
+#include "../slang-capture-replay/capture_utility.h"
// implementation of C interface
@@ -116,7 +118,18 @@ SLANG_API SlangResult slang_createGlobalSession(
}
}
- *outGlobalSession = globalSession.detach();
+ // Check if the SLANG_CAPTURE_ENABLE_ENV is enabled
+ if (SlangCapture::isCaptureLayerEnabled())
+ {
+ SlangCapture::GlobalSessionCapture* globalSessionCapture =
+ new SlangCapture::GlobalSessionCapture(globalSession.detach());
+ Slang::ComPtr<SlangCapture::GlobalSessionCapture> result(globalSessionCapture);
+ *outGlobalSession = result.detach();
+ }
+ else
+ {
+ *outGlobalSession = globalSession.detach();
+ }
#ifdef SLANG_ENABLE_IR_BREAK_ALLOC
// Reset inst debug alloc counter to 0 so IRInsts for user code always starts from 0.