Merge NewSwapChainBase in SwapChainBase
Bug: dawn:269 Change-Id: I514c210f88e2bf1f501e2d814f8ab931c5ed724f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126423 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
4299bd0ac9
commit
1226684b09
|
@ -1778,15 +1778,15 @@ ResultOrError<Ref<SwapChainBase>> DeviceBase::CreateSwapChain(
|
|||
descriptor);
|
||||
}
|
||||
|
||||
NewSwapChainBase* previousSwapChain = surface->GetAttachedSwapChain();
|
||||
ResultOrError<Ref<NewSwapChainBase>> maybeNewSwapChain =
|
||||
SwapChainBase* previousSwapChain = surface->GetAttachedSwapChain();
|
||||
ResultOrError<Ref<SwapChainBase>> maybeNewSwapChain =
|
||||
CreateSwapChainImpl(surface, previousSwapChain, descriptor);
|
||||
|
||||
if (previousSwapChain != nullptr) {
|
||||
previousSwapChain->DetachFromSurface();
|
||||
}
|
||||
|
||||
Ref<NewSwapChainBase> newSwapChain;
|
||||
Ref<SwapChainBase> newSwapChain;
|
||||
DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain));
|
||||
|
||||
newSwapChain->SetIsAttached();
|
||||
|
|
|
@ -471,9 +471,9 @@ class DeviceBase : public RefCountedWithExternalCount {
|
|||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) = 0;
|
||||
// Note that previousSwapChain may be nullptr, or come from a different backend.
|
||||
virtual ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
virtual ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<Ref<TextureBase>> CreateTextureImpl(
|
||||
const TextureDescriptor* descriptor) = 0;
|
||||
|
|
|
@ -48,7 +48,6 @@ class SamplerBase;
|
|||
class Surface;
|
||||
class ShaderModuleBase;
|
||||
class SwapChainBase;
|
||||
class NewSwapChainBase;
|
||||
class TextureBase;
|
||||
class TextureViewBase;
|
||||
|
||||
|
|
|
@ -230,12 +230,12 @@ Surface::~Surface() {
|
|||
}
|
||||
}
|
||||
|
||||
NewSwapChainBase* Surface::GetAttachedSwapChain() {
|
||||
SwapChainBase* Surface::GetAttachedSwapChain() {
|
||||
ASSERT(!IsError());
|
||||
return mSwapChain.Get();
|
||||
}
|
||||
|
||||
void Surface::SetAttachedSwapChain(NewSwapChainBase* swapChain) {
|
||||
void Surface::SetAttachedSwapChain(SwapChainBase* swapChain) {
|
||||
ASSERT(!IsError());
|
||||
mSwapChain = swapChain;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ class Surface final : public ErrorMonad {
|
|||
|
||||
Surface(InstanceBase* instance, const SurfaceDescriptor* descriptor);
|
||||
|
||||
void SetAttachedSwapChain(NewSwapChainBase* swapChain);
|
||||
NewSwapChainBase* GetAttachedSwapChain();
|
||||
void SetAttachedSwapChain(SwapChainBase* swapChain);
|
||||
SwapChainBase* GetAttachedSwapChain();
|
||||
|
||||
// These are valid to call on all Surfaces.
|
||||
enum class Type {
|
||||
|
@ -96,7 +96,7 @@ class Surface final : public ErrorMonad {
|
|||
Type mType;
|
||||
|
||||
// The swapchain will set this to null when it is destroyed.
|
||||
Ref<NewSwapChainBase> mSwapChain;
|
||||
Ref<SwapChainBase> mSwapChain;
|
||||
|
||||
// MetalLayer
|
||||
void* mMetalLayer = nullptr;
|
||||
|
|
|
@ -31,21 +31,9 @@ class ErrorSwapChain final : public SwapChainBase {
|
|||
explicit ErrorSwapChain(DeviceBase* device) : SwapChainBase(device, ObjectBase::kError) {}
|
||||
|
||||
private:
|
||||
void APIConfigure(wgpu::TextureFormat format,
|
||||
wgpu::TextureUsage allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) override {
|
||||
GetDevice()->HandleError(DAWN_VALIDATION_ERROR("%s is an error swapchain.", this));
|
||||
}
|
||||
|
||||
TextureViewBase* APIGetCurrentTextureView() override {
|
||||
GetDevice()->HandleError(DAWN_VALIDATION_ERROR("%s is an error swapchain.", this));
|
||||
return TextureViewBase::MakeError(GetDevice());
|
||||
}
|
||||
|
||||
void APIPresent() override {
|
||||
GetDevice()->HandleError(DAWN_VALIDATION_ERROR("%s is an error swapchain.", this));
|
||||
}
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override { UNREACHABLE(); }
|
||||
MaybeError PresentImpl() override { UNREACHABLE(); }
|
||||
void DetachFromSurfaceImpl() override { UNREACHABLE(); }
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
@ -92,7 +80,7 @@ MaybeError ValidateSwapChainDescriptor(const DeviceBase* device,
|
|||
return {};
|
||||
}
|
||||
|
||||
TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain) {
|
||||
TextureDescriptor GetSwapChainBaseTextureDescriptor(SwapChainBase* swapChain) {
|
||||
TextureDescriptor desc;
|
||||
desc.usage = swapChain->GetUsage();
|
||||
desc.dimension = wgpu::TextureDimension::e2D;
|
||||
|
@ -104,43 +92,20 @@ TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain)
|
|||
return desc;
|
||||
}
|
||||
|
||||
// SwapChainBase
|
||||
|
||||
SwapChainBase::SwapChainBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
|
||||
GetObjectTrackingList()->Track(this);
|
||||
}
|
||||
|
||||
SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
||||
: ApiObjectBase(device, tag) {}
|
||||
|
||||
SwapChainBase::~SwapChainBase() {}
|
||||
|
||||
void SwapChainBase::DestroyImpl() {}
|
||||
|
||||
// static
|
||||
SwapChainBase* SwapChainBase::MakeError(DeviceBase* device) {
|
||||
return new ErrorSwapChain(device);
|
||||
}
|
||||
|
||||
ObjectType SwapChainBase::GetType() const {
|
||||
return ObjectType::SwapChain;
|
||||
}
|
||||
|
||||
// Implementation of NewSwapChainBase
|
||||
|
||||
NewSwapChainBase::NewSwapChainBase(DeviceBase* device,
|
||||
Surface* surface,
|
||||
const SwapChainDescriptor* descriptor)
|
||||
: SwapChainBase(device),
|
||||
mAttached(false),
|
||||
SwapChainBase::SwapChainBase(DeviceBase* device,
|
||||
Surface* surface,
|
||||
const SwapChainDescriptor* descriptor)
|
||||
: ApiObjectBase(device, kLabelNotImplemented),
|
||||
mWidth(descriptor->width),
|
||||
mHeight(descriptor->height),
|
||||
mFormat(descriptor->format),
|
||||
mUsage(descriptor->usage),
|
||||
mPresentMode(descriptor->presentMode),
|
||||
mSurface(surface) {}
|
||||
mSurface(surface) {
|
||||
GetObjectTrackingList()->Track(this);
|
||||
}
|
||||
|
||||
NewSwapChainBase::~NewSwapChainBase() {
|
||||
SwapChainBase::~SwapChainBase() {
|
||||
if (mCurrentTextureView != nullptr) {
|
||||
ASSERT(mCurrentTextureView->GetTexture()->GetTextureState() ==
|
||||
TextureBase::TextureState::Destroyed);
|
||||
|
@ -149,7 +114,21 @@ NewSwapChainBase::~NewSwapChainBase() {
|
|||
ASSERT(!mAttached);
|
||||
}
|
||||
|
||||
void NewSwapChainBase::DetachFromSurface() {
|
||||
SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag)
|
||||
: ApiObjectBase(device, tag) {}
|
||||
|
||||
// static
|
||||
SwapChainBase* SwapChainBase::MakeError(DeviceBase* device) {
|
||||
return new ErrorSwapChain(device);
|
||||
}
|
||||
|
||||
void SwapChainBase::DestroyImpl() {}
|
||||
|
||||
ObjectType SwapChainBase::GetType() const {
|
||||
return ObjectType::SwapChain;
|
||||
}
|
||||
|
||||
void SwapChainBase::DetachFromSurface() {
|
||||
if (mAttached) {
|
||||
DetachFromSurfaceImpl();
|
||||
mSurface = nullptr;
|
||||
|
@ -157,19 +136,19 @@ void NewSwapChainBase::DetachFromSurface() {
|
|||
}
|
||||
}
|
||||
|
||||
void NewSwapChainBase::SetIsAttached() {
|
||||
void SwapChainBase::SetIsAttached() {
|
||||
mAttached = true;
|
||||
}
|
||||
|
||||
void NewSwapChainBase::APIConfigure(wgpu::TextureFormat format,
|
||||
wgpu::TextureUsage allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
void SwapChainBase::APIConfigure(wgpu::TextureFormat format,
|
||||
wgpu::TextureUsage allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
GetDevice()->HandleError(
|
||||
DAWN_VALIDATION_ERROR("Configure is invalid for surface-based swapchains."));
|
||||
}
|
||||
|
||||
TextureViewBase* NewSwapChainBase::APIGetCurrentTextureView() {
|
||||
TextureViewBase* SwapChainBase::APIGetCurrentTextureView() {
|
||||
Ref<TextureViewBase> result;
|
||||
if (GetDevice()->ConsumedError(GetCurrentTextureView(), &result,
|
||||
"calling %s.GetCurrentTextureView()", this)) {
|
||||
|
@ -178,7 +157,7 @@ TextureViewBase* NewSwapChainBase::APIGetCurrentTextureView() {
|
|||
return result.Detach();
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> NewSwapChainBase::GetCurrentTextureView() {
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChainBase::GetCurrentTextureView() {
|
||||
DAWN_TRY(ValidateGetCurrentTextureView());
|
||||
|
||||
if (mCurrentTextureView != nullptr) {
|
||||
|
@ -204,7 +183,7 @@ ResultOrError<Ref<TextureViewBase>> NewSwapChainBase::GetCurrentTextureView() {
|
|||
return mCurrentTextureView;
|
||||
}
|
||||
|
||||
void NewSwapChainBase::APIPresent() {
|
||||
void SwapChainBase::APIPresent() {
|
||||
if (GetDevice()->ConsumedError(ValidatePresent())) {
|
||||
return;
|
||||
}
|
||||
|
@ -218,39 +197,39 @@ void NewSwapChainBase::APIPresent() {
|
|||
mCurrentTextureView = nullptr;
|
||||
}
|
||||
|
||||
uint32_t NewSwapChainBase::GetWidth() const {
|
||||
uint32_t SwapChainBase::GetWidth() const {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
uint32_t NewSwapChainBase::GetHeight() const {
|
||||
uint32_t SwapChainBase::GetHeight() const {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
wgpu::TextureFormat NewSwapChainBase::GetFormat() const {
|
||||
wgpu::TextureFormat SwapChainBase::GetFormat() const {
|
||||
return mFormat;
|
||||
}
|
||||
|
||||
wgpu::TextureUsage NewSwapChainBase::GetUsage() const {
|
||||
wgpu::TextureUsage SwapChainBase::GetUsage() const {
|
||||
return mUsage;
|
||||
}
|
||||
|
||||
wgpu::PresentMode NewSwapChainBase::GetPresentMode() const {
|
||||
wgpu::PresentMode SwapChainBase::GetPresentMode() const {
|
||||
return mPresentMode;
|
||||
}
|
||||
|
||||
Surface* NewSwapChainBase::GetSurface() const {
|
||||
Surface* SwapChainBase::GetSurface() const {
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
bool NewSwapChainBase::IsAttached() const {
|
||||
bool SwapChainBase::IsAttached() const {
|
||||
return mAttached;
|
||||
}
|
||||
|
||||
wgpu::BackendType NewSwapChainBase::GetBackendType() const {
|
||||
wgpu::BackendType SwapChainBase::GetBackendType() const {
|
||||
return GetDevice()->GetAdapter()->GetBackendType();
|
||||
}
|
||||
|
||||
MaybeError NewSwapChainBase::ValidatePresent() const {
|
||||
MaybeError SwapChainBase::ValidatePresent() const {
|
||||
DAWN_TRY(GetDevice()->ValidateIsAlive());
|
||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||
|
||||
|
@ -263,7 +242,7 @@ MaybeError NewSwapChainBase::ValidatePresent() const {
|
|||
return {};
|
||||
}
|
||||
|
||||
MaybeError NewSwapChainBase::ValidateGetCurrentTextureView() const {
|
||||
MaybeError SwapChainBase::ValidateGetCurrentTextureView() const {
|
||||
DAWN_TRY(GetDevice()->ValidateIsAlive());
|
||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||
|
||||
|
|
|
@ -28,35 +28,15 @@ MaybeError ValidateSwapChainDescriptor(const DeviceBase* device,
|
|||
const Surface* surface,
|
||||
const SwapChainDescriptor* descriptor);
|
||||
|
||||
TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain);
|
||||
TextureDescriptor GetSwapChainBaseTextureDescriptor(SwapChainBase* swapChain);
|
||||
|
||||
class SwapChainBase : public ApiObjectBase {
|
||||
public:
|
||||
explicit SwapChainBase(DeviceBase* device);
|
||||
SwapChainBase(DeviceBase* device, Surface* surface, const SwapChainDescriptor* descriptor);
|
||||
|
||||
static SwapChainBase* MakeError(DeviceBase* device);
|
||||
|
||||
ObjectType GetType() const override;
|
||||
|
||||
// Dawn API
|
||||
virtual void APIConfigure(wgpu::TextureFormat format,
|
||||
wgpu::TextureUsage allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) = 0;
|
||||
virtual TextureViewBase* APIGetCurrentTextureView() = 0;
|
||||
virtual void APIPresent() = 0;
|
||||
|
||||
protected:
|
||||
SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
||||
~SwapChainBase() override;
|
||||
void DestroyImpl() override;
|
||||
};
|
||||
|
||||
// The base class for surface-based SwapChains that aren't ready yet.
|
||||
class NewSwapChainBase : public SwapChainBase {
|
||||
public:
|
||||
NewSwapChainBase(DeviceBase* device, Surface* surface, const SwapChainDescriptor* descriptor);
|
||||
|
||||
// This is called when the swapchain is detached when one of the following happens:
|
||||
//
|
||||
// - The surface it is attached to is being destroyed.
|
||||
|
@ -80,9 +60,9 @@ class NewSwapChainBase : public SwapChainBase {
|
|||
void APIConfigure(wgpu::TextureFormat format,
|
||||
wgpu::TextureUsage allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) override;
|
||||
TextureViewBase* APIGetCurrentTextureView() override;
|
||||
void APIPresent() override;
|
||||
uint32_t height);
|
||||
TextureViewBase* APIGetCurrentTextureView();
|
||||
void APIPresent();
|
||||
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
|
@ -94,10 +74,12 @@ class NewSwapChainBase : public SwapChainBase {
|
|||
wgpu::BackendType GetBackendType() const;
|
||||
|
||||
protected:
|
||||
~NewSwapChainBase() override;
|
||||
SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
||||
~SwapChainBase() override;
|
||||
void DestroyImpl() override;
|
||||
|
||||
private:
|
||||
bool mAttached;
|
||||
bool mAttached = false;
|
||||
uint32_t mWidth;
|
||||
uint32_t mHeight;
|
||||
wgpu::TextureFormat mFormat;
|
||||
|
|
|
@ -440,9 +440,9 @@ ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
|
|||
OwnedCompilationMessages* compilationMessages) {
|
||||
return ShaderModule::Create(this, descriptor, parseResult, compilationMessages);
|
||||
}
|
||||
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
return SwapChain::Create(this, surface, previousSwapChain, descriptor);
|
||||
}
|
||||
|
|
|
@ -186,9 +186,9 @@ class Device final : public d3d::Device {
|
|||
const ShaderModuleDescriptor* descriptor,
|
||||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) override;
|
||||
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureBase>> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
||||
|
|
|
@ -77,7 +77,7 @@ DXGI_USAGE ToDXGIUsage(wgpu::TextureUsage usage) {
|
|||
// static
|
||||
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
|
||||
DAWN_TRY(swapchain->Initialize(previousSwapChain));
|
||||
|
@ -94,7 +94,7 @@ void SwapChain::DestroyImpl() {
|
|||
// Initializes the swapchain on the surface. Note that `previousSwapChain` may or may not be
|
||||
// nullptr. If it is not nullptr it means that it is the swapchain previously in use on the
|
||||
// surface and that we have a chance to reuse it's underlying IDXGISwapChain and "buffers".
|
||||
MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
||||
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
|
||||
ASSERT(GetSurface()->GetType() == Surface::Type::WindowsHWND);
|
||||
|
||||
// Precompute the configuration parameters we want for the DXGI swapchain.
|
||||
|
@ -116,8 +116,7 @@ MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
|||
"D3D12 SwapChain cannot switch backend types from %s to %s.",
|
||||
previousSwapChain->GetBackendType(), wgpu::BackendType::D3D12);
|
||||
|
||||
// TODO(crbug.com/dawn/269): use ToBackend once OldSwapChainBase is removed.
|
||||
SwapChain* previousD3D12SwapChain = static_cast<SwapChain*>(previousSwapChain);
|
||||
SwapChain* previousD3D12SwapChain = ToBackend(previousSwapChain);
|
||||
|
||||
// TODO(crbug.com/dawn/269): Figure out switching an HWND between devices, it might
|
||||
// require just losing the reference to the swapchain, but might also need to wait for
|
||||
|
|
|
@ -27,11 +27,11 @@ namespace dawn::native::d3d12 {
|
|||
class Device;
|
||||
class Texture;
|
||||
|
||||
class SwapChain final : public NewSwapChainBase {
|
||||
class SwapChain final : public SwapChainBase {
|
||||
public:
|
||||
static ResultOrError<Ref<SwapChain>> Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor);
|
||||
|
||||
private:
|
||||
|
@ -39,8 +39,8 @@ class SwapChain final : public NewSwapChainBase {
|
|||
|
||||
void DestroyImpl() override;
|
||||
|
||||
using NewSwapChainBase::NewSwapChainBase;
|
||||
MaybeError Initialize(NewSwapChainBase* previousSwapChain);
|
||||
using SwapChainBase::SwapChainBase;
|
||||
MaybeError Initialize(SwapChainBase* previousSwapChain);
|
||||
|
||||
struct Config {
|
||||
// Information that's passed to the D3D12 swapchain creation call.
|
||||
|
@ -50,7 +50,7 @@ class SwapChain final : public NewSwapChainBase {
|
|||
DXGI_USAGE usage;
|
||||
};
|
||||
|
||||
// NewSwapChainBase implementation
|
||||
// SwapChainBase implementation
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
|
|
|
@ -111,9 +111,9 @@ class Device final : public DeviceBase {
|
|||
const ShaderModuleDescriptor* descriptor,
|
||||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) override;
|
||||
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureBase>> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
||||
|
|
|
@ -215,9 +215,9 @@ ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
|
|||
OwnedCompilationMessages* compilationMessages) {
|
||||
return ShaderModule::Create(this, descriptor, parseResult, compilationMessages);
|
||||
}
|
||||
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
return SwapChain::Create(this, surface, previousSwapChain, descriptor);
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ namespace dawn::native::metal {
|
|||
class Device;
|
||||
class Texture;
|
||||
|
||||
class SwapChain final : public NewSwapChainBase {
|
||||
class SwapChain final : public SwapChainBase {
|
||||
public:
|
||||
static ResultOrError<Ref<SwapChain>> Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor);
|
||||
|
||||
SwapChain(DeviceBase* device, Surface* surface, const SwapChainDescriptor* descriptor);
|
||||
|
@ -40,8 +40,8 @@ class SwapChain final : public NewSwapChainBase {
|
|||
private:
|
||||
void DestroyImpl() override;
|
||||
|
||||
using NewSwapChainBase::NewSwapChainBase;
|
||||
MaybeError Initialize(NewSwapChainBase* previousSwapChain);
|
||||
using SwapChainBase::SwapChainBase;
|
||||
MaybeError Initialize(SwapChainBase* previousSwapChain);
|
||||
|
||||
NSRef<CAMetalLayer> mLayer;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace dawn::native::metal {
|
|||
// static
|
||||
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
|
||||
DAWN_TRY(swapchain->Initialize(previousSwapChain));
|
||||
|
@ -35,7 +35,7 @@ ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
|
|||
}
|
||||
|
||||
SwapChain::SwapChain(DeviceBase* dev, Surface* sur, const SwapChainDescriptor* desc)
|
||||
: NewSwapChainBase(dev, sur, desc) {}
|
||||
: SwapChainBase(dev, sur, desc) {}
|
||||
|
||||
SwapChain::~SwapChain() = default;
|
||||
|
||||
|
@ -44,7 +44,7 @@ void SwapChain::DestroyImpl() {
|
|||
DetachFromSurface();
|
||||
}
|
||||
|
||||
MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
||||
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
|
||||
ASSERT(GetSurface()->GetType() == Surface::Type::MetalLayer);
|
||||
|
||||
if (previousSwapChain != nullptr) {
|
||||
|
|
|
@ -173,9 +173,9 @@ ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
|
|||
DAWN_TRY(module->Initialize(parseResult, compilationMessages));
|
||||
return module;
|
||||
}
|
||||
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
return SwapChain::Create(this, surface, previousSwapChain, descriptor);
|
||||
}
|
||||
|
@ -424,14 +424,14 @@ MaybeError RenderPipeline::Initialize() {
|
|||
// static
|
||||
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
|
||||
DAWN_TRY(swapchain->Initialize(previousSwapChain));
|
||||
return swapchain;
|
||||
}
|
||||
|
||||
MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
||||
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
|
||||
if (previousSwapChain != nullptr) {
|
||||
// TODO(crbug.com/dawn/269): figure out what should happen when surfaces are used by
|
||||
// multiple backends one after the other. It probably needs to block until the backend
|
||||
|
|
|
@ -146,9 +146,9 @@ class Device final : public DeviceBase {
|
|||
const ShaderModuleDescriptor* descriptor,
|
||||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) override;
|
||||
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureBase>> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
||||
|
@ -291,17 +291,17 @@ class ShaderModule final : public ShaderModuleBase {
|
|||
OwnedCompilationMessages* compilationMessages);
|
||||
};
|
||||
|
||||
class SwapChain final : public NewSwapChainBase {
|
||||
class SwapChain final : public SwapChainBase {
|
||||
public:
|
||||
static ResultOrError<Ref<SwapChain>> Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor);
|
||||
~SwapChain() override;
|
||||
|
||||
private:
|
||||
using NewSwapChainBase::NewSwapChainBase;
|
||||
MaybeError Initialize(NewSwapChainBase* previousSwapChain);
|
||||
using SwapChainBase::SwapChainBase;
|
||||
MaybeError Initialize(SwapChainBase* previousSwapChain);
|
||||
|
||||
Ref<Texture> mTexture;
|
||||
|
||||
|
|
|
@ -238,9 +238,9 @@ ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
|
|||
OwnedCompilationMessages* compilationMessages) {
|
||||
return ShaderModule::Create(this, descriptor, parseResult, compilationMessages);
|
||||
}
|
||||
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
return DAWN_VALIDATION_ERROR("New swapchains not implemented.");
|
||||
}
|
||||
|
|
|
@ -112,9 +112,9 @@ class Device final : public DeviceBase {
|
|||
const ShaderModuleDescriptor* descriptor,
|
||||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) override;
|
||||
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureBase>> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
||||
|
|
|
@ -189,9 +189,9 @@ ResultOrError<Ref<ShaderModuleBase>> Device::CreateShaderModuleImpl(
|
|||
OwnedCompilationMessages* compilationMessages) {
|
||||
return ShaderModule::Create(this, descriptor, parseResult, compilationMessages);
|
||||
}
|
||||
ResultOrError<Ref<NewSwapChainBase>> Device::CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> Device::CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
return SwapChain::Create(this, surface, previousSwapChain, descriptor);
|
||||
}
|
||||
|
|
|
@ -135,9 +135,9 @@ class Device final : public DeviceBase {
|
|||
const ShaderModuleDescriptor* descriptor,
|
||||
ShaderModuleParseResult* parseResult,
|
||||
OwnedCompilationMessages* compilationMessages) override;
|
||||
ResultOrError<Ref<NewSwapChainBase>> CreateSwapChainImpl(
|
||||
ResultOrError<Ref<SwapChainBase>> CreateSwapChainImpl(
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureBase>> CreateTextureImpl(const TextureDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<TextureViewBase>> CreateTextureViewImpl(
|
||||
|
|
|
@ -208,7 +208,7 @@ uint32_t MinImageCountForPresentMode(VkPresentModeKHR mode) {
|
|||
// static
|
||||
ResultOrError<Ref<SwapChain>> SwapChain::Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor) {
|
||||
Ref<SwapChain> swapchain = AcquireRef(new SwapChain(device, surface, descriptor));
|
||||
DAWN_TRY(swapchain->Initialize(previousSwapChain));
|
||||
|
@ -224,7 +224,7 @@ void SwapChain::DestroyImpl() {
|
|||
|
||||
// Note that when we need to re-create the swapchain because it is out of date,
|
||||
// previousSwapChain can be set to `this`.
|
||||
MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
||||
MaybeError SwapChain::Initialize(SwapChainBase* previousSwapChain) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
Adapter* adapter = ToBackend(GetDevice()->GetAdapter());
|
||||
|
||||
|
@ -241,8 +241,7 @@ MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) {
|
|||
"Vulkan SwapChain cannot switch backend types from %s to %s.",
|
||||
previousSwapChain->GetBackendType(), wgpu::BackendType::Vulkan);
|
||||
|
||||
// TODO(crbug.com/dawn/269): use ToBackend once OldSwapChainBase is removed.
|
||||
SwapChain* previousVulkanSwapChain = static_cast<SwapChain*>(previousSwapChain);
|
||||
SwapChain* previousVulkanSwapChain = ToBackend(previousSwapChain);
|
||||
|
||||
// TODO(crbug.com/dawn/269): Figure out switching a single surface between multiple
|
||||
// Vulkan devices on different VkInstances. Probably needs to block too!
|
||||
|
|
|
@ -27,17 +27,17 @@ class Device;
|
|||
class Texture;
|
||||
struct VulkanSurfaceInfo;
|
||||
|
||||
class SwapChain : public NewSwapChainBase {
|
||||
class SwapChain : public SwapChainBase {
|
||||
public:
|
||||
static ResultOrError<Ref<SwapChain>> Create(Device* device,
|
||||
Surface* surface,
|
||||
NewSwapChainBase* previousSwapChain,
|
||||
SwapChainBase* previousSwapChain,
|
||||
const SwapChainDescriptor* descriptor);
|
||||
~SwapChain() override;
|
||||
|
||||
private:
|
||||
using NewSwapChainBase::NewSwapChainBase;
|
||||
MaybeError Initialize(NewSwapChainBase* previousSwapChain);
|
||||
using SwapChainBase::SwapChainBase;
|
||||
MaybeError Initialize(SwapChainBase* previousSwapChain);
|
||||
void DestroyImpl() override;
|
||||
|
||||
struct Config {
|
||||
|
@ -62,7 +62,7 @@ class SwapChain : public NewSwapChainBase {
|
|||
ResultOrError<Config> ChooseConfig(const VulkanSurfaceInfo& surfaceInfo) const;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewInternal(bool isReentrant = false);
|
||||
|
||||
// NewSwapChainBase implementation
|
||||
// SwapChainBase implementation
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
|
|
|
@ -200,13 +200,9 @@ TEST_P(DeviceLostTest, CreateShaderModuleFails) {
|
|||
})"));
|
||||
}
|
||||
|
||||
// Tests that CreateSwapChain fails when device is lost
|
||||
TEST_P(DeviceLostTest, CreateSwapChainFails) {
|
||||
LoseDeviceForTesting();
|
||||
|
||||
wgpu::SwapChainDescriptor descriptor = {};
|
||||
ASSERT_DEVICE_ERROR(device.CreateSwapChain(nullptr, &descriptor));
|
||||
}
|
||||
// Note that no device lost tests are done for swapchain because it is awkward to create a
|
||||
// wgpu::Surface in this file. SwapChainValidationTests.CreateSwapChainFailsAfterDevLost covers
|
||||
// this validation.
|
||||
|
||||
// Tests that CreateTexture fails when device is lost
|
||||
TEST_P(DeviceLostTest, CreateTextureFails) {
|
||||
|
|
|
@ -166,13 +166,6 @@ TEST_P(SwapChainValidationTests, InvalidCreationFormat) {
|
|||
ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &desc));
|
||||
}
|
||||
|
||||
// Checks that the implementation must be zero.
|
||||
TEST_P(SwapChainValidationTests, InvalidWithImplementation) {
|
||||
wgpu::SwapChainDescriptor desc = goodDescriptor;
|
||||
desc.implementation = 1;
|
||||
ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &desc));
|
||||
}
|
||||
|
||||
// Check swapchain operations with an error swapchain are errors
|
||||
TEST_P(SwapChainValidationTests, OperationsOnErrorSwapChain) {
|
||||
wgpu::SwapChain swapchain;
|
||||
|
@ -322,7 +315,7 @@ TEST_P(SwapChainValidationTests, SwapChainIsInvalidAfterSurfaceDestruction_After
|
|||
}
|
||||
|
||||
// Test that new swap chain present fails after device is lost
|
||||
TEST_P(SwapChainValidationTests, NewSwapChainPresentFailsAfterDeviceLost) {
|
||||
TEST_P(SwapChainValidationTests, SwapChainPresentFailsAfterDeviceLost) {
|
||||
wgpu::SwapChain swapchain = device.CreateSwapChain(surface, &goodDescriptor);
|
||||
wgpu::TextureView view = swapchain.GetCurrentTextureView();
|
||||
|
||||
|
@ -331,7 +324,7 @@ TEST_P(SwapChainValidationTests, NewSwapChainPresentFailsAfterDeviceLost) {
|
|||
}
|
||||
|
||||
// Test that new swap chain get current texture view fails after device is lost
|
||||
TEST_P(SwapChainValidationTests, NewSwapChainGetCurrentTextureViewFailsAfterDevLost) {
|
||||
TEST_P(SwapChainValidationTests, SwapChainGetCurrentTextureViewFailsAfterDevLost) {
|
||||
wgpu::SwapChain swapchain = device.CreateSwapChain(surface, &goodDescriptor);
|
||||
|
||||
LoseDeviceForTesting();
|
||||
|
@ -339,7 +332,7 @@ TEST_P(SwapChainValidationTests, NewSwapChainGetCurrentTextureViewFailsAfterDevL
|
|||
}
|
||||
|
||||
// Test that creation of a new swapchain fails after device is lost
|
||||
TEST_P(SwapChainValidationTests, CreateNewSwapChainFailsAfterDevLost) {
|
||||
TEST_P(SwapChainValidationTests, CreateSwapChainFailsAfterDevLost) {
|
||||
LoseDeviceForTesting();
|
||||
ASSERT_DEVICE_ERROR(device.CreateSwapChain(surface, &goodDescriptor));
|
||||
}
|
||||
|
|
|
@ -108,9 +108,9 @@ class DeviceMock : public DeviceBase {
|
|||
ShaderModuleParseResult*,
|
||||
OwnedCompilationMessages*),
|
||||
(override));
|
||||
MOCK_METHOD(ResultOrError<Ref<NewSwapChainBase>>,
|
||||
MOCK_METHOD(ResultOrError<Ref<SwapChainBase>>,
|
||||
CreateSwapChainImpl,
|
||||
(Surface*, NewSwapChainBase*, const SwapChainDescriptor*),
|
||||
(Surface*, SwapChainBase*, const SwapChainDescriptor*),
|
||||
(override));
|
||||
MOCK_METHOD(ResultOrError<Ref<TextureBase>>,
|
||||
CreateTextureImpl,
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
|
||||
namespace dawn::native {
|
||||
|
||||
SwapChainMock::SwapChainMock(DeviceBase* device) : SwapChainBase(device) {
|
||||
SwapChainMock::SwapChainMock(DeviceBase* device,
|
||||
Surface* surface,
|
||||
const SwapChainDescriptor* descriptor)
|
||||
: SwapChainBase(device, surface, descriptor) {
|
||||
ON_CALL(*this, DestroyImpl).WillByDefault([this]() { this->SwapChainBase::DestroyImpl(); });
|
||||
}
|
||||
|
||||
|
|
|
@ -24,17 +24,14 @@ namespace dawn::native {
|
|||
|
||||
class SwapChainMock : public SwapChainBase {
|
||||
public:
|
||||
explicit SwapChainMock(DeviceBase* device);
|
||||
SwapChainMock(DeviceBase* device, Surface* surface, const SwapChainDescriptor* descriptor);
|
||||
~SwapChainMock() override;
|
||||
|
||||
MOCK_METHOD(void, DestroyImpl, (), (override));
|
||||
|
||||
MOCK_METHOD(void,
|
||||
APIConfigure,
|
||||
(wgpu::TextureFormat, wgpu::TextureUsage, uint32_t, uint32_t),
|
||||
(override));
|
||||
MOCK_METHOD(TextureViewBase*, APIGetCurrentTextureView, (), (override));
|
||||
MOCK_METHOD(void, APIPresent, (), (override));
|
||||
MOCK_METHOD(ResultOrError<Ref<TextureViewBase>>, GetCurrentTextureViewImpl, (), (override));
|
||||
MOCK_METHOD(MaybeError, PresentImpl, (), (override));
|
||||
MOCK_METHOD(void, DetachFromSurfaceImpl, (), (override));
|
||||
};
|
||||
|
||||
} // namespace dawn::native
|
||||
|
|
Loading…
Reference in New Issue