diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-03-09 15:23:42 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-03-09 15:25:54 +0100 |
commit | d744d3046e755d7e92b2eeee61da8364ce885e30 (patch) | |
tree | d2dc6c865c27a707462dfd2d514891c8299adfff /thirdparty/vulkan | |
parent | 709b176db08199b4fcd6733565b09fc0d259eee7 (diff) |
vulkan: Re-add option to build Vulkan-Loader statically
Upstream removed the option in KhronosGroup/Vulkan-Loader#260, which
breaks our current use case.
This commit reverts KhronosGroup/Vulkan-Loader#260 is our vendored
loader.
We may need to re-evaluate how we link the loader, but until then,
reverting this PR fixes Windows support after the upgrade to a recent
SDK version in #36932.
Diffstat (limited to 'thirdparty/vulkan')
-rw-r--r-- | thirdparty/vulkan/loader/loader.c | 2 | ||||
-rw-r--r-- | thirdparty/vulkan/loader/loader.h | 3 | ||||
-rw-r--r-- | thirdparty/vulkan/loader/vk_loader_platform.h | 16 | ||||
-rw-r--r-- | thirdparty/vulkan/patches/Vulkan-Loader-revert-pr260.patch | 57 |
4 files changed, 77 insertions, 1 deletions
diff --git a/thirdparty/vulkan/loader/loader.c b/thirdparty/vulkan/loader/loader.c index 87d08d5116..c7cdb47122 100644 --- a/thirdparty/vulkan/loader/loader.c +++ b/thirdparty/vulkan/loader/loader.c @@ -7330,7 +7330,7 @@ out: return result; } -#if defined(_WIN32) +#if defined(_WIN32) && defined(LOADER_DYNAMIC_LIB) BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { switch (reason) { case DLL_PROCESS_ATTACH: diff --git a/thirdparty/vulkan/loader/loader.h b/thirdparty/vulkan/loader/loader.h index 5e9495521b..56745a968d 100644 --- a/thirdparty/vulkan/loader/loader.h +++ b/thirdparty/vulkan/loader/loader.h @@ -420,6 +420,9 @@ static inline void loader_init_dispatch(void *obj, const void *data) { // Global variables used across files extern struct loader_struct loader; extern THREAD_LOCAL_DECL struct loader_instance *tls_instance; +#if defined(_WIN32) && !defined(LOADER_DYNAMIC_LIB) +extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init); +#endif extern loader_platform_thread_mutex loader_lock; extern loader_platform_thread_mutex loader_json_lock; diff --git a/thirdparty/vulkan/loader/vk_loader_platform.h b/thirdparty/vulkan/loader/vk_loader_platform.h index 7824e35d6b..62e8e3ae09 100644 --- a/thirdparty/vulkan/loader/vk_loader_platform.h +++ b/thirdparty/vulkan/loader/vk_loader_platform.h @@ -330,9 +330,25 @@ typedef HANDLE loader_platform_thread; // The once init functionality is not used when building a DLL on Windows. This is because there is no way to clean up the // resources allocated by anything allocated by once init. This isn't a problem for static libraries, but it is for dynamic // ones. When building a DLL, we use DllMain() instead to allow properly cleaning up resources. +#if defined(LOADER_DYNAMIC_LIB) #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) +#else +#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT; +#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) INIT_ONCE var; +#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func) +static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) { + void (*func)(void) = (void (*)(void))Parameter; + func(); + return TRUE; +} +static void loader_platform_thread_once_fn(void *ctl, void (*func)(void)) { + assert(func != NULL); + assert(ctl != NULL); + InitOnceExecuteOnce((PINIT_ONCE)ctl, InitFuncWrapper, (void *)func, NULL); +} +#endif // Thread IDs: typedef DWORD loader_platform_thread_id; diff --git a/thirdparty/vulkan/patches/Vulkan-Loader-revert-pr260.patch b/thirdparty/vulkan/patches/Vulkan-Loader-revert-pr260.patch new file mode 100644 index 0000000000..1267e560df --- /dev/null +++ b/thirdparty/vulkan/patches/Vulkan-Loader-revert-pr260.patch @@ -0,0 +1,57 @@ +diff --git a/thirdparty/vulkan/loader/loader.c b/thirdparty/vulkan/loader/loader.c +index 87d08d5116..c7cdb47122 100644 +--- a/thirdparty/vulkan/loader/loader.c ++++ b/thirdparty/vulkan/loader/loader.c +@@ -7330,7 +7330,7 @@ out: + return result; + } + +-#if defined(_WIN32) ++#if defined(_WIN32) && defined(LOADER_DYNAMIC_LIB) + BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { + switch (reason) { + case DLL_PROCESS_ATTACH: +diff --git a/thirdparty/vulkan/loader/loader.h b/thirdparty/vulkan/loader/loader.h +index 5e9495521b..56745a968d 100644 +--- a/thirdparty/vulkan/loader/loader.h ++++ b/thirdparty/vulkan/loader/loader.h +@@ -420,6 +420,9 @@ static inline void loader_init_dispatch(void *obj, const void *data) { + // Global variables used across files + extern struct loader_struct loader; + extern THREAD_LOCAL_DECL struct loader_instance *tls_instance; ++#if defined(_WIN32) && !defined(LOADER_DYNAMIC_LIB) ++extern LOADER_PLATFORM_THREAD_ONCE_DEFINITION(once_init); ++#endif + extern loader_platform_thread_mutex loader_lock; + extern loader_platform_thread_mutex loader_json_lock; + +diff --git a/thirdparty/vulkan/loader/vk_loader_platform.h b/thirdparty/vulkan/loader/vk_loader_platform.h +index 7824e35d6b..62e8e3ae09 100644 +--- a/thirdparty/vulkan/loader/vk_loader_platform.h ++++ b/thirdparty/vulkan/loader/vk_loader_platform.h +@@ -330,9 +330,25 @@ typedef HANDLE loader_platform_thread; + // The once init functionality is not used when building a DLL on Windows. This is because there is no way to clean up the + // resources allocated by anything allocated by once init. This isn't a problem for static libraries, but it is for dynamic + // ones. When building a DLL, we use DllMain() instead to allow properly cleaning up resources. ++#if defined(LOADER_DYNAMIC_LIB) + #define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) + #define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) + #define LOADER_PLATFORM_THREAD_ONCE(ctl, func) ++#else ++#define LOADER_PLATFORM_THREAD_ONCE_DECLARATION(var) INIT_ONCE var = INIT_ONCE_STATIC_INIT; ++#define LOADER_PLATFORM_THREAD_ONCE_DEFINITION(var) INIT_ONCE var; ++#define LOADER_PLATFORM_THREAD_ONCE(ctl, func) loader_platform_thread_once_fn(ctl, func) ++static BOOL CALLBACK InitFuncWrapper(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) { ++ void (*func)(void) = (void (*)(void))Parameter; ++ func(); ++ return TRUE; ++} ++static void loader_platform_thread_once_fn(void *ctl, void (*func)(void)) { ++ assert(func != NULL); ++ assert(ctl != NULL); ++ InitOnceExecuteOnce((PINIT_ONCE)ctl, InitFuncWrapper, (void *)func, NULL); ++} ++#endif + + // Thread IDs: + typedef DWORD loader_platform_thread_id; |