summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-api.cpp73
-rw-r--r--source/slang/slang-compiler.h39
-rw-r--r--source/slang/slang-diagnostic-defs.h7
-rw-r--r--source/slang/slang-language-server.cpp4
-rw-r--r--source/slang/slang.cpp266
5 files changed, 306 insertions, 83 deletions
diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp
index e510fc9a2..16d6a07f1 100644
--- a/source/slang/slang-api.cpp
+++ b/source/slang/slang-api.cpp
@@ -23,11 +23,12 @@ SLANG_API SlangSession* spCreateSession(const char*)
return globalSession.detach();
}
-// Attempt to load a previously compiled core module from the same file system location as the slang
-// dll. Returns SLANG_OK when the cache is sucessfully loaded. Also returns the filename to the core
-// module cache and the timestamp of current slang dll.
-SlangResult tryLoadCoreModuleFromCache(
+// Attempt to load a previously compiled builtin module from the same file system location as the
+// slang dll. Returns SLANG_OK when the cache is sucessfully loaded. Also returns the filename to
+// the builtin module cache and the timestamp of current slang dll.
+SlangResult tryLoadBuiltinModuleFromCache(
slang::IGlobalSession* globalSession,
+ slang::BuiltinModuleName builtinModuleName,
Slang::String& outCachePath,
uint64_t& outTimestamp)
{
@@ -36,7 +37,10 @@ SlangResult tryLoadCoreModuleFromCache(
uint64_t currentLibTimestamp =
Slang::SharedLibraryUtils::getSharedLibraryTimestamp((void*)slang_createGlobalSession);
auto dirName = Slang::Path::getParentDirectory(fileName);
- auto cacheFileName = Slang::Path::combine(dirName, "slang-core-module.bin");
+ auto cacheFileName = Slang::Path::combine(
+ dirName,
+ Slang::String("slang-") + Slang::getBuiltinModuleNameStr(builtinModuleName) +
+ "-module.bin");
outTimestamp = currentLibTimestamp;
outCachePath = cacheFileName;
if (currentLibTimestamp == 0)
@@ -52,21 +56,24 @@ SlangResult tryLoadCoreModuleFromCache(
auto cacheTimestamp = *(uint64_t*)(cacheData.getData());
if (cacheTimestamp != currentLibTimestamp)
return SLANG_FAIL;
- SLANG_RETURN_ON_FAIL(globalSession->loadCoreModule(
+ SLANG_RETURN_ON_FAIL(globalSession->loadBuiltinModule(
+ builtinModuleName,
(uint8_t*)cacheData.getData() + sizeof(uint64_t),
cacheData.getSizeInBytes() - sizeof(uint64_t)));
return SLANG_OK;
}
-SlangResult trySaveCoreModuleToCache(
+SlangResult trySaveBuiltinModuleToCache(
slang::IGlobalSession* globalSession,
+ slang::BuiltinModuleName builtinModuleName,
const Slang::String& cacheFilename,
uint64_t dllTimestamp)
{
if (dllTimestamp != 0 && cacheFilename.getLength() != 0)
{
Slang::ComPtr<ISlangBlob> coreModuleBlobPtr;
- SLANG_RETURN_ON_FAIL(globalSession->saveCoreModule(
+ SLANG_RETURN_ON_FAIL(globalSession->saveBuiltinModule(
+ builtinModuleName,
SLANG_ARCHIVE_TYPE_RIFF_LZ4,
coreModuleBlobPtr.writeRef()));
@@ -85,6 +92,15 @@ SlangResult trySaveCoreModuleToCache(
SLANG_API SlangResult
slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobalSession)
{
+ SlangGlobalSessionDesc desc = {};
+ desc.apiVersion = (uint32_t)apiVersion;
+ return slang_createGlobalSession2(&desc, outGlobalSession);
+}
+
+SLANG_API SlangResult slang_createGlobalSession2(
+ const SlangGlobalSessionDesc* desc,
+ slang::IGlobalSession** outGlobalSession)
+{
Slang::ComPtr<slang::IGlobalSession> globalSession;
#ifdef SLANG_ENABLE_IR_BREAK_ALLOC
@@ -94,7 +110,7 @@ slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobal
#endif
SLANG_RETURN_ON_FAIL(
- slang_createGlobalSessionWithoutCoreModule(apiVersion, globalSession.writeRef()));
+ slang_createGlobalSessionWithoutCoreModule(desc->apiVersion, globalSession.writeRef()));
// If we have the embedded core module, load from that, else compile it
ISlangBlob* coreModuleBlob = slang_getEmbeddedCoreModule();
@@ -112,17 +128,48 @@ slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobal
#if SLANG_PROFILE_CORE_MODULE_COMPILE
auto startTime = std::chrono::high_resolution_clock::now();
#else
- if (tryLoadCoreModuleFromCache(globalSession, cacheFilename, dllTimestamp) != SLANG_OK)
+ if (tryLoadBuiltinModuleFromCache(
+ globalSession,
+ slang::BuiltinModuleName::Core,
+ cacheFilename,
+ dllTimestamp) != SLANG_OK)
#endif
{
// Compile std lib from embeded source.
- SLANG_RETURN_ON_FAIL(globalSession->compileCoreModule(0));
+ 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.
- trySaveCoreModuleToCache(globalSession, cacheFilename, dllTimestamp);
+ trySaveBuiltinModuleToCache(
+ globalSession,
+ slang::BuiltinModuleName::Core,
+ cacheFilename,
+ dllTimestamp);
+ }
+ }
+
+ if (desc->enableGLSL)
+ {
+ Slang::String cacheFilename;
+ uint64_t dllTimestamp = 0;
+ if (tryLoadBuiltinModuleFromCache(
+ globalSession,
+ slang::BuiltinModuleName::GLSL,
+ cacheFilename,
+ dllTimestamp) != SLANG_OK)
+ {
+ SLANG_RETURN_ON_FAIL(
+ globalSession->compileBuiltinModule(slang::BuiltinModuleName::GLSL, 0));
+
+ // Store the compiled core module to cache file.
+ trySaveBuiltinModuleToCache(
+ globalSession,
+ slang::BuiltinModuleName::GLSL,
+ cacheFilename,
+ dllTimestamp);
}
}
@@ -130,7 +177,7 @@ slang_createGlobalSession(SlangInt apiVersion, slang::IGlobalSession** outGlobal
if (SlangRecord::isRecordLayerEnabled())
{
SlangRecord::GlobalSessionRecorder* globalSessionRecorder =
- new SlangRecord::GlobalSessionRecorder(globalSession.detach());
+ new SlangRecord::GlobalSessionRecorder(desc, globalSession.detach());
Slang::ComPtr<SlangRecord::GlobalSessionRecorder> result(globalSessionRecorder);
*outGlobalSession = result.detach();
}
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index cc4fc8dcc..38725fff3 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -3430,6 +3430,18 @@ public:
SLANG_NO_THROW SlangResult SLANG_MCALL
saveCoreModule(SlangArchiveType archiveType, ISlangBlob** outBlob) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL compileBuiltinModule(
+ slang::BuiltinModuleName moduleName,
+ slang::CompileCoreModuleFlags flags) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL loadBuiltinModule(
+ slang::BuiltinModuleName moduleName,
+ const void* coreModule,
+ size_t coreModuleSizeInBytes) override;
+ SLANG_NO_THROW SlangResult SLANG_MCALL saveBuiltinModule(
+ slang::BuiltinModuleName moduleName,
+ SlangArchiveType archiveType,
+ ISlangBlob** outBlob) override;
+
SLANG_NO_THROW SlangCapabilityID SLANG_MCALL findCapability(char const* name) override;
SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerForTransition(
@@ -3470,7 +3482,8 @@ public:
Scope* coreLanguageScope = nullptr;
Scope* hlslLanguageScope = nullptr;
Scope* slangLanguageScope = nullptr;
- Scope* autodiffLanguageScope = nullptr;
+ Scope* glslLanguageScope = nullptr;
+ Name* glslModuleName = nullptr;
ModuleDecl* baseModuleDecl = nullptr;
List<RefPtr<Module>> coreModules;
@@ -3543,11 +3556,17 @@ public:
/// Get the built in linkage -> handy to get the core module from
Linkage* getBuiltinLinkage() const { return m_builtinLinkage; }
+ Module* getBuiltinModule(slang::BuiltinModuleName builtinModuleName);
+
Name* getCompletionRequestTokenName() const { return m_completionTokenName; }
void init();
- void addBuiltinSource(Scope* scope, String const& path, ISlangBlob* sourceBlob);
+ void addBuiltinSource(
+ Scope* scope,
+ String const& path,
+ ISlangBlob* sourceBlob,
+ Module*& outModule);
~Session();
void addDownstreamCompileTime(double time) { m_downstreamCompileTime += time; }
@@ -3571,9 +3590,21 @@ public:
int m_typeDictionarySize = 0;
private:
+ struct BuiltinModuleInfo
+ {
+ const char* name;
+ Scope* languageScope;
+ };
+
+ BuiltinModuleInfo getBuiltinModuleInfo(slang::BuiltinModuleName name);
+
void _initCodeGenTransitionMap();
- SlangResult _readBuiltinModule(ISlangFileSystem* fileSystem, Scope* scope, String moduleName);
+ SlangResult _readBuiltinModule(
+ ISlangFileSystem* fileSystem,
+ Scope* scope,
+ String moduleName,
+ Module*& outModule);
SlangResult _loadRequest(EndToEndCompileRequest* request, const void* data, size_t size);
@@ -3592,6 +3623,8 @@ private:
double m_totalCompileTime = 0.0;
};
+const char* getBuiltinModuleNameStr(slang::BuiltinModuleName name);
+
void checkTranslationUnit(
TranslationUnitRequest* translationUnit,
LoadedModuleDictionary& loadedModules);
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index fa96b89f9..ca99ac11d 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -1856,6 +1856,13 @@ DIAGNOSTIC(
Error,
errorInImportedModule,
"import of module '$0' failed because of a compilation error")
+
+DIAGNOSTIC(
+ 38201,
+ Error,
+ glslModuleNotAvailable,
+ "'glsl' module is not available from the current global session. To enable GLSL compatibility "
+ "mode, specify 'SlangGlobalSessionDesc::enableGLSL' when creating the global session.")
DIAGNOSTIC(39999, Fatal, complationCeased, "compilation ceased")
// 39xxx - Type layout and parameter binding.
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index f9cc6f711..43e5b31ef 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -82,7 +82,9 @@ slang::IGlobalSession* LanguageServerCore::getOrCreateGlobalSession()
if (!m_session)
{
// Just create the global session in the regular way if there isn't one set
- if (SLANG_FAILED(slang_createGlobalSession(SLANG_API_VERSION, m_session.writeRef())))
+ SlangGlobalSessionDesc desc = {};
+ desc.enableGLSL = true;
+ if (SLANG_FAILED(slang_createGlobalSession2(&desc, m_session.writeRef())))
{
return nullptr;
}
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 6a242d5ce..8d73cc0ef 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -18,6 +18,7 @@
#include "../core/slang-file-system.h"
#include "../core/slang-memory-file-system.h"
#include "../core/slang-writer.h"
+#include "core/slang-shared-library.h"
#include "slang-ast-dump.h"
#include "slang-check-impl.h"
#include "slang-check.h"
@@ -220,15 +221,17 @@ void Session::init()
coreLanguageScope = builtinAstBuilder->create<Scope>();
coreLanguageScope->nextSibling = baseLanguageScope;
- autodiffLanguageScope = builtinAstBuilder->create<Scope>();
- autodiffLanguageScope->nextSibling = coreLanguageScope;
-
hlslLanguageScope = builtinAstBuilder->create<Scope>();
- hlslLanguageScope->nextSibling = autodiffLanguageScope;
+ hlslLanguageScope->nextSibling = coreLanguageScope;
slangLanguageScope = builtinAstBuilder->create<Scope>();
slangLanguageScope->nextSibling = hlslLanguageScope;
+ glslLanguageScope = builtinAstBuilder->create<Scope>();
+ glslLanguageScope->nextSibling = slangLanguageScope;
+
+ glslModuleName = getNameObj("glsl");
+
{
for (Index i = 0; i < Index(SourceLanguage::CountOf); ++i)
{
@@ -248,6 +251,17 @@ void Session::init()
spirvCoreGrammarInfo = SPIRVCoreGrammarInfo::getEmbeddedVersion();
}
+Module* Session::getBuiltinModule(slang::BuiltinModuleName name)
+{
+ auto info = getBuiltinModuleInfo(name);
+ auto builtinLinkage = getBuiltinLinkage();
+ auto moduleNameObj = builtinLinkage->getNamePool()->getName(info.name);
+ RefPtr<Module> module;
+ if (builtinLinkage->mapNameToLoadedModules.tryGetValue(moduleNameObj, module))
+ return module.get();
+ return nullptr;
+}
+
void Session::_initCodeGenTransitionMap()
{
// TODO(JS): Might want to do something about these in the future...
@@ -314,7 +328,10 @@ void Session::addBuiltins(char const* sourcePath, char const* source)
auto sourceBlob = StringBlob::moveCreate(String(source));
// TODO(tfoley): Add ability to directly new builtins to the appropriate scope
- addBuiltinSource(coreLanguageScope, sourcePath, sourceBlob);
+ Module* module = nullptr;
+ addBuiltinSource(coreLanguageScope, sourcePath, sourceBlob, module);
+ if (module)
+ coreModules.add(module);
}
void Session::setSharedLibraryLoader(ISlangSharedLibraryLoader* loader)
@@ -376,31 +393,101 @@ void Session::writeCoreModuleDoc(String config)
}
}
-SlangResult Session::compileCoreModule(slang::CompileCoreModuleFlags compileFlags)
+const char* getBuiltinModuleNameStr(slang::BuiltinModuleName name)
{
- SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
+ const char* result = nullptr;
+ switch (name)
+ {
+ case slang::BuiltinModuleName::Core:
+ result = "core";
+ break;
+ case slang::BuiltinModuleName::GLSL:
+ result = "glsl";
+ break;
+ default:
+ SLANG_UNEXPECTED("Unknown builtin module");
+ }
+ return result;
+}
+
+Session::BuiltinModuleInfo Session::getBuiltinModuleInfo(slang::BuiltinModuleName name)
+{
+ Session::BuiltinModuleInfo result;
- if (m_builtinLinkage->mapNameToLoadedModules.getCount())
+ result.name = getBuiltinModuleNameStr(name);
+
+ switch (name)
{
- // Already have a core module loaded
- return SLANG_FAIL;
+ case slang::BuiltinModuleName::Core:
+ result.languageScope = coreLanguageScope;
+ break;
+ case slang::BuiltinModuleName::GLSL:
+ result.name = "glsl";
+ result.languageScope = glslLanguageScope;
+ break;
+ default:
+ SLANG_UNEXPECTED("Unknown builtin module");
}
+ return result;
+}
+
+SlangResult Session::compileCoreModule(slang::CompileCoreModuleFlags compileFlags)
+{
+ return compileBuiltinModule(slang::BuiltinModuleName::Core, compileFlags);
+}
+
+SlangResult Session::compileBuiltinModule(
+ slang::BuiltinModuleName moduleName,
+ slang::CompileCoreModuleFlags compileFlags)
+{
+ SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
#ifdef _DEBUG
- // Print a message in debug builds to notice the user that compiling the core module
- // can take a while.
- time_t beginTime;
- time(&beginTime);
- fprintf(stderr, "Compiling core module on debug build, this can take a while.\n");
+ time_t beginTime = 0;
+ if (moduleName == slang::BuiltinModuleName::Core)
+ {
+ // Print a message in debug builds to notice the user that compiling the core module
+ // can take a while.
+ time(&beginTime);
+ fprintf(stderr, "Compiling core module on debug build, this can take a while.\n");
+ }
#endif
+ BuiltinModuleInfo builtinModuleInfo = getBuiltinModuleInfo(moduleName);
+ auto moduleNameObj = m_builtinLinkage->getNamePool()->getName(builtinModuleInfo.name);
+ if (m_builtinLinkage->mapNameToLoadedModules.tryGetValue(moduleNameObj))
+ {
+ // Already have the builtin module loaded
+ return SLANG_FAIL;
+ }
- // TODO(JS): Could make this return a SlangResult as opposed to exception
- StringBuilder coreModuleSrcBuilder;
- coreModuleSrcBuilder << (const char*)getCoreLibraryCode()->getBufferPointer()
+ StringBuilder moduleSrcBuilder;
+ switch (moduleName)
+ {
+ case slang::BuiltinModuleName::Core:
+ moduleSrcBuilder << (const char*)getCoreLibraryCode()->getBufferPointer()
<< (const char*)getHLSLLibraryCode()->getBufferPointer()
<< (const char*)getAutodiffLibraryCode()->getBufferPointer();
- auto coreModuleSrcBlob = StringBlob::moveCreate(coreModuleSrcBuilder.produceString());
- addBuiltinSource(coreLanguageScope, "core", coreModuleSrcBlob);
+ break;
+ case slang::BuiltinModuleName::GLSL:
+ moduleSrcBuilder << (const char*)getGLSLLibraryCode()->getBufferPointer();
+ break;
+ }
+
+ // TODO(JS): Could make this return a SlangResult as opposed to exception
+ auto moduleSrcBlob = StringBlob::moveCreate(moduleSrcBuilder.produceString());
+ Module* compiledModule = nullptr;
+ addBuiltinSource(
+ builtinModuleInfo.languageScope,
+ builtinModuleInfo.name,
+ moduleSrcBlob,
+ compiledModule);
+
+ if (moduleName == slang::BuiltinModuleName::Core)
+ {
+ // We need to retain this AST so that we can use it in other code
+ // (Note that the `Scope` type does not retain the AST it points to)
+ coreModules.add(compiledModule);
+ }
if (compileFlags & slang::CompileCoreModuleFlag::WriteDocumentation)
{
@@ -422,31 +509,57 @@ SlangResult Session::compileCoreModule(slang::CompileCoreModuleFlags compileFlag
finalizeSharedASTBuilder();
#ifdef _DEBUG
- time_t endTime;
- time(&endTime);
- fprintf(stderr, "Compiling core module took %.2f seconds.\n", difftime(endTime, beginTime));
+ if (moduleName == slang::BuiltinModuleName::Core)
+ {
+ time_t endTime;
+ time(&endTime);
+ fprintf(stderr, "Compiling core module took %.2f seconds.\n", difftime(endTime, beginTime));
+ }
#endif
return SLANG_OK;
}
SlangResult Session::loadCoreModule(const void* coreModule, size_t coreModuleSizeInBytes)
{
+ return loadBuiltinModule(slang::BuiltinModuleName::Core, coreModule, coreModuleSizeInBytes);
+}
+
+SlangResult Session::loadBuiltinModule(
+ slang::BuiltinModuleName moduleName,
+ const void* moduleData,
+ size_t sizeInBytes)
+{
SLANG_PROFILE;
- if (m_builtinLinkage->mapNameToLoadedModules.getCount())
+
+ SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
+
+ BuiltinModuleInfo builtinModuleInfo = getBuiltinModuleInfo(moduleName);
+ auto nameObj = m_builtinLinkage->getNamePool()->getName(builtinModuleInfo.name);
+ if (m_builtinLinkage->mapNameToLoadedModules.containsKey(nameObj))
{
// Already have a core module loaded
return SLANG_FAIL;
}
- SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
-
// Make a file system to read it from
ComPtr<ISlangFileSystemExt> fileSystem;
- SLANG_RETURN_ON_FAIL(loadArchiveFileSystem(coreModule, coreModuleSizeInBytes, fileSystem));
+ SLANG_RETURN_ON_FAIL(loadArchiveFileSystem(moduleData, sizeInBytes, fileSystem));
// Let's try loading serialized modules and adding them
- SLANG_RETURN_ON_FAIL(_readBuiltinModule(fileSystem, coreLanguageScope, "core"));
+ Module* module = nullptr;
+ SLANG_RETURN_ON_FAIL(_readBuiltinModule(
+ fileSystem,
+ builtinModuleInfo.languageScope,
+ builtinModuleInfo.name,
+ module));
+
+ if (moduleName == slang::BuiltinModuleName::Core)
+ {
+ // We need to retain this AST so that we can use it in other code
+ // (Note that the `Scope` type does not retain the AST it points to)
+ coreModules.add(module);
+ }
finalizeSharedASTBuilder();
return SLANG_OK;
@@ -454,12 +567,22 @@ SlangResult Session::loadCoreModule(const void* coreModule, size_t coreModuleSiz
SlangResult Session::saveCoreModule(SlangArchiveType archiveType, ISlangBlob** outBlob)
{
+ return saveBuiltinModule(slang::BuiltinModuleName::Core, archiveType, outBlob);
+}
+
+SlangResult Session::saveBuiltinModule(
+ slang::BuiltinModuleName builtinModuleName,
+ SlangArchiveType archiveType,
+ ISlangBlob** outBlob)
+{
if (m_builtinLinkage->mapNameToLoadedModules.getCount() == 0)
{
// There is no standard lib loaded
return SLANG_FAIL;
}
+ BuiltinModuleInfo builtinModuleInfo = getBuiltinModuleInfo(builtinModuleName);
+
// Make a file system to read it from
ComPtr<ISlangMutableFileSystem> fileSystem;
SLANG_RETURN_ON_FAIL(createArchiveFileSystem(archiveType, fileSystem));
@@ -471,32 +594,38 @@ SlangResult Session::saveCoreModule(SlangArchiveType archiveType, ISlangBlob** o
return SLANG_FAIL;
}
+ RefPtr<Module> module;
+ m_builtinLinkage->mapNameToLoadedModules.tryGetValue(
+ getNameObj(UnownedStringSlice(builtinModuleInfo.name)),
+ module);
+ if (!module)
+ {
+ return SLANG_FAIL;
+ }
+
SLANG_AST_BUILDER_RAII(m_builtinLinkage->getASTBuilder());
- for (const auto& [moduleName, module] : m_builtinLinkage->mapNameToLoadedModules)
- {
- // Set up options
- SerialContainerUtil::WriteOptions options;
+ // Set up options
+ SerialContainerUtil::WriteOptions options;
- // Save with SourceLocation information
- options.optionFlags |= SerialOptionFlag::SourceLocation;
+ // Save with SourceLocation information
+ options.optionFlags |= SerialOptionFlag::SourceLocation;
- // TODO(JS): Should this be the Session::getBuiltinSourceManager()?
- options.sourceManager = m_builtinLinkage->getSourceManager();
+ // TODO(JS): Should this be the Session::getBuiltinSourceManager()?
+ options.sourceManager = m_builtinLinkage->getSourceManager();
- StringBuilder builder;
- builder << moduleName->text << ".slang-module";
+ StringBuilder builder;
+ builder << builtinModuleInfo.name << ".slang-module";
- OwnedMemoryStream stream(FileAccess::Write);
+ OwnedMemoryStream stream(FileAccess::Write);
- SLANG_RETURN_ON_FAIL(SerialContainerUtil::write(module, options, &stream));
+ SLANG_RETURN_ON_FAIL(SerialContainerUtil::write(module, options, &stream));
- auto contents = stream.getContents();
+ auto contents = stream.getContents();
- // Write into the file system
- SLANG_RETURN_ON_FAIL(
- fileSystem->saveFile(builder.getBuffer(), contents.getBuffer(), contents.getCount()));
- }
+ // Write into the file system
+ SLANG_RETURN_ON_FAIL(
+ fileSystem->saveFile(builder.getBuffer(), contents.getBuffer(), contents.getCount()));
// Now need to convert into a blob
SLANG_RETURN_ON_FAIL(archiveFileSystem->storeArchive(true, outBlob));
@@ -506,7 +635,8 @@ SlangResult Session::saveCoreModule(SlangArchiveType archiveType, ISlangBlob** o
SlangResult Session::_readBuiltinModule(
ISlangFileSystem* fileSystem,
Scope* scope,
- String moduleName)
+ String moduleName,
+ Module*& outModule)
{
// Get the name of the module
StringBuilder moduleFilename;
@@ -590,9 +720,7 @@ SlangResult Session::_readBuiltinModule(
scope->nextSibling = subScope;
}
- // We need to retain this AST so that we can use it in other code
- // (Note that the `Scope` type does not retain the AST it points to)
- coreModules.add(module);
+ outModule = module.get();
}
return SLANG_OK;
@@ -2169,7 +2297,9 @@ Scope* TranslationUnitRequest::getLanguageScope()
case SourceLanguage::HLSL:
languageScope = getSession()->hlslLanguageScope;
break;
-
+ case SourceLanguage::GLSL:
+ languageScope = getSession()->glslLanguageScope;
+ break;
case SourceLanguage::Slang:
default:
languageScope = getSession()->slangLanguageScope;
@@ -3136,7 +3266,9 @@ void FrontEndCompileRequest::parseTranslationUnit(TranslationUnitRequest* transl
case SourceLanguage::HLSL:
languageScope = getSession()->hlslLanguageScope;
break;
-
+ case SourceLanguage::GLSL:
+ languageScope = getSession()->glslLanguageScope;
+ break;
case SourceLanguage::Slang:
default:
languageScope = getSession()->slangLanguageScope;
@@ -4132,6 +4264,16 @@ RefPtr<Module> Linkage::findOrImportModule(
return previouslyLoadedModule;
}
+ if (name == getSessionImpl()->glslModuleName)
+ {
+ // This is a builtin glsl module, just load it from embedded definition.
+ auto glslModule = getSessionImpl()->getBuiltinModule(slang::BuiltinModuleName::GLSL);
+ if (!glslModule)
+ {
+ sink->diagnose(loc, Diagnostics::glslModuleNotAvailable, name);
+ }
+ return glslModule;
+ }
// Next, try to find the file of the given name,
// using our ordinary include-handling logic.
@@ -4168,17 +4310,7 @@ RefPtr<Module> Linkage::findOrImportModule(
if (SLANG_FAILED(
includeSystem.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo)))
{
- if (name && name->text == "glsl")
- {
- // This is a builtin glsl module, just load it from embedded definition.
- fileContents = getSessionImpl()->getGLSLLibraryCode();
- filePathInfo = PathInfo::makeFromString("glsl");
- checkBinaryModule = 0;
- }
- else
- {
- continue;
- }
+ continue;
}
// Maybe this was loaded previously at a different relative name?
@@ -6088,7 +6220,11 @@ RefPtr<Module> findOrImportModule(
return linkage->findOrImportModule(name, loc, sink, loadedModules);
}
-void Session::addBuiltinSource(Scope* scope, String const& path, ISlangBlob* sourceBlob)
+void Session::addBuiltinSource(
+ Scope* scope,
+ String const& path,
+ ISlangBlob* sourceBlob,
+ Module*& outModule)
{
SourceManager* sourceManager = getBuiltinSourceManager();
@@ -6151,9 +6287,7 @@ void Session::addBuiltinSource(Scope* scope, String const& path, ISlangBlob* sou
scope->nextSibling = subScope;
}
- // We need to retain this AST so that we can use it in other code
- // (Note that the `Scope` type does not retain the AST it points to)
- coreModules.add(module);
+ outModule = module;
}
Session::~Session()