Skip to content

Commit c54bc9e

Browse files
csyongheslangbot
andauthoredMar 25, 2025
Don't load cached builtin module in slang-bootstrap. (shader-slang#6667)
* Don't load cached builtin module in slang-bootstrap. * Fixes. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
1 parent 0d7d646 commit c54bc9e

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed
 

‎source/slang/slang-api.cpp

+31-22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../slang-record-replay/util/record-utility.h"
1010
#include "slang-capability.h"
1111
#include "slang-compiler.h"
12+
#include "slang-internal.h"
1213
#include "slang-repro.h"
1314

1415
// implementation of C interface
@@ -124,8 +125,9 @@ slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobal
124125
return slang_createGlobalSession2(&desc, outGlobalSession);
125126
}
126127

127-
SLANG_API SlangResult slang_createGlobalSession2(
128+
SLANG_API SlangResult slang_createGlobalSessionImpl(
128129
const SlangGlobalSessionDesc* desc,
130+
const Slang::GlobalSessionInternalDesc* internalDesc,
129131
slang::IGlobalSession** outGlobalSession)
130132
{
131133
Slang::ComPtr<slang::IGlobalSession> globalSession;
@@ -151,24 +153,20 @@ SLANG_API SlangResult slang_createGlobalSession2(
151153
{
152154
Slang::String cacheFilename;
153155
uint64_t dllTimestamp = 0;
154-
#define SLANG_PROFILE_CORE_MODULE_COMPILE 0
155-
#if SLANG_PROFILE_CORE_MODULE_COMPILE
156-
auto startTime = std::chrono::high_resolution_clock::now();
157-
#else
158-
if (tryLoadBuiltinModuleFromCache(
156+
SlangResult loadFromCacheResult = SLANG_FAIL;
157+
if (!internalDesc->isBootstrap)
158+
{
159+
loadFromCacheResult = tryLoadBuiltinModuleFromCache(
159160
globalSession,
160161
slang::BuiltinModuleName::Core,
161162
cacheFilename,
162-
dllTimestamp) != SLANG_OK)
163-
#endif
163+
dllTimestamp);
164+
}
165+
if (loadFromCacheResult != SLANG_OK)
164166
{
165167
// Compile std lib from embeded source.
166168
SLANG_RETURN_ON_FAIL(
167169
globalSession->compileBuiltinModule(slang::BuiltinModuleName::Core, 0));
168-
#if SLANG_PROFILE_CORE_MODULE_COMPILE
169-
auto timeElapsed = std::chrono::high_resolution_clock::now() - startTime;
170-
printf("core module compilation time: %.1fms\n", timeElapsed.count() / 1000000.0);
171-
#endif
172170
// Store the compiled core module to cache file.
173171
trySaveBuiltinModuleToCache(
174172
globalSession,
@@ -182,18 +180,21 @@ SLANG_API SlangResult slang_createGlobalSession2(
182180
{
183181
Slang::String cacheFilename;
184182
uint64_t dllTimestamp = 0;
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)))
183+
SlangResult loadFromCacheResult = SLANG_FAIL;
184+
if (!internalDesc->isBootstrap)
194185
{
186+
loadFromCacheResult =
187+
tryLoadBuiltinModuleFromDLL(globalSession, slang::BuiltinModuleName::GLSL);
188+
if (SLANG_FAILED(loadFromCacheResult))
189+
{
190+
loadFromCacheResult = tryLoadBuiltinModuleFromCache(
191+
globalSession,
192+
slang::BuiltinModuleName::GLSL,
193+
cacheFilename,
194+
dllTimestamp);
195+
}
195196
}
196-
else
197+
if (SLANG_FAILED(loadFromCacheResult))
197198
{
198199
SLANG_RETURN_ON_FAIL(
199200
globalSession->compileBuiltinModule(slang::BuiltinModuleName::GLSL, 0));
@@ -228,6 +229,14 @@ SLANG_API SlangResult slang_createGlobalSession2(
228229
return SLANG_OK;
229230
}
230231

232+
SLANG_API SlangResult slang_createGlobalSession2(
233+
const SlangGlobalSessionDesc* desc,
234+
slang::IGlobalSession** outGlobalSession)
235+
{
236+
Slang::GlobalSessionInternalDesc internalDesc = {};
237+
return slang_createGlobalSessionImpl(desc, &internalDesc, outGlobalSession);
238+
}
239+
231240
SLANG_API void slang_shutdown()
232241
{
233242
Slang::PerformanceProfiler::getProfiler()->dispose();

‎source/slang/slang-internal.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef SLANG_INTERNAL_H_INCLUDED
2+
#define SLANG_INTERNAL_H_INCLUDED
3+
4+
#include "slang.h"
5+
6+
namespace Slang
7+
{
8+
struct GlobalSessionInternalDesc
9+
{
10+
bool isBootstrap = false;
11+
};
12+
} // namespace Slang
13+
14+
SLANG_API SlangResult slang_createGlobalSessionImpl(
15+
const SlangGlobalSessionDesc* desc,
16+
const Slang::GlobalSessionInternalDesc* internalDesc,
17+
slang::IGlobalSession** outGlobalSession);
18+
19+
#endif

‎source/slangc/main.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SLANG_API void spSetCommandLineCompilerMode(SlangCompileRequest* request);
66

77
#include "../core/slang-io.h"
88
#include "../core/slang-test-tool-util.h"
9+
#include "../slang/slang-internal.h"
910

1011
using namespace Slang;
1112

@@ -102,7 +103,12 @@ SLANG_TEST_TOOL_API SlangResult innerMain(
102103
// Just create the global session in the regular way if there isn't one set
103104
SlangGlobalSessionDesc desc = {};
104105
desc.enableGLSL = true;
105-
SLANG_RETURN_ON_FAIL(slang_createGlobalSession2(&desc, session.writeRef()));
106+
Slang::GlobalSessionInternalDesc internalDesc = {};
107+
#ifdef SLANG_BOOTSTRAP
108+
internalDesc.isBootstrap = true;
109+
#endif
110+
SLANG_RETURN_ON_FAIL(
111+
slang_createGlobalSessionImpl(&desc, &internalDesc, session.writeRef()));
106112
}
107113

108114
if (!shouldEmbedPrelude(argv, argc))

‎tools/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ generator(
6262
TARGET_NAME
6363
slang-bootstrap
6464
USE_FEWER_WARNINGS
65+
EXTRA_COMPILE_DEFINITIONS_PRIVATE
66+
SLANG_BOOTSTRAP=1
6567
LINK_WITH_PUBLIC
6668
slang-without-embedded-core-module
6769
LINK_WITH_PRIVATE

0 commit comments

Comments
 (0)