Make SwapChain use a CreateView() instead of APICreateView()
This simplifies reference management and make the swapchain's reentrant code avoid APIEntryPoints. Bug: dawn:723 Change-Id: I6c456b9ec349c73d783dbb12a284f322d0be4e1a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/84763 Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
3d45533446
commit
e690a6654a
|
@ -316,34 +316,38 @@ namespace dawn::native {
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureViewBase* NewSwapChainBase::APIGetCurrentTextureView() {
|
TextureViewBase* NewSwapChainBase::APIGetCurrentTextureView() {
|
||||||
if (GetDevice()->ConsumedError(ValidateGetCurrentTextureView())) {
|
Ref<TextureViewBase> result;
|
||||||
|
if (GetDevice()->ConsumedError(GetCurrentTextureView(), &result,
|
||||||
|
"calling %s.GetCurrentTextureView()", this)) {
|
||||||
return TextureViewBase::MakeError(GetDevice());
|
return TextureViewBase::MakeError(GetDevice());
|
||||||
}
|
}
|
||||||
|
return result.Detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultOrError<Ref<TextureViewBase>> NewSwapChainBase::GetCurrentTextureView() {
|
||||||
|
DAWN_TRY(ValidateGetCurrentTextureView());
|
||||||
|
|
||||||
if (mCurrentTextureView != nullptr) {
|
if (mCurrentTextureView != nullptr) {
|
||||||
// Calling GetCurrentTextureView always returns a new reference so add it even when
|
// Calling GetCurrentTextureView always returns a new reference.
|
||||||
// reusing the existing texture view.
|
return mCurrentTextureView;
|
||||||
mCurrentTextureView->Reference();
|
|
||||||
return mCurrentTextureView.Get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureViewBase* view = nullptr;
|
DAWN_TRY_ASSIGN(mCurrentTextureView, GetCurrentTextureViewImpl());
|
||||||
if (GetDevice()->ConsumedError(GetCurrentTextureViewImpl(), &view)) {
|
|
||||||
return TextureViewBase::MakeError(GetDevice());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that the return texture view matches exactly what was given for this descriptor.
|
// Check that the return texture view matches exactly what was given for this descriptor.
|
||||||
ASSERT(view->GetTexture()->GetFormat().format == mFormat);
|
ASSERT(mCurrentTextureView->GetTexture()->GetFormat().format == mFormat);
|
||||||
ASSERT(IsSubset(mUsage, view->GetTexture()->GetUsage()));
|
ASSERT(IsSubset(mUsage, mCurrentTextureView->GetTexture()->GetUsage()));
|
||||||
ASSERT(view->GetLevelCount() == 1);
|
ASSERT(mCurrentTextureView->GetLevelCount() == 1);
|
||||||
ASSERT(view->GetLayerCount() == 1);
|
ASSERT(mCurrentTextureView->GetLayerCount() == 1);
|
||||||
ASSERT(view->GetDimension() == wgpu::TextureViewDimension::e2D);
|
ASSERT(mCurrentTextureView->GetDimension() == wgpu::TextureViewDimension::e2D);
|
||||||
ASSERT(view->GetTexture()->GetMipLevelVirtualSize(view->GetBaseMipLevel()).width == mWidth);
|
ASSERT(mCurrentTextureView->GetTexture()
|
||||||
ASSERT(view->GetTexture()->GetMipLevelVirtualSize(view->GetBaseMipLevel()).height ==
|
->GetMipLevelVirtualSize(mCurrentTextureView->GetBaseMipLevel())
|
||||||
mHeight);
|
.width == mWidth);
|
||||||
|
ASSERT(mCurrentTextureView->GetTexture()
|
||||||
|
->GetMipLevelVirtualSize(mCurrentTextureView->GetBaseMipLevel())
|
||||||
|
.height == mHeight);
|
||||||
|
|
||||||
mCurrentTextureView = view;
|
return mCurrentTextureView;
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewSwapChainBase::APIPresent() {
|
void NewSwapChainBase::APIPresent() {
|
||||||
|
|
|
@ -154,7 +154,8 @@ namespace dawn::native {
|
||||||
// manner, starting with GetCurrentTextureViewImpl.
|
// manner, starting with GetCurrentTextureViewImpl.
|
||||||
|
|
||||||
// The returned texture view must match the swapchain descriptor exactly.
|
// The returned texture view must match the swapchain descriptor exactly.
|
||||||
virtual ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() = 0;
|
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
|
// The call to present must destroy the current view's texture so further access to it are
|
||||||
// invalid.
|
// invalid.
|
||||||
virtual MaybeError PresentImpl() = 0;
|
virtual MaybeError PresentImpl() = 0;
|
||||||
|
|
|
@ -668,12 +668,17 @@ namespace dawn::native {
|
||||||
return {clampedCopyExtentWidth, clampedCopyExtentHeight, extent.depthOrArrayLayers};
|
return {clampedCopyExtentWidth, clampedCopyExtentHeight, extent.depthOrArrayLayers};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultOrError<Ref<TextureViewBase>> TextureBase::CreateView(
|
||||||
|
const TextureViewDescriptor* descriptor) {
|
||||||
|
return GetDevice()->CreateTextureView(this, descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
TextureViewBase* TextureBase::APICreateView(const TextureViewDescriptor* descriptor) {
|
TextureViewBase* TextureBase::APICreateView(const TextureViewDescriptor* descriptor) {
|
||||||
DeviceBase* device = GetDevice();
|
DeviceBase* device = GetDevice();
|
||||||
|
|
||||||
Ref<TextureViewBase> result;
|
Ref<TextureViewBase> result;
|
||||||
if (device->ConsumedError(device->CreateTextureView(this, descriptor), &result,
|
if (device->ConsumedError(CreateView(descriptor), &result, "calling %s.CreateView(%s).",
|
||||||
"calling %s.CreateView(%s).", this, descriptor)) {
|
this, descriptor)) {
|
||||||
return TextureViewBase::MakeError(device);
|
return TextureViewBase::MakeError(device);
|
||||||
}
|
}
|
||||||
return result.Detach();
|
return result.Detach();
|
||||||
|
|
|
@ -91,6 +91,9 @@ namespace dawn::native {
|
||||||
const Origin3D& origin,
|
const Origin3D& origin,
|
||||||
const Extent3D& extent) const;
|
const Extent3D& extent) const;
|
||||||
|
|
||||||
|
ResultOrError<Ref<TextureViewBase>> CreateView(
|
||||||
|
const TextureViewDescriptor* descriptor = nullptr);
|
||||||
|
|
||||||
// Dawn API
|
// Dawn API
|
||||||
TextureViewBase* APICreateView(const TextureViewDescriptor* descriptor = nullptr);
|
TextureViewBase* APICreateView(const TextureViewDescriptor* descriptor = nullptr);
|
||||||
void APIDestroy();
|
void APIDestroy();
|
||||||
|
|
|
@ -332,7 +332,7 @@ namespace dawn::native::d3d12 {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<TextureViewBase*> SwapChain::GetCurrentTextureViewImpl() {
|
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
// Synchronously wait until previous operations on the next swapchain buffer are finished.
|
// Synchronously wait until previous operations on the next swapchain buffer are finished.
|
||||||
|
@ -346,9 +346,7 @@ namespace dawn::native::d3d12 {
|
||||||
TextureDescriptor descriptor = GetSwapChainBaseTextureDescriptor(this);
|
TextureDescriptor descriptor = GetSwapChainBaseTextureDescriptor(this);
|
||||||
DAWN_TRY_ASSIGN(mApiTexture, Texture::Create(ToBackend(GetDevice()), &descriptor,
|
DAWN_TRY_ASSIGN(mApiTexture, Texture::Create(ToBackend(GetDevice()), &descriptor,
|
||||||
mBuffers[mCurrentBuffer]));
|
mBuffers[mCurrentBuffer]));
|
||||||
|
return mApiTexture->CreateView();
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
|
||||||
return mApiTexture->APICreateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError SwapChain::DetachAndWaitForDeallocation() {
|
MaybeError SwapChain::DetachAndWaitForDeallocation() {
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace dawn::native::d3d12 {
|
||||||
|
|
||||||
// NewSwapChainBase implementation
|
// NewSwapChainBase implementation
|
||||||
MaybeError PresentImpl() override;
|
MaybeError PresentImpl() override;
|
||||||
ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
|
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||||
void DetachFromSurfaceImpl() override;
|
void DetachFromSurfaceImpl() override;
|
||||||
|
|
||||||
// Does the swapchain initialization steps assuming there is nothing we can reuse.
|
// Does the swapchain initialization steps assuming there is nothing we can reuse.
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace dawn::native::metal {
|
||||||
Ref<Texture> mTexture;
|
Ref<Texture> mTexture;
|
||||||
|
|
||||||
MaybeError PresentImpl() override;
|
MaybeError PresentImpl() override;
|
||||||
ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
|
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||||
void DetachFromSurfaceImpl() override;
|
void DetachFromSurfaceImpl() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace dawn::native::metal {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<TextureViewBase*> SwapChain::GetCurrentTextureViewImpl() {
|
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||||
ASSERT(mCurrentDrawable == nullptr);
|
ASSERT(mCurrentDrawable == nullptr);
|
||||||
mCurrentDrawable = [*mLayer nextDrawable];
|
mCurrentDrawable = [*mLayer nextDrawable];
|
||||||
|
|
||||||
|
@ -137,8 +137,7 @@ namespace dawn::native::metal {
|
||||||
|
|
||||||
mTexture = Texture::CreateWrapping(ToBackend(GetDevice()), &textureDesc,
|
mTexture = Texture::CreateWrapping(ToBackend(GetDevice()), &textureDesc,
|
||||||
[*mCurrentDrawable texture]);
|
[*mCurrentDrawable texture]);
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
return mTexture->CreateView();
|
||||||
return mTexture->APICreateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::DetachFromSurfaceImpl() {
|
void SwapChain::DetachFromSurfaceImpl() {
|
||||||
|
|
|
@ -421,13 +421,12 @@ namespace dawn::native::null {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<TextureViewBase*> SwapChain::GetCurrentTextureViewImpl() {
|
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||||
TextureDescriptor textureDesc = GetSwapChainBaseTextureDescriptor(this);
|
TextureDescriptor textureDesc = GetSwapChainBaseTextureDescriptor(this);
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
||||||
mTexture = AcquireRef(
|
mTexture = AcquireRef(
|
||||||
new Texture(GetDevice(), &textureDesc, TextureBase::TextureState::OwnedInternal));
|
new Texture(GetDevice(), &textureDesc, TextureBase::TextureState::OwnedInternal));
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
return mTexture->CreateView();
|
||||||
return mTexture->APICreateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::DetachFromSurfaceImpl() {
|
void SwapChain::DetachFromSurfaceImpl() {
|
||||||
|
|
|
@ -297,7 +297,7 @@ namespace dawn::native::null {
|
||||||
Ref<Texture> mTexture;
|
Ref<Texture> mTexture;
|
||||||
|
|
||||||
MaybeError PresentImpl() override;
|
MaybeError PresentImpl() override;
|
||||||
ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
|
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||||
void DetachFromSurfaceImpl() override;
|
void DetachFromSurfaceImpl() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -593,11 +593,11 @@ namespace dawn::native::vulkan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<TextureViewBase*> SwapChain::GetCurrentTextureViewImpl() {
|
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewImpl() {
|
||||||
return GetCurrentTextureViewInternal();
|
return GetCurrentTextureViewInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<TextureViewBase*> SwapChain::GetCurrentTextureViewInternal(bool isReentrant) {
|
ResultOrError<Ref<TextureViewBase>> SwapChain::GetCurrentTextureViewInternal(bool isReentrant) {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
// Transiently create a semaphore that will be signaled when the presentation engine is done
|
// Transiently create a semaphore that will be signaled when the presentation engine is done
|
||||||
|
@ -664,8 +664,7 @@ namespace dawn::native::vulkan {
|
||||||
|
|
||||||
// In the happy path we can use the swapchain image directly.
|
// In the happy path we can use the swapchain image directly.
|
||||||
if (!mConfig.needsBlit) {
|
if (!mConfig.needsBlit) {
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
return mTexture->CreateView();
|
||||||
return mTexture->APICreateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The blit texture always perfectly matches what the user requested for the swapchain.
|
// The blit texture always perfectly matches what the user requested for the swapchain.
|
||||||
|
@ -673,8 +672,7 @@ namespace dawn::native::vulkan {
|
||||||
TextureDescriptor desc = GetSwapChainBaseTextureDescriptor(this);
|
TextureDescriptor desc = GetSwapChainBaseTextureDescriptor(this);
|
||||||
DAWN_TRY_ASSIGN(mBlitTexture,
|
DAWN_TRY_ASSIGN(mBlitTexture,
|
||||||
Texture::Create(device, &desc, VK_IMAGE_USAGE_TRANSFER_SRC_BIT));
|
Texture::Create(device, &desc, VK_IMAGE_USAGE_TRANSFER_SRC_BIT));
|
||||||
// TODO(dawn:723): change to not use AcquireRef for reentrant object creation.
|
return mBlitTexture->CreateView();
|
||||||
return mBlitTexture->APICreateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapChain::DetachFromSurfaceImpl() {
|
void SwapChain::DetachFromSurfaceImpl() {
|
||||||
|
|
|
@ -75,11 +75,11 @@ namespace dawn::native::vulkan {
|
||||||
bool needsBlit = false;
|
bool needsBlit = false;
|
||||||
};
|
};
|
||||||
ResultOrError<Config> ChooseConfig(const VulkanSurfaceInfo& surfaceInfo) const;
|
ResultOrError<Config> ChooseConfig(const VulkanSurfaceInfo& surfaceInfo) const;
|
||||||
ResultOrError<TextureViewBase*> GetCurrentTextureViewInternal(bool isReentrant = false);
|
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewInternal(bool isReentrant = false);
|
||||||
|
|
||||||
// NewSwapChainBase implementation
|
// NewSwapChainBase implementation
|
||||||
MaybeError PresentImpl() override;
|
MaybeError PresentImpl() override;
|
||||||
ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override;
|
ResultOrError<Ref<TextureViewBase>> GetCurrentTextureViewImpl() override;
|
||||||
void DetachFromSurfaceImpl() override;
|
void DetachFromSurfaceImpl() override;
|
||||||
|
|
||||||
Config mConfig;
|
Config mConfig;
|
||||||
|
|
Loading…
Reference in New Issue