Add the webgpu.h swapchain creation path

This commit changes wgpu::Device::CreateSwapChain to take an additional
wgpu::Surface argument. Passing nullptr is enough to stay on the
previous swapchain implementation, until the new one is ready.

In order to support both the "old" implementation-based swapchains and
the "new" surface-based swapchains. SwapChainBase is now split into
three abstract classes:

 - SwapChainBase that has a virtual method for each of the
wgpu::SwapChain methods.
 - OldSwapChainBase that corresponds to the implementation-based
swapchains.
 - NewSwapChainBase that will contain the surface-based swapchain
implementation and will eventually just be renamed to SwapChainBase.

The interaction of the surface-based swapchains with the Surface objects
aren't implemented yet, neither are the swapchain methods. Only creation
works.

Validation tests for surface-based swapchain creation are added in the
end2end test target because they need to create OS windows.

Bug: dawn:269

Change-Id: I7e07d6c666479867b9a16d7b1b8c181d5dbd69a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15281
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez
2020-01-23 17:20:38 +00:00
committed by Commit Bot service account
parent a5a6e4f5bb
commit d87e676845
31 changed files with 460 additions and 73 deletions

View File

@@ -19,6 +19,7 @@
#include "dawn_native/DynamicUploader.h"
#include "dawn_native/ErrorData.h"
#include "dawn_native/Instance.h"
#include "dawn_native/Surface.h"
#include <spirv_cross.hpp>
@@ -147,7 +148,12 @@ namespace dawn_native { namespace null {
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) {
return new SwapChain(this, descriptor);
return new OldSwapChain(this, descriptor);
}
ResultOrError<SwapChainBase*> Device::CreateSwapChainImpl(
Surface* surface,
const SwapChainDescriptor* descriptor) {
return new SwapChain(this, surface, descriptor);
}
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor, TextureBase::TextureState::OwnedInternal);
@@ -349,20 +355,29 @@ namespace dawn_native { namespace null {
// SwapChain
SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor)
: SwapChainBase(device, descriptor) {
const auto& im = GetImplementation();
im.Init(im.userData, nullptr);
SwapChain::SwapChain(Device* device, Surface* surface, const SwapChainDescriptor* descriptor)
: NewSwapChainBase(device, surface, descriptor) {
}
SwapChain::~SwapChain() {
}
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
// OldSwapChain
OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor)
: OldSwapChainBase(device, descriptor) {
const auto& im = GetImplementation();
im.Init(im.userData, nullptr);
}
OldSwapChain::~OldSwapChain() {
}
TextureBase* OldSwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
return GetDevice()->CreateTexture(descriptor);
}
MaybeError SwapChain::OnBeforePresent(TextureBase*) {
MaybeError OldSwapChain::OnBeforePresent(TextureBase*) {
return {};
}

View File

@@ -125,6 +125,9 @@ namespace dawn_native { namespace null {
const ShaderModuleDescriptor* descriptor) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
const SwapChainDescriptor* descriptor) override;
ResultOrError<SwapChainBase*> CreateSwapChainImpl(
Surface* surface,
const SwapChainDescriptor* descriptor) override;
ResultOrError<TextureBase*> CreateTextureImpl(const TextureDescriptor* descriptor) override;
ResultOrError<TextureViewBase*> CreateTextureViewImpl(
TextureBase* texture,
@@ -197,10 +200,16 @@ namespace dawn_native { namespace null {
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
};
class SwapChain : public SwapChainBase {
class SwapChain : public NewSwapChainBase {
public:
SwapChain(Device* device, const SwapChainDescriptor* descriptor);
SwapChain(Device* device, Surface* surface, const SwapChainDescriptor* descriptor);
~SwapChain();
};
class OldSwapChain : public OldSwapChainBase {
public:
OldSwapChain(Device* device, const SwapChainDescriptor* descriptor);
~OldSwapChain();
protected:
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;