Skip to content

slang wants to load libslang-glslang-<version>.so even when it does not build it #11662

Description

@rg3igalia

I'm exploring the possiblity of integrating basic slang support into Vulkan CTS (i.e. using shaders in the slang language to generate binary SPIR-V for tests). CTS now mainly uses glslang for shader code, with some exceptions and subgroups of tests using SPIR-V assembly and a few tests that use HLSL.

I've only spent a bit of time exploring/entertaining this idea and I'm not familiar with slang, but the goal here is building slang as a static library and linking that into the deqp-vk binary, so the binary can be run as-is without changing anything in the environment. This also implies slang would not be "installed" after being built and is similar to how glslang is currently integrated and allows the deqp-vk binary to be run directly from the output build directory of CTS.

The first issue I've encountered when building slang as a static library and using it from a toy program as I would use it from CTS is that the resulting program insists on loading libslang-glslang-<version>.so at runtime, and in a scenario where that library has not been installed, it fails to do so because it's not in any system directory. It even tries to do that when the dynamic library is not being built at all!

For reference, this is how I'm configuring slang in my toy environment:

mkdir build
cd build
cmake \
-DCMAKE_BUILD_TYPE=Debug                \
-DSLANG_ENABLE_GFX=OFF                  \
-DSLANG_ENABLE_SLANG_RHI=OFF            \
-DSLANG_ENABLE_TESTS=OFF                \
-DSLANG_ENABLE_SLANGD=OFF               \
-DSLANG_ENABLE_REPLAYER=OFF             \
-DSLANG_SLANG_LLVM_FLAVOR=DISABLE       \
-DSLANG_ENABLE_EXAMPLES=OFF             \
-DSLANG_ENABLE_XLIB=OFF                 \
-DSLANG_ENABLE_CUDA=OFF                 \
-DSLANG_ENABLE_OPTIX=OFF                \
-DSLANG_ENABLE_NVAPI=OFF                \
-DSLANG_ENABLE_AFTERMATH=OFF            \
-DSLANG_ENABLE_SLANG_GLSLANG=OFF        \
-DSLANG_ENABLE_DXIL=OFF                 \
-DSLANG_ENABLE_PCH=OFF                  \
-DSLANG_LIB_TYPE=STATIC                 \
-DSLANG_ENABLE_SLANGC=OFF		\
-DSLANG_ENABLE_SLANGI=OFF		\
-DSLANG_ENABLE_SLANGRT=OFF		\
..

This is the error I get when I run the toy program:

error[E00100]: failed to load downstream compiler 'spirv-opt'
note[E99996]: failed to load dynamic library 'pthread'
note[E99996]: failed to load dynamic library 'slang-glslang-2026.11'

Again, libslang-glslang-<version>.so is not being built when slang is configured as specified above. I noticed the library is being loaded from locateGlslangSpirvDownstreamCompiler, which is in turn used in several locateCompilers methods. If I force that part to be skipped with this change:

diff --git a/source/compiler-core/slang-downstream-compiler-util.cpp b/source/compiler-core/slang-downstream-compiler-util.cpp
index 68fc241b9..1da173570 100644
--- a/source/compiler-core/slang-downstream-compiler-util.cpp
+++ b/source/compiler-core/slang-downstream-compiler-util.cpp
@@ -360,10 +360,10 @@ DownstreamCompilerMatchVersion DownstreamCompilerUtil::getCompiledVersion()
     outFuncs[int(SLANG_PASS_THROUGH_NVRTC)] = &NVRTCDownstreamCompilerUtil::locateCompilers;
     outFuncs[int(SLANG_PASS_THROUGH_DXC)] = &DXCDownstreamCompilerUtil::locateCompilers;
     outFuncs[int(SLANG_PASS_THROUGH_FXC)] = &FXCDownstreamCompilerUtil::locateCompilers;
-    outFuncs[int(SLANG_PASS_THROUGH_GLSLANG)] = &GlslangDownstreamCompilerUtil::locateCompilers;
-    outFuncs[int(SLANG_PASS_THROUGH_SPIRV_OPT)] = &SpirvOptDownstreamCompilerUtil::locateCompilers;
+    outFuncs[int(SLANG_PASS_THROUGH_GLSLANG)] = nullptr;
+    outFuncs[int(SLANG_PASS_THROUGH_SPIRV_OPT)] = nullptr;
     outFuncs[int(SLANG_PASS_THROUGH_LLVM)] = &LLVMDownstreamCompilerUtil::locateCompilers;
-    outFuncs[int(SLANG_PASS_THROUGH_SPIRV_DIS)] = &SpirvDisDownstreamCompilerUtil::locateCompilers;
+    outFuncs[int(SLANG_PASS_THROUGH_SPIRV_DIS)] = nullptr;
     outFuncs[int(SLANG_PASS_THROUGH_METAL)] = &MetalDownstreamCompilerUtil::locateCompilers;
     outFuncs[int(SLANG_PASS_THROUGH_TINT)] = &TintDownstreamCompilerUtil::locateCompilers;
 }

Then the resulting toy program still works, does not crash, and is able to generate SPIR-V from slang as expected. Could something like this be ifdef'd depending on configuration options?

Thanks in advance.

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions