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()); ASSERT(!IsError());
if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTexture.Get()))) { if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTextureView.Get()))) {
return; return;
} }

View File

@ -68,7 +68,7 @@ namespace dawn_native {
~OldSwapChainBase() override; ~OldSwapChainBase() override;
const DawnSwapChainImplementation& GetImplementation(); const DawnSwapChainImplementation& GetImplementation();
virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0; virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0;
virtual MaybeError OnBeforePresent(TextureBase* texture) = 0; virtual MaybeError OnBeforePresent(TextureViewBase* view) = 0;
private: private:
MaybeError ValidateConfigure(wgpu::TextureFormat format, 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)); return new Texture(ToBackend(GetDevice()), descriptor, std::move(d3d12Texture));
} }
MaybeError SwapChain::OnBeforePresent(TextureBase* texture) { MaybeError SwapChain::OnBeforePresent(TextureViewBase* view) {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
CommandRecordingContext* commandContext; CommandRecordingContext* commandContext;
DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext()); DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext());
// Perform the necessary transition for the texture to be presented. // 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()); DAWN_TRY(device->ExecutePendingCommandContext());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,13 +53,14 @@ namespace dawn_native { namespace vulkan {
.Detach(); .Detach();
} }
MaybeError SwapChain::OnBeforePresent(TextureBase* texture) { MaybeError SwapChain::OnBeforePresent(TextureViewBase* view) {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
// Perform the necessary pipeline barriers for the texture to be used with the usage // Perform the necessary pipeline barriers for the texture to be used with the usage
// requested by the implementation. // requested by the implementation.
CommandRecordingContext* recordingContext = device->GetPendingRecordingContext(); CommandRecordingContext* recordingContext = device->GetPendingRecordingContext();
ToBackend(texture)->TransitionFullUsage(recordingContext, mTextureUsage); ToBackend(view->GetTexture())
->TransitionUsageNow(recordingContext, mTextureUsage, view->GetSubresourceRange());
DAWN_TRY(device->SubmitPendingCommands()); DAWN_TRY(device->SubmitPendingCommands());

View File

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