Add support for UWP CoreWindow in SwapChain and Surface

Add SurfaceDescriptorFromWindowsCoreWindow structure in codegen.
Add WindowsCoreWindow surface type.
Add support for WindowsCoreWindow surface in SwapChain.

Bug: dawn:766
Change-Id: If89258dc68896b9ba22c677d37ca3ba68c6fceb7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48762
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: 陈俊嘉 <cjj19970505@live.cn>
This commit is contained in:
陈俊嘉 2021-04-27 16:43:27 +00:00 committed by Commit Bot service account
parent 12c6305674
commit 74326fe2c8
5 changed files with 97 additions and 20 deletions

View File

@ -1897,6 +1897,14 @@
{"name": "window", "type": "uint32_t"}
]
},
"surface descriptor from windows core window": {
"category": "structure",
"chained": true,
"javascript": false,
"members": [
{"name": "core window", "type": "void", "annotation": "*"}
]
},
"swap chain": {
"category": "object",
"methods": [
@ -1937,7 +1945,8 @@
{"value": 4, "name": "surface descriptor from canvas HTML selector"},
{"value": 5, "name": "shader module SPIRV descriptor"},
{"value": 6, "name": "shader module WGSL descriptor"},
{"value": 7, "name": "primitive depth clamping state"}
{"value": 7, "name": "primitive depth clamping state"},
{"value": 8, "name": "surface descriptor from windows core window"}
]
},
"texture": {

View File

@ -149,7 +149,8 @@
"client_side_structures": [
"SurfaceDescriptorFromMetalLayer",
"SurfaceDescriptorFromWindowsHWND",
"SurfaceDescriptorFromXlib"
"SurfaceDescriptorFromXlib",
"SurfaceDescriptorFromWindowsCoreWindow"
],
"client_side_commands": [
"BufferMapAsync",

View File

@ -20,8 +20,8 @@
#include "dawn_native/SwapChain.h"
#if defined(DAWN_PLATFORM_WINDOWS)
# include "common/windows_with_undefs.h"
#endif // DAWN_PLATFORM_WINDOWS
# include <windows.ui.core.h>
#endif // defined(DAWN_PLATFORM_WINDOWS)
#if defined(DAWN_USE_X11)
# include "common/xlib_with_undefs.h"
@ -42,6 +42,7 @@ namespace dawn_native {
DAWN_TRY(ValidateSingleSType(descriptor->nextInChain,
wgpu::SType::SurfaceDescriptorFromMetalLayer,
wgpu::SType::SurfaceDescriptorFromWindowsHWND,
wgpu::SType::SurfaceDescriptorFromWindowsCoreWindow,
wgpu::SType::SurfaceDescriptorFromXlib));
#if defined(DAWN_ENABLE_BACKEND_METAL)
@ -56,17 +57,31 @@ 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) {
return DAWN_VALIDATION_ERROR("Unsupported sType");
}
// Validate the hwnd using the windows.h IsWindow function.
if (hwndDesc) {
if (IsWindow(static_cast<HWND>(hwndDesc->hwnd)) == 0) {
return DAWN_VALIDATION_ERROR("Invalid HWND");
}
return {};
}
# endif // defined(DAWN_PLATFORM_WIN32)
const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr;
FindInChain(descriptor->nextInChain, &coreWindowDesc);
if (coreWindowDesc) {
// Validate the coreWindow by query for ICoreWindow interface
ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWindow;
if (coreWindowDesc->coreWindow == nullptr ||
FAILED(static_cast<IUnknown*>(coreWindowDesc->coreWindow)
->QueryInterface(IID_PPV_ARGS(&coreWindow)))) {
return DAWN_VALIDATION_ERROR("Invalid CoreWindow");
}
return {};
}
return DAWN_VALIDATION_ERROR("Unsupported sType");
#endif // defined(DAWN_PLATFORM_WINDOWS)
#if defined(DAWN_USE_X11)
const SurfaceDescriptorFromXlib* xDesc = nullptr;
@ -98,22 +113,33 @@ namespace dawn_native {
ASSERT(descriptor->nextInChain != nullptr);
const SurfaceDescriptorFromMetalLayer* metalDesc = nullptr;
const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr;
const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr;
const SurfaceDescriptorFromXlib* xDesc = nullptr;
FindInChain(descriptor->nextInChain, &metalDesc);
FindInChain(descriptor->nextInChain, &hwndDesc);
FindInChain(descriptor->nextInChain, &coreWindowDesc);
FindInChain(descriptor->nextInChain, &xDesc);
ASSERT(metalDesc || hwndDesc || xDesc);
if (metalDesc) {
mType = Type::MetalLayer;
mMetalLayer = metalDesc->layer;
} else if (hwndDesc) {
#if defined(DAWN_PLATFORM_WIN32)
mType = Type::WindowsHWND;
mHInstance = hwndDesc->hinstance;
mHWND = hwndDesc->hwnd;
#endif // defined(DAWN_PLATFORM_WIN32)
} else if (coreWindowDesc) {
#if defined(DAWN_PLATFORM_WINDOWS)
mType = Type::WindowsCoreWindow;
mCoreWindow = static_cast<IUnknown*>(coreWindowDesc->coreWindow);
#endif // defined(DAWN_PLATFORM_WINDOWS)
} else if (xDesc) {
mType = Type::Xlib;
mXDisplay = xDesc->display;
mXWindow = xDesc->window;
} else {
UNREACHABLE();
}
}
@ -154,6 +180,15 @@ namespace dawn_native {
return mHWND;
}
void* Surface::GetCoreWindow() const {
ASSERT(mType == Type::WindowsCoreWindow);
#if defined(DAWN_PLATFORM_WINDOWS)
return mCoreWindow.Get();
#else
return nullptr;
#endif
}
void* Surface::GetXDisplay() const {
ASSERT(mType == Type::Xlib);
return mXDisplay;

View File

@ -21,6 +21,12 @@
#include "dawn_native/dawn_platform.h"
#include "common/Platform.h"
#if defined(DAWN_PLATFORM_WINDOWS)
# include "dawn_native/d3d12/d3d12_platform.h"
#endif // defined(DAWN_PLATFORM_WINDOWS)
namespace dawn_native {
MaybeError ValidateSurfaceDescriptor(const InstanceBase* instance,
@ -39,7 +45,7 @@ namespace dawn_native {
NewSwapChainBase* GetAttachedSwapChain();
// These are valid to call on all Surfaces.
enum class Type { MetalLayer, WindowsHWND, Xlib };
enum class Type { MetalLayer, WindowsHWND, WindowsCoreWindow, Xlib };
Type GetType() const;
InstanceBase* GetInstance();
@ -50,6 +56,9 @@ namespace dawn_native {
void* GetHInstance() const;
void* GetHWND() const;
// Valid to call if the type is WindowsCoreWindow
void* GetCoreWindow() const;
// Valid to call if the type is WindowsXlib
void* GetXDisplay() const;
uint32_t GetXWindow() const;
@ -70,6 +79,11 @@ namespace dawn_native {
void* mHInstance = nullptr;
void* mHWND = nullptr;
#if defined(DAWN_PLATFORM_WINDOWS)
// WindowsCoreWindow
ComPtr<IUnknown> mCoreWindow;
#endif // defined(DAWN_PLATFORM_WINDOWS)
// Xlib
void* mXDisplay = nullptr;
uint32_t mXWindow = 0;

View File

@ -244,11 +244,29 @@ namespace dawn_native { namespace d3d12 {
"Getting IDXGIFactory2"));
ComPtr<IDXGISwapChain1> swapChain1;
switch (GetSurface()->GetType()) {
#if defined(DAWN_PLATFORM_WIN32)
case Surface::Type::WindowsHWND: {
DAWN_TRY(CheckHRESULT(
factory2->CreateSwapChainForHwnd(device->GetCommandQueue().Get(),
static_cast<HWND>(GetSurface()->GetHWND()),
&swapChainDesc, nullptr, nullptr, &swapChain1),
"Creating the IDXGISwapChain1"));
break;
}
#endif // defined(DAWN_PLATFORM_WIN32)
case Surface::Type::WindowsCoreWindow: {
DAWN_TRY(CheckHRESULT(factory2->CreateSwapChainForCoreWindow(
device->GetCommandQueue().Get(),
static_cast<IUnknown*>(GetSurface()->GetCoreWindow()),
&swapChainDesc, nullptr, &swapChain1),
"Creating the IDXGISwapChain1"));
break;
}
default:
UNREACHABLE();
}
DAWN_TRY(CheckHRESULT(swapChain1.As(&mDXGISwapChain), "Gettting IDXGISwapChain1"));
return CollectSwapChainBuffers();