From bcfcbd970ec7182b63cdda9421e475c85c1b2753 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 18 Feb 2022 13:13:19 -0700 Subject: [PATCH] dawn/native: add DAWN_NO_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_NO_WINDOWS_UI` to disable this functionality and enable compilation of Dawn with Zig/MinGW compilers. We do not consume Dawn's build system (cmake or otherwise), and so I have not added integration with that. I ammhappy to do whatever is required in order for such a patch to be accepted, however. I'm also happy to ensure this works going forward well into the future should it break over time. Signed-off-by: Stephen Gutekanst Change-Id: If41cafb95666946115b58567fef753df3fbe940a --- src/dawn/native/Surface.cpp | 4 +++- src/dawn/native/d3d12/SwapChainD3D12.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dawn/native/Surface.cpp b/src/dawn/native/Surface.cpp index ff6fd07559d..e898547e794 100644 --- a/src/dawn/native/Surface.cpp +++ b/src/dawn/native/Surface.cpp @@ -19,7 +19,7 @@ #include "dawn/native/Instance.h" #include "dawn/native/SwapChain.h" -#if defined(DAWN_PLATFORM_WINDOWS) +#if defined(DAWN_PLATFORM_WINDOWS) && !defined(DAWN_NO_WINDOWS_UI) # include # include #endif // defined(DAWN_PLATFORM_WINDOWS) @@ -106,6 +106,7 @@ namespace dawn::native { return {}; } # endif // defined(DAWN_PLATFORM_WIN32) +# if !defined(DAWN_NO_WINDOWS_UI) const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr; FindInChain(descriptor->nextInChain, &coreWindowDesc); if (coreWindowDesc) { @@ -128,6 +129,7 @@ namespace dawn::native { "Invalid SwapChainPanel"); return {}; } +#endif // !defined(DAWN_NO_WINDOWS_UI) #endif // defined(DAWN_PLATFORM_WINDOWS) #if defined(DAWN_USE_X11) diff --git a/src/dawn/native/d3d12/SwapChainD3D12.cpp b/src/dawn/native/d3d12/SwapChainD3D12.cpp index 38d47d0eed9..6070e62ce87 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_NO_WINDOWS_UI) #include +#endif // !defined(DAWN_NO_WINDOWS_UI) #include @@ -266,6 +268,7 @@ namespace dawn::native::d3d12 { "Creating the IDXGISwapChain1")); break; } +# if !defined(DAWN_NO_WINDOWS_UI) case Surface::Type::WindowsSwapChainPanel: { DAWN_TRY(CheckHRESULT( factory2->CreateSwapChainForComposition(device->GetCommandQueue().Get(), @@ -279,6 +282,9 @@ namespace dawn::native::d3d12 { "Setting SwapChain")); break; } +# else // !defined(DAWN_NO_WINDOWS_UI) + case Surface::Type::WindowsSwapChainPanel: UNREACHABLE(); +# endif // !defined(DAWN_NO_WINDOWS_UI) default: UNREACHABLE(); }