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:
parent
2cdb9f1ed1
commit
62442aceb0
src/dawn_native/d3d12
|
@ -223,22 +223,27 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
|
||||
if (mInCompute) {
|
||||
std::vector<D3D12_RESOURCE_BARRIER> 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<Buffer*>(mBindings[index][binding])
|
||||
->TrackUsageAndTransitionNow(commandContext,
|
||||
wgpu::BufferUsage::Storage);
|
||||
case wgpu::BindingType::StorageBuffer: {
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (static_cast<Buffer*>(mBindings[index][binding])
|
||||
->TrackUsageAndGetResourceBarrier(
|
||||
commandContext, &barrier, wgpu::BufferUsage::Storage)) {
|
||||
barriers.push_back(barrier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case wgpu::BindingType::ReadonlyStorageTexture: {
|
||||
TextureViewBase* view =
|
||||
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
||||
ToBackend(view->GetTexture())
|
||||
->TrackUsageAndTransitionNow(commandContext,
|
||||
kReadonlyStorageTexture,
|
||||
->TransitionUsageAndGetResourceBarrier(
|
||||
commandContext, &barriers, kReadonlyStorageTexture,
|
||||
view->GetSubresourceRange());
|
||||
break;
|
||||
}
|
||||
|
@ -246,8 +251,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
TextureViewBase* view =
|
||||
static_cast<TextureViewBase*>(mBindings[index][binding]);
|
||||
ToBackend(view->GetTexture())
|
||||
->TrackUsageAndTransitionNow(commandContext,
|
||||
wgpu::TextureUsage::Storage,
|
||||
->TransitionUsageAndGetResourceBarrier(
|
||||
commandContext, &barriers, wgpu::TextureUsage::Storage,
|
||||
view->GetSubresourceRange());
|
||||
break;
|
||||
}
|
||||
|
@ -267,6 +272,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!barriers.empty()) {
|
||||
commandList->ResourceBarrier(barriers.size(), barriers.data());
|
||||
}
|
||||
}
|
||||
DidApply();
|
||||
|
||||
|
|
|
@ -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(
|
||||
CommandRecordingContext* commandContext,
|
||||
std::vector<D3D12_RESOURCE_BARRIER>* barriers,
|
||||
|
|
|
@ -62,6 +62,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
void TrackUsageAndGetResourceBarrierForPass(CommandRecordingContext* commandContext,
|
||||
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
|
||||
const PassTextureUsage& textureUsages);
|
||||
void TransitionUsageAndGetResourceBarrier(CommandRecordingContext* commandContext,
|
||||
std::vector<D3D12_RESOURCE_BARRIER>* barrier,
|
||||
wgpu::TextureUsage usage,
|
||||
const SubresourceRange& range);
|
||||
void TrackUsageAndTransitionNow(CommandRecordingContext* commandContext,
|
||||
wgpu::TextureUsage usage,
|
||||
const SubresourceRange& range);
|
||||
|
|
Loading…
Reference in New Issue