diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 01d1433899..bc4052995d 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -223,32 +223,37 @@ namespace dawn_native { namespace d3d12 { } if (mInCompute) { + std::vector barriers; for (BindGroupIndex index : IterateBitSet(mBindGroupLayoutsMask)) { for (BindingIndex binding : IterateBitSet(mBindingsNeedingBarrier[index])) { wgpu::BindingType bindingType = mBindingTypes[index][binding]; switch (bindingType) { - case wgpu::BindingType::StorageBuffer: - static_cast(mBindings[index][binding]) - ->TrackUsageAndTransitionNow(commandContext, - wgpu::BufferUsage::Storage); + case wgpu::BindingType::StorageBuffer: { + D3D12_RESOURCE_BARRIER barrier; + if (static_cast(mBindings[index][binding]) + ->TrackUsageAndGetResourceBarrier( + commandContext, &barrier, wgpu::BufferUsage::Storage)) { + barriers.push_back(barrier); + } break; + } case wgpu::BindingType::ReadonlyStorageTexture: { TextureViewBase* view = static_cast(mBindings[index][binding]); ToBackend(view->GetTexture()) - ->TrackUsageAndTransitionNow(commandContext, - kReadonlyStorageTexture, - view->GetSubresourceRange()); + ->TransitionUsageAndGetResourceBarrier( + commandContext, &barriers, kReadonlyStorageTexture, + view->GetSubresourceRange()); break; } case wgpu::BindingType::WriteonlyStorageTexture: { TextureViewBase* view = static_cast(mBindings[index][binding]); ToBackend(view->GetTexture()) - ->TrackUsageAndTransitionNow(commandContext, - wgpu::TextureUsage::Storage, - view->GetSubresourceRange()); + ->TransitionUsageAndGetResourceBarrier( + commandContext, &barriers, wgpu::TextureUsage::Storage, + view->GetSubresourceRange()); break; } case wgpu::BindingType::StorageTexture: @@ -267,6 +272,10 @@ namespace dawn_native { namespace d3d12 { } } } + + if (!barriers.empty()) { + commandList->ResourceBarrier(barriers.size(), barriers.data()); + } } DidApply(); diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 6ccd2e3e4c..dff3f66663 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -686,6 +686,14 @@ namespace dawn_native { namespace d3d12 { } } + void Texture::TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext, + std::vector* barrier, + wgpu::TextureUsage usage, + const SubresourceRange& range) { + TransitionUsageAndGetResourceBarrier(commandContext, barrier, + D3D12TextureUsage(usage, GetFormat()), range); + } + void Texture::TransitionUsageAndGetResourceBarrier( CommandRecordingContext* commandContext, std::vector* barriers, diff --git a/src/dawn_native/d3d12/TextureD3D12.h b/src/dawn_native/d3d12/TextureD3D12.h index d2df6bea69..0bebb93ced 100644 --- a/src/dawn_native/d3d12/TextureD3D12.h +++ b/src/dawn_native/d3d12/TextureD3D12.h @@ -62,6 +62,10 @@ namespace dawn_native { namespace d3d12 { void TrackUsageAndGetResourceBarrierForPass(CommandRecordingContext* commandContext, std::vector* barrier, const PassTextureUsage& textureUsages); + void TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext, + std::vector* barrier, + wgpu::TextureUsage usage, + const SubresourceRange& range); void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext, wgpu::TextureUsage usage, const SubresourceRange& range);