Include Vulkan-Loader patches in repo

This commit is contained in:
BtbN 2021-04-05 08:47:23 +02:00
parent 2e8328cf23
commit 44aea690d1
7 changed files with 357 additions and 5 deletions

View file

@ -8,6 +8,9 @@ RUN \
apt-get -y install build-essential yasm nasm pkgconf git curl wget cmake unzip subversion autoconf automake libtool autopoint cmake clang texinfo texi2html gperf gettext itstool ragel libc6-dev libssl-dev gtk-doc-tools gobject-introspection gawk meson ninja-build p7zip-full python3-distutils python3-apt python-is-python3 && \ apt-get -y install build-essential yasm nasm pkgconf git curl wget cmake unzip subversion autoconf automake libtool autopoint cmake clang texinfo texi2html gperf gettext itstool ragel libc6-dev libssl-dev gtk-doc-tools gobject-introspection gawk meson ninja-build p7zip-full python3-distutils python3-apt python-is-python3 && \
apt-get -y clean apt-get -y clean
RUN git config --global user.email "builder@localhost" && \
git config --global user.name "Builder"
ENV CARGO_HOME="/opt/cargo" RUSTUP_HOME="/opt/rustup" PATH="/opt/cargo/bin:${PATH}" ENV CARGO_HOME="/opt/cargo" RUSTUP_HOME="/opt/rustup" PATH="/opt/cargo/bin:${PATH}"
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --no-modify-path RUN curl https://sh.rustup.rs -sSf | bash -s -- -y --no-modify-path
RUN cargo install cargo-c && rm -rf "${CARGO_HOME}"/{registry,git} RUN cargo install cargo-c && rm -rf "${CARGO_HOME}"/{registry,git}

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -xe set -xe
mkdir /stage mkdir -p /stage
cd /stage cd /stage
source /stage.sh source /stage.sh
ffbuild_dockerbuild ffbuild_dockerbuild

View file

@ -0,0 +1,76 @@
From cc0b0633e19356c45caa66c5ac18f8f49ba3e214 Mon Sep 17 00:00:00 2001
From: Syoyo Fujita <syoyo@lighttransport.com>
Date: Thu, 28 May 2020 21:38:16 +0900
Subject: [PATCH 1/4] Fix build on MinGW cross compiling environment.
---
loader/CMakeLists.txt | 4 +++-
loader/loader.c | 13 +++++++++++++
loader/loader.rc | 4 ++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index db1ad7807..04faf23cc 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -151,7 +151,7 @@ if(WIN32)
if (USE_MASM)
enable_language(ASM_MASM)
endif ()
- if(CMAKE_ASM_MASM_COMPILER_WORKS OR JWASM_FOUND)
+ if((CMAKE_ASM_MASM_COMPILER_WORKS AND NOT CMAKE_CROSSCOMPILING) OR JWASM_FOUND)
if(MINGW)
set(CMAKE_ASM_MASM_FLAGS ${CMAKE_ASM_MASM_FLAGS} ${JWASM_FLAGS})
elseif(NOT CMAKE_CL_64 AND NOT JWASM_FOUND)
@@ -171,6 +171,8 @@ if(WIN32)
add_library(loader-unknown-chain OBJECT unknown_ext_chain.c)
target_compile_options(loader-unknown-chain PUBLIC "$<$<CONFIG:DEBUG>:${LOCAL_C_FLAGS_REL}>")
target_compile_options(loader-unknown-chain PUBLIC ${MSVC_LOADER_COMPILE_OPTIONS})
+
+ target_include_directories(loader-unknown-chain PRIVATE "$<TARGET_PROPERTY:Vulkan::Headers,INTERFACE_INCLUDE_DIRECTORIES>")
endif()
elseif(APPLE)
# For MacOS, use the C code and force the compiler's tail-call optimization instead of using assembly code.
diff --git a/loader/loader.c b/loader/loader.c
index 6a60ee7bc..20790c12c 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -79,6 +79,19 @@
typedef HRESULT (APIENTRY *PFN_CreateDXGIFactory1)(REFIID riid, void **ppFactory);
static PFN_CreateDXGIFactory1 fpCreateDXGIFactory1;
+
+#if defined(__MINGW32__)
+// MinGW header may not have some definitions(cfgmgr32.h).
+#if !defined(CM_GETIDLIST_FILTER_CLASS)
+#define CM_GETIDLIST_FILTER_CLASS (0x200)
+#endif
+
+#if !defined(CM_GETIDLIST_FILTER_PRESENT)
+#define CM_GETIDLIST_FILTER_PRESENT (0x100)
+#endif
+
+#endif // __MINGW32__
+
#endif
// This is a CMake generated file with #defines for any functions/includes
diff --git a/loader/loader.rc b/loader/loader.rc
index 18eb5e6c1..2a9988d00 100755
--- a/loader/loader.rc
+++ b/loader/loader.rc
@@ -43,7 +43,11 @@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+#if defined(__MINGW32__)
+#include <winresrc.h>
+#else
#include "winres.h"
+#endif
#define VER_FILE_VERSION VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILDNO
--
2.25.1

