xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/vulkan/doc/Allocators.md (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Allocators
2
3Allocator helpers are used in the command buffer objects as a means to allocate memory for the
4latter. Regardless of the inner workings of the allocation method they use, they use the same
5interface in the ANGLE code.
6
7## Allocator types
8
9There are currently two types of allocators defined in ANGLE:
10
11* Pool allocators; and
12
13* Ring buffer allocators.
14
15**ANGLE uses pool allocators by default.** To switch to ring buffer allocators, the flag
16`angle_enable_vulkan_shared_ring_buffer_cmd_alloc` should be enabled in GN args. This flag appears
17as `ANGLE_ENABLE_VULKAN_SHARED_RING_BUFFER_CMD_ALLOC` in the code, which is used to select the
18allocator type.
19
20### Common interface
21
22In `SecondaryCommandBuffer.h`, the helper classes related to the selected allocator type are
23aliased as the following:
24
25* `SecondaryCommandMemoryAllocator`
26
27  * This is the main allocator object used in the allocator helper classes. It is used as a type
28	for some of the allocator helpers' public functions.
29
30* `SecondaryCommandBlockPool`
31
32  * This allocator is used in `SecondaryCommandBuffer`.
33
34* `SecondaryCommandBlockAllocator`
35
36  * This allocator is defined in `CommandBufferHelperCommon`, and by extension, is used in its
37	derived helper classes for render pass and outside render pass command buffer helpers.
38
39
40### Pool allocator helpers
41
42_Files: `AllocatorHelperPool.cpp` and `AllocatorHelperPool.h`_
43
44- `SecondaryCommandMemoryAllocator` -> `DedicatedCommandMemoryAllocator` -> `angle::PoolAllocator`
45
46- `SecondaryCommandBlockPool` -> `DedicatedCommandBlockPool`
47
48- `SecondaryCommandBlockAllocator` -> `DedicatedCommandBlockAllocator`
49
50#### Notes
51
52* `attachAllocator()` and `detachAllocator()` functions are no-ops for the pool allocators.
53
54* Regarding `SecondaryCommandBlockAllocator` in pool allocators:
55
56  * `init()` works only with pool allocators.
57
58  * `hasAllocatorLinks()` always returns `false`.
59
60  * `terminateLastCommandBlock()` is no-op.
61
62### Ring buffer allocator helpers
63
64_Files: `AllocatorHelperRing.cpp` and `AllocatorHelperRing.h`_
65
66- `SecondaryCommandMemoryAllocator` -> `SharedCommandMemoryAllocator` -> `angle::SharedRingBufferAllocator`
67
68- `SecondaryCommandBlockPool` -> `SharedCommandBlockPool`
69
70- `SecondaryCommandBlockAllocator` -> `SharedCommandBlockAllocator`
71
72#### Notes
73
74* It can be seen that in the context's initialization and destruction, and flushing the command
75  processor's commands, there are calls to attach and detach an allocator (via `attachAllocator()`
76  and `detachAllocator()`). Please note that **these functions are only defined for ring buffer
77  allocators**.
78
79* Regarding `SecondaryCommandBlockAllocator` in ring buffer allocators:
80
81  * `init()` is no-op.
82
83  * `hasAllocatorLinks()` checks the allocator and the shared checkpoint.
84
85  * `terminateLastCommandBlock()` is only used in ring buffer allocators.
86