Optimize subresource tracking - use texture view

Bug: dawn:441

Change-Id: I5cdfc1d84b27eb0b127d34ee829ceedf15f1150c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22321
Commit-Queue: Yunchao He <yunchao.he@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Yunchao He 2020-06-15 18:26:12 +00:00 committed by Commit Bot service account
parent ee7debf44d
commit 1c2a039e04
13 changed files with 25 additions and 23 deletions

View File

@ -199,7 +199,7 @@ namespace dawn_native {
}
ASSERT(!IsError());
if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTexture.Get()))) {
if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTextureView.Get()))) {
return;
}

View File

@ -68,7 +68,7 @@ namespace dawn_native {
~OldSwapChainBase() override;
const DawnSwapChainImplementation& GetImplementation();
virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0;
virtual MaybeError OnBeforePresent(TextureBase* texture) = 0;
virtual MaybeError OnBeforePresent(TextureViewBase* view) = 0;
private:
MaybeError ValidateConfigure(wgpu::TextureFormat format,

View File

@ -48,14 +48,16 @@ namespace dawn_native { namespace d3d12 {
return new Texture(ToBackend(GetDevice()), descriptor, std::move(d3d12Texture));
}
MaybeError SwapChain::OnBeforePresent(TextureBase* texture) {
MaybeError SwapChain::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(texture)->TrackAllUsageAndTransitionNow(commandContext, mTextureUsage);
ToBackend(view->GetTexture())
->TrackUsageAndTransitionNow(commandContext, mTextureUsage,
view->GetSubresourceRange());
DAWN_TRY(device->ExecutePendingCommandContext());

View File

@ -28,7 +28,7 @@ namespace dawn_native { namespace d3d12 {
protected:
~SwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureBase* texture) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;
wgpu::TextureUsage mTextureUsage;
};

View File

@ -32,7 +32,7 @@ namespace dawn_native { namespace metal {
protected:
~OldSwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureBase* texture) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;
};
class SwapChain final : public NewSwapChainBase {

View File

@ -51,7 +51,7 @@ namespace dawn_native { namespace metal {
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
}
MaybeError OldSwapChain::OnBeforePresent(TextureBase*) {
MaybeError OldSwapChain::OnBeforePresent(TextureViewBase*) {
return {};
}

View File

@ -443,7 +443,7 @@ namespace dawn_native { namespace null {
return GetDevice()->CreateTexture(descriptor);
}
MaybeError OldSwapChain::OnBeforePresent(TextureBase*) {
MaybeError OldSwapChain::OnBeforePresent(TextureViewBase*) {
return {};
}

View File

@ -268,7 +268,7 @@ namespace dawn_native { namespace null {
protected:
~OldSwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureBase*) override;
MaybeError OnBeforePresent(TextureViewBase*) override;
};
class NativeSwapChainImpl {

View File

@ -44,7 +44,7 @@ namespace dawn_native { namespace opengl {
TextureBase::TextureState::OwnedExternal);
}
MaybeError SwapChain::OnBeforePresent(TextureBase*) {
MaybeError SwapChain::OnBeforePresent(TextureViewBase*) {
return {};
}

View File

@ -30,7 +30,7 @@ namespace dawn_native { namespace opengl {
protected:
~SwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureBase* texture) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;
};
}} // namespace dawn_native::opengl

View File

@ -153,16 +153,15 @@ namespace dawn_native { namespace vulkan {
break;
case wgpu::BindingType::ReadonlyStorageTexture:
case wgpu::BindingType::WriteonlyStorageTexture:
// TODO (yunchao.he@intel.com): Do the transition for texture's
// subresource via its view.
ToBackend(
static_cast<TextureViewBase*>(mBindings[index][bindingIndex])
->GetTexture())
->TransitionFullUsage(recordingContext,
wgpu::TextureUsage::Storage);
case wgpu::BindingType::WriteonlyStorageTexture: {
TextureViewBase* view =
static_cast<TextureViewBase*>(mBindings[index][bindingIndex]);
ToBackend(view->GetTexture())
->TransitionUsageNow(recordingContext,
wgpu::TextureUsage::Storage,
view->GetSubresourceRange());
break;
}
case wgpu::BindingType::StorageTexture:
// Not implemented.

View File

@ -53,13 +53,14 @@ namespace dawn_native { namespace vulkan {
.Detach();
}
MaybeError SwapChain::OnBeforePresent(TextureBase* texture) {
MaybeError SwapChain::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(texture)->TransitionFullUsage(recordingContext, mTextureUsage);
ToBackend(view->GetTexture())
->TransitionUsageNow(recordingContext, mTextureUsage, view->GetSubresourceRange());
DAWN_TRY(device->SubmitPendingCommands());

View File

@ -32,7 +32,7 @@ namespace dawn_native { namespace vulkan {
~SwapChain() override;
TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override;
MaybeError OnBeforePresent(TextureBase* texture) override;
MaybeError OnBeforePresent(TextureViewBase* view) override;
private:
wgpu::TextureUsage mTextureUsage;