View file

@ -0,0 +1,87 @@
From 1733181194d4f356e599a748c6d8c5009541604f Mon Sep 17 00:00:00 2001
From: BtbN <btbn@btbn.de>
Date: Mon, 7 Sep 2020 20:07:39 +0200
Subject: [PATCH 2/4] Fixes for MinGW build
Adapted from https://github.com/msys2/MINGW-packages/blob/348f1d46d9d273a2cc928deadf9d9114f7a69c2f/mingw-w64-vulkan-loader/002-proper-def-files-for-32bit.patch
---
loader/CMakeLists.txt | 6 ++++--
loader/loader.h | 4 +++-
tests/layers/vk_format_utils.h | 4 +++-
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index 04faf23cc..b5f90393d 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -67,6 +67,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
if(WIN32)
# Use static MSVCRT libraries
+ if(MSVC)
foreach(configuration
in
CMAKE_C_FLAGS_DEBUG
@@ -85,6 +86,7 @@ if(WIN32)
"${${configuration}}")
endif()
endforeach()
+ endif()
if(ENABLE_WIN10_ONECORE)
# Note: When linking your app or driver to OneCore.lib, be sure to remove any links to non-umbrella libs (such as
@@ -231,7 +233,7 @@ if(WIN32)
"")
target_link_libraries(vulkan Vulkan::Headers)
- if(ENABLE_WIN10_ONECORE)
+ if(ENABLE_WIN10_ONECORE AND MSVC)
target_link_libraries(vulkan OneCoreUAP.lib LIBCMT.LIB LIBCMTD.LIB LIBVCRUNTIME.LIB LIBUCRT.LIB)
set_target_properties(vulkan PROPERTIES LINK_FLAGS "/NODEFAULTLIB")
else()
@@ -318,11 +320,11 @@ else()
)
# cmake-format: on
endif()
+endif()
if(NOT APPLE)
target_compile_definitions(vulkan PRIVATE _XOPEN_SOURCE=500) # hush compiler warnings for readlink
endif()
-endif()
# Generate pkg-config file.
include(FindPkgConfig QUIET)
diff --git a/loader/loader.h b/loader/loader.h
index ea0c976b5..64ad08693 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -38,7 +38,9 @@
#include "vk_layer_dispatch_table.h"
#include "vk_loader_extensions.h"
-#if defined(__GNUC__) && __GNUC__ >= 4
+#if defined(_WIN32)
+#define LOADER_EXPORT __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
#define LOADER_EXPORT __attribute__((visibility("default")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define LOADER_EXPORT __attribute__((visibility("default")))
diff --git a/tests/layers/vk_format_utils.h b/tests/layers/vk_format_utils.h
index e76f9ec2f..ef06e12af 100644
--- a/tests/layers/vk_format_utils.h
+++ b/tests/layers/vk_format_utils.h
@@ -25,7 +25,9 @@
#include "vulkan/vulkan.h"
#if !defined(VK_LAYER_EXPORT)
-#if defined(__GNUC__) && __GNUC__ >= 4
+#if defined(_WIN32)
+#define VK_LAYER_EXPORT __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
#define VK_LAYER_EXPORT __attribute__((visibility("default")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define VK_LAYER_EXPORT __attribute__((visibility("default")))
--
2.25.1

