summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-03-24 17:01:55 -0700
committerGitHub <noreply@github.com>2025-03-24 17:01:55 -0700
commitc54bc9ebff0691c397885363e0da7a122e3e407d (patch)
treef29681f8aa35b5b01e169a35a77cdd81317a8330
parent0d7d6468dfcabb759ec40921e5da3a8598f1c770 (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>
-rw-r--r--source/slang/slang-api.cpp53
-rw-r--r--source/slang/slang-internal.h19
-rw-r--r--source/slangc/main.cpp8
-rw-r--r--tools/CMakeLists.txt2
4 files changed, 59 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))
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 7c2e80e61..d558f299e 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -62,6 +62,8 @@ generator(
TARGET_NAME
slang-bootstrap
USE_FEWER_WARNINGS
+ EXTRA_COMPILE_DEFINITIONS_PRIVATE
+ SLANG_BOOTSTRAP=1
LINK_WITH_PUBLIC
slang-without-embedded-core-module
LINK_WITH_PRIVATE