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>
Allocator helpers are used in the command buffer objects as a means to allocate memory for the latter. Regardless of the inner workings of the allocation method they use, they use the same interface in the ANGLE code.
There are currently two types of allocators defined in ANGLE:
Pool allocators; and
Ring buffer allocators.
ANGLE uses pool allocators by default. To switch to ring buffer allocators, the flag
angle_enable_vulkan_shared_ring_buffer_cmd_alloc should be enabled in GN args. This flag appears
as ANGLE_ENABLE_VULKAN_SHARED_RING_BUFFER_CMD_ALLOC in the code, which is used to select the
allocator type.
In SecondaryCommandBuffer.h, the helper classes related to the selected allocator type are
aliased as the following:
SecondaryCommandMemoryAllocator
SecondaryCommandBlockPool
SecondaryCommandBuffer.
SecondaryCommandBlockAllocator
CommandBufferHelperCommon, and by extension, is used in its
derived helper classes for render pass and outside render pass command buffer helpers.
Files: AllocatorHelperPool.cpp and AllocatorHelperPool.h
SecondaryCommandMemoryAllocator -> DedicatedCommandMemoryAllocator -> angle::PoolAllocator
SecondaryCommandBlockPool -> DedicatedCommandBlockPool
SecondaryCommandBlockAllocator -> DedicatedCommandBlockAllocator
attachAllocator() and detachAllocator() functions are no-ops for the pool allocators.
Regarding SecondaryCommandBlockAllocator in pool allocators:
init() works only with pool allocators.
hasAllocatorLinks() always returns false.
terminateLastCommandBlock() is no-op.
Files: AllocatorHelperRing.cpp and AllocatorHelperRing.h
SecondaryCommandMemoryAllocator -> SharedCommandMemoryAllocator -> angle::SharedRingBufferAllocator
SecondaryCommandBlockPool -> SharedCommandBlockPool
SecondaryCommandBlockAllocator -> SharedCommandBlockAllocator
It can be seen that in the context’s initialization and destruction, and flushing the command
processor’s commands, there are calls to attach and detach an allocator (via attachAllocator()
and detachAllocator()). Please note that these functions are only defined for ring buffer
allocators.
Regarding SecondaryCommandBlockAllocator in ring buffer allocators:
init() is no-op.
hasAllocatorLinks() checks the allocator and the shared checkpoint.
terminateLastCommandBlock() is only used in ring buffer allocators.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
# Allocators
Allocator helpers are used in the command buffer objects as a means to allocate memory for the
latter. Regardless of the inner workings of the allocation method they use, they use the same
interface in the ANGLE code.
## Allocator types
There are currently two types of allocators defined in ANGLE:
* Pool allocators; and
* Ring buffer allocators.
**ANGLE uses pool allocators by default.** To switch to ring buffer allocators, the flag
`angle_enable_vulkan_shared_ring_buffer_cmd_alloc` should be enabled in GN args. This flag appears
as `ANGLE_ENABLE_VULKAN_SHARED_RING_BUFFER_CMD_ALLOC` in the code, which is used to select the
allocator type.
### Common interface
In `SecondaryCommandBuffer.h`, the helper classes related to the selected allocator type are
aliased as the following:
* `SecondaryCommandMemoryAllocator`
* This is the main allocator object used in the allocator helper classes. It is used as a type
for some of the allocator helpers' public functions.
* `SecondaryCommandBlockPool`
* This allocator is used in `SecondaryCommandBuffer`.
* `SecondaryCommandBlockAllocator`
* This allocator is defined in `CommandBufferHelperCommon`, and by extension, is used in its
derived helper classes for render pass and outside render pass command buffer helpers.
### Pool allocator helpers
_Files: `AllocatorHelperPool.cpp` and `AllocatorHelperPool.h`_
- `SecondaryCommandMemoryAllocator` -> `DedicatedCommandMemoryAllocator` -> `angle::PoolAllocator`
- `SecondaryCommandBlockPool` -> `DedicatedCommandBlockPool`
- `SecondaryCommandBlockAllocator` -> `DedicatedCommandBlockAllocator`
#### Notes
* `attachAllocator()` and `detachAllocator()` functions are no-ops for the pool allocators.
* Regarding `SecondaryCommandBlockAllocator` in pool allocators:
* `init()` works only with pool allocators.
* `hasAllocatorLinks()` always returns `false`.
* `terminateLastCommandBlock()` is no-op.
### Ring buffer allocator helpers
_Files: `AllocatorHelperRing.cpp` and `AllocatorHelperRing.h`_
- `SecondaryCommandMemoryAllocator` -> `SharedCommandMemoryAllocator` -> `angle::SharedRingBufferAllocator`
- `SecondaryCommandBlockPool` -> `SharedCommandBlockPool`
- `SecondaryCommandBlockAllocator` -> `SharedCommandBlockAllocator`
#### Notes
* It can be seen that in the context's initialization and destruction, and flushing the command
processor's commands, there are calls to attach and detach an allocator (via `attachAllocator()`
and `detachAllocator()`). Please note that **these functions are only defined for ring buffer
allocators**.
* Regarding `SecondaryCommandBlockAllocator` in ring buffer allocators:
* `init()` is no-op.
* `hasAllocatorLinks()` checks the allocator and the shared checkpoint.
* `terminateLastCommandBlock()` is only used in ring buffer allocators.