Make GetCurrentTextureView use an internal GetCurrentTexture
This is a small refactor in preparation for exposing GetCurrentTexture on the SwapChain. Bug: dawn:1551 Change-Id: I7cc8ec4a9042f48c4af7b2cc2126b1d9248a2003 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133462 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Loko Kung <lokokung@google.com>
This commit is contained in:
parent
26e41edeea
commit
858ccc8a0c
|
@ -31,7 +31,7 @@ class ErrorSwapChain final : public SwapChainBase {
|
|||
explicit ErrorSwapChain(DeviceBase* device) : SwapChainBase(device, ObjectBase::kError) {}
|
||||
|
||||
private:
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override { UNREACHABLE(); }
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override { UNREACHABLE(); }
|
||||
MaybeError PresentImpl() override { UNREACHABLE(); }
|
||||
void DetachFromSurfaceImpl() override { UNREACHABLE(); }
|
||||
};
|
||||
|
@ -113,9 +113,8 @@ SwapChainBase::SwapChainBase(DeviceBase* device,
|
|||
}
|
||||
|
||||
SwapChainBase::~SwapChainBase() {
|
||||
if (mCurrentTextureView != nullptr) {
|
||||
ASSERT(mCurrentTextureView->GetTexture()->GetTextureState() ==
|
||||
TextureBase::TextureState::Destroyed);
|
||||
if (mCurrentTexture != nullptr) {
|
||||
ASSERT(mCurrentTexture->GetTextureState() == TextureBase::TextureState::Destroyed);
|
||||
}
|
||||
|
||||
ASSERT(!mAttached);
|
||||
|
@ -164,30 +163,32 @@ TextureViewBase* SwapChainBase::APIGetCurrentTextureView() {
|
|||
return result.Detach();
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChainBase::GetCurrentTextureView() {
|
||||
DAWN_TRY(ValidateGetCurrentTextureView());
|
||||
ResultOrError<Ref<TextureBase>> SwapChainBase::GetCurrentTexture() {
|
||||
DAWN_TRY(ValidateGetCurrentTexture());
|
||||
|
||||
if (mCurrentTextureView != nullptr) {
|
||||
// Calling GetCurrentTextureView always returns a new reference.
|
||||
return mCurrentTextureView;
|
||||
if (mCurrentTexture != nullptr) {
|
||||
// Calling GetCurrentTexture always returns a new reference.
|
||||
return mCurrentTexture;
|
||||
}
|
||||
|
||||
DAWN_TRY_ASSIGN(mCurrentTextureView, GetCurrentTextureViewImpl());
|
||||
DAWN_TRY_ASSIGN(mCurrentTexture, GetCurrentTextureImpl());
|
||||
|
||||
// Check that the return texture view matches exactly what was given for this descriptor.
|
||||
ASSERT(mCurrentTextureView->GetTexture()->GetFormat().format == mFormat);
|
||||
ASSERT(IsSubset(mUsage, mCurrentTextureView->GetTexture()->GetUsage()));
|
||||
ASSERT(mCurrentTextureView->GetLevelCount() == 1);
|
||||
ASSERT(mCurrentTextureView->GetLayerCount() == 1);
|
||||
ASSERT(mCurrentTextureView->GetDimension() == wgpu::TextureViewDimension::e2D);
|
||||
ASSERT(mCurrentTextureView->GetTexture()
|
||||
->GetMipLevelSingleSubresourceVirtualSize(mCurrentTextureView->GetBaseMipLevel())
|
||||
.width == mWidth);
|
||||
ASSERT(mCurrentTextureView->GetTexture()
|
||||
->GetMipLevelSingleSubresourceVirtualSize(mCurrentTextureView->GetBaseMipLevel())
|
||||
.height == mHeight);
|
||||
// Check that the return texture matches exactly what was given for this descriptor.
|
||||
ASSERT(mCurrentTexture->GetFormat().format == mFormat);
|
||||
ASSERT(IsSubset(mUsage, mCurrentTexture->GetUsage()));
|
||||
ASSERT(mCurrentTexture->GetDimension() == wgpu::TextureDimension::e2D);
|
||||
ASSERT(mCurrentTexture->GetWidth() == mWidth);
|
||||
ASSERT(mCurrentTexture->GetHeight() == mHeight);
|
||||
ASSERT(mCurrentTexture->GetNumMipLevels() == 1);
|
||||
ASSERT(mCurrentTexture->GetArrayLayers() == 1);
|
||||
|
||||
return mCurrentTextureView;
|
||||
return mCurrentTexture;
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChainBase::GetCurrentTextureView() {
|
||||
Ref<TextureBase> currentTexture;
|
||||
DAWN_TRY_ASSIGN(currentTexture, GetCurrentTexture());
|
||||
return currentTexture->CreateView();
|
||||
}
|
||||
|
||||
void SwapChainBase::APIPresent() {
|
||||
|
@ -199,9 +200,8 @@ void SwapChainBase::APIPresent() {
|
|||
return;
|
||||
}
|
||||
|
||||
ASSERT(mCurrentTextureView->GetTexture()->GetTextureState() ==
|
||||
TextureBase::TextureState::Destroyed);
|
||||
mCurrentTextureView = nullptr;
|
||||
ASSERT(mCurrentTexture->GetTextureState() == TextureBase::TextureState::Destroyed);
|
||||
mCurrentTexture = nullptr;
|
||||
}
|
||||
|
||||
uint32_t SwapChainBase::GetWidth() const {
|
||||
|
@ -242,18 +242,18 @@ MaybeError SwapChainBase::ValidatePresent() const {
|
|||
|
||||
DAWN_INVALID_IF(!mAttached, "Cannot call Present called on detached %s.", this);
|
||||
|
||||
DAWN_INVALID_IF(
|
||||
mCurrentTextureView == nullptr,
|
||||
"GetCurrentTextureView was not called on %s this frame prior to calling Present.", this);
|
||||
DAWN_INVALID_IF(mCurrentTexture == nullptr,
|
||||
"GetCurrentTexture was not called on %s this frame prior to calling Present.",
|
||||
this);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
MaybeError SwapChainBase::ValidateGetCurrentTextureView() const {
|
||||
MaybeError SwapChainBase::ValidateGetCurrentTexture() const {
|
||||
DAWN_TRY(GetDevice()->ValidateIsAlive());
|
||||
DAWN_TRY(GetDevice()->ValidateObject(this));
|
||||
|
||||
DAWN_INVALID_IF(!mAttached, "Cannot call GetCurrentTextureView on detached %s.", this);
|
||||
DAWN_INVALID_IF(!mAttached, "Cannot call GetCurrentTexture on detached %s.", this);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -87,19 +87,21 @@ class SwapChainBase : public ApiObjectBase {
|
|||
// This is a weak reference to the surface. If the surface is destroyed it will call
|
||||
// DetachFromSurface and mSurface will be updated to nullptr.
|
||||
Surface* mSurface = nullptr;
|
||||
Ref<TextureViewBase> mCurrentTextureView;
|
||||
Ref<TextureBase> mCurrentTexture;
|
||||
|
||||
MaybeError ValidatePresent() const;
|
||||
MaybeError ValidateGetCurrentTextureView() const;
|
||||
MaybeError ValidateGetCurrentTexture() const;
|
||||
|
||||
// GetCurrentTextureViewImpl and PresentImpl are guaranteed to be called in an interleaved
|
||||
// manner, starting with GetCurrentTextureViewImpl.
|
||||
// GetCurrentTextureImpl and PresentImpl are guaranteed to be called in an interleaved manner,
|
||||
// starting with GetCurrentTextureImpl.
|
||||
|
||||
// The returned texture must match the swapchain descriptor exactly.
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTexture();
|
||||
virtual ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() = 0;
|
||||
|
||||
// The returned texture view must match the swapchain descriptor exactly.
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureView();
|
||||
virtual ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() = 0;
|
||||
// The call to present must destroy the current view's texture so further access to it are
|
||||
// invalid.
|
||||
|
||||
// The call to present must destroy the current texture so further access to it are invalid.
|
||||
virtual MaybeError PresentImpl() = 0;
|
||||
|
||||
// Guaranteed to be called exactly once during the lifetime of the SwapChain. After it is
|
||||
|
|
|
@ -68,11 +68,11 @@ MaybeError SwapChain::PresentImpl() {
|
|||
return {};
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureImpl() {
|
||||
// Create the API side objects for this use of the swapchain's buffer.
|
||||
TextureDescriptor descriptor = GetSwapChainBaseTextureDescriptor(this);
|
||||
DAWN_TRY_ASSIGN(mApiTexture, Texture::Create(ToBackend(GetDevice()), &descriptor, mBuffer));
|
||||
return mApiTexture->CreateView();
|
||||
return mApiTexture;
|
||||
}
|
||||
|
||||
MaybeError SwapChain::DetachAndWaitForDeallocation() {
|
||||
|
|
|
@ -40,7 +40,7 @@ class SwapChain final : public d3d::SwapChain {
|
|||
|
||||
// SwapChainBase implementation
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
|
||||
// d3d::SwapChain implementation
|
||||
|
|
|
@ -89,7 +89,7 @@ MaybeError SwapChain::PresentImpl() {
|
|||
return {};
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureImpl() {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
// Synchronously wait until previous operations on the next swapchain buffer are finished.
|
||||
|
@ -103,7 +103,7 @@ ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
|||
TextureDescriptor descriptor = GetSwapChainBaseTextureDescriptor(this);
|
||||
DAWN_TRY_ASSIGN(mApiTexture,
|
||||
Texture::Create(ToBackend(GetDevice()), &descriptor, mBuffers[mCurrentBuffer]));
|
||||
return mApiTexture->CreateView();
|
||||
return mApiTexture;
|
||||
}
|
||||
|
||||
MaybeError SwapChain::DetachAndWaitForDeallocation() {
|
||||
|
|
|
@ -41,7 +41,7 @@ class SwapChain final : public d3d::SwapChain {
|
|||
|
||||
// SwapChainBase implementation
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
|
||||
// d3d::SwapChain implementation
|
||||
|
|
|
@ -49,7 +49,7 @@ class SwapChain final : public SwapChainBase {
|
|||
Ref<Texture> mTexture;
|
||||
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ MaybeError SwapChain::PresentImpl() {
|
|||
return {};
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureImpl() {
|
||||
ASSERT(mCurrentDrawable == nullptr);
|
||||
mCurrentDrawable = [*mLayer nextDrawable];
|
||||
|
||||
|
@ -99,7 +99,7 @@ ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
|||
|
||||
mTexture =
|
||||
Texture::CreateWrapping(ToBackend(GetDevice()), &textureDesc, [*mCurrentDrawable texture]);
|
||||
return mTexture->CreateView();
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
void SwapChain::DetachFromSurfaceImpl() {
|
||||
|
|
|
@ -458,11 +458,11 @@ MaybeError SwapChain::PresentImpl() {
|
|||
return {};
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureImpl() {
|
||||
TextureDescriptor textureDesc = GetSwapChainBaseTextureDescriptor(this);
|
||||
mTexture = AcquireRef(
|
||||
new Texture(GetDevice(), &textureDesc, TextureBase::TextureState::OwnedInternal));
|
||||
return mTexture->CreateView();
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
void SwapChain::DetachFromSurfaceImpl() {
|
||||
|
|
|
@ -311,7 +311,7 @@ class SwapChain final : public SwapChainBase {
|
|||
Ref<Texture> mTexture;
|
||||
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -613,11 +613,11 @@ MaybeError SwapChain::PresentImpl() {
|
|||
}
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||
return GetCurrentTextureViewInternal();
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureImpl() {
|
||||
return GetCurrentTextureInternal();
|
||||
}
|
||||
|
||||
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewInternal(bool isReentrant) {
|
||||
ResultOrError<Ref<TextureBase>> SwapChain::GetCurrentTextureInternal(bool isReentrant) {
|
||||
Device* device = ToBackend(GetDevice());
|
||||
|
||||
// Transiently create a semaphore that will be signaled when the presentation engine is done
|
||||
|
@ -664,7 +664,7 @@ ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewInternal(boo
|
|||
|
||||
// Re-initialize the VkSwapchain and try getting the texture again.
|
||||
DAWN_TRY(Initialize(this));
|
||||
return GetCurrentTextureViewInternal(true);
|
||||
return GetCurrentTextureInternal(true);
|
||||
}
|
||||
|
||||
// TODO(crbug.com/dawn/269): Allow losing the surface at Dawn's API level?
|
||||
|
@ -684,14 +684,14 @@ ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewInternal(boo
|
|||
|
||||
// In the happy path we can use the swapchain image directly.
|
||||
if (!mConfig.needsBlit) {
|
||||
return mTexture->CreateView();
|
||||
return mTexture;
|
||||
}
|
||||
|
||||
// The blit texture always perfectly matches what the user requested for the swapchain.
|
||||
// We need to add the Vulkan TRANSFER_SRC flag for the vkCmdBlitImage call.
|
||||
TextureDescriptor desc = GetSwapChainBaseTextureDescriptor(this);
|
||||
DAWN_TRY_ASSIGN(mBlitTexture, Texture::Create(device, &desc, VK_IMAGE_USAGE_TRANSFER_SRC_BIT));
|
||||
return mBlitTexture->CreateView();
|
||||
return mBlitTexture;
|
||||
}
|
||||
|
||||
void SwapChain::DetachFromSurfaceImpl() {
|
||||
|
|
|
@ -64,11 +64,11 @@ class SwapChain : public SwapChainBase {
|
|||
bool needsBlit = false;
|
||||
};
|
||||
ResultOrError<Config> ChooseConfig(const VulkanSurfaceInfo& surfaceInfo) const;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewInternal(bool isReentrant = false);
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureInternal(bool isReentrant = false);
|
||||
|
||||
// SwapChainBase implementation
|
||||
MaybeError PresentImpl() override;
|
||||
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||
ResultOrError<Ref<TextureBase>> GetCurrentTextureImpl() override;
|
||||
void DetachFromSurfaceImpl() override;
|
||||
|
||||
Config mConfig;
|
||||
|
|
|
@ -29,7 +29,7 @@ class SwapChainMock : public SwapChainBase {
|
|||
|
||||
MOCK_METHOD(void, DestroyImpl, (), (override));
|
||||
|
||||
MOCK_METHOD(ResultOrError<Ref<TextureViewBase>>, GetCurrentTextureViewImpl, (), (override));
|
||||
MOCK_METHOD(ResultOrError<Ref<TextureBase>>, GetCurrentTextureImpl, (), (override));
|
||||
MOCK_METHOD(MaybeError, PresentImpl, (), (override));
|
||||
MOCK_METHOD(void, DetachFromSurfaceImpl, (), (override));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue