diff options
| author | Yong He <yonghe@outlook.com> | 2025-03-24 17:01:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-24 17:01:55 -0700 |
| commit | c54bc9ebff0691c397885363e0da7a122e3e407d (patch) | |
| tree | f29681f8aa35b5b01e169a35a77cdd81317a8330 /source | |
| parent | 0d7d6468dfcabb759ec40921e5da3a8598f1c770 (diff) | |
Don't load cached builtin module in slang-bootstrap. (#6667)
* Don't load cached builtin module in slang-bootstrap.
* Fixes.
* format code
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-api.cpp | 53 | ||||
| -rw-r--r-- | source/slang/slang-internal.h | 19 | ||||
| -rw-r--r-- | source/slangc/main.cpp | 8 |
3 files changed, 57 insertions, 23 deletions
diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp index 701f49355..9b7b605a2 100644 --- a/source/slang/slang-api.cpp +++ b/source/slang/slang-api.cpp @@ -9,6 +9,7 @@ #include "../slang-record-replay/util/record-utility.h" #include "slang-capability.h" #include "slang-compiler.h" +#include "slang-internal.h" #include "slang-repro.h" // implementation of C interface @@ -124,8 +125,9 @@ slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobal return slang_createGlobalSession2(&desc, outGlobalSession); } -SLANG_API SlangResult slang_createGlobalSession2( +SLANG_API SlangResult slang_createGlobalSessionImpl( const SlangGlobalSessionDesc* desc, + const Slang::GlobalSessionInternalDesc* internalDesc, slang::IGlobalSession** outGlobalSession) { Slang::ComPtr<slang::IGlobalSession> globalSession; @@ -151,24 +153,20 @@ SLANG_API SlangResult slang_createGlobalSession2( { Slang::String cacheFilename; uint64_t dllTimestamp = 0; -#define SLANG_PROFILE_CORE_MODULE_COMPILE 0 -#if SLANG_PROFILE_CORE_MODULE_COMPILE - auto startTime = std::chrono::high_resolution_clock::now(); -#else - if (tryLoadBuiltinModuleFromCache( + SlangResult loadFromCacheResult = SLANG_FAIL; + if (!internalDesc->isBootstrap) + { + loadFromCacheResult = tryLoadBuiltinModuleFromCache( globalSession, slang::BuiltinModuleName::Core, cacheFilename, - dllTimestamp) != SLANG_OK) -#endif + dllTimestamp); + } + if (loadFromCacheResult != SLANG_OK) { // Compile std lib from embeded source. SLANG_RETURN_ON_FAIL( globalSession->compileBuiltinModule(slang::BuiltinModuleName::Core, 0)); -#if SLANG_PROFILE_CORE_MODULE_COMPILE - auto timeElapsed = std::chrono::high_resolution_clock::now() - startTime; - printf("core module compilation time: %.1fms\n", timeElapsed.count() / 1000000.0); -#endif // Store the compiled core module to cache file. trySaveBuiltinModuleToCache( globalSession, @@ -182,18 +180,21 @@ SLANG_API SlangResult slang_createGlobalSession2( { Slang::String cacheFilename; uint64_t dllTimestamp = 0; - if (SLANG_SUCCEEDED( - tryLoadBuiltinModuleFromDLL(globalSession, slang::BuiltinModuleName::GLSL))) - { - } - else if (SLANG_SUCCEEDED(tryLoadBuiltinModuleFromCache( - globalSession, - slang::BuiltinModuleName::GLSL, - cacheFilename, - dllTimestamp))) + SlangResult loadFromCacheResult = SLANG_FAIL; + if (!internalDesc->isBootstrap) { + loadFromCacheResult = + tryLoadBuiltinModuleFromDLL(globalSession, slang::BuiltinModuleName::GLSL); + if (SLANG_FAILED(loadFromCacheResult)) + { + loadFromCacheResult = tryLoadBuiltinModuleFromCache( + globalSession, + slang::BuiltinModuleName::GLSL, + cacheFilename, + dllTimestamp); + } } - else + if (SLANG_FAILED(loadFromCacheResult)) { SLANG_RETURN_ON_FAIL( globalSession->compileBuiltinModule(slang::BuiltinModuleName::GLSL, 0)); @@ -228,6 +229,14 @@ SLANG_API SlangResult slang_createGlobalSession2( return SLANG_OK; } +SLANG_API SlangResult slang_createGlobalSession2( + const SlangGlobalSessionDesc* desc, + slang::IGlobalSession** outGlobalSession) +{ + Slang::GlobalSessionInternalDesc internalDesc = {}; + return slang_createGlobalSessionImpl(desc, &internalDesc, outGlobalSession); +} + SLANG_API void slang_shutdown() { Slang::PerformanceProfiler::getProfiler()->dispose(); diff --git a/source/slang/slang-internal.h b/source/slang/slang-internal.h new file mode 100644 index 000000000..b6dad195c --- /dev/null +++ b/source/slang/slang-internal.h @@ -0,0 +1,19 @@ +#ifndef SLANG_INTERNAL_H_INCLUDED +#define SLANG_INTERNAL_H_INCLUDED + +#include "slang.h" + +namespace Slang +{ +struct GlobalSessionInternalDesc +{ + bool isBootstrap = false; +}; +} // namespace Slang + +SLANG_API SlangResult slang_createGlobalSessionImpl( + const SlangGlobalSessionDesc* desc, + const Slang::GlobalSessionInternalDesc* internalDesc, + slang::IGlobalSession** outGlobalSession); + +#endif diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index 718de6968..ae663e050 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -6,6 +6,7 @@ SLANG_API void spSetCommandLineCompilerMode(SlangCompileRequest* request); #include "../core/slang-io.h" #include "../core/slang-test-tool-util.h" +#include "../slang/slang-internal.h" using namespace Slang; @@ -102,7 +103,12 @@ SLANG_TEST_TOOL_API SlangResult innerMain( // Just create the global session in the regular way if there isn't one set SlangGlobalSessionDesc desc = {}; desc.enableGLSL = true; - SLANG_RETURN_ON_FAIL(slang_createGlobalSession2(&desc, session.writeRef())); + Slang::GlobalSessionInternalDesc internalDesc = {}; +#ifdef SLANG_BOOTSTRAP + internalDesc.isBootstrap = true; +#endif + SLANG_RETURN_ON_FAIL( + slang_createGlobalSessionImpl(&desc, &internalDesc, session.writeRef())); } if (!shouldEmbedPrelude(argv, argc)) |
