|
1 | 1 | // slang-api.cpp
|
2 | 2 |
|
3 | 3 | #include "../core/slang-performance-profiler.h"
|
| 4 | +#include "../core/slang-platform.h" |
4 | 5 | #include "../core/slang-rtti-info.h"
|
5 | 6 | #include "../core/slang-shared-library.h"
|
6 | 7 | #include "../core/slang-signal.h"
|
@@ -63,6 +64,32 @@ SlangResult tryLoadBuiltinModuleFromCache(
|
63 | 64 | return SLANG_OK;
|
64 | 65 | }
|
65 | 66 |
|
| 67 | +// Attempt to load a precompiled builtin module from slang-xxx-module.dll. |
| 68 | +SlangResult tryLoadBuiltinModuleFromDLL( |
| 69 | + slang::IGlobalSession* globalSession, |
| 70 | + slang::BuiltinModuleName builtinModuleName) |
| 71 | +{ |
| 72 | + Slang::String moduleFileName = |
| 73 | + Slang::String("slang-") + Slang::getBuiltinModuleNameStr(builtinModuleName) + "-module"; |
| 74 | + |
| 75 | + Slang::SharedLibrary::Handle libHandle = nullptr; |
| 76 | + |
| 77 | + SLANG_RETURN_ON_FAIL(Slang::SharedLibrary::load(moduleFileName.getBuffer(), libHandle)); |
| 78 | + if (!libHandle) |
| 79 | + return SLANG_FAIL; |
| 80 | + void* ptr = Slang::SharedLibrary::findSymbolAddressByName(libHandle, "slang_getEmbeddedModule"); |
| 81 | + if (!ptr) |
| 82 | + return SLANG_FAIL; |
| 83 | + typedef ISlangBlob*(GetEmbeddedModuleFunc)(); |
| 84 | + auto getEmbeddedModule = (GetEmbeddedModuleFunc*)ptr; |
| 85 | + auto blob = getEmbeddedModule(); |
| 86 | + SLANG_RETURN_ON_FAIL(globalSession->loadBuiltinModule( |
| 87 | + builtinModuleName, |
| 88 | + (uint8_t*)blob->getBufferPointer(), |
| 89 | + blob->getBufferSize())); |
| 90 | + return SLANG_OK; |
| 91 | +} |
| 92 | + |
66 | 93 | SlangResult trySaveBuiltinModuleToCache(
|
67 | 94 | slang::IGlobalSession* globalSession,
|
68 | 95 | slang::BuiltinModuleName builtinModuleName,
|
@@ -155,11 +182,18 @@ SLANG_API SlangResult slang_createGlobalSession2(
|
155 | 182 | {
|
156 | 183 | Slang::String cacheFilename;
|
157 | 184 | uint64_t dllTimestamp = 0;
|
158 |
| - if (tryLoadBuiltinModuleFromCache( |
159 |
| - globalSession, |
160 |
| - slang::BuiltinModuleName::GLSL, |
161 |
| - cacheFilename, |
162 |
| - dllTimestamp) != SLANG_OK) |
| 185 | + if (SLANG_SUCCEEDED( |
| 186 | + tryLoadBuiltinModuleFromDLL(globalSession, slang::BuiltinModuleName::GLSL))) |
| 187 | + { |
| 188 | + } |
| 189 | + else if (SLANG_SUCCEEDED(tryLoadBuiltinModuleFromCache( |
| 190 | + globalSession, |
| 191 | + slang::BuiltinModuleName::GLSL, |
| 192 | + cacheFilename, |
| 193 | + dllTimestamp))) |
| 194 | + { |
| 195 | + } |
| 196 | + else |
163 | 197 | {
|
164 | 198 | SLANG_RETURN_ON_FAIL(
|
165 | 199 | globalSession->compileBuiltinModule(slang::BuiltinModuleName::GLSL, 0));
|
|
0 commit comments