From ae96f04c0a9ce142da191a4d7ad91d85bf3b3d58 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Fri, 13 Mar 2020 23:34:40 +0000 Subject: [PATCH] Slab-allocate frontend D3D12 bind groups Bug: dawn:340 Change-Id: Ie613a1b8e445a385c10eb377983440ace9ad3f4a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16746 Commit-Queue: Austin Eng Reviewed-by: Kai Ninomiya --- src/dawn_native/d3d12/BindGroupD3D12.cpp | 13 +++++++++++++ src/dawn_native/d3d12/BindGroupD3D12.h | 8 ++++++-- src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp | 14 +++++++++++++- src/dawn_native/d3d12/BindGroupLayoutD3D12.h | 7 +++++++ src/dawn_native/d3d12/DeviceD3D12.cpp | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp index 29def10dfd..6a708133c2 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp @@ -24,6 +24,19 @@ namespace dawn_native { namespace d3d12 { + // static + BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { + return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); + } + + BindGroup::BindGroup(Device* device, const BindGroupDescriptor* descriptor) + : BindGroupBase(this, device, descriptor) { + } + + BindGroup::~BindGroup() { + ToBackend(GetLayout())->DeallocateBindGroup(this); + } + ResultOrError BindGroup::Populate(ShaderVisibleDescriptorAllocator* allocator) { Device* device = ToBackend(GetDevice()); diff --git a/src/dawn_native/d3d12/BindGroupD3D12.h b/src/dawn_native/d3d12/BindGroupD3D12.h index b65af78c23..dc5fb75665 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.h +++ b/src/dawn_native/d3d12/BindGroupD3D12.h @@ -15,6 +15,7 @@ #ifndef DAWNNATIVE_D3D12_BINDGROUPD3D12_H_ #define DAWNNATIVE_D3D12_BINDGROUPD3D12_H_ +#include "common/PlacementAllocated.h" #include "common/Serial.h" #include "dawn_native/BindGroup.h" #include "dawn_native/d3d12/d3d12_platform.h" @@ -24,9 +25,12 @@ namespace dawn_native { namespace d3d12 { class Device; class ShaderVisibleDescriptorAllocator; - class BindGroup : public BindGroupBaseOwnBindingData { + class BindGroup : public BindGroupBase, public PlacementAllocated { public: - using BindGroupBaseOwnBindingData::BindGroupBaseOwnBindingData; + static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); + + BindGroup(Device* device, const BindGroupDescriptor* descriptor); + ~BindGroup() override; // Returns true if the BindGroup was successfully populated. ResultOrError Populate(ShaderVisibleDescriptorAllocator* allocator); diff --git a/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp b/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp index 80e9d8c430..6f8e000655 100644 --- a/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp @@ -15,12 +15,15 @@ #include "dawn_native/d3d12/BindGroupLayoutD3D12.h" #include "common/BitSetIterator.h" +#include "dawn_native/d3d12/BindGroupD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h" namespace dawn_native { namespace d3d12 { BindGroupLayout::BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor) - : BindGroupLayoutBase(device, descriptor), mDescriptorCounts{} { + : BindGroupLayoutBase(device, descriptor), + mDescriptorCounts{}, + mBindGroupAllocator(MakeFrontendBindGroupAllocator(4096)) { const auto& groupInfo = GetBindingInfo(); for (uint32_t binding : IterateBitSet(groupInfo.mask)) { @@ -143,6 +146,15 @@ namespace dawn_native { namespace d3d12 { } } + BindGroup* BindGroupLayout::AllocateBindGroup(Device* device, + const BindGroupDescriptor* descriptor) { + return mBindGroupAllocator.Allocate(device, descriptor); + } + + void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) { + mBindGroupAllocator.Deallocate(bindGroup); + } + const std::array& BindGroupLayout::GetBindingOffsets() const { return mBindingOffsets; } diff --git a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h index e5766e635d..7d393ec65d 100644 --- a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h +++ b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h @@ -17,16 +17,21 @@ #include "dawn_native/BindGroupLayout.h" +#include "common/SlabAllocator.h" #include "dawn_native/d3d12/d3d12_platform.h" namespace dawn_native { namespace d3d12 { + class BindGroup; class Device; class BindGroupLayout : public BindGroupLayoutBase { public: BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor); + BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor); + void DeallocateBindGroup(BindGroup* bindGroup); + enum DescriptorType { CBV, UAV, @@ -47,6 +52,8 @@ namespace dawn_native { namespace d3d12 { std::array mBindingOffsets; std::array mDescriptorCounts; D3D12_DESCRIPTOR_RANGE mRanges[DescriptorType::Count]; + + SlabAllocator mBindGroupAllocator; }; }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 4715bbd85a..91cc8f6988 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -219,7 +219,7 @@ namespace dawn_native { namespace d3d12 { ResultOrError Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { - return new BindGroup(this, descriptor); + return BindGroup::Create(this, descriptor); } ResultOrError Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) {