diff options
| author | Yong He <yonghe@outlook.com> | 2025-01-31 05:02:26 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-31 21:02:26 +0800 |
| commit | eebe849075c21d163739cbc5e976e7b5b6837e7f (patch) | |
| tree | ec3fd562da49385fbd5d4a6deebac78b9fe74c09 /source | |
| parent | ae778e3424b39cbeb1f367339f654560de416d30 (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')
| -rw-r--r-- | source/slang-glsl-module/CMakeLists.txt | 39 | ||||
| -rw-r--r-- | source/slang-glsl-module/slang-embedded-glsl-module.cpp | 17 | ||||
| -rw-r--r-- | source/slang-record-replay/util/emum-to-string.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-api.cpp | 44 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 23 | ||||
| -rw-r--r-- | source/slangc/CMakeLists.txt | 1 |
6 files changed, 115 insertions, 10 deletions
diff --git a/source/slang-glsl-module/CMakeLists.txt b/source/slang-glsl-module/CMakeLists.txt new file mode 100644 index 000000000..d42b31ee6 --- /dev/null +++ b/source/slang-glsl-module/CMakeLists.txt @@ -0,0 +1,39 @@ +# +# Generate an embeddable glsl module +# + +set(glsl_module_generated_header_dir ${CMAKE_CURRENT_BINARY_DIR}) +set(glsl_module_generated_header + ${glsl_module_generated_header_dir}/slang-glsl-module-generated.h +) +add_custom_command( + OUTPUT ${glsl_module_generated_header} + COMMAND + slang-bootstrap -archive-type riff-lz4 -save-glsl-module-bin-source + ${glsl_module_generated_header} + DEPENDS slang-bootstrap + VERBATIM +) + +set(glsl_module_common_args + . + MODULE + FOLDER + generated + LINK_WITH_PRIVATE + core + USE_EXTRA_WARNINGS + EXPLICIT_SOURCE + ./slang-embedded-glsl-module.cpp +) + +slang_add_target( + ${glsl_module_common_args} + TARGET_NAME slang-glsl-module + EXCLUDE_FROM_ALL + EXTRA_COMPILE_DEFINITIONS_PRIVATE SLANG_SHARED_LIBRARY_TOOL + EXPORT_SET_NAME SlangTargets + EXPLICIT_SOURCE ${glsl_module_generated_header} + INCLUDE_DIRECTORIES_PRIVATE ${glsl_module_generated_header_dir} + INSTALL +) diff --git a/source/slang-glsl-module/slang-embedded-glsl-module.cpp b/source/slang-glsl-module/slang-embedded-glsl-module.cpp new file mode 100644 index 000000000..7435f1edb --- /dev/null +++ b/source/slang-glsl-module/slang-embedded-glsl-module.cpp @@ -0,0 +1,17 @@ +#include "../core/slang-array-view.h" +#include "../core/slang-basic.h" +#include "../core/slang-blob.h" + +static const uint8_t g_glslModule[] = { +#include "slang-glsl-module-generated.h" +}; + +static Slang::StaticBlob g_glslModuleBlob((const void*)g_glslModule, sizeof(g_glslModule)); + +extern "C" +{ + SLANG_DLL_EXPORT ISlangBlob* slang_getEmbeddedModule() + { + return &g_glslModuleBlob; + } +} diff --git a/source/slang-record-replay/util/emum-to-string.h b/source/slang-record-replay/util/emum-to-string.h index b19782126..1647ab24b 100644 --- a/source/slang-record-replay/util/emum-to-string.h +++ b/source/slang-record-replay/util/emum-to-string.h @@ -226,6 +226,7 @@ static Slang::String CompilerOptionNameToString(const slang::CompilerOptionName CASE(ReferenceModule); CASE(SaveCoreModule); CASE(SaveCoreModuleBinSource); + CASE(SaveGLSLModuleBinSource); CASE(TrackLiveness); CASE(LoopInversion); CASE(CountOfParsableOptions); 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: diff --git a/source/slangc/CMakeLists.txt b/source/slangc/CMakeLists.txt index 59d691bf4..32ad02541 100644 --- a/source/slangc/CMakeLists.txt +++ b/source/slangc/CMakeLists.txt @@ -5,6 +5,7 @@ if(SLANG_ENABLE_SLANGC) USE_FEWER_WARNINGS DEBUG_DIR ${slang_SOURCE_DIR} LINK_WITH_PRIVATE core slang Threads::Threads + REQUIRES slang-glsl-module INSTALL EXPORT_SET_NAME SlangTargets ) |
