diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 3650fc0178..6358567f4f 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -199,7 +199,7 @@ namespace dawn_native { } ASSERT(!IsError()); - if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTexture.Get()))) { + if (GetDevice()->ConsumedError(OnBeforePresent(mCurrentTextureView.Get()))) { return; } diff --git a/src/dawn_native/SwapChain.h b/src/dawn_native/SwapChain.h index 3997611972..6e32e53404 100644 --- a/src/dawn_native/SwapChain.h +++ b/src/dawn_native/SwapChain.h @@ -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, diff --git a/src/dawn_native/d3d12/SwapChainD3D12.cpp b/src/dawn_native/d3d12/SwapChainD3D12.cpp index ee5e9cc371..74798059df 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn_native/d3d12/SwapChainD3D12.cpp @@ -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()); diff --git a/src/dawn_native/d3d12/SwapChainD3D12.h b/src/dawn_native/d3d12/SwapChainD3D12.h index ee92e09cbf..6938e20ada 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.h +++ b/src/dawn_native/d3d12/SwapChainD3D12.h @@ -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; }; diff --git a/src/dawn_native/metal/SwapChainMTL.h b/src/dawn_native/metal/SwapChainMTL.h index adfd6322dc..19abc7facd 100644 --- a/src/dawn_native/metal/SwapChainMTL.h +++ b/src/dawn_native/metal/SwapChainMTL.h @@ -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 { diff --git a/src/dawn_native/metal/SwapChainMTL.mm b/src/dawn_native/metal/SwapChainMTL.mm index 2a5ffb1243..f581da9835 100644 --- a/src/dawn_native/metal/SwapChainMTL.mm +++ b/src/dawn_native/metal/SwapChainMTL.mm @@ -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 {}; } diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index c19670e8dc..adc44f0974 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -443,7 +443,7 @@ namespace dawn_native { namespace null { return GetDevice()->CreateTexture(descriptor); } - MaybeError OldSwapChain::OnBeforePresent(TextureBase*) { + MaybeError OldSwapChain::OnBeforePresent(TextureViewBase*) { return {}; } diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index 42fce4d2e5..f6f361185c 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -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 { diff --git a/src/dawn_native/opengl/SwapChainGL.cpp b/src/dawn_native/opengl/SwapChainGL.cpp index 40efd0a27d..8223a2ceb1 100644 --- a/src/dawn_native/opengl/SwapChainGL.cpp +++ b/src/dawn_native/opengl/SwapChainGL.cpp @@ -44,7 +44,7 @@ namespace dawn_native { namespace opengl { TextureBase::TextureState::OwnedExternal); } - MaybeError SwapChain::OnBeforePresent(TextureBase*) { + MaybeError SwapChain::OnBeforePresent(TextureViewBase*) { return {}; } diff --git a/src/dawn_native/opengl/SwapChainGL.h b/src/dawn_native/opengl/SwapChainGL.h index a483e70c6b..0cce92594a 100644 --- a/src/dawn_native/opengl/SwapChainGL.h +++ b/src/dawn_native/opengl/SwapChainGL.h @@ -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 diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index 73d6bbcb9d..f1003c1e86 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -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(mBindings[index][bindingIndex]) - ->GetTexture()) - ->TransitionFullUsage(recordingContext, - wgpu::TextureUsage::Storage); + case wgpu::BindingType::WriteonlyStorageTexture: { + TextureViewBase* view = + static_cast(mBindings[index][bindingIndex]); + ToBackend(view->GetTexture()) + ->TransitionUsageNow(recordingContext, + wgpu::TextureUsage::Storage, + view->GetSubresourceRange()); break; - + } case wgpu::BindingType::StorageTexture: // Not implemented. diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index 99c4775717..660128776d 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -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()); diff --git a/src/dawn_native/vulkan/SwapChainVk.h b/src/dawn_native/vulkan/SwapChainVk.h index 7765fc0c50..9ee1792f60 100644 --- a/src/dawn_native/vulkan/SwapChainVk.h +++ b/src/dawn_native/vulkan/SwapChainVk.h @@ -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;