Eagerly destroy CommandBuffer commands after submission

Command buffers hold references to all encoded objects. Freeing them
eagerly significantly reduces the amount memory held before the JS GC
clears the command buffers.

Bug: dawn:262, dawn:372
Change-Id: I68dfa973f980fba8d94611ed1de3c593bdb91a63
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26562
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Enrico Galli
2020-08-13 20:25:39 +00:00
committed by Commit Bot service account
parent f7905c3cb5
commit 76d9e34bbc
20 changed files with 203 additions and 129 deletions

View File

@@ -19,17 +19,17 @@
#include <type_traits>
// Make our own Base - Backend object pair, reusing the CommandBuffer name
// Make our own Base - Backend object pair, reusing the AdapterBase name
namespace dawn_native {
class CommandBufferBase : public RefCounted {};
class AdapterBase : public RefCounted {};
} // namespace dawn_native
using namespace dawn_native;
class MyCommandBuffer : public CommandBufferBase {};
class MyAdapter : public AdapterBase {};
struct MyBackendTraits {
using CommandBufferType = MyCommandBuffer;
using AdapterType = MyAdapter;
};
// Instanciate ToBackend for our "backend"
@@ -41,48 +41,47 @@ auto ToBackend(T&& common) -> decltype(ToBackendBase<MyBackendTraits>(common)) {
// Test that ToBackend correctly converts pointers to base classes.
TEST(ToBackend, Pointers) {
{
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
const CommandBufferBase* base = cmdBuf;
MyAdapter* adapter = new MyAdapter;
const AdapterBase* base = adapter;
auto backendCmdBuf = ToBackend(base);
static_assert(std::is_same<decltype(backendCmdBuf), const MyCommandBuffer*>::value, "");
ASSERT_EQ(cmdBuf, backendCmdBuf);
auto backendAdapter = ToBackend(base);
static_assert(std::is_same<decltype(backendAdapter), const MyAdapter*>::value, "");
ASSERT_EQ(adapter, backendAdapter);
cmdBuf->Release();
adapter->Release();
}
{
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
CommandBufferBase* base = cmdBuf;
MyAdapter* adapter = new MyAdapter;
AdapterBase* base = adapter;
auto backendCmdBuf = ToBackend(base);
static_assert(std::is_same<decltype(backendCmdBuf), MyCommandBuffer*>::value, "");
ASSERT_EQ(cmdBuf, backendCmdBuf);
auto backendAdapter = ToBackend(base);
static_assert(std::is_same<decltype(backendAdapter), MyAdapter*>::value, "");
ASSERT_EQ(adapter, backendAdapter);
cmdBuf->Release();
adapter->Release();
}
}
// Test that ToBackend correctly converts Refs to base classes.
TEST(ToBackend, Ref) {
{
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
const Ref<CommandBufferBase> base(cmdBuf);
MyAdapter* adapter = new MyAdapter;
const Ref<AdapterBase> base(adapter);
const auto& backendCmdBuf = ToBackend(base);
static_assert(std::is_same<decltype(ToBackend(base)), const Ref<MyCommandBuffer>&>::value,
"");
ASSERT_EQ(cmdBuf, backendCmdBuf.Get());
const auto& backendAdapter = ToBackend(base);
static_assert(std::is_same<decltype(ToBackend(base)), const Ref<MyAdapter>&>::value, "");
ASSERT_EQ(adapter, backendAdapter.Get());
cmdBuf->Release();
adapter->Release();
}
{
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
Ref<CommandBufferBase> base(cmdBuf);
MyAdapter* adapter = new MyAdapter;
Ref<AdapterBase> base(adapter);
auto backendCmdBuf = ToBackend(base);
static_assert(std::is_same<decltype(ToBackend(base)), Ref<MyCommandBuffer>&>::value, "");
ASSERT_EQ(cmdBuf, backendCmdBuf.Get());
auto backendAdapter = ToBackend(base);
static_assert(std::is_same<decltype(ToBackend(base)), Ref<MyAdapter>&>::value, "");
ASSERT_EQ(adapter, backendAdapter.Get());
cmdBuf->Release();
adapter->Release();
}
}