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"} {"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": { "swap chain": {
"category": "object", "category": "object",
"methods": [ "methods": [
@ -1937,7 +1945,8 @@
{"value": 4, "name": "surface descriptor from canvas HTML selector"}, {"value": 4, "name": "surface descriptor from canvas HTML selector"},
{"value": 5, "name": "shader module SPIRV descriptor"}, {"value": 5, "name": "shader module SPIRV descriptor"},
{"value": 6, "name": "shader module WGSL 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": { "texture": {

View File

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

View File

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

View File

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

View File

@ -244,11 +244,29 @@ namespace dawn_native { namespace d3d12 {
"Getting IDXGIFactory2")); "Getting IDXGIFactory2"));
ComPtr<IDXGISwapChain1> swapChain1; ComPtr<IDXGISwapChain1> swapChain1;
DAWN_TRY(CheckHRESULT( switch (GetSurface()->GetType()) {
factory2->CreateSwapChainForHwnd(device->GetCommandQueue().Get(), #if defined(DAWN_PLATFORM_WIN32)
static_cast<HWND>(GetSurface()->GetHWND()), case Surface::Type::WindowsHWND: {
&swapChainDesc, nullptr, nullptr, &swapChain1), DAWN_TRY(CheckHRESULT(
"Creating the IDXGISwapChain1")); 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")); DAWN_TRY(CheckHRESULT(swapChain1.As(&mDXGISwapChain), "Gettting IDXGISwapChain1"));
return CollectSwapChainBuffers(); return CollectSwapChainBuffers();