summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-31 05:02:26 -0800
committerGitHub <noreply@github.com>2025-01-31 21:02:26 +0800
commiteebe849075c21d163739cbc5e976e7b5b6837e7f (patch)
treeec3fd562da49385fbd5d4a6deebac78b9fe74c09 /source/slang
parentae778e3424b39cbeb1f367339f654560de416d30 (diff)
Distribute slang-glsl-module.bin in release packages. (#6233)
* Distribute slang-glsl-module.bin in release packages. * Fix. * fix2. * Build glsl modlue into a dll.
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-api.cpp44
-rw-r--r--source/slang/slang-options.cpp23
2 files changed, 57 insertions, 10 deletions
diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp
index 16d6a07f1..701f49355 100644
--- a/source/slang/slang-api.cpp
+++ b/source/slang/slang-api.cpp
@@ -1,6 +1,7 @@
// slang-api.cpp
#include "../core/slang-performance-profiler.h"
+#include "../core/slang-platform.h"
#include "../core/slang-rtti-info.h"
#include "../core/slang-shared-library.h"
#include "../core/slang-signal.h"
@@ -63,6 +64,32 @@ SlangResult tryLoadBuiltinModuleFromCache(
return SLANG_OK;
}
+// Attempt to load a precompiled builtin module from slang-xxx-module.dll.
+SlangResult tryLoadBuiltinModuleFromDLL(
+ slang::IGlobalSession* globalSession,
+ slang::BuiltinModuleName builtinModuleName)
+{
+ Slang::String moduleFileName =
+ Slang::String("slang-") + Slang::getBuiltinModuleNameStr(builtinModuleName) + "-module";
+
+ Slang::SharedLibrary::Handle libHandle = nullptr;
+
+ SLANG_RETURN_ON_FAIL(Slang::SharedLibrary::load(moduleFileName.getBuffer(), libHandle));
+ if (!libHandle)
+ return SLANG_FAIL;
+ void* ptr = Slang::SharedLibrary::findSymbolAddressByName(libHandle, "slang_getEmbeddedModule");
+ if (!ptr)
+ return SLANG_FAIL;
+ typedef ISlangBlob*(GetEmbeddedModuleFunc)();
+ auto getEmbeddedModule = (GetEmbeddedModuleFunc*)ptr;
+ auto blob = getEmbeddedModule();
+ SLANG_RETURN_ON_FAIL(globalSession->loadBuiltinModule(
+ builtinModuleName,
+ (uint8_t*)blob->getBufferPointer(),
+ blob->getBufferSize()));
+ return SLANG_OK;
+}
+
SlangResult trySaveBuiltinModuleToCache(
slang::IGlobalSession* globalSession,
slang::BuiltinModuleName builtinModuleName,
@@ -155,11 +182,18 @@ SLANG_API SlangResult slang_createGlobalSession2(
{
Slang::String cacheFilename;
uint64_t dllTimestamp = 0;
- if (tryLoadBuiltinModuleFromCache(
- globalSession,
- slang::BuiltinModuleName::GLSL,
- cacheFilename,
- dllTimestamp) != SLANG_OK)
+ if (SLANG_SUCCEEDED(
+ tryLoadBuiltinModuleFromDLL(globalSession, slang::BuiltinModuleName::GLSL)))
+ {
+ }
+ else if (SLANG_SUCCEEDED(tryLoadBuiltinModuleFromCache(
+ globalSession,
+ slang::BuiltinModuleName::GLSL,
+ cacheFilename,
+ dllTimestamp)))
+ {
+ }
+ else
{
SLANG_RETURN_ON_FAIL(
globalSession->compileBuiltinModule(slang::BuiltinModuleName::GLSL, 0));
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index a0e8515eb..2b4d64cd9 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -888,6 +888,11 @@ void initCommandOptions(CommandOptions& options)
"-save-core-module-bin-source <filename>",
"Same as -save-core-module but output "
"the data as a C array.\n"},
+ {OptionKind::SaveGLSLModuleBinSource,
+ "-save-glsl-module-bin-source",
+ "-save-glsl-module-bin-source <filename>",
+ "Save the serialized glsl module "
+ "as a C array.\n"},
{OptionKind::TrackLiveness,
"-track-liveness",
nullptr,
@@ -2203,14 +2208,24 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
break;
}
case OptionKind::SaveCoreModuleBinSource:
+ case OptionKind::SaveGLSLModuleBinSource:
{
CommandLineArg fileName;
SLANG_RETURN_ON_FAIL(m_reader.expectArg(fileName));
ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(m_session->saveCoreModule(m_archiveType, blob.writeRef()));
-
+ if (optionKind == OptionKind::SaveCoreModuleBinSource)
+ {
+ SLANG_RETURN_ON_FAIL(m_session->saveCoreModule(m_archiveType, blob.writeRef()));
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(m_session->saveBuiltinModule(
+ slang::BuiltinModuleName::GLSL,
+ m_archiveType,
+ blob.writeRef()));
+ }
StringBuilder builder;
StringWriter writer(&builder, 0);
@@ -2763,9 +2778,7 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
case OptionKind::Help:
{
SLANG_RETURN_ON_FAIL(_parseHelp(arg));
-
- // We retun an error so after this has successfully passed, we quit
- return SLANG_FAIL;
+ return SLANG_OK;
}
case OptionKind::EmitSpirvViaGLSL:
case OptionKind::EmitSpirvDirectly: