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>
diff --git a/src/dawn_native/opengl/BindGroupGL.cpp b/src/dawn_native/opengl/BindGroupGL.cpp
new file mode 100644
index 0000000..383607b
--- /dev/null
+++ b/src/dawn_native/opengl/BindGroupGL.cpp
@@ -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
diff --git a/src/dawn_native/opengl/BindGroupGL.h b/src/dawn_native/opengl/BindGroupGL.h
new file mode 100644
index 0000000..9ce8ed7
--- /dev/null
+++ b/src/dawn_native/opengl/BindGroupGL.h
@@ -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_
diff --git a/src/dawn_native/opengl/BindGroupLayoutGL.cpp b/src/dawn_native/opengl/BindGroupLayoutGL.cpp
new file mode 100644
index 0000000..7c098c8
--- /dev/null
+++ b/src/dawn_native/opengl/BindGroupLayoutGL.cpp
@@ -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
diff --git a/src/dawn_native/opengl/BindGroupLayoutGL.h b/src/dawn_native/opengl/BindGroupLayoutGL.h
new file mode 100644
index 0000000..ab8dab4
--- /dev/null
+++ b/src/dawn_native/opengl/BindGroupLayoutGL.h
@@ -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_
diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp
index 26d2c33..7cf41a0 100644
--- a/src/dawn_native/opengl/DeviceGL.cpp
+++ b/src/dawn_native/opengl/DeviceGL.cpp
@@ -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 @@
 
     ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
         const BindGroupDescriptor* descriptor) {
-        return new BindGroup(this, descriptor);
+        return BindGroup::Create(this, descriptor);
     }
     ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
         const BindGroupLayoutDescriptor* descriptor) {
diff --git a/src/dawn_native/opengl/Forward.h b/src/dawn_native/opengl/Forward.h
index 8b4f20b..bd2cc76 100644
--- a/src/dawn_native/opengl/Forward.h
+++ b/src/dawn_native/opengl/Forward.h
@@ -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;