File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ set(SOURCE
1818 src/HLSLTokenizer.cpp
1919)
2020
21+ option (DILIGENT_USE_STATIC_DXC "Link DXC statically and bypass dlopen" OFF )
22+
2123set (DXC_SUPPORTED FALSE )
2224if ((PLATFORM_WIN32 AND NOT MINGW_BUILD) OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_LINUX)
2325 set (DXC_SUPPORTED TRUE )
@@ -143,8 +145,14 @@ if (DXC_SUPPORTED)
143145 endif ()
144146
145147 if (NOT PLATFORM_WIN32)
146- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
147- CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
148+ if (DILIGENT_USE_STATIC_DXC)
149+ target_compile_definitions (Diligent-ShaderTools PRIVATE DILIGENT_USE_STATIC_DXC=1)
150+ target_link_libraries (Diligent-ShaderTools
151+ PUBLIC
152+ LLVMSupport
153+ dxcompiler
154+ )
155+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
148156 target_link_libraries (Diligent-ShaderTools PRIVATE dl)
149157 endif ()
150158 endif ()
@@ -176,6 +184,13 @@ if(ENABLE_SPIRV)
176184 endif ()
177185
178186 if (${USE_SPIRV_TOOLS} )
187+ if (NOT PLATFORM_WIN32 AND DILIGENT_USE_STATIC_DXC)
188+ cmake_policy (SET CMP0079 NEW)
189+ target_link_libraries (SPIRV-Tools-opt
190+ PUBLIC
191+ LLVMSupport
192+ )
193+ endif ()
179194 target_link_libraries (Diligent-ShaderTools
180195 PRIVATE
181196 SPIRV-Tools-opt
Original file line number Diff line number Diff line change @@ -33,26 +33,34 @@ namespace Diligent
3333
3434void DXCompilerLibrary::Load ()
3535{
36+ #if defined(DILIGENT_USE_STATIC_DXC)
37+ m_Library = reinterpret_cast <void *>(0x1 );
38+ m_DxcCreateInstance = &DxcCreateInstance;
39+ #else
3640 if (!m_LibName.empty ())
3741 m_Library = dlopen (m_LibName.c_str (), RTLD_LOCAL | RTLD_LAZY);
3842
3943 if (m_Library == nullptr )
4044 m_Library = dlopen (" libdxcompiler.so" , RTLD_LOCAL | RTLD_LAZY);
4145
42- // try to load from default path
4346 if (m_Library == nullptr )
4447 m_Library = dlopen (" /usr/lib/dxc/libdxcompiler.so" , RTLD_LOCAL | RTLD_LAZY);
4548
46- m_DxcCreateInstance = m_Library != nullptr ? reinterpret_cast <DxcCreateInstanceProc>(dlsym (m_Library, " DxcCreateInstance" )) : nullptr ;
49+ m_DxcCreateInstance = m_Library != nullptr
50+ ? reinterpret_cast <DxcCreateInstanceProc>(dlsym (m_Library, " DxcCreateInstance" ))
51+ : nullptr ;
52+ #endif
4753}
4854
4955void DXCompilerLibrary::Unload ()
5056{
57+ #if !defined(DILIGENT_USE_STATIC_DXC)
5158 if (m_Library != nullptr )
5259 {
5360 dlclose (m_Library);
5461 m_Library = nullptr ;
5562 }
63+ #endif
5664}
5765
5866} // namespace Diligent
You can’t perform that action at this time.
0 commit comments