Slab-allocate OpenGL bind groups

Now that all backends use slab-allocated bind groups, this patch also
moves the BindGroup implementation with owned-data into the Null backend.

Bug: dawn:340
Change-Id: I08a952075b382008fb82f1fbab3f779cc05bc2a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16747
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Austin Eng 2020-03-13 23:51:50 +00:00 committed by Commit Bot service account
parent ae96f04c0a
commit 463c394905
12 changed files with 197 additions and 49 deletions

View File

@ -412,6 +412,10 @@ source_set("libdawn_native_sources") {
sources += [
"src/dawn_native/opengl/BackendGL.cpp",
"src/dawn_native/opengl/BackendGL.h",
"src/dawn_native/opengl/BindGroupGL.cpp",
"src/dawn_native/opengl/BindGroupGL.h",
"src/dawn_native/opengl/BindGroupLayoutGL.cpp",
"src/dawn_native/opengl/BindGroupLayoutGL.h",
"src/dawn_native/opengl/BufferGL.cpp",
"src/dawn_native/opengl/BufferGL.h",
"src/dawn_native/opengl/CommandBufferGL.cpp",

View File

@ -181,26 +181,6 @@ namespace dawn_native {
return {};
}
// OwnBindingDataHolder
OwnBindingDataHolder::OwnBindingDataHolder(size_t size)
: mBindingDataAllocation(malloc(size)) // malloc is guaranteed to return a
// pointer aligned enough for the allocation
{
}
OwnBindingDataHolder::~OwnBindingDataHolder() {
free(mBindingDataAllocation);
}
// BindGroupBaseOwnBindingData
BindGroupBaseOwnBindingData::BindGroupBaseOwnBindingData(DeviceBase* device,
const BindGroupDescriptor* descriptor)
: OwnBindingDataHolder(descriptor->layout->GetBindingDataSize()),
BindGroupBase(device, descriptor, mBindingDataAllocation) {
}
// BindGroup
BindGroupBase::BindGroupBase(DeviceBase* device,

View File

@ -77,24 +77,6 @@ namespace dawn_native {
BindGroupLayoutBase::BindingDataPointers mBindingData;
};
// Helper class so |BindGroupBaseOwnBindingData| can allocate memory for its binding data,
// before calling the BindGroupBase base class constructor.
class OwnBindingDataHolder {
protected:
explicit OwnBindingDataHolder(size_t size);
~OwnBindingDataHolder();
void* mBindingDataAllocation;
};
// We don't have the complexity of placement-allocation of bind group data in
// the Null backend. This class, keeps the binding data in a separate allocation for simplicity.
class BindGroupBaseOwnBindingData : private OwnBindingDataHolder, public BindGroupBase {
public:
BindGroupBaseOwnBindingData(DeviceBase* device, const BindGroupDescriptor* descriptor);
~BindGroupBaseOwnBindingData() override = default;
};
} // namespace dawn_native
#endif // DAWNNATIVE_BINDGROUP_H_

View File

@ -295,6 +295,10 @@ if (DAWN_ENABLE_OPENGL)
${DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES}
"opengl/BackendGL.cpp"
"opengl/BackendGL.h"
"opengl/BindGroupGL.cpp"
"opengl/BindGroupGL.h"
"opengl/BindGroupLayoutGL.cpp"
"opengl/BindGroupLayoutGL.h"
"opengl/BufferGL.cpp"
"opengl/BufferGL.h"
"opengl/CommandBufferGL.cpp"

View File

@ -252,6 +252,25 @@ namespace dawn_native { namespace null {
mLastSubmittedSerial++;
}
// BindGroupDataHolder
BindGroupDataHolder::BindGroupDataHolder(size_t size)
: mBindingDataAllocation(malloc(size)) // malloc is guaranteed to return a
// pointer aligned enough for the allocation
{
}
BindGroupDataHolder::~BindGroupDataHolder() {
free(mBindingDataAllocation);
}
// BindGroup
BindGroup::BindGroup(DeviceBase* device, const BindGroupDescriptor* descriptor)
: BindGroupDataHolder(descriptor->layout->GetBindingDataSize()),
BindGroupBase(device, descriptor, mBindingDataAllocation) {
}
// Buffer
struct BufferMapOperation : PendingOperation {

View File

@ -38,7 +38,7 @@
namespace dawn_native { namespace null {
class Adapter;
using BindGroup = BindGroupBaseOwnBindingData;
class BindGroup;
using BindGroupLayout = BindGroupLayoutBase;
class Buffer;
class CommandBuffer;
@ -157,6 +157,24 @@ namespace dawn_native { namespace null {
ResultOrError<DeviceBase*> CreateDeviceImpl(const DeviceDescriptor* descriptor) override;
};
// Helper class so |BindGroup| can allocate memory for its binding data,
// before calling the BindGroupBase base class constructor.
class BindGroupDataHolder {
protected:
explicit BindGroupDataHolder(size_t size);
~BindGroupDataHolder();
void* mBindingDataAllocation;
};
// We don't have the complexity of placement-allocation of bind group data in
// the Null backend. This class, keeps the binding data in a separate allocation for simplicity.
class BindGroup : private BindGroupDataHolder, public BindGroupBase {
public:
BindGroup(DeviceBase* device, const BindGroupDescriptor* descriptor);
~BindGroup() override = default;
};
class Buffer : public BufferBase {
public:
Buffer(Device* device, const BufferDescriptor* descriptor);

View File

@ -0,0 +1,35 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn_native/opengl/BindGroupGL.h"
#include "dawn_native/opengl/BindGroupLayoutGL.h"
#include "dawn_native/opengl/DeviceGL.h"
namespace dawn_native { namespace opengl {
BindGroup::BindGroup(Device* device, const BindGroupDescriptor* descriptor)
: BindGroupBase(this, device, descriptor) {
}
BindGroup::~BindGroup() {
ToBackend(GetLayout())->DeallocateBindGroup(this);
}
// static
BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
}
}} // namespace dawn_native::opengl

View File

@ -0,0 +1,36 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWNNATIVE_OPENGL_BINDGROUPGL_H_
#define DAWNNATIVE_OPENGL_BINDGROUPGL_H_
#include "common/PlacementAllocated.h"
#include "dawn_native/BindGroup.h"
namespace dawn_native { namespace opengl {
class BindGroupLayout;
class Device;
class BindGroup : public BindGroupBase, public PlacementAllocated {
public:
BindGroup(Device* device, const BindGroupDescriptor* descriptor);
~BindGroup() override;
static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor);
};
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGL_BINDGROUPGL_H_

View File

@ -0,0 +1,36 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn_native/opengl/BindGroupLayoutGL.h"
#include "dawn_native/opengl/BindGroupGL.h"
namespace dawn_native { namespace opengl {
BindGroupLayout::BindGroupLayout(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor)
: BindGroupLayoutBase(device, descriptor),
mBindGroupAllocator(MakeFrontendBindGroupAllocator<BindGroup>(4096)) {
}
BindGroup* BindGroupLayout::AllocateBindGroup(Device* device,
const BindGroupDescriptor* descriptor) {
return mBindGroupAllocator.Allocate(device, descriptor);
}
void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) {
mBindGroupAllocator.Deallocate(bindGroup);
}
}} // namespace dawn_native::opengl

View File

@ -0,0 +1,39 @@
// Copyright 2020 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWNNATIVE_OPENGL_BINDGROUPLAYOUTGL_H_
#define DAWNNATIVE_OPENGL_BINDGROUPLAYOUTGL_H_
#include "common/SlabAllocator.h"
#include "dawn_native/BindGroupLayout.h"
namespace dawn_native { namespace opengl {
class BindGroup;
class Device;
class BindGroupLayout : public BindGroupLayoutBase {
public:
BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor);
void DeallocateBindGroup(BindGroup* bindGroup);
private:
SlabAllocator<BindGroup> mBindGroupAllocator;
};
}} // namespace dawn_native::opengl
#endif // DAWNNATIVE_OPENGL_BINDGROUPLAYOUTGL_H_

View File

@ -15,10 +15,11 @@
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/BackendConnection.h"
#include "dawn_native/BindGroup.h"
#include "dawn_native/BindGroupLayout.h"
#include "dawn_native/DynamicUploader.h"
#include "dawn_native/ErrorData.h"
#include "dawn_native/opengl/BindGroupGL.h"
#include "dawn_native/opengl/BindGroupLayoutGL.h"
#include "dawn_native/opengl/BufferGL.h"
#include "dawn_native/opengl/CommandBufferGL.h"
#include "dawn_native/opengl/ComputePipelineGL.h"
@ -82,7 +83,7 @@ namespace dawn_native { namespace opengl {
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return new BindGroup(this, descriptor);
return BindGroup::Create(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {

View File

@ -17,17 +17,11 @@
#include "dawn_native/ToBackend.h"
namespace dawn_native {
class BindGroupBaseOwnBindingData;
class BindGroupLayoutBase;
struct RenderPassDescriptor;
} // namespace dawn_native
namespace dawn_native { namespace opengl {
class Adapter;
using BindGroup = BindGroupBaseOwnBindingData;
using BindGroupLayout = BindGroupLayoutBase;
class BindGroup;
class BindGroupLayout;
class Buffer;
class CommandBuffer;
class ComputePipeline;