diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index ee5f541236..e902a6f92a 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -631,8 +631,6 @@ source_set("sources") { "opengl/SamplerGL.h", "opengl/ShaderModuleGL.cpp", "opengl/ShaderModuleGL.h", - "opengl/SwapChainGL.cpp", - "opengl/SwapChainGL.h", "opengl/TextureGL.cpp", "opengl/TextureGL.h", "opengl/UtilsEGL.cpp", diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index f8d90ba09a..960e3d8b17 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -500,8 +500,6 @@ if (DAWN_ENABLE_OPENGL) "opengl/SamplerGL.h" "opengl/ShaderModuleGL.cpp" "opengl/ShaderModuleGL.h" - "opengl/SwapChainGL.cpp" - "opengl/SwapChainGL.h" "opengl/TextureGL.cpp" "opengl/TextureGL.h" "opengl/UtilsEGL.cpp" diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp index e795bc2f04..4f94754742 100644 --- a/src/dawn/native/Device.cpp +++ b/src/dawn/native/Device.cpp @@ -1746,27 +1746,20 @@ ResultOrError> DeviceBase::CreateSwapChain( descriptor); } - // TODO(dawn:269): Remove this code path once implementation-based swapchains are removed. - if (surface == nullptr) { - return CreateSwapChainImpl(descriptor); - } else { - ASSERT(descriptor->implementation == 0); + NewSwapChainBase* previousSwapChain = surface->GetAttachedSwapChain(); + ResultOrError> maybeNewSwapChain = + CreateSwapChainImpl(surface, previousSwapChain, descriptor); - NewSwapChainBase* previousSwapChain = surface->GetAttachedSwapChain(); - ResultOrError> maybeNewSwapChain = - CreateSwapChainImpl(surface, previousSwapChain, descriptor); - - if (previousSwapChain != nullptr) { - previousSwapChain->DetachFromSurface(); - } - - Ref newSwapChain; - DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain)); - - newSwapChain->SetIsAttached(); - surface->SetAttachedSwapChain(newSwapChain.Get()); - return newSwapChain; + if (previousSwapChain != nullptr) { + previousSwapChain->DetachFromSurface(); } + + Ref newSwapChain; + DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain)); + + newSwapChain->SetIsAttached(); + surface->SetAttachedSwapChain(newSwapChain.Get()); + return newSwapChain; } ResultOrError> DeviceBase::CreateTexture(const TextureDescriptor* descriptor) { diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h index f05bc667dd..2de70894c7 100644 --- a/src/dawn/native/Device.h +++ b/src/dawn/native/Device.h @@ -463,8 +463,6 @@ class DeviceBase : public RefCountedWithExternalCount { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) = 0; - virtual ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) = 0; // Note that previousSwapChain may be nullptr, or come from a different backend. virtual ResultOrError> CreateSwapChainImpl( Surface* surface, diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp index a43067fb26..f4dd0b32b0 100644 --- a/src/dawn/native/SwapChain.cpp +++ b/src/dawn/native/SwapChain.cpp @@ -53,51 +53,41 @@ class ErrorSwapChain final : public SwapChainBase { MaybeError ValidateSwapChainDescriptor(const DeviceBase* device, const Surface* surface, const SwapChainDescriptor* descriptor) { - if (descriptor->implementation != 0) { - DAWN_INVALID_IF(surface != nullptr, "Exactly one of surface or implementation must be set"); + DAWN_INVALID_IF(descriptor->implementation != 0, + "Implementation-based swapchains are no longer supported."); - DawnSwapChainImplementation* impl = - reinterpret_cast(descriptor->implementation); + DAWN_INVALID_IF(surface == nullptr, "At least one of surface or implementation must be set"); + DAWN_INVALID_IF(surface->IsError(), "[Surface] is invalid."); - DAWN_INVALID_IF(!impl->Init || !impl->Destroy || !impl->Configure || - !impl->GetNextTexture || !impl->Present, - "Implementation is incomplete"); - - } else { - DAWN_INVALID_IF(surface == nullptr, - "At least one of surface or implementation must be set"); - DAWN_INVALID_IF(surface->IsError(), "[Surface] is invalid."); - - DAWN_TRY(ValidatePresentMode(descriptor->presentMode)); + DAWN_TRY(ValidatePresentMode(descriptor->presentMode)); // TODO(crbug.com/dawn/160): Lift this restriction once wgpu::Instance::GetPreferredSurfaceFormat is // implemented. // TODO(dawn:286): #if DAWN_PLATFORM_IS(ANDROID) - constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::RGBA8Unorm; + constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::RGBA8Unorm; #else - constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::BGRA8Unorm; + constexpr wgpu::TextureFormat kRequireSwapChainFormat = wgpu::TextureFormat::BGRA8Unorm; #endif // !DAWN_PLATFORM_IS(ANDROID) - DAWN_INVALID_IF(descriptor->format != kRequireSwapChainFormat, - "Format (%s) is not %s, which is (currently) the only accepted format.", - descriptor->format, kRequireSwapChainFormat); + DAWN_INVALID_IF(descriptor->format != kRequireSwapChainFormat, + "Format (%s) is not %s, which is (currently) the only accepted format.", + descriptor->format, kRequireSwapChainFormat); - DAWN_INVALID_IF(descriptor->usage != wgpu::TextureUsage::RenderAttachment, - "Usage (%s) is not %s, which is (currently) the only accepted usage.", - descriptor->usage, wgpu::TextureUsage::RenderAttachment); + DAWN_INVALID_IF(descriptor->usage != wgpu::TextureUsage::RenderAttachment, + "Usage (%s) is not %s, which is (currently) the only accepted usage.", + descriptor->usage, wgpu::TextureUsage::RenderAttachment); - DAWN_INVALID_IF(descriptor->width == 0 || descriptor->height == 0, - "Swap Chain size (width: %u, height: %u) is empty.", descriptor->width, - descriptor->height); + DAWN_INVALID_IF(descriptor->width == 0 || descriptor->height == 0, + "Swap Chain size (width: %u, height: %u) is empty.", descriptor->width, + descriptor->height); - DAWN_INVALID_IF( - descriptor->width > device->GetLimits().v1.maxTextureDimension2D || - descriptor->height > device->GetLimits().v1.maxTextureDimension2D, - "Swap Chain size (width: %u, height: %u) is greater than the maximum 2D texture " - "size (width: %u, height: %u).", - descriptor->width, descriptor->height, device->GetLimits().v1.maxTextureDimension2D, - device->GetLimits().v1.maxTextureDimension2D); - } + DAWN_INVALID_IF( + descriptor->width > device->GetLimits().v1.maxTextureDimension2D || + descriptor->height > device->GetLimits().v1.maxTextureDimension2D, + "Swap Chain size (width: %u, height: %u) is greater than the maximum 2D texture " + "size (width: %u, height: %u).", + descriptor->width, descriptor->height, device->GetLimits().v1.maxTextureDimension2D, + device->GetLimits().v1.maxTextureDimension2D); return {}; } @@ -136,131 +126,6 @@ ObjectType SwapChainBase::GetType() const { return ObjectType::SwapChain; } -// OldSwapChainBase - -OldSwapChainBase::OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor) - : SwapChainBase(device), - mImplementation(*reinterpret_cast(descriptor->implementation)) { -} - -OldSwapChainBase::~OldSwapChainBase() { - if (!IsError()) { - const auto& im = GetImplementation(); - im.Destroy(im.userData); - } -} - -void OldSwapChainBase::APIConfigure(wgpu::TextureFormat format, - wgpu::TextureUsage allowedUsage, - uint32_t width, - uint32_t height) { - if (GetDevice()->ConsumedError(ValidateConfigure(format, allowedUsage, width, height))) { - return; - } - ASSERT(!IsError()); - - allowedUsage |= wgpu::TextureUsage::Present; - - mFormat = format; - mAllowedUsage = allowedUsage; - mWidth = width; - mHeight = height; - mImplementation.Configure(mImplementation.userData, static_cast(format), - static_cast(allowedUsage), width, height); -} - -TextureViewBase* OldSwapChainBase::APIGetCurrentTextureView() { - if (GetDevice()->ConsumedError(ValidateGetCurrentTextureView())) { - return TextureViewBase::MakeError(GetDevice()); - } - ASSERT(!IsError()); - - // Return the same current texture view until Present is called. - if (mCurrentTextureView != nullptr) { - // Calling GetCurrentTextureView always returns a new reference so add it even when - // reuse the existing texture view. - mCurrentTextureView->Reference(); - return mCurrentTextureView.Get(); - } - - // Create the backing texture and the view. - TextureDescriptor descriptor; - descriptor.dimension = wgpu::TextureDimension::e2D; - descriptor.size.width = mWidth; - descriptor.size.height = mHeight; - descriptor.size.depthOrArrayLayers = 1; - descriptor.sampleCount = 1; - descriptor.format = mFormat; - descriptor.mipLevelCount = 1; - descriptor.usage = mAllowedUsage; - - // Get the texture but remove the external refcount because it is never passed outside - // of dawn_native - mCurrentTexture = AcquireRef(GetNextTextureImpl(&descriptor)); - - mCurrentTextureView = mCurrentTexture->APICreateView(); - return mCurrentTextureView.Get(); -} - -void OldSwapChainBase::APIPresent() { - if (GetDevice()->ConsumedError(ValidatePresent())) { - return; - } - ASSERT(!IsError()); - - if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTextureView.Get()))) { - return; - } - - mImplementation.Present(mImplementation.userData); - - mCurrentTexture = nullptr; - mCurrentTextureView = nullptr; -} - -const DawnSwapChainImplementation& OldSwapChainBase::GetImplementation() { - ASSERT(!IsError()); - return mImplementation; -} - -MaybeError OldSwapChainBase::ValidateConfigure(wgpu::TextureFormat format, - wgpu::TextureUsage allowedUsage, - uint32_t width, - uint32_t height) const { - DAWN_TRY(GetDevice()->ValidateIsAlive()); - DAWN_TRY(GetDevice()->ValidateObject(this)); - - DAWN_TRY(ValidateTextureUsage(allowedUsage)); - DAWN_TRY(ValidateTextureFormat(format)); - - DAWN_INVALID_IF(width == 0 || height == 0, - "Configuration size (width: %u, height: %u) for %s is empty.", width, height, - this); - - return {}; -} - -MaybeError OldSwapChainBase::ValidateGetCurrentTextureView() const { - DAWN_TRY(GetDevice()->ValidateIsAlive()); - DAWN_TRY(GetDevice()->ValidateObject(this)); - - // If width is 0, it implies swap chain has never been configured - DAWN_INVALID_IF(mWidth == 0, "%s was not configured prior to calling GetNextTexture.", this); - - return {}; -} - -MaybeError OldSwapChainBase::ValidatePresent() const { - DAWN_TRY(GetDevice()->ValidateIsAlive()); - DAWN_TRY(GetDevice()->ValidateObject(this)); - - DAWN_INVALID_IF( - mCurrentTextureView == nullptr, - "GetCurrentTextureView was not called on %s this frame prior to calling Present.", this); - - return {}; -} - // Implementation of NewSwapChainBase NewSwapChainBase::NewSwapChainBase(DeviceBase* device, diff --git a/src/dawn/native/SwapChain.h b/src/dawn/native/SwapChain.h index 36ed02a0de..55cddffdd9 100644 --- a/src/dawn/native/SwapChain.h +++ b/src/dawn/native/SwapChain.h @@ -52,42 +52,6 @@ class SwapChainBase : public ApiObjectBase { void DestroyImpl() override; }; -// The base class for implementation-based SwapChains that are deprecated. -class OldSwapChainBase : public SwapChainBase { - public: - OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor); - - // Dawn API - void APIConfigure(wgpu::TextureFormat format, - wgpu::TextureUsage allowedUsage, - uint32_t width, - uint32_t height) override; - TextureViewBase* APIGetCurrentTextureView() override; - void APIPresent() override; - - protected: - ~OldSwapChainBase() override; - const DawnSwapChainImplementation& GetImplementation(); - virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0; - virtual MaybeError OnBeforePresent(TextureViewBase* view) = 0; - - private: - MaybeError ValidateConfigure(wgpu::TextureFormat format, - wgpu::TextureUsage allowedUsage, - uint32_t width, - uint32_t height) const; - MaybeError ValidateGetCurrentTextureView() const; - MaybeError ValidatePresent() const; - - DawnSwapChainImplementation mImplementation = {}; - wgpu::TextureFormat mFormat = {}; - wgpu::TextureUsage mAllowedUsage; - uint32_t mWidth = 0; - uint32_t mHeight = 0; - Ref mCurrentTexture; - Ref mCurrentTextureView; -}; - // The base class for surface-based SwapChains that aren't ready yet. class NewSwapChainBase : public SwapChainBase { public: diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp index 8c6051ac3c..fb1b59816a 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -440,10 +440,6 @@ ResultOrError> Device::CreateShaderModuleImpl( OwnedCompilationMessages* compilationMessages) { return ShaderModule::Create(this, descriptor, parseResult, compilationMessages); } -ResultOrError> Device::CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) { - return OldSwapChain::Create(this, descriptor); -} ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h index 94ac06df12..d339bc84a0 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.h +++ b/src/dawn/native/d3d12/DeviceD3D12.h @@ -186,8 +186,6 @@ class Device final : public d3d::Device { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) override; - ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) override; ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/d3d12/SwapChainD3D12.cpp b/src/dawn/native/d3d12/SwapChainD3D12.cpp index ae6531990c..2de9e0fc57 100644 --- a/src/dawn/native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn/native/d3d12/SwapChainD3D12.cpp @@ -74,64 +74,6 @@ DXGI_USAGE ToDXGIUsage(wgpu::TextureUsage usage) { } // namespace -// OldSwapChain - -// static -Ref OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { - return AcquireRef(new OldSwapChain(device, descriptor)); -} - -OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor) - : OldSwapChainBase(device, descriptor) { - const auto& im = GetImplementation(); - DawnWSIContextD3D12 wsiContext = {}; - wsiContext.device = ToAPI(GetDevice()); - im.Init(im.userData, &wsiContext); - - ASSERT(im.textureUsage != WGPUTextureUsage_None); - mTextureUsage = static_cast(im.textureUsage); -} - -OldSwapChain::~OldSwapChain() = default; - -TextureBase* OldSwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { - DeviceBase* device = GetDevice(); - const auto& im = GetImplementation(); - DawnSwapChainNextTexture next = {}; - DawnSwapChainError error = im.GetNextTexture(im.userData, &next); - if (error) { - device->HandleError(DAWN_INTERNAL_ERROR(error)); - return nullptr; - } - - ComPtr d3d12Texture = static_cast(next.texture.ptr); - Ref dawnTexture; - if (device->ConsumedError( - Texture::Create(ToBackend(GetDevice()), descriptor, std::move(d3d12Texture)), - &dawnTexture)) { - return nullptr; - } - - return dawnTexture.Detach(); -} - -MaybeError OldSwapChain::OnBeforePresent(TextureViewBase* view) { - Device* device = ToBackend(GetDevice()); - - CommandRecordingContext* commandContext; - DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext()); - - // Perform the necessary transition for the texture to be presented. - ToBackend(view->GetTexture()) - ->TrackUsageAndTransitionNow(commandContext, mTextureUsage, view->GetSubresourceRange()); - - DAWN_TRY(device->ExecutePendingCommandContext()); - - return {}; -} - -// SwapChain - // static ResultOrError> SwapChain::Create(Device* device, Surface* surface, diff --git a/src/dawn/native/d3d12/SwapChainD3D12.h b/src/dawn/native/d3d12/SwapChainD3D12.h index 53ad519c55..d73de531cd 100644 --- a/src/dawn/native/d3d12/SwapChainD3D12.h +++ b/src/dawn/native/d3d12/SwapChainD3D12.h @@ -27,19 +27,6 @@ namespace dawn::native::d3d12 { class Device; class Texture; -class OldSwapChain final : public OldSwapChainBase { - public: - static Ref Create(Device* device, const SwapChainDescriptor* descriptor); - - protected: - OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~OldSwapChain() override; - TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; - MaybeError OnBeforePresent(TextureViewBase* view) override; - - wgpu::TextureUsage mTextureUsage; -}; - class SwapChain final : public NewSwapChainBase { public: static ResultOrError> Create(Device* device, diff --git a/src/dawn/native/metal/DeviceMTL.h b/src/dawn/native/metal/DeviceMTL.h index c892e61db1..39b75e616a 100644 --- a/src/dawn/native/metal/DeviceMTL.h +++ b/src/dawn/native/metal/DeviceMTL.h @@ -111,8 +111,6 @@ class Device final : public DeviceBase { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) override; - ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) override; ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/metal/DeviceMTL.mm b/src/dawn/native/metal/DeviceMTL.mm index 840e3c8543..3889525302 100644 --- a/src/dawn/native/metal/DeviceMTL.mm +++ b/src/dawn/native/metal/DeviceMTL.mm @@ -215,10 +215,6 @@ ResultOrError> Device::CreateShaderModuleImpl( OwnedCompilationMessages* compilationMessages) { return ShaderModule::Create(this, descriptor, parseResult, compilationMessages); } -ResultOrError> Device::CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) { - return OldSwapChain::Create(this, descriptor); -} ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/metal/SwapChainMTL.h b/src/dawn/native/metal/SwapChainMTL.h index de5cd5c5d4..328d8fa9e2 100644 --- a/src/dawn/native/metal/SwapChainMTL.h +++ b/src/dawn/native/metal/SwapChainMTL.h @@ -27,17 +27,6 @@ namespace dawn::native::metal { class Device; class Texture; -class OldSwapChain final : public OldSwapChainBase { - public: - static Ref Create(Device* deivce, const SwapChainDescriptor* descriptor); - - protected: - OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~OldSwapChain() override; - TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; - MaybeError OnBeforePresent(TextureViewBase* view) override; -}; - class SwapChain final : public NewSwapChainBase { public: static ResultOrError> Create(Device* device, diff --git a/src/dawn/native/metal/SwapChainMTL.mm b/src/dawn/native/metal/SwapChainMTL.mm index 7097b3af49..27c44fc706 100644 --- a/src/dawn/native/metal/SwapChainMTL.mm +++ b/src/dawn/native/metal/SwapChainMTL.mm @@ -24,44 +24,6 @@ namespace dawn::native::metal { -// OldSwapChain - -// static -Ref OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { - return AcquireRef(new OldSwapChain(device, descriptor)); -} - -OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor) - : OldSwapChainBase(device, descriptor) { - const auto& im = GetImplementation(); - DawnWSIContextMetal wsiContext = {}; - wsiContext.device = ToBackend(GetDevice())->GetMTLDevice(); - wsiContext.queue = ToBackend(GetDevice())->GetMTLQueue(); - im.Init(im.userData, &wsiContext); -} - -OldSwapChain::~OldSwapChain() {} - -TextureBase* OldSwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { - const auto& im = GetImplementation(); - DawnSwapChainNextTexture next = {}; - DawnSwapChainError error = im.GetNextTexture(im.userData, &next); - if (error) { - GetDevice()->HandleError(DAWN_INTERNAL_ERROR(error)); - return nullptr; - } - - id nativeTexture = reinterpret_cast>(next.texture.ptr); - - return Texture::CreateWrapping(ToBackend(GetDevice()), descriptor, nativeTexture).Detach(); -} - -MaybeError OldSwapChain::OnBeforePresent(TextureViewBase*) { - return {}; -} - -// SwapChain - // static ResultOrError> SwapChain::Create(Device* device, Surface* surface, diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp index 30cf6cb1b3..194867db39 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp @@ -173,10 +173,6 @@ ResultOrError> Device::CreateShaderModuleImpl( DAWN_TRY(module->Initialize(parseResult, compilationMessages)); return module; } -ResultOrError> Device::CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) { - return AcquireRef(new OldSwapChain(this, descriptor)); -} ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, @@ -476,24 +472,6 @@ MaybeError ShaderModule::Initialize(ShaderModuleParseResult* parseResult, return InitializeBase(parseResult, compilationMessages); } -// 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()->APICreateTexture(descriptor); -} - -MaybeError OldSwapChain::OnBeforePresent(TextureViewBase*) { - return {}; -} - uint32_t Device::GetOptimalBytesPerRowAlignment() const { return 1; } diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h index 1f0c7d9f22..70e29a7f69 100644 --- a/src/dawn/native/null/DeviceNull.h +++ b/src/dawn/native/null/DeviceNull.h @@ -146,8 +146,6 @@ class Device final : public DeviceBase { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) override; - ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) override; ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, @@ -312,16 +310,6 @@ class SwapChain final : public NewSwapChainBase { void DetachFromSurfaceImpl() override; }; -class OldSwapChain final : public OldSwapChainBase { - public: - OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - - protected: - ~OldSwapChain() override; - TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; - MaybeError OnBeforePresent(TextureViewBase*) override; -}; - class Texture : public TextureBase { public: Texture(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state); diff --git a/src/dawn/native/opengl/DeviceGL.cpp b/src/dawn/native/opengl/DeviceGL.cpp index 2e4f8a9116..3298ac92af 100644 --- a/src/dawn/native/opengl/DeviceGL.cpp +++ b/src/dawn/native/opengl/DeviceGL.cpp @@ -31,7 +31,6 @@ #include "dawn/native/opengl/RenderPipelineGL.h" #include "dawn/native/opengl/SamplerGL.h" #include "dawn/native/opengl/ShaderModuleGL.h" -#include "dawn/native/opengl/SwapChainGL.h" #include "dawn/native/opengl/TextureGL.h" namespace { @@ -239,10 +238,6 @@ ResultOrError> Device::CreateShaderModuleImpl( OwnedCompilationMessages* compilationMessages) { return ShaderModule::Create(this, descriptor, parseResult, compilationMessages); } -ResultOrError> Device::CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) { - return AcquireRef(new SwapChain(this, descriptor)); -} ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/opengl/DeviceGL.h b/src/dawn/native/opengl/DeviceGL.h index 0a3de79571..cc066802e7 100644 --- a/src/dawn/native/opengl/DeviceGL.h +++ b/src/dawn/native/opengl/DeviceGL.h @@ -112,8 +112,6 @@ class Device final : public DeviceBase { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) override; - ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) override; ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/opengl/SwapChainGL.cpp b/src/dawn/native/opengl/SwapChainGL.cpp deleted file mode 100644 index 2c4e3bd3fe..0000000000 --- a/src/dawn/native/opengl/SwapChainGL.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2017 The Dawn Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "dawn/native/opengl/SwapChainGL.h" - -#include "dawn/native/opengl/DeviceGL.h" -#include "dawn/native/opengl/Forward.h" -#include "dawn/native/opengl/TextureGL.h" - -#include "dawn/dawn_wsi.h" - -namespace dawn::native::opengl { - -SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor) - : OldSwapChainBase(device, descriptor) { - const auto& im = GetImplementation(); - im.Init(im.userData, nullptr); -} - -SwapChain::~SwapChain() {} - -TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { - const auto& im = GetImplementation(); - DawnSwapChainNextTexture next = {}; - DawnSwapChainError error = im.GetNextTexture(im.userData, &next); - if (error) { - GetDevice()->HandleError(DAWN_INTERNAL_ERROR(error)); - return nullptr; - } - GLuint nativeTexture = next.texture.u32; - return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture, - TextureBase::TextureState::OwnedExternal); -} - -MaybeError SwapChain::OnBeforePresent(TextureViewBase*) { - return {}; -} - -} // namespace dawn::native::opengl diff --git a/src/dawn/native/opengl/SwapChainGL.h b/src/dawn/native/opengl/SwapChainGL.h deleted file mode 100644 index 0c1456489b..0000000000 --- a/src/dawn/native/opengl/SwapChainGL.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 The Dawn Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_DAWN_NATIVE_OPENGL_SWAPCHAINGL_H_ -#define SRC_DAWN_NATIVE_OPENGL_SWAPCHAINGL_H_ - -#include "dawn/native/SwapChain.h" - -#include "dawn/native/opengl/opengl_platform.h" - -namespace dawn::native::opengl { - -class Device; - -class SwapChain final : public OldSwapChainBase { - public: - SwapChain(Device* device, const SwapChainDescriptor* descriptor); - - protected: - ~SwapChain() override; - TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; - MaybeError OnBeforePresent(TextureViewBase* view) override; -}; - -} // namespace dawn::native::opengl - -#endif // SRC_DAWN_NATIVE_OPENGL_SWAPCHAINGL_H_ diff --git a/src/dawn/native/vulkan/DeviceVk.cpp b/src/dawn/native/vulkan/DeviceVk.cpp index 822e155626..b57fa1e844 100644 --- a/src/dawn/native/vulkan/DeviceVk.cpp +++ b/src/dawn/native/vulkan/DeviceVk.cpp @@ -189,10 +189,6 @@ ResultOrError> Device::CreateShaderModuleImpl( OwnedCompilationMessages* compilationMessages) { return ShaderModule::Create(this, descriptor, parseResult, compilationMessages); } -ResultOrError> Device::CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) { - return OldSwapChain::Create(this, descriptor); -} ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/vulkan/DeviceVk.h b/src/dawn/native/vulkan/DeviceVk.h index e118acfea2..cab5a182b9 100644 --- a/src/dawn/native/vulkan/DeviceVk.h +++ b/src/dawn/native/vulkan/DeviceVk.h @@ -135,8 +135,6 @@ class Device final : public DeviceBase { const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult, OwnedCompilationMessages* compilationMessages) override; - ResultOrError> CreateSwapChainImpl( - const SwapChainDescriptor* descriptor) override; ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, diff --git a/src/dawn/native/vulkan/SwapChainVk.cpp b/src/dawn/native/vulkan/SwapChainVk.cpp index d5139dfeca..e45242b4c3 100644 --- a/src/dawn/native/vulkan/SwapChainVk.cpp +++ b/src/dawn/native/vulkan/SwapChainVk.cpp @@ -34,56 +34,6 @@ namespace dawn::native::vulkan { -// OldSwapChain - -// static -Ref OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { - return AcquireRef(new OldSwapChain(device, descriptor)); -} - -OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor) - : OldSwapChainBase(device, descriptor) { - const auto& im = GetImplementation(); - DawnWSIContextVulkan wsiContext = {}; - im.Init(im.userData, &wsiContext); - - ASSERT(im.textureUsage != WGPUTextureUsage_None); - mTextureUsage = static_cast(im.textureUsage); -} - -OldSwapChain::~OldSwapChain() {} - -TextureBase* OldSwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) { - const auto& im = GetImplementation(); - DawnSwapChainNextTexture next = {}; - DawnSwapChainError error = im.GetNextTexture(im.userData, &next); - - if (error) { - GetDevice()->HandleError(DAWN_INTERNAL_ERROR(error)); - return nullptr; - } - - ::VkImage image = NativeNonDispatachableHandleFromU64<::VkImage>(next.texture.u64); - VkImage nativeTexture = VkImage::CreateFromHandle(image); - return Texture::CreateForSwapChain(ToBackend(GetDevice()), descriptor, nativeTexture).Detach(); -} - -MaybeError OldSwapChain::OnBeforePresent(TextureViewBase* view) { - Device* device = ToBackend(GetDevice()); - - // Perform the necessary pipeline barriers for the texture to be used with the usage - // requested by the implementation. - CommandRecordingContext* recordingContext = device->GetPendingRecordingContext(); - ToBackend(view->GetTexture()) - ->TransitionUsageNow(recordingContext, mTextureUsage, view->GetSubresourceRange()); - - DAWN_TRY(device->SubmitPendingCommands()); - - return {}; -} - -// SwapChain - namespace { ResultOrError CreateVulkanSurface(Adapter* adapter, Surface* surface) { diff --git a/src/dawn/native/vulkan/SwapChainVk.h b/src/dawn/native/vulkan/SwapChainVk.h index 7163de71ef..beb6c321b9 100644 --- a/src/dawn/native/vulkan/SwapChainVk.h +++ b/src/dawn/native/vulkan/SwapChainVk.h @@ -27,21 +27,6 @@ class Device; class Texture; struct VulkanSurfaceInfo; -class OldSwapChain : public OldSwapChainBase { - public: - static Ref Create(Device* device, const SwapChainDescriptor* descriptor); - - protected: - OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~OldSwapChain() override; - - TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; - MaybeError OnBeforePresent(TextureViewBase* texture) override; - - private: - wgpu::TextureUsage mTextureUsage; -}; - class SwapChain : public NewSwapChainBase { public: static ResultOrError> Create(Device* device, diff --git a/src/dawn/tests/unittests/native/mocks/DeviceMock.h b/src/dawn/tests/unittests/native/mocks/DeviceMock.h index 681a93635b..6739810900 100644 --- a/src/dawn/tests/unittests/native/mocks/DeviceMock.h +++ b/src/dawn/tests/unittests/native/mocks/DeviceMock.h @@ -108,10 +108,6 @@ class DeviceMock : public DeviceBase { ShaderModuleParseResult*, OwnedCompilationMessages*), (override)); - MOCK_METHOD(ResultOrError>, - CreateSwapChainImpl, - (const SwapChainDescriptor*), - (override)); MOCK_METHOD(ResultOrError>, CreateSwapChainImpl, (Surface*, NewSwapChainBase*, const SwapChainDescriptor*),