forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslang-module.cpp
255 lines (217 loc) · 7.96 KB
/
slang-module.cpp
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "slang-module.h"
#include "../util/record-utility.h"
#include "slang-session.h"
namespace SlangRecord
{
ModuleRecorder::ModuleRecorder(
SessionRecorder* sessionRecorder,
slang::IModule* module,
RecordManager* recordManager)
: IComponentTypeRecorder(module, recordManager)
, m_sessionRecorder(sessionRecorder)
, m_actualModule(module)
, m_recordManager(recordManager)
{
SLANG_RECORD_ASSERT(m_actualModule != nullptr);
SLANG_RECORD_ASSERT(m_recordManager != nullptr);
m_moduleHandle = reinterpret_cast<uint64_t>(m_actualModule.get());
slangRecordLog(LogLevel::Verbose, "%s: %p\n", __PRETTY_FUNCTION__, module);
}
ISlangUnknown* ModuleRecorder::getInterface(const Guid& guid)
{
if (guid == IModuleRecorder::getTypeGuid())
return static_cast<IModuleRecorder*>(this);
else
return nullptr;
}
SLANG_NO_THROW slang::DeclReflection* ModuleRecorder::getModuleReflection()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
slang::DeclReflection* res = (slang::DeclReflection*)m_actualModule->getModuleReflection();
return res;
}
SLANG_NO_THROW SlangResult
ModuleRecorder::findEntryPointByName(char const* name, slang::IEntryPoint** outEntryPoint)
{
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
ParameterRecorder* recorder{};
{
recorder = m_recordManager->beginMethodRecord(
ApiCallId::IModule_findEntryPointByName,
m_moduleHandle);
recorder->recordString(name);
recorder = m_recordManager->endMethodRecord();
}
SlangResult res = m_actualModule->findEntryPointByName(name, outEntryPoint);
{
recorder->recordAddress(*outEntryPoint);
m_recordManager->apendOutput();
}
if (SLANG_OK == res)
{
IEntryPointRecorder* entryPointRecord = getEntryPointRecorder(*outEntryPoint);
*outEntryPoint = static_cast<slang::IEntryPoint*>(entryPointRecord);
}
return res;
}
SLANG_NO_THROW SlangInt32 ModuleRecorder::getDefinedEntryPointCount()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
SlangInt32 res = m_actualModule->getDefinedEntryPointCount();
return res;
}
SLANG_NO_THROW SlangResult
ModuleRecorder::getDefinedEntryPoint(SlangInt32 index, slang::IEntryPoint** outEntryPoint)
{
// This call is to find the existing entry point, so it has been created already. Therefore, we
// don't create a new one and assert the error if it is not found in our map.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
ParameterRecorder* recorder{};
{
recorder = m_recordManager->beginMethodRecord(
ApiCallId::IModule_getDefinedEntryPoint,
m_moduleHandle);
recorder->recordInt32(index);
recorder = m_recordManager->endMethodRecord();
}
SlangResult res = m_actualModule->getDefinedEntryPoint(index, outEntryPoint);
{
recorder->recordAddress(*outEntryPoint);
m_recordManager->apendOutput();
}
if (*outEntryPoint)
{
IEntryPointRecorder* entryPointRecord = nullptr;
bool ret = m_mapEntryPointToRecord.tryGetValue(*outEntryPoint, entryPointRecord);
if (!ret)
{
SLANG_RECORD_ASSERT(!"Entrypoint not found in mapEntryPointToRecord");
}
ComPtr<slang::IEntryPoint> result(static_cast<slang::IEntryPoint*>(entryPointRecord));
*outEntryPoint = result.detach();
}
else
*outEntryPoint = nullptr;
return res;
}
SLANG_NO_THROW SlangResult ModuleRecorder::serialize(ISlangBlob** outSerializedBlob)
{
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
ParameterRecorder* recorder{};
{
recorder = m_recordManager->beginMethodRecord(ApiCallId::IModule_serialize, m_moduleHandle);
recorder = m_recordManager->endMethodRecord();
}
SlangResult res = m_actualModule->serialize(outSerializedBlob);
{
recorder->recordAddress(*outSerializedBlob);
m_recordManager->apendOutput();
}
return res;
}
SLANG_NO_THROW SlangResult ModuleRecorder::writeToFile(char const* fileName)
{
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
ParameterRecorder* recorder{};
{
recorder =
m_recordManager->beginMethodRecord(ApiCallId::IModule_writeToFile, m_moduleHandle);
recorder->recordString(fileName);
recorder = m_recordManager->endMethodRecord();
}
SlangResult res = m_actualModule->writeToFile(fileName);
return res;
}
SLANG_NO_THROW const char* ModuleRecorder::getName()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
const char* res = m_actualModule->getName();
return res;
}
SLANG_NO_THROW const char* ModuleRecorder::getFilePath()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
const char* res = m_actualModule->getFilePath();
return res;
}
SLANG_NO_THROW const char* ModuleRecorder::getUniqueIdentity()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
const char* res = m_actualModule->getUniqueIdentity();
return res;
}
SLANG_NO_THROW SlangResult ModuleRecorder::findAndCheckEntryPoint(
char const* name,
SlangStage stage,
slang::IEntryPoint** outEntryPoint,
ISlangBlob** outDiagnostics)
{
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
ParameterRecorder* recorder{};
{
recorder = m_recordManager->beginMethodRecord(
ApiCallId::IModule_findAndCheckEntryPoint,
m_moduleHandle);
recorder->recordString(name);
recorder->recordEnumValue(stage);
recorder = m_recordManager->endMethodRecord();
}
SlangResult res =
m_actualModule->findAndCheckEntryPoint(name, stage, outEntryPoint, outDiagnostics);
{
recorder->recordAddress(*outEntryPoint);
recorder->recordAddress(outDiagnostics ? *outDiagnostics : nullptr);
m_recordManager->apendOutput();
}
if (SLANG_OK == res)
{
IEntryPointRecorder* entryPointRecord = getEntryPointRecorder(*outEntryPoint);
*outEntryPoint = static_cast<slang::IEntryPoint*>(entryPointRecord);
}
return res;
}
SLANG_NO_THROW SlangInt32 ModuleRecorder::getDependencyFileCount()
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
SlangInt32 res = m_actualModule->getDependencyFileCount();
return res;
}
SLANG_NO_THROW char const* ModuleRecorder::getDependencyFilePath(SlangInt32 index)
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
const char* res = m_actualModule->getDependencyFilePath(index);
return res;
}
IEntryPointRecorder* ModuleRecorder::getEntryPointRecorder(slang::IEntryPoint* entryPoint)
{
IEntryPointRecorder* entryPointRecord = nullptr;
bool ret = m_mapEntryPointToRecord.tryGetValue(entryPoint, entryPointRecord);
if (!ret)
{
entryPointRecord = new EntryPointRecorder(m_sessionRecorder, entryPoint, m_recordManager);
Slang::ComPtr<IEntryPointRecorder> result(entryPointRecord);
m_entryPointsRecordAllocation.add(result);
m_mapEntryPointToRecord.add(entryPoint, result.detach());
return entryPointRecord;
}
else
{
Slang::ComPtr<IEntryPointRecorder> result(entryPointRecord);
return result.detach();
}
}
SlangResult ModuleRecorder::disassemble(ISlangBlob** outBlob)
{
// No need to record this call as it is just a query.
slangRecordLog(LogLevel::Verbose, "%s\n", __PRETTY_FUNCTION__);
auto res = m_actualModule->disassemble(outBlob);
return res;
}
} // namespace SlangRecord