@@ -94,17 +94,15 @@ Session* GlobalSession::createSession(int compileTarget)
94
94
return new Session (session);
95
95
}
96
96
97
- Module* Session::loadModuleFromSource (const std::string& slangCode)
97
+ Module* Session::loadModuleFromSource (const std::string& slangCode, const std::string& name, const std::string& path )
98
98
{
99
99
Slang::ComPtr<IModule> module;
100
100
{
101
- const char * name = " " ;
102
- const char * path = " " ;
103
101
Slang::ComPtr<slang::IBlob> diagnosticsBlob;
104
102
Slang::ComPtr<ISlangBlob> slangCodeBlob = Slang::RawBlob::create (
105
103
slangCode.c_str (), slangCode.size ());
106
104
module = m_interface->loadModuleFromSource (
107
- name, path, slangCodeBlob, diagnosticsBlob.writeRef ());
105
+ name. c_str () , path. c_str () , slangCodeBlob, diagnosticsBlob.writeRef ());
108
106
if (!module)
109
107
{
110
108
g_error.type = std::string (" USER" );
@@ -161,6 +159,38 @@ EntryPoint* Module::findAndCheckEntryPoint(const std::string& name, int stage)
161
159
return new EntryPoint (entryPoint);
162
160
}
163
161
162
+ int Module::getDefinedEntryPointCount ()
163
+ {
164
+ return moduleInterface ()->getDefinedEntryPointCount ();
165
+ }
166
+
167
+ EntryPoint* Module::getDefinedEntryPoint (int index)
168
+ {
169
+ if (moduleInterface ()->getDefinedEntryPointCount () <= index )
170
+ return nullptr ;
171
+
172
+ Slang::ComPtr<IEntryPoint> entryPoint;
173
+ {
174
+ Slang::ComPtr<slang::IBlob> diagnosticsBlob;
175
+ SlangResult result = moduleInterface ()->getDefinedEntryPoint (index , entryPoint.writeRef ());
176
+ if (!SLANG_SUCCEEDED (result))
177
+ {
178
+ g_error.type = std::string (" USER" );
179
+ g_error.result = result;
180
+
181
+ if (diagnosticsBlob->getBufferSize ())
182
+ {
183
+ char * diagnostics = (char *)diagnosticsBlob->getBufferPointer ();
184
+ g_error.message = std::string (diagnostics);
185
+ }
186
+ return nullptr ;
187
+ }
188
+ }
189
+
190
+ return new EntryPoint (entryPoint);
191
+ }
192
+
193
+
164
194
ComponentType* Session::createCompositeComponentType (
165
195
const std::vector<ComponentType*>& components)
166
196
{
@@ -235,9 +265,9 @@ std::string ComponentType::getEntryPointCode(int entryPointIndex, int targetInde
235
265
return {};
236
266
}
237
267
238
- // Since spirv code is binary, we can't return it as a string, we will need to use emscripten::val
268
+ // Since result code is binary, we can't return it as a string, we will need to use emscripten::val
239
269
// to wrap it and return it to the javascript side.
240
- emscripten::val ComponentType::getEntryPointCodeSpirv (int entryPointIndex, int targetIndex)
270
+ emscripten::val ComponentType::getEntryPointCodeBlob (int entryPointIndex, int targetIndex)
241
271
{
242
272
Slang::ComPtr<IBlob> kernelBlob;
243
273
Slang::ComPtr<ISlangBlob> diagnosticBlob;
@@ -262,6 +292,60 @@ emscripten::val ComponentType::getEntryPointCodeSpirv(int entryPointIndex, int t
262
292
ptr));
263
293
}
264
294
295
+ std::string ComponentType::getTargetCode (int targetIndex)
296
+ {
297
+ {
298
+ Slang::ComPtr<IBlob> kernelBlob;
299
+ Slang::ComPtr<ISlangBlob> diagnosticBlob;
300
+ SlangResult result = interface ()->getTargetCode (
301
+ targetIndex,
302
+ kernelBlob.writeRef (),
303
+ diagnosticBlob.writeRef ());
304
+ if (result != SLANG_OK)
305
+ {
306
+ g_error.type = std::string (" USER" );
307
+ g_error.result = result;
308
+ g_error.message = std::string (
309
+ (char *)diagnosticBlob->getBufferPointer (),
310
+ (char *)diagnosticBlob->getBufferPointer () +
311
+ diagnosticBlob->getBufferSize ());
312
+ return " " ;
313
+ }
314
+ std::string targetCode = std::string (
315
+ (char *)kernelBlob->getBufferPointer (),
316
+ (char *)kernelBlob->getBufferPointer () + kernelBlob->getBufferSize ());
317
+ return targetCode;
318
+ }
319
+
320
+ return {};
321
+ }
322
+
323
+ // Since result code is binary, we can't return it as a string, we will need to use emscripten::val
324
+ // to wrap it and return it to the javascript side.
325
+ emscripten::val ComponentType::getTargetCodeBlob (int targetIndex)
326
+ {
327
+ Slang::ComPtr<IBlob> kernelBlob;
328
+ Slang::ComPtr<ISlangBlob> diagnosticBlob;
329
+ SlangResult result = interface ()->getTargetCode (
330
+ targetIndex,
331
+ kernelBlob.writeRef (),
332
+ diagnosticBlob.writeRef ());
333
+ if (result != SLANG_OK)
334
+ {
335
+ g_error.type = std::string (" USER" );
336
+ g_error.result = result;
337
+ g_error.message = std::string (
338
+ (char *)diagnosticBlob->getBufferPointer (),
339
+ (char *)diagnosticBlob->getBufferPointer () +
340
+ diagnosticBlob->getBufferSize ());
341
+ return {};
342
+ }
343
+
344
+ const uint8_t * ptr = (uint8_t *)kernelBlob->getBufferPointer ();
345
+ return emscripten::val (emscripten::typed_memory_view (kernelBlob->getBufferSize (),
346
+ ptr));
347
+ }
348
+
265
349
namespace lsp
266
350
{
267
351
Position translate (Slang::LanguageServerProtocol::Position p)
0 commit comments