1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#include "slang-filesystem.h"
#include "../../core/slang-io.h"
#include "../util/record-utility.h"
#include "output-stream.h"
#include <stdlib.h>
namespace SlangRecord
{
// We don't actually need to record the methods of ISlangFileSystemExt, we just want to record the
// file content and save them into disk.
FileSystemRecorder::FileSystemRecorder(
ISlangFileSystemExt* fileSystem,
RecordManager* recordManager)
: m_actualFileSystem(fileSystem), m_recordManager(recordManager)
{
SLANG_RECORD_ASSERT(m_actualFileSystem);
SLANG_RECORD_ASSERT(m_recordManager);
slangRecordLog(LogLevel::Verbose, "%s: %p\n", __PRETTY_FUNCTION__, m_actualFileSystem.get());
}
void* FileSystemRecorder::castAs(const Slang::Guid& guid)
{
return getInterface(guid);
}
ISlangUnknown* FileSystemRecorder::getInterface(const Slang::Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid())
return static_cast<ISlangFileSystem*>(this);
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 FileSystemRecorder::loadFile(char const* path, ISlangBlob** outBlob)
{
slangRecordLog(
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 record directory.
if ((res == SLANG_OK) && (*outBlob != nullptr) && ((*outBlob)->getBufferSize() != 0))
{
Slang::String filePath =
Slang::Path::combine(m_recordManager->getRecordFileDirectory(), path);
Slang::String dirPath = Slang::Path::getParentDirectory(filePath);
if (!File::exists(dirPath))
{
slangRecordLog(
LogLevel::Debug,
"Create directory: %s to save captured shader file: %s\n",
dirPath.getBuffer(),
filePath.getBuffer());
if (!Path::createDirectoryRecursive(dirPath))
{
slangRecordLog(
LogLevel::Error,
"Fail to create directory: %s\n",
dirPath.getBuffer());
return SLANG_FAIL;
}
}
FileOutputStream fileStream(filePath);
fileStream.write((*outBlob)->getBufferPointer(), (*outBlob)->getBufferSize());
fileStream.flush();
}
return res;
}
SLANG_NO_THROW SlangResult
FileSystemRecorder::getFileUniqueIdentity(const char* path, ISlangBlob** outUniqueIdentity)
{
slangRecordLog(
LogLevel::Verbose,
"%p: %s :\"%s\"\n",
m_actualFileSystem.get(),
__PRETTY_FUNCTION__,
path);
SlangResult res = m_actualFileSystem->getFileUniqueIdentity(path, outUniqueIdentity);
return res;
}
SLANG_NO_THROW SlangResult FileSystemRecorder::calcCombinedPath(
SlangPathType fromPathType,
const char* fromPath,
const char* path,
ISlangBlob** pathOut)
{
slangRecordLog(
LogLevel::Verbose,
"%p: %s, :%s\n",
m_actualFileSystem.get(),
__PRETTY_FUNCTION__,
path);
SlangResult res = m_actualFileSystem->calcCombinedPath(fromPathType, fromPath, path, pathOut);
return res;
}
SLANG_NO_THROW SlangResult
FileSystemRecorder::getPathType(const char* path, SlangPathType* pathTypeOut)
{
slangRecordLog(
LogLevel::Verbose,
"%p: %s, :%s\n",
m_actualFileSystem.get(),
__PRETTY_FUNCTION__,
path);
SlangResult res = m_actualFileSystem->getPathType(path, pathTypeOut);
return res;
}
SLANG_NO_THROW SlangResult
FileSystemRecorder::getPath(PathKind kind, const char* path, ISlangBlob** outPath)
{
slangRecordLog(
LogLevel::Verbose,
"%p: %s, :%s\n",
m_actualFileSystem.get(),
__PRETTY_FUNCTION__,
path);
SlangResult res = m_actualFileSystem->getPath(kind, path, outPath);
return res;
}
SLANG_NO_THROW void FileSystemRecorder::clearCache()
{
slangRecordLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __PRETTY_FUNCTION__);
m_actualFileSystem->clearCache();
}
SLANG_NO_THROW SlangResult FileSystemRecorder::enumeratePathContents(
const char* path,
FileSystemContentsCallBack callback,
void* userData)
{
slangRecordLog(
LogLevel::Verbose,
"%p: %s, :%s\n",
m_actualFileSystem.get(),
__PRETTY_FUNCTION__,
path);
SlangResult res = m_actualFileSystem->enumeratePathContents(path, callback, userData);
return res;
}
SLANG_NO_THROW OSPathKind FileSystemRecorder::getOSPathKind()
{
slangRecordLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __PRETTY_FUNCTION__);
OSPathKind pathKind = m_actualFileSystem->getOSPathKind();
return pathKind;
}
} // namespace SlangRecord
|