Command Buffers#
Vulkan command buffers are objects used to record various API commands, such as drawing operations and memory transfer. They can then be submitted to a device queue for execution by the hardware. The advantage of this approach is that all the hard work of setting up the drawing commands can potentially be done in advance, and in multiple threads.
Vulkan provides two levels of command buffers:
Primary command buffers, which can execute secondary command buffers, and which are submitted to queues.
Secondary command buffers, which can be executed by primary command buffers, and which are not directly submitted to queues.
Command buffer usage flags#
On PowerVR hardware, the command buffer usage flag should be left unset (0
) unless the application requires specific behaviour.
The following list contains the current usage flags that the API exposes, and their appropriate use cases:
VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
– this flag informs the driver that the command buffer will be submitted multiple times. As a result, the driver must perform a copy of the entire buffer after it is submitted to a queue. Applications should only set this flag if absolutely necessary.Note
This method is faster than manually creating another identical buffer every frame. If the application requires this type of functionally, then the flag should be set on secondary command buffers, and primary command buffers are always rebuilt. The copy of secondary command buffers is made when the secondary command buffer is recorded into the primary command buffer (
vkCmdExecuteCommands
) rather than when the buffer is submitted to a queue (vkQueueSubmit
).VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
– this flag must be set if the command buffer is a secondary, and it is executing inside a render-pass.
Transient command buffers#
Currently on PowerVR hardware there is no performance benefit gained from using Vulkan transient command buffers. This is subject to change with future driver updates.
Secondary command buffers#
In Vulkan, the use of secondary command buffers may benefit performance significantly. An application may build several secondary command buffers on separate threads preparing commands for the next frame, while the main thread is executing the primary command buffer. Once the secondary command buffers are ready by signalling through some sort of thread synchronisation, the work can be enqueued into the primary command buffer and the process can be repeated.