D3D12: Remove `mViewAllocator` in `BindGroupLayout`
This patch removes `mViewAllocator` in `BindGroupLayout` as it can
be easily got from `mDevice` without much computation.
Bug: chromium:42241306
Change-Id: Icd6a56336c45c5855a5c921af3f04de220f6e174
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/217414
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp b/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
index 2cf9ce6..2ea4c8e 100644
--- a/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
+++ b/src/dawn/native/d3d12/BindGroupLayoutD3D12.cpp
@@ -210,7 +210,6 @@
descriptorRanges.push_back(range);
}
- mViewAllocator = device->GetViewStagingDescriptorAllocator(GetCbvUavSrvDescriptorCount());
mSamplerAllocator = device->GetSamplerStagingDescriptorAllocator(GetSamplerDescriptorCount());
}
@@ -220,8 +219,10 @@
uint32_t viewSizeIncrement = 0;
CPUDescriptorHeapAllocation viewAllocation;
if (GetCbvUavSrvDescriptorCount() > 0) {
- DAWN_ASSERT(mViewAllocator != nullptr);
- DAWN_TRY((*mViewAllocator).Use([&](auto viewAllocator) -> MaybeError {
+ auto* viewAllocator =
+ device->GetViewStagingDescriptorAllocator(GetCbvUavSrvDescriptorCount());
+ DAWN_ASSERT(viewAllocator != nullptr);
+ DAWN_TRY((*viewAllocator).Use([&](auto viewAllocator) -> MaybeError {
DAWN_TRY_ASSIGN(viewAllocation, viewAllocator->AllocateCPUDescriptors());
viewSizeIncrement = viewAllocator->GetSizeIncrement();
return {};
@@ -245,7 +246,10 @@
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup,
CPUDescriptorHeapAllocation* viewAllocation) {
if (viewAllocation->IsValid()) {
- (*mViewAllocator)->Deallocate(viewAllocation);
+ Device* device = ToBackend(bindGroup->GetDevice());
+ auto* viewAllocator =
+ device->GetViewStagingDescriptorAllocator(GetCbvUavSrvDescriptorCount());
+ (*viewAllocator)->Deallocate(viewAllocation);
}
mBindGroupAllocator->Deallocate(bindGroup);
diff --git a/src/dawn/native/d3d12/BindGroupLayoutD3D12.h b/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
index 5912d86..36e1e0f 100644
--- a/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
+++ b/src/dawn/native/d3d12/BindGroupLayoutD3D12.h
@@ -100,10 +100,9 @@
MutexProtected<SlabAllocator<BindGroup>> mBindGroupAllocator;
- // TODO(https://crbug.com/dawn/2361): Rewrite those members with raw_ptr<T>.
+ // TODO(https://crbug.com/dawn/2361): Rewrite this member with raw_ptr<T>.
// This is currently failing with MSVC cl.exe compiler.
RAW_PTR_EXCLUSION MutexProtected<StagingDescriptorAllocator>* mSamplerAllocator = nullptr;
- RAW_PTR_EXCLUSION MutexProtected<StagingDescriptorAllocator>* mViewAllocator = nullptr;
};
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index 7929842..4d167ce 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -744,8 +744,9 @@
MutexProtected<StagingDescriptorAllocator>* Device::GetViewStagingDescriptorAllocator(
uint32_t descriptorCount) const {
DAWN_ASSERT(descriptorCount <= kMaxViewDescriptorsPerBindGroup);
+ DAWN_ASSERT(descriptorCount > 0);
// This is Log2 of the next power of two, plus 1.
- uint32_t allocatorIndex = descriptorCount == 0 ? 0 : Log2Ceil(descriptorCount) + 1;
+ uint32_t allocatorIndex = Log2Ceil(descriptorCount) + 1;
return mViewAllocators[allocatorIndex].get();
}