-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For future reference: static linking across different platforms #6741
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merge back new DXC version's main
…linked but only to be used as a dependency rather than CLI. To keep existing functionality, this define has to be set before including dxcapi.h and the library calling has to call DxcInitialize at the start of the program (or at least before calling any DXC function) and DxcShutdown when DXC should be cleaned up correctly. When enabling static linking, the CLI projects are disabled since they assume dynamic linking. DllMain has been modified to deal with this properly as well.
…et's see if this gets linux to compile
…ese commits need to be cleaned up at some point because it's very hacky, but it seems to build & link on Linux (execution isn't tested yet). Proper fix is fixing the dependencies, but ain't nobody got time for that.
… prevent recursive issues that's present on linux builds (but only on GitHub CI runners?)
You can test this locally with the following command:git-clang-format --diff 6c2b9f340e19e44743ba821a750f85e4ce44bb1b b37088d419abeddfa682b696ddf84c6653287a1a -- include/dxc/Support/D3DReflection.h include/dxc/Support/Unicode.h include/dxc/Test/D3DReflectionDumper.h include/dxc/Test/D3DReflectionStrings.h include/dxc/WinAdapter.h include/dxc/dxcapi.h lib/DxcSupport/Unicode.cpp lib/DxcSupport/dxcapi.use.cpp lib/DxilContainer/D3DReflectionDumper.cpp lib/DxilContainer/D3DReflectionStrings.cpp lib/HLSL/DxilContainerReflection.cpp projects/dxilconv/tools/dxbc2dxil/dxbc2dxil.cpp tools/clang/include/clang/AST/Attr.h tools/clang/tools/dxa/dxa.cpp tools/clang/tools/dxcompiler/DXCompiler.cpp tools/clang/tools/dxcompiler/dxcapi.cpp tools/clang/tools/dxcvalidator/dxcvalidator.cpp tools/clang/tools/dxr/dxr.cpp tools/clang/unittests/HLSLExec/ExecutionTest.cpp tools/clang/unittests/HLSLTestLib/FileCheckerTest.cpp tools/dxexp/dxexp.cpp View the diff from clang-format here.diff --git a/include/dxc/dxcapi.h b/include/dxc/dxcapi.h
index 97e883b23..edc89e6c9 100644
--- a/include/dxc/dxcapi.h
+++ b/include/dxc/dxcapi.h
@@ -47,14 +47,16 @@ struct IDxcIncludeHandler;
/// \brief Typedef for DxcCreateInstance function pointer.
///
-/// This can be used with GetProcAddress to get the DxcCreateInstance function (if it's not statically linked).
+/// This can be used with GetProcAddress to get the DxcCreateInstance function
+/// (if it's not statically linked).
typedef HRESULT(__stdcall *DxcCreateInstanceProc)(_In_ REFCLSID rclsid,
_In_ REFIID riid,
_Out_ LPVOID *ppv);
/// \brief Typedef for DxcCreateInstance2 function pointer.
///
-/// This can be used with GetProcAddress to get the DxcCreateInstance2 function (if it's not statically linked).
+/// This can be used with GetProcAddress to get the DxcCreateInstance2 function
+/// (if it's not statically linked).
typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(_In_ IMalloc *pMalloc,
_In_ REFCLSID rclsid,
_In_ REFIID riid,
@@ -90,12 +92,14 @@ extern "C" DXC_API_IMPORT
#ifdef ENABLE_DXC_STATIC_LINKING
-/// \brief This function has to be called before any DXC calls to initialize it if it's statically linked.
+/// \brief This function has to be called before any DXC calls to initialize it
+/// if it's statically linked.
///
/// If dynamically linked, this will automatically be called.
extern "C" HRESULT __stdcall DxcInitialize();
-/// \brief This function has to be called after all DXC calls (shutdown) to free everything it if it's statically linked.
+/// \brief This function has to be called after all DXC calls (shutdown) to free
+/// everything it if it's statically linked.
///
/// If dynamically linked, this will automatically be called.
extern "C" void __stdcall DxcShutdown(BOOL isProcessTermination);
diff --git a/lib/HLSL/DxilContainerReflection.cpp b/lib/HLSL/DxilContainerReflection.cpp
index 2ec42b4b3..d0ae5a063 100644
--- a/lib/HLSL/DxilContainerReflection.cpp
+++ b/lib/HLSL/DxilContainerReflection.cpp
@@ -2876,7 +2876,7 @@ public:
// Use D3D_RETURN_PARAMETER_INDEX to get description of the return value.
STDMETHOD_(ID3D12FunctionParameterReflection *, GetFunctionParameter)
(INT ParameterIndex) { return &g_InvalidFunctionParameter; }
-
+
STDMETHOD_(UINT64, GetRequiresFlags)() { return m_FeatureFlags; }
};
diff --git a/tools/clang/tools/dxcompiler/DXCompiler.cpp b/tools/clang/tools/dxcompiler/DXCompiler.cpp
index 21ecf584a..e12ab0e69 100644
--- a/tools/clang/tools/dxcompiler/DXCompiler.cpp
+++ b/tools/clang/tools/dxcompiler/DXCompiler.cpp
@@ -102,7 +102,7 @@ HRESULT __stdcall DxcInitialize() {
void __stdcall DxcShutdown(BOOL isProcessTermination) {
#if defined(LLVM_ON_UNIX)
- (void) isProcessTermination;
+ (void)isProcessTermination;
DxcSetThreadMallocToDefault();
::hlsl::options::cleanupHlslOptTable();
::llvm::sys::fs::CleanupPerThreadFileSystem();
@@ -115,7 +115,8 @@ void __stdcall DxcShutdown(BOOL isProcessTermination) {
::hlsl::options::cleanupHlslOptTable();
::llvm::sys::fs::CleanupPerThreadFileSystem();
::llvm::llvm_shutdown();
- if (!isProcessTermination) { // FreeLibrary has been called or the DLL load failed
+ if (!isProcessTermination) { // FreeLibrary has been called or the DLL load
+ // failed
DxilLibCleanup(DxilLibCleanUpType::UnloadLibrary);
} else { // Process termination. We should not call FreeLibrary()
DxilLibCleanup(DxilLibCleanUpType::ProcessTermination);
@@ -130,7 +131,7 @@ void __stdcall DxcShutdown(BOOL isProcessTermination) {
#ifndef ENABLE_DXC_STATIC_LINKING
#if defined(LLVM_ON_UNIX)
HRESULT __attribute__((constructor)) DllMain() { return DxcInitialize(); }
-void __attribute__((destructor)) DllShutdown(){ DxcShutdown();}
+void __attribute__((destructor)) DllShutdown() { DxcShutdown(); }
#else // LLVM_ON_UNIX
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID reserved) {
BOOL result = TRUE;
|
…ble to change the path that pointed to optimizer.hpp
…ed some missing node information to the implementation.
…ed some missing node information to the implementation.:
…iler into feat_query_all_function_properties3
…on info (where it makes sense). Only unit tests that provide unique scenarios have been touched. Fixed some misformatting in D3DReflectionDumper. Apparently m_pProps can be NULL, so made it S_OK instead of E_FAIL. Fixed problem with GetInputNode/GetOutputNode where it returned a string pointer of a C++ struct which implictly copied due to not being const&.
… else. Changed it to use ShaderReflection1 and LibraryReflection1
… in checks, same for ShaderReflection1. Also fixed the RDAT3 in wavesize-compute-node-rdat.hlsl
…s_as.hlsl is compiled as lib_6_8
…iler into feat_query_all_function_properties
…om/Oxsomi/DirectXShaderCompiler into feat_query_all_function_properties
Closing as main on my fork is now merging all sorts of things. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following PR is meant more as a showcase of hacky solutions to get static linking to work across different platforms.
I'm not expecting this to get merged of course, it's just to demonstrate my findings and hopefully something can be improved internally to fix these issues in a better way down the road.
It demonstrates the following issues, that when solved can make static linking possible:
As an additional note, I hope the wchars can be phased out slowly too, as on linux/OSX these unexpectedly (for me at least) these are UTF32 rather than UTF16. UTF8 would be nice.