D3D12: Combine all the barriers before dispatch() in one call

This patch combines all the resource barriers added before each
dispatch() into one call to reduce the number of ResourceBarrier() call
in the D3D12 command list.

BUG=dawn:522

Change-Id: I31d1520925e79f6a4ef8168a3713466866b2108c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28100
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2020-09-04 01:41:17 +00:00 committed by Commit Bot service account
parent 2cdb9f1ed1
commit 62442aceb0
3 changed files with 31 additions and 10 deletions

View File

@ -223,22 +223,27 @@ namespace dawn_native { namespace d3d12 {
} }
if (mInCompute) { if (mInCompute) {
std::vector<D3D12_RESOURCE_BARRIER> barriers;
for (BindGroupIndex index : IterateBitSet(mBindGroupLayoutsMask)) { for (BindGroupIndex index : IterateBitSet(mBindGroupLayoutsMask)) {
for (BindingIndex binding : IterateBitSet(mBindingsNeedingBarrier[index])) { for (BindingIndex binding : IterateBitSet(mBindingsNeedingBarrier[index])) {
wgpu::BindingType bindingType = mBindingTypes[index][binding]; wgpu::BindingType bindingType = mBindingTypes[index][binding];
switch (bindingType) { switch (bindingType) {
case wgpu::BindingType::StorageBuffer: case wgpu::BindingType::StorageBuffer: {
static_cast<Buffer*>(mBindings[index][binding]) D3D12_RESOURCE_BARRIER barrier;
->TrackUsageAndTransitionNow(commandContext, if (static_cast<Buffer*>(mBindings[index][binding])
wgpu::BufferUsage::Storage); ->TrackUsageAndGetResourceBarrier(
commandContext, &barrier, wgpu::BufferUsage::Storage)) {
barriers.push_back(barrier);
}
break; break;
}
case wgpu::BindingType::ReadonlyStorageTexture: { case wgpu::BindingType::ReadonlyStorageTexture: {
TextureViewBase* view = TextureViewBase* view =
static_cast<TextureViewBase*>(mBindings[index][binding]); static_cast<TextureViewBase*>(mBindings[index][binding]);
ToBackend(view->GetTexture()) ToBackend(view->GetTexture())
->TrackUsageAndTransitionNow(commandContext, ->TransitionUsageAndGetResourceBarrier(
kReadonlyStorageTexture, commandContext, &barriers, kReadonlyStorageTexture,
view->GetSubresourceRange()); view->GetSubresourceRange());
break; break;
} }
@ -246,8 +251,8 @@ namespace dawn_native { namespace d3d12 {
TextureViewBase* view = TextureViewBase* view =
static_cast<TextureViewBase*>(mBindings[index][binding]); static_cast<TextureViewBase*>(mBindings[index][binding]);
ToBackend(view->GetTexture()) ToBackend(view->GetTexture())
->TrackUsageAndTransitionNow(commandContext, ->TransitionUsageAndGetResourceBarrier(
wgpu::TextureUsage::Storage, commandContext, &barriers, wgpu::TextureUsage::Storage,
view->GetSubresourceRange()); view->GetSubresourceRange());
break; break;
} }
@ -267,6 +272,10 @@ namespace dawn_native { namespace d3d12 {
} }
} }
} }
if (!barriers.empty()) {
commandList->ResourceBarrier(barriers.size(), barriers.data());
}
} }
DidApply(); DidApply();

View File

@ -686,6 +686,14 @@ namespace dawn_native { namespace d3d12 {
} }
} }
void Texture::TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
wgpu::TextureUsage usage,
const SubresourceRange& range) {
TransitionUsageAndGetResourceBarrier(commandContext, barrier,
D3D12TextureUsage(usage, GetFormat()), range);
}
void Texture::TransitionUsageAndGetResourceBarrier( void Texture::TransitionUsageAndGetResourceBarrier(
CommandRecordingContext* commandContext, CommandRecordingContext* commandContext,
std::vector<D3D12_RESOURCE_BARRIER>* barriers, std::vector<D3D12_RESOURCE_BARRIER>* barriers,

View File

@ -62,6 +62,10 @@ namespace dawn_native { namespace d3d12 {
void TrackUsageAndGetResourceBarrierForPass(CommandRecordingContext* commandContext, void TrackUsageAndGetResourceBarrierForPass(CommandRecordingContext* commandContext,
std::vector<D3D12_RESOURCE_BARRIER>* barrier, std::vector<D3D12_RESOURCE_BARRIER>* barrier,
const PassTextureUsage& textureUsages); const PassTextureUsage& textureUsages);
void TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
wgpu::TextureUsage usage,
const SubresourceRange& range);
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext, void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
wgpu::TextureUsage usage, wgpu::TextureUsage usage,
const SubresourceRange& range); const SubresourceRange& range);