diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-06-20 20:59:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-20 20:59:33 -0700 |
| commit | d349fd9e1f65fd32b2f4ea0e38c5084256d0dd04 (patch) | |
| tree | 3e4869c01b041830f06b953abbb835284abcb89f /source/slang-capture-replay/slang-filesystem.cpp | |
| parent | c3c1cb6776eacdc01ea5bc197b635471960994e4 (diff) | |
Add capture logic to other interfaces. (#4412)
* Add capture logic to other interfaces.
Add capture logics to ISession, IModule, ITypeConformance, IEntryPoint
ICompositeComponentType.
Add few encode methods to encode the array.
Fix some capture logic in global session. We will not need to encode
the null_ptr output before actual actual of the captured APIs.
Previously we used this as a place holder, but it's actually not
necessary, it can be detected if the output is not captured during
replay.
* capture/replay: dump the shader files to disk
Dump the shader files to disk.
Also set a default directory for the capture files.
Diffstat (limited to 'source/slang-capture-replay/slang-filesystem.cpp')
| -rw-r--r-- | source/slang-capture-replay/slang-filesystem.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/source/slang-capture-replay/slang-filesystem.cpp b/source/slang-capture-replay/slang-filesystem.cpp index fac6cf66e..0de17162e 100644 --- a/source/slang-capture-replay/slang-filesystem.cpp +++ b/source/slang-capture-replay/slang-filesystem.cpp @@ -1,12 +1,17 @@ #include "slang-filesystem.h" #include "capture_utility.h" +#include "output-stream.h" namespace SlangCapture { - FileSystemCapture::FileSystemCapture(ISlangFileSystemExt* fileSystem) - : m_actualFileSystem(fileSystem) + // We don't actually need to capture the methods of ISlangFileSystemExt, we just want to capture the file content + // and save them into disk. + FileSystemCapture::FileSystemCapture(ISlangFileSystemExt* fileSystem, CaptureManager* captureManager) + : m_actualFileSystem(fileSystem), + m_captureManager(captureManager) { SLANG_CAPTURE_ASSERT(m_actualFileSystem); + SLANG_CAPTURE_ASSERT(m_captureManager); slangCaptureLog(LogLevel::Verbose, "%s: %p\n", __PRETTY_FUNCTION__, m_actualFileSystem.get()); } @@ -27,12 +32,31 @@ namespace SlangCapture return nullptr; } + // TODO: There could be a potential issue that could not be able to dump the generated file content correctly. + // Details: https://github.com/shader-slang/slang/issues/4423. SLANG_NO_THROW SlangResult FileSystemCapture::loadFile( char const* path, ISlangBlob** outBlob) { slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __PRETTY_FUNCTION__, path); SlangResult res = m_actualFileSystem->loadFile(path, outBlob); + + // Since the loadFile method could be implemented by client, we can't guarantee the result is always as expected, + // we will check every thing to make sure we won't crash at writing file. + // + // We can only dump the file content after this 'loadFile' call, no matter this call crashes or file is not + // found, we can't save the file anyway, so we don't need to pay special care to the crash recovery. We will + // know something wrong with the loadFile call if we can't find the file in the capture directory. + if ((res == SLANG_OK) && (*outBlob != nullptr) && ((*outBlob)->getBufferSize() != 0)) + { + std::filesystem::path filePath = m_captureManager->getCaptureFileDirectory(); + filePath = filePath / path; + + FileOutputStream fileStream(filePath.string().c_str()); + + fileStream.write((*outBlob)->getBufferPointer(), (*outBlob)->getBufferSize()); + fileStream.flush(); + } return res; } |
