From 48e5dc5d49998aa6ca0e3607491dd11f6402a956 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 10 Jul 2022 15:13:02 -0700 Subject: [PATCH] Add DAWN_USE_WINDOWS_UI option for Zig & MinGW compilers In Mach engine, we're compiling Dawn using Zig as a C/C++ compiler. Zig provides it's own libc implementation, build system, and system headers. Dawn today makes use of newer `windows.ui.*.h` headers introduced in more recent Windows versions. However, Zig relies on MinGW for it's system headers and it is not straightforward/desirable to use the official Windows SDK headers: Zig does not have these headers today. Since Dawn does not truly require these headers, we are using a preprocessor directive `DAWN_USE_WINDOWS_UI` to disable this functionality and enable compilation of Dawn with Zig/MinGW compilers. I have based the implementation on the existing `DAWN_USE_X11` and `DAWN_USE_WAYLAND` build configuration approaches. Signed-off-by: Stephen Gutekanst Change-Id: If41cafb95666946115b58567fef753df3fbe940a --- CMakeLists.txt | 7 +++++++ scripts/dawn_features.gni | 1 + src/dawn/common/BUILD.gn | 3 +++ src/dawn/native/Surface.cpp | 20 ++++++++++---------- src/dawn/native/Surface.h | 4 ++-- src/dawn/native/d3d12/SwapChainD3D12.cpp | 4 ++++ 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f27535d476..1e68bd5f844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,8 +84,10 @@ set(ENABLE_DESKTOP_GL OFF) set(ENABLE_VULKAN OFF) set(USE_WAYLAND OFF) set(USE_X11 OFF) +set(USE_WINDOWS_UI OFF) set(BUILD_SAMPLES OFF) if (WIN32) + set(USE_WINDOWS_UI ON) set(ENABLE_D3D12 ON) if (NOT WINDOWS_STORE) # Enable Vulkan in win32 compilation only @@ -129,6 +131,7 @@ option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backe option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF) option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND}) option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) +option_if_not_defined(DAWN_USE_WINDOWS_UI "Enable support for Windows UI surface" ${USE_WINDOWS_UI}) option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES}) option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF) @@ -270,6 +273,7 @@ message(STATUS "Dawn build Null backend: ${DAWN_ENABLE_NULL}") message(STATUS "Dawn build with asserts in all configurations: ${DAWN_ALWAYS_ASSERT}") message(STATUS "Dawn build Wayland support: ${DAWN_USE_WAYLAND}") message(STATUS "Dawn build X11 support: ${DAWN_USE_X11}") +message(STATUS "Dawn build Windows UI support: ${DAWN_USE_WINDOWS_UI}") message(STATUS "Dawn build samples: ${DAWN_BUILD_SAMPLES}") message(STATUS "Dawn build Node bindings: ${DAWN_BUILD_NODE_BINDINGS}") @@ -413,6 +417,9 @@ endif() if (DAWN_USE_X11) target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11") endif() +if (DAWN_USE_WINDOWS_UI) + target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_WINDOWS_UI") +endif() if (WIN32) target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN") endif() diff --git a/scripts/dawn_features.gni b/scripts/dawn_features.gni index 5eec131bb69..ef042192d24 100644 --- a/scripts/dawn_features.gni +++ b/scripts/dawn_features.gni @@ -30,6 +30,7 @@ if (build_with_chromium) { # Enable the compilation for UWP dawn_is_winuwp = is_win && target_os == "winuwp" +dawn_use_windows_ui = is_win declare_args() { # TODO(dawn:1545): Re-enable dawn_use_angle on Android. In non-component diff --git a/src/dawn/common/BUILD.gn b/src/dawn/common/BUILD.gn index f46d108747a..baa9fd2646a 100644 --- a/src/dawn/common/BUILD.gn +++ b/src/dawn/common/BUILD.gn @@ -86,6 +86,9 @@ config("internal_config") { if (dawn_use_x11) { defines += [ "DAWN_USE_X11" ] } + if (dawn_use_windows_ui) { + defines += [ "DAWN_USE_WINDOWS_UI" ] + } if (dawn_enable_error_injection) { defines += [ "DAWN_ENABLE_ERROR_INJECTION" ] diff --git a/src/dawn/native/Surface.cpp b/src/dawn/native/Surface.cpp index 39b0cbb4b3d..9b3ef2a7f21 100644 --- a/src/dawn/native/Surface.cpp +++ b/src/dawn/native/Surface.cpp @@ -19,10 +19,10 @@ #include "dawn/native/Instance.h" #include "dawn/native/SwapChain.h" -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) #include #include -#endif // DAWN_PLATFORM_IS(WINDOWS) +#endif // defined(DAWN_USE_WINDOWS_UI) #if defined(DAWN_USE_X11) #include "dawn/common/xlib_with_undefs.h" @@ -98,7 +98,6 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance, } #endif // DAWN_PLATFORM_IS(ANDROID) -#if DAWN_PLATFORM_IS(WINDOWS) #if DAWN_PLATFORM_IS(WIN32) const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr; FindInChain(descriptor->nextInChain, &hwndDesc); @@ -107,6 +106,7 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance, return {}; } #endif // DAWN_PLATFORM_IS(WIN32) +#if defined(DAWN_USE_WINDOWS_UI) const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr; FindInChain(descriptor->nextInChain, &coreWindowDesc); if (coreWindowDesc) { @@ -129,7 +129,7 @@ MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance, "Invalid SwapChainPanel"); return {}; } -#endif // DAWN_PLATFORM_IS(WINDOWS) +#endif // defined(DAWN_USE_WINDOWS_UI) #if defined(DAWN_USE_WAYLAND) const SurfaceDescriptorFromWaylandSurface* waylandDesc = nullptr; @@ -203,15 +203,15 @@ Surface::Surface(InstanceBase* instance, const SurfaceDescriptor* descriptor) mHInstance = hwndDesc->hinstance; mHWND = hwndDesc->hwnd; } else if (coreWindowDesc) { -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) mType = Type::WindowsCoreWindow; mCoreWindow = static_cast(coreWindowDesc->coreWindow); -#endif // DAWN_PLATFORM_IS(WINDOWS) +#endif // defined(DAWN_USE_WINDOWS_UI) } else if (swapChainPanelDesc) { -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) mType = Type::WindowsSwapChainPanel; mSwapChainPanel = static_cast(swapChainPanelDesc->swapChainPanel); -#endif // DAWN_PLATFORM_IS(WINDOWS) +#endif // defined(DAWN_USE_WINDOWS_UI) } else if (xDesc) { mType = Type::XlibWindow; mXDisplay = xDesc->display; @@ -283,7 +283,7 @@ void* Surface::GetHWND() const { IUnknown* Surface::GetCoreWindow() const { ASSERT(!IsError()); ASSERT(mType == Type::WindowsCoreWindow); -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) return mCoreWindow.Get(); #else return nullptr; @@ -293,7 +293,7 @@ IUnknown* Surface::GetCoreWindow() const { IUnknown* Surface::GetSwapChainPanel() const { ASSERT(!IsError()); ASSERT(mType == Type::WindowsSwapChainPanel); -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) return mSwapChainPanel.Get(); #else return nullptr; diff --git a/src/dawn/native/Surface.h b/src/dawn/native/Surface.h index 96da3c25494..871ea2737df 100644 --- a/src/dawn/native/Surface.h +++ b/src/dawn/native/Surface.h @@ -112,13 +112,13 @@ class Surface final : public ErrorMonad { void* mHInstance = nullptr; void* mHWND = nullptr; -#if DAWN_PLATFORM_IS(WINDOWS) +#if defined(DAWN_USE_WINDOWS_UI) // WindowsCoreWindow ComPtr mCoreWindow; // WindowsSwapChainPanel ComPtr mSwapChainPanel; -#endif // DAWN_PLATFORM_IS(WINDOWS) +#endif // defined(DAWN_USE_WINDOWS_UI) // Xlib void* mXDisplay = nullptr; diff --git a/src/dawn/native/d3d12/SwapChainD3D12.cpp b/src/dawn/native/d3d12/SwapChainD3D12.cpp index 32116c48b3d..2c95c7e8f4e 100644 --- a/src/dawn/native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn/native/d3d12/SwapChainD3D12.cpp @@ -14,7 +14,9 @@ #include "dawn/native/d3d12/SwapChainD3D12.h" +#if defined(DAWN_USE_WINDOWS_UI) #include +#endif // defined(DAWN_USE_WINDOWS_UI) #include @@ -257,6 +259,7 @@ MaybeError SwapChain::InitializeSwapChainFromScratch() { "Creating the IDXGISwapChain1")); break; } +#if defined(DAWN_USE_WINDOWS_UI) case Surface::Type::WindowsCoreWindow: { DAWN_TRY(CheckHRESULT( factory2->CreateSwapChainForCoreWindow(device->GetCommandQueue().Get(), @@ -278,6 +281,7 @@ MaybeError SwapChain::InitializeSwapChainFromScratch() { "Setting SwapChain")); break; } +#endif // defined(DAWN_USE_WINDOWS_UI) default: UNREACHABLE(); }