Add UWP support
Add necessary cflags and cflags_cc for winrt compilation. Add 'dawn_is_winuwp'. Set 'dawn_enable_vulkan' and 'dawn_supports_glfw_for_windowing' when compiling for UWP. Link d3d12, d3d11 and dxgi stub libs when compiling for UWP. Use LoadPackagedLibrary instead of LoadLibraryA in DynamicLib when compiling for UWP. Swapchain related changes will be in another commit. Bug: dawn:766 Change-Id: I1210798a21cc175bab77281403d262d4bfb02d99 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48480 Commit-Queue: 陈俊嘉 <cjj19970505@live.cn> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
This commit is contained in:
parent
e6a12d5efa
commit
02336e6f99
|
@ -26,6 +26,9 @@ if (build_with_chromium) {
|
|||
}
|
||||
}
|
||||
|
||||
# Enable the compilation for UWP
|
||||
dawn_is_winuwp = is_win && target_os == "winuwp"
|
||||
|
||||
declare_args() {
|
||||
dawn_use_angle = true
|
||||
|
||||
|
@ -62,8 +65,9 @@ declare_args() {
|
|||
dawn_enable_opengl = is_linux && !is_chromeos
|
||||
|
||||
# Enables the compilation of Dawn's Vulkan backend
|
||||
dawn_enable_vulkan = is_linux || is_chromeos || is_win || is_fuchsia ||
|
||||
is_android || dawn_use_swiftshader
|
||||
# Disables vulkan when compiling for UWP, since UWP only supports d3d
|
||||
dawn_enable_vulkan = is_linux || is_chromeos || (is_win && !dawn_is_winuwp) ||
|
||||
is_fuchsia || is_android || dawn_use_swiftshader
|
||||
|
||||
# Enable use of reflection compiler in spirv-cross. This is needed
|
||||
# if performing reflection on systems that the platform language
|
||||
|
@ -90,5 +94,6 @@ declare_args() {
|
|||
dawn_enable_vulkan_loader = dawn_enable_vulkan && is_mac
|
||||
}
|
||||
|
||||
# UWP only supports CoreWindow for windowing
|
||||
dawn_supports_glfw_for_windowing =
|
||||
is_win || (is_linux && !is_chromeos) || is_mac
|
||||
(is_win && !dawn_is_winuwp) || (is_linux && !is_chromeos) || is_mac
|
||||
|
|
|
@ -129,6 +129,16 @@ config("dawn_internal") {
|
|||
# Dawn extends wgpu enums with internal enums.
|
||||
# MSVC considers these invalid switch values. crbug.com/dawn/397.
|
||||
cflags += [ "/wd4063" ]
|
||||
if (dawn_is_winuwp) {
|
||||
# /ZW makes sure we don't add calls that are forbidden in UWP.
|
||||
# and /EHsc is required to be used in combination with it,
|
||||
# even if it is already added by the windows GN defaults,
|
||||
# we still add it to make every /ZW paired with a /EHsc
|
||||
cflags_cc = [
|
||||
"/ZW:nostdlib",
|
||||
"/EHsc",
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
#if DAWN_PLATFORM_WINDOWS
|
||||
# include "common/windows_with_undefs.h"
|
||||
# if DAWN_PLATFORM_WINUWP
|
||||
# include "common/WindowsUtils.h"
|
||||
# endif
|
||||
#elif DAWN_PLATFORM_POSIX
|
||||
# include <dlfcn.h>
|
||||
#else
|
||||
|
@ -43,8 +46,11 @@ bool DynamicLib::Valid() const {
|
|||
|
||||
bool DynamicLib::Open(const std::string& filename, std::string* error) {
|
||||
#if DAWN_PLATFORM_WINDOWS
|
||||
# if DAWN_PLATFORM_WINUWP
|
||||
mHandle = LoadPackagedLibrary(UTF8ToWStr(filename.c_str()).c_str(), 0);
|
||||
# else
|
||||
mHandle = LoadLibraryA(filename.c_str());
|
||||
|
||||
# endif
|
||||
if (mHandle == nullptr && error != nullptr) {
|
||||
*error = "Windows Error: " + std::to_string(GetLastError());
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ class PlacementAllocated {
|
|||
void operator delete(void* ptr) {
|
||||
// Object is placement-allocated. Don't free the memory.
|
||||
}
|
||||
|
||||
void operator delete(void*, void*) {
|
||||
// This is added to match new(size_t size, void* ptr)
|
||||
// Otherwise it triggers C4291 warning in MSVC
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COMMON_PLACEMENTALLOCATED_H_
|
||||
|
|
|
@ -16,7 +16,15 @@
|
|||
#define COMMON_PLATFORM_H_
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# include <winapifamily.h>
|
||||
# define DAWN_PLATFORM_WINDOWS 1
|
||||
# if WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
|
||||
# define DAWN_PLATFORM_WIN32 1
|
||||
# elif WINAPI_FAMILY == WINAPI_FAMILY_PC_APP
|
||||
# define DAWN_PLATFORM_WINUWP 1
|
||||
# else
|
||||
# error "Unsupported Windows platform."
|
||||
# endif
|
||||
|
||||
#elif defined(__linux__)
|
||||
# define DAWN_PLATFORM_LINUX 1
|
||||
|
|
|
@ -311,6 +311,20 @@ source_set("dawn_native_sources") {
|
|||
|
||||
if (is_win) {
|
||||
libs += [ "user32.lib" ]
|
||||
if (dawn_is_winuwp) {
|
||||
# UWP has a limited DLL search space.
|
||||
# So we have to link with stub libs provided by Windows SDK
|
||||
# to load DLLs correctly.
|
||||
libs += [
|
||||
"dxgi.lib",
|
||||
"d3d12.lib",
|
||||
"d3d11.lib",
|
||||
|
||||
# TODO(dawn:766):
|
||||
# Somehow use dxcompiler.lib makes CoreApp unable to activate
|
||||
# WinPIX should be added as third party tools and linked statically
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (dawn_enable_d3d12) {
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace dawn_native {
|
|||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
#if defined(DAWN_PLATFORM_WINDOWS)
|
||||
#if defined(DAWN_PLATFORM_WIN32)
|
||||
const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr;
|
||||
FindInChain(descriptor->nextInChain, &hwndDesc);
|
||||
if (!hwndDesc) {
|
||||
|
@ -66,7 +66,7 @@ namespace dawn_native {
|
|||
if (IsWindow(static_cast<HWND>(hwndDesc->hwnd)) == 0) {
|
||||
return DAWN_VALIDATION_ERROR("Invalid HWND");
|
||||
}
|
||||
#endif // defined(DAWN_PLATFORM_WINDOWS)
|
||||
#endif // defined(DAWN_PLATFORM_WIN32)
|
||||
|
||||
#if defined(DAWN_USE_X11)
|
||||
const SurfaceDescriptorFromXlib* xDesc = nullptr;
|
||||
|
|
|
@ -114,6 +114,15 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
MaybeError PlatformFunctions::LoadD3D12() {
|
||||
#if DAWN_PLATFORM_WINUWP
|
||||
d3d12CreateDevice = &D3D12CreateDevice;
|
||||
d3d12GetDebugInterface = &D3D12GetDebugInterface;
|
||||
d3d12SerializeRootSignature = &D3D12SerializeRootSignature;
|
||||
d3d12CreateRootSignatureDeserializer = &D3D12CreateRootSignatureDeserializer;
|
||||
d3d12SerializeVersionedRootSignature = &D3D12SerializeVersionedRootSignature;
|
||||
d3d12CreateVersionedRootSignatureDeserializer =
|
||||
&D3D12CreateVersionedRootSignatureDeserializer;
|
||||
#else
|
||||
std::string error;
|
||||
if (!mD3D12Lib.Open("d3d12.dll", &error) ||
|
||||
!mD3D12Lib.GetProc(&d3d12CreateDevice, "D3D12CreateDevice", &error) ||
|
||||
|
@ -128,32 +137,48 @@ namespace dawn_native { namespace d3d12 {
|
|||
"D3D12CreateVersionedRootSignatureDeserializer", &error)) {
|
||||
return DAWN_INTERNAL_ERROR(error.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError PlatformFunctions::LoadD3D11() {
|
||||
#if DAWN_PLATFORM_WINUWP
|
||||
d3d11on12CreateDevice = &D3D11On12CreateDevice;
|
||||
#else
|
||||
std::string error;
|
||||
if (!mD3D11Lib.Open("d3d11.dll", &error) ||
|
||||
!mD3D11Lib.GetProc(&d3d11on12CreateDevice, "D3D11On12CreateDevice", &error)) {
|
||||
return DAWN_INTERNAL_ERROR(error.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError PlatformFunctions::LoadDXGI() {
|
||||
#if DAWN_PLATFORM_WINUWP
|
||||
dxgiGetDebugInterface1 = &DXGIGetDebugInterface1;
|
||||
createDxgiFactory2 = &CreateDXGIFactory2;
|
||||
#else
|
||||
std::string error;
|
||||
if (!mDXGILib.Open("dxgi.dll", &error) ||
|
||||
!mDXGILib.GetProc(&dxgiGetDebugInterface1, "DXGIGetDebugInterface1", &error) ||
|
||||
!mDXGILib.GetProc(&createDxgiFactory2, "CreateDXGIFactory2", &error)) {
|
||||
return DAWN_INTERNAL_ERROR(error.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void PlatformFunctions::LoadDXCLibraries() {
|
||||
// TODO(dawn:766)
|
||||
// Statically linked with dxcompiler.lib in UWP
|
||||
// currently linked with dxcompiler.lib making CoreApp unable to activate
|
||||
// LoadDXIL and LoadDXCompiler will fail in UWP, but LoadFunctions() can still be
|
||||
// successfully executed.
|
||||
|
||||
const std::string& windowsSDKBasePath = GetWindowsSDKBasePath();
|
||||
|
||||
LoadDXIL(windowsSDKBasePath);
|
||||
|
@ -199,12 +224,15 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
MaybeError PlatformFunctions::LoadFXCompiler() {
|
||||
#if DAWN_PLATFORM_WINUWP
|
||||
d3dCompile = &D3DCompile;
|
||||
#else
|
||||
std::string error;
|
||||
if (!mFXCompilerLib.Open("d3dcompiler_47.dll", &error) ||
|
||||
!mFXCompilerLib.GetProc(&d3dCompile, "D3DCompile", &error)) {
|
||||
return DAWN_INTERNAL_ERROR(error.c_str());
|
||||
}
|
||||
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -217,6 +245,11 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
void PlatformFunctions::LoadPIXRuntime() {
|
||||
// TODO(dawn:766):
|
||||
// In UWP PIX should be statically linked WinPixEventRuntime_UAP.lib
|
||||
// So maybe we should put WinPixEventRuntime as a third party package
|
||||
// Currently PIX is not going to be loaded in UWP since the following
|
||||
// mPIXEventRuntimeLib.Open will fail.
|
||||
if (!mPIXEventRuntimeLib.Open("WinPixEventRuntime.dll") ||
|
||||
!mPIXEventRuntimeLib.GetProc(&pixBeginEventOnCommandList,
|
||||
"PIXBeginEventOnCommandList") ||
|
||||
|
|
|
@ -95,7 +95,7 @@ static_library("dawn_utils") {
|
|||
libs = []
|
||||
frameworks = []
|
||||
|
||||
if (is_win) {
|
||||
if (is_win && !dawn_is_winuwp) {
|
||||
sources += [ "WindowsDebugLogger.cpp" ]
|
||||
} else {
|
||||
sources += [ "EmptyDebugLogger.cpp" ]
|
||||
|
|
Loading…
Reference in New Issue