From f38ee85a396bbc2a0ad2dba8f14f5a34d61457ee Mon Sep 17 00:00:00 2001 From: Mikhail Paulyshka Date: Sat, 21 Jul 2018 13:43:33 +0300 Subject: [PATCH] [build] Fix compilation on MSVC (#505) * [build] do not use shared_library/objects property with MSVC * [util] use ./com/com_include.h instead of windef.h It is required for Windows 10 SDK. * [util] store thread procedure lambda in std::function * [dxgi] fix annoying MSVC warning warning C4099: 'IDXGIVkInteropDevice': type name first seen using 'class' now seen using 'struct' --- meson.build | 2 ++ src/d3d11/meson.build | 3 ++- src/dxgi/dxgi_interfaces.h | 2 +- src/dxgi/meson.build | 3 ++- src/util/thread.h | 31 ++++++++++--------------------- src/util/util_string.h | 2 +- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/meson.build b/meson.build index 931ba156b..1be823af9 100644 --- a/meson.build +++ b/meson.build @@ -7,8 +7,10 @@ add_project_arguments('-DNOMINMAX', language : 'cpp') dxvk_compiler = meson.get_compiler('cpp') if dxvk_compiler.get_id() == 'msvc' dxvk_cpp_std='c++latest' + dxvk_msvc=true else dxvk_cpp_std='c++1z' + dxvk_msvc=false endif if dxvk_compiler.get_id() == 'msvc' diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index f3727e5ef..28cc2eeb6 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -34,7 +34,8 @@ d3d11_dll = shared_library('d3d11'+dll_ext, d3d11_src, dependencies : [ lib_dxgi, dxbc_dep, dxvk_dep ], include_directories : dxvk_include_path, install : true, - objects : 'd3d11'+def_spec_ext, + objects : not dxvk_msvc ? 'd3d11'+def_spec_ext : [], + vs_module_defs : 'd3d11'+def_spec_ext, override_options : ['cpp_std='+dxvk_cpp_std]) d3d11_dep = declare_dependency( diff --git a/src/dxgi/dxgi_interfaces.h b/src/dxgi/dxgi_interfaces.h index ca354c028..7ed83a4cc 100644 --- a/src/dxgi/dxgi_interfaces.h +++ b/src/dxgi/dxgi_interfaces.h @@ -13,7 +13,7 @@ namespace dxvk { class DxvkImage; } -class IDXGIVkInteropDevice; +struct IDXGIVkInteropDevice; /** * \brief Private DXGI device interface diff --git a/src/dxgi/meson.build b/src/dxgi/meson.build index 8cbb1d75f..3f4315d04 100644 --- a/src/dxgi/meson.build +++ b/src/dxgi/meson.build @@ -22,7 +22,8 @@ dxgi_dll = shared_library('dxgi'+dll_ext, dxgi_src, glsl_generator.process(dxgi_ dependencies : [ dxvk_dep ], include_directories : dxvk_include_path, install : true, - objects : 'dxgi'+def_spec_ext, + vs_module_defs : 'dxgi'+def_spec_ext, + objects : not dxvk_msvc ? 'dxgi'+def_spec_ext : [], override_options : ['cpp_std='+dxvk_cpp_std]) dxgi_dep = declare_dependency( diff --git a/src/util/thread.h b/src/util/thread.h index 35c64e42c..3bb17ea22 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -2,8 +2,8 @@ #include "util_error.h" -#include -#include +#include +#include "./com/com_include.h" /* * This is needed mostly for winelib builds. Wine needs to setup each thread that @@ -16,29 +16,18 @@ namespace dxvk { class thread { private: HANDLE m_handle; + std::function proc; - template - class thread_proc { - private: - T proc; - public: - thread_proc(T &proc) : proc(proc) {} - - static DWORD WINAPI nativeProc(void *arg) { - thread_proc *proc = reinterpret_cast(arg); - proc->proc(); - delete proc; - return 0; - } - }; + static DWORD WINAPI nativeProc(void *arg) { + auto* proc = reinterpret_cast(arg); + proc->proc(); + return 0; + } public: - template - explicit thread(T &&func) { - thread_proc *proc = new thread_proc(func); - m_handle = ::CreateThread(nullptr, 0, thread_proc::nativeProc, proc, 0, nullptr); + explicit thread(std::function func) : proc(func) { + m_handle = ::CreateThread(nullptr, 0, thread::nativeProc, this, 0, nullptr); if (!m_handle) { - delete proc; throw DxvkError("Failed to create thread"); } } diff --git a/src/util/util_string.h b/src/util/util_string.h index 191c462d1..ca42114d7 100644 --- a/src/util/util_string.h +++ b/src/util/util_string.h @@ -2,7 +2,7 @@ #include #include -#include +#include "./com/com_include.h" namespace dxvk::str {