Hash :
684ff60b
Author :
Date :
2022-06-21T10:52:31
Vulkan: Add shared ring buffer cmd alloc feature
* Added RingBufferAllocator.cpp with implementation.
* Main classes:
* RingBufferAllocator (fast allocation with bulk deallocation)
* SharedRingBufferAllocator (wrapper to help with shared use and
multiple threads)
* Implemented "angle_enable_vulkan_shared_ring_buffer_cmd_alloc"
feature. (Disabled by default)
* Details (from the original CL)
* The angle::PoolAllocator replaced with
angle::RingBufferAllocator.
* Before, there was separate angle::PoolAllocator per each
CommandBufferHelper. Now, a single angle::RingBufferAllocator
is shared between multiple CommandBufferHelper objects.
* Commands data from multiple CommandBufferHelpers is
tightly packed without fragmentation.
* Significantly less memory overhead, observed with enabled
async queue.
* Moved the parts of the code related to the allocators into the
classes in the new AllocatorHelperPool and AllocatorHelperRing files
for better management. The allocator can be switched by changing the
following BUILD flag:
`angle_enable_vulkan_shared_ring_buffer_cmd_alloc`
* It is connected to the following macro:
ANGLE_ENABLE_VULKAN_SHARED_RING_BUFFER_CMD_ALLOC
* The two main allocator classes in each file are aliased as:
* SecondaryCommandBlockAllocator (in CommandBufferHelper objects)
* SecondaryCommandBlockPool (in SecondaryCommandBuffer)
* Also added placeholder functions for VulkanSecondaryCommandBuffer.
* Added descriptions regarding the two allocators.
* renderer/vulkan/doc/Allocators.md
Credit: Original CL authored by Igor Nazarov <i.nazarov@samsung.com>
Bug: angleproject:6401
Bug: b/256666069
Change-Id: I0f24793eef6334bf4ff8e327b9665338807dad37
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3715968
Reviewed-by: Charlie Lao <cclao@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// AllocatorHelperPool:
// Implements the pool allocator helpers used in the command buffers.
//
#include "libANGLE/renderer/vulkan/AllocatorHelperPool.h"
#include "libANGLE/renderer/vulkan/SecondaryCommandBuffer.h"
namespace rx
{
namespace vk
{
void DedicatedCommandBlockAllocator::resetAllocator()
{
mAllocator.pop();
mAllocator.push();
}
void DedicatedCommandBlockPool::reset(CommandBufferCommandTracker *commandBufferTracker)
{
mCommandBuffer->clearCommands();
mCurrentWritePointer = nullptr;
mCurrentBytesRemaining = 0;
commandBufferTracker->reset();
}
// Initialize the SecondaryCommandBuffer by setting the allocator it will use
angle::Result DedicatedCommandBlockPool::initialize(DedicatedCommandMemoryAllocator *allocator)
{
ASSERT(allocator);
ASSERT(mCommandBuffer->hasEmptyCommands());
mAllocator = allocator;
allocateNewBlock();
// Set first command to Invalid to start
reinterpret_cast<CommandHeaderIDType &>(*mCurrentWritePointer) = 0;
return angle::Result::Continue;
}
bool DedicatedCommandBlockPool::empty() const
{
return mCommandBuffer->checkEmptyForPoolAlloc();
}
void DedicatedCommandBlockPool::allocateNewBlock(size_t blockSize)
{
ASSERT(mAllocator);
mCurrentWritePointer = mAllocator->fastAllocate(blockSize);
mCurrentBytesRemaining = blockSize;
mCommandBuffer->pushToCommands(mCurrentWritePointer);
}
void DedicatedCommandBlockPool::getMemoryUsageStats(size_t *usedMemoryOut,
size_t *allocatedMemoryOut) const
{
mCommandBuffer->getMemoryUsageStatsForPoolAlloc(kBlockSize, usedMemoryOut, allocatedMemoryOut);
}
} // namespace vk
} // namespace rx