Skip to content

Commit

Permalink
dawn/native: add DAWN_NO_WINDOWS_UI option for Zig & MinGW compilers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: If41cafb95666946115b58567fef753df3fbe940a
  • Loading branch information
slimsag committed Apr 20, 2022
1 parent 93a2bed commit bcfcbd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dawn/native/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.ui.core.h>
# include <windows.ui.xaml.controls.h>
#endif // defined(DAWN_PLATFORM_WINDOWS)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/dawn/native/d3d12/SwapChainD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "dawn/native/d3d12/SwapChainD3D12.h"

#if !defined(DAWN_NO_WINDOWS_UI)
#include <windows.ui.xaml.media.dxinterop.h>
#endif // !defined(DAWN_NO_WINDOWS_UI)

#include <utility>

Expand Down Expand Up @@ -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(),
Expand All @@ -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();
}
Expand Down

0 comments on commit bcfcbd9

Please sign in to comment.