Add support for windows SwapChainPanel in SwapChain and Surface

Add SurfaceDescriptorFromWindowsSwapChainPanel structure in codegen.
Add WindowsSwapChainPanel surface type.
Add support for WindowsSwapChainPanel surface in SwapChain.

Bug: dawn:766
Change-Id: I1d59262b912ee445c90a7ec6e22b442f2fb1bf00
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/53840
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
陈俊嘉 2021-06-09 08:44:07 +00:00 committed by Dawn LUCI CQ
parent 9c375faf4c
commit 11379a3b59
6 changed files with 67 additions and 3 deletions

View File

@ -1784,6 +1784,14 @@
{"name": "core window", "type": "void", "annotation": "*"} {"name": "core window", "type": "void", "annotation": "*"}
] ]
}, },
"surface descriptor from windows swap chain panel": {
"category": "structure",
"chained": true,
"javascript": false,
"members": [
{"name": "swap chain panel", "type": "void", "annotation": "*"}
]
},
"swap chain": { "swap chain": {
"category": "object", "category": "object",
"methods": [ "methods": [
@ -1827,7 +1835,8 @@
{"value": 7, "name": "primitive depth clamping state"}, {"value": 7, "name": "primitive depth clamping state"},
{"value": 8, "name": "surface descriptor from windows core window"}, {"value": 8, "name": "surface descriptor from windows core window"},
{"value": 9, "name": "external texture binding entry"}, {"value": 9, "name": "external texture binding entry"},
{"value": 10, "name": "external texture binding layout"} {"value": 10, "name": "external texture binding layout"},
{"value": 11, "name": "surface descriptor from windows swap chain panel"}
] ]
}, },
"texture": { "texture": {

View File

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

View File

@ -32,4 +32,7 @@
// Macros defined to produce compiler intrinsics // Macros defined to produce compiler intrinsics
#undef MemoryBarrier #undef MemoryBarrier
// Macro defined as an alias of GetTickCount
#undef GetCurrentTime
#endif // COMMON_WINDOWS_WITH_UNDEFS_H_ #endif // COMMON_WINDOWS_WITH_UNDEFS_H_

View File

@ -21,6 +21,7 @@
#if defined(DAWN_PLATFORM_WINDOWS) #if defined(DAWN_PLATFORM_WINDOWS)
# include <windows.ui.core.h> # include <windows.ui.core.h>
# include <windows.ui.xaml.controls.h>
#endif // defined(DAWN_PLATFORM_WINDOWS) #endif // defined(DAWN_PLATFORM_WINDOWS)
#if defined(DAWN_USE_X11) #if defined(DAWN_USE_X11)
@ -43,6 +44,7 @@ namespace dawn_native {
wgpu::SType::SurfaceDescriptorFromMetalLayer, wgpu::SType::SurfaceDescriptorFromMetalLayer,
wgpu::SType::SurfaceDescriptorFromWindowsHWND, wgpu::SType::SurfaceDescriptorFromWindowsHWND,
wgpu::SType::SurfaceDescriptorFromWindowsCoreWindow, wgpu::SType::SurfaceDescriptorFromWindowsCoreWindow,
wgpu::SType::SurfaceDescriptorFromWindowsSwapChainPanel,
wgpu::SType::SurfaceDescriptorFromXlib)); wgpu::SType::SurfaceDescriptorFromXlib));
#if defined(DAWN_ENABLE_BACKEND_METAL) #if defined(DAWN_ENABLE_BACKEND_METAL)
@ -80,6 +82,18 @@ namespace dawn_native {
} }
return {}; return {};
} }
const SurfaceDescriptorFromWindowsSwapChainPanel* swapChainPanelDesc = nullptr;
FindInChain(descriptor->nextInChain, &swapChainPanelDesc);
if (swapChainPanelDesc) {
// Validate the swapChainPanel by querying for ISwapChainPanel interface
ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> swapChainPanel;
if (swapChainPanelDesc->swapChainPanel == nullptr ||
FAILED(static_cast<IUnknown*>(swapChainPanelDesc->swapChainPanel)
->QueryInterface(IID_PPV_ARGS(&swapChainPanel)))) {
return DAWN_VALIDATION_ERROR("Invalid SwapChainPanel");
}
return {};
}
return DAWN_VALIDATION_ERROR("Unsupported sType"); return DAWN_VALIDATION_ERROR("Unsupported sType");
#endif // defined(DAWN_PLATFORM_WINDOWS) #endif // defined(DAWN_PLATFORM_WINDOWS)
@ -114,10 +128,12 @@ namespace dawn_native {
const SurfaceDescriptorFromMetalLayer* metalDesc = nullptr; const SurfaceDescriptorFromMetalLayer* metalDesc = nullptr;
const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr; const SurfaceDescriptorFromWindowsHWND* hwndDesc = nullptr;
const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr; const SurfaceDescriptorFromWindowsCoreWindow* coreWindowDesc = nullptr;
const SurfaceDescriptorFromWindowsSwapChainPanel* swapChainPanelDesc = 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, &coreWindowDesc);
FindInChain(descriptor->nextInChain, &swapChainPanelDesc);
FindInChain(descriptor->nextInChain, &xDesc); FindInChain(descriptor->nextInChain, &xDesc);
ASSERT(metalDesc || hwndDesc || xDesc); ASSERT(metalDesc || hwndDesc || xDesc);
if (metalDesc) { if (metalDesc) {
@ -131,6 +147,11 @@ namespace dawn_native {
#if defined(DAWN_PLATFORM_WINDOWS) #if defined(DAWN_PLATFORM_WINDOWS)
mType = Type::WindowsCoreWindow; mType = Type::WindowsCoreWindow;
mCoreWindow = static_cast<IUnknown*>(coreWindowDesc->coreWindow); mCoreWindow = static_cast<IUnknown*>(coreWindowDesc->coreWindow);
#endif // defined(DAWN_PLATFORM_WINDOWS)
} else if (swapChainPanelDesc) {
#if defined(DAWN_PLATFORM_WINDOWS)
mType = Type::WindowsSwapChainPanel;
mSwapChainPanel = static_cast<IUnknown*>(swapChainPanelDesc->swapChainPanel);
#endif // defined(DAWN_PLATFORM_WINDOWS) #endif // defined(DAWN_PLATFORM_WINDOWS)
} else if (xDesc) { } else if (xDesc) {
mType = Type::Xlib; mType = Type::Xlib;
@ -187,6 +208,15 @@ namespace dawn_native {
#endif #endif
} }
IUnknown* Surface::GetSwapChainPanel() const {
ASSERT(mType == Type::WindowsSwapChainPanel);
#if defined(DAWN_PLATFORM_WINDOWS)
return mSwapChainPanel.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

@ -50,7 +50,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, WindowsCoreWindow, Xlib }; enum class Type { MetalLayer, WindowsHWND, WindowsCoreWindow, WindowsSwapChainPanel, Xlib };
Type GetType() const; Type GetType() const;
InstanceBase* GetInstance(); InstanceBase* GetInstance();
@ -64,6 +64,9 @@ namespace dawn_native {
// Valid to call if the type is WindowsCoreWindow // Valid to call if the type is WindowsCoreWindow
IUnknown* GetCoreWindow() const; IUnknown* GetCoreWindow() const;
// Valid to call if the type is WindowsSwapChainPanel
IUnknown* GetSwapChainPanel() 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;
@ -87,6 +90,9 @@ namespace dawn_native {
#if defined(DAWN_PLATFORM_WINDOWS) #if defined(DAWN_PLATFORM_WINDOWS)
// WindowsCoreWindow // WindowsCoreWindow
ComPtr<IUnknown> mCoreWindow; ComPtr<IUnknown> mCoreWindow;
// WindowsSwapChainPanel
ComPtr<IUnknown> mSwapChainPanel;
#endif // defined(DAWN_PLATFORM_WINDOWS) #endif // defined(DAWN_PLATFORM_WINDOWS)
// Xlib // Xlib

View File

@ -21,6 +21,8 @@
#include <dawn/dawn_wsi.h> #include <dawn/dawn_wsi.h>
#include <windows.ui.xaml.media.dxinterop.h>
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
namespace { namespace {
@ -261,6 +263,19 @@ namespace dawn_native { namespace d3d12 {
"Creating the IDXGISwapChain1")); "Creating the IDXGISwapChain1"));
break; break;
} }
case Surface::Type::WindowsSwapChainPanel: {
DAWN_TRY(CheckHRESULT(
factory2->CreateSwapChainForComposition(device->GetCommandQueue().Get(),
&swapChainDesc, nullptr, &swapChain1),
"Creating the IDXGISwapChain1"));
ComPtr<ISwapChainPanelNative> swapChainPanelNative;
DAWN_TRY(CheckHRESULT(GetSurface()->GetSwapChainPanel()->QueryInterface(
IID_PPV_ARGS(&swapChainPanelNative)),
"Getting ISwapChainPanelNative"));
DAWN_TRY(CheckHRESULT(swapChainPanelNative->SetSwapChain(swapChain1.Get()),
"Setting SwapChain"));
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
} }