View file

@ -0,0 +1,28 @@
From b42b70be453766f56b9ac21c11190b1b5fd74179 Mon Sep 17 00:00:00 2001
From: BtbN <btbn@btbn.de>
Date: Mon, 7 Sep 2020 20:33:23 +0200
Subject: [PATCH 3/4] Define appropiate minimum Windows-Version
---
loader/vk_loader_platform.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h
index abf078c28..40c532a95 100644
--- a/loader/vk_loader_platform.h
+++ b/loader/vk_loader_platform.h
@@ -24,6 +24,11 @@
#pragma once
#if defined(_WIN32)
+
+#define WINVER 0x0601
+#define _WIN32_WINNT 0x0601
+#define STRSAFE_NO_DEPRECATE 1
+
// WinSock2.h must be included *BEFORE* windows.h
#include <winsock2.h>
#endif // _WIN32
--
2.25.1

View file

@ -0,0 +1,153 @@
From 62ff1c9f106a70257cff2fead1bdf1a3c3590239 Mon Sep 17 00:00:00 2001
From: BtbN <btbn@btbn.de>
Date: Sun, 4 Apr 2021 23:29:53 +0200
Subject: [PATCH 4/4] Unlock building static loader on any OS
Based in parts on https://github.com/shinchiro/mpv-winbuild-cmake/blob/master/packages/vulkan-0001-cross-compile-static-linking-hacks.patch
---
CMakeLists.txt | 2 --
loader/CMakeLists.txt | 23 ++++++++++++++++++++++-
loader/loader.c | 2 +-
loader/loader.h | 3 +++
loader/vk_loader_platform.h | 16 ++++++++++++++++
5 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a26e38408..1c3bab61f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,9 +38,7 @@ else()
option(BUILD_TESTS "Build Tests" OFF)
endif()
-if(APPLE)
option(BUILD_STATIC_LOADER "Build a loader that can be statically linked" OFF)
-endif()
if(BUILD_STATIC_LOADER)
message(WARNING "The BUILD_STATIC_LOADER option has been set. Note that this will only work on MacOS and is not supported "
diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index b5f90393d..8fa4b01c5 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -217,6 +217,22 @@ if(WIN32)
target_compile_options(loader-opt PUBLIC ${MSVC_LOADER_COMPILE_OPTIONS})
target_include_directories(loader-opt PRIVATE "$<TARGET_PROPERTY:Vulkan::Headers,INTERFACE_INCLUDE_DIRECTORIES>")
+ if(BUILD_STATIC_LOADER)
+ add_library(vulkan
+ STATIC
+ $<TARGET_OBJECTS:loader-opt>
+ $<TARGET_OBJECTS:loader-norm>
+ $<TARGET_OBJECTS:loader-unknown-chain>
+ ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-1.def
+ ${CMAKE_CURRENT_SOURCE_DIR}/loader.rc)
+ set_target_properties(vulkan
+ PROPERTIES LINK_FLAGS_DEBUG
+ "/ignore:4098"
+ OUTPUT_NAME
+ vulkan-1
+ PREFIX
+ lib)
+ else()
add_library(vulkan
SHARED
$<TARGET_OBJECTS:loader-opt>
@@ -231,6 +247,8 @@ if(WIN32)
vulkan-1
PREFIX
"")
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS LOADER_DYNAMIC_LIB)
+ endif()
target_link_libraries(vulkan Vulkan::Headers)
if(ENABLE_WIN10_ONECORE AND MSVC)
@@ -252,17 +270,19 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-typedef-redefinition")
endif()
- if(APPLE AND BUILD_STATIC_LOADER)
+ if(BUILD_STATIC_LOADER)
add_library(vulkan STATIC ${NORMAL_LOADER_SRCS} ${OPT_LOADER_SRCS})
else()
add_library(vulkan SHARED ${NORMAL_LOADER_SRCS} ${OPT_LOADER_SRCS})
endif()
add_dependencies(vulkan loader_asm_gen_files)
+ if (NOT BUILD_STATIC_LOADER)
set_target_properties(vulkan
PROPERTIES SOVERSION
"1"
VERSION
"${VulkanHeaders_VERSION_MAJOR}.${VulkanHeaders_VERSION_MINOR}.${VulkanHeaders_VERSION_PATCH}")
+ endif()
target_link_libraries(vulkan ${CMAKE_DL_LIBS} m)
if (NOT ANDROID)
target_link_libraries(vulkan pthread)
@@ -333,6 +353,7 @@ if(PKG_CONFIG_FOUND)
foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endforeach()
+ set(PRIVATE_LIBS "${PRIVATE_LIBS} -lshlwapi -lcfgmgr32")
if(WIN32)
set(VULKAN_LIB_SUFFIX "-1")
endif ()
diff --git a/loader/loader.c b/loader/loader.c
index 20790c12c..582808e99 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -7887,7 +7887,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/loader/loader.h b/loader/loader.h
index 64ad08693..0ee906734 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -436,6 +436,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;
extern loader_platform_thread_mutex loader_preload_icd_lock;
diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h
index 40c532a95..d55193766 100644
--- a/loader/vk_loader_platform.h
+++ b/loader/vk_loader_platform.h
@@ -397,9 +397,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;
--
2.25.1

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
LOADER_REPO="https://github.com/BtbN/Vulkan-Loader.git" LOADER_REPO="https://github.com/KhronosGroup/Vulkan-Loader.git"
LOADER_COMMIT="62ff1c9f106a70257cff2fead1bdf1a3c3590239" LOADER_COMMIT="7ea01c139ffc7c33cd12bd258c1bc8bf530c6d2d"
ffbuild_enabled() { ffbuild_enabled() {
[[ $ADDINS_STR != *vulkan* ]] && return -1 [[ $ADDINS_STR != *vulkan* ]] && return -1
@ -10,13 +10,18 @@ ffbuild_enabled() {
ffbuild_dockerstage() { ffbuild_dockerstage() {
to_df "ADD $SELF /stage.sh" to_df "ADD $SELF /stage.sh"
to_df "ADD patches/vulkan /stage/patches"
to_df "RUN run_stage" to_df "RUN run_stage"
} }
ffbuild_dockerbuild() { ffbuild_dockerbuild() {
mkdir vulkan && cd vulkan git clone "$LOADER_REPO" loader
git -C loader checkout "$LOADER_COMMIT"
git-mini-clone "$LOADER_REPO" "$LOADER_COMMIT" loader for patch in patches/*.patch; do
echo "Applying $patch"
git -C loader am -3 < "$patch"
done
HEADERS_REPO="$(grep -A10 'name.*:.*Vulkan-Headers' loader/scripts/known_good.json | grep url | head -n1 | cut -d'"' -f4)" HEADERS_REPO="$(grep -A10 'name.*:.*Vulkan-Headers' loader/scripts/known_good.json | grep url | head -n1 | cut -d'"' -f4)"
HEADERS_COMMIT="$(grep -A10 'name.*:.*Vulkan-Headers' loader/scripts/known_good.json | grep commit | head -n1 | cut -d'"' -f4)" HEADERS_COMMIT="$(grep -A10 'name.*:.*Vulkan-Headers' loader/scripts/known_good.json | grep commit | head -n1 | cut -d'"' -f4)"