6
votes

I am trying to set up a multi-threaded renderer with Vulkan and I have a question about command pools.

Here https://on-demand.gputechconf.com/siggraph/2016/video/sig1625-tristan-lorach-vulkan-nvidia-essentials.mp4 at 13 minutes, they talk about how you should make 1 command pool per FRAME and cycle them in a ring buffer. enter image description here

Why allocate 3 command pools per thread(one for each frame in a 3-frame ring buffer) instead of having just one command pool per thread and having 3 command buffers from it?

3

3 Answers

7
votes

I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.

Actually the speaker says so if you do not just read slides but get the full presentation.

6
votes

It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.

From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.

Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.

-1
votes

Writing operations to command buffers may cause some work to happen on its parent command buffer pools. For example, memory allocations. That's why you should not do multiple operations affecting the same pool from several threads without synchronizing it. Therefore you may prefer to have dedicated pools per each thread/frame pair to simplify synchronization. Resetting command buffers in bulk using their pools is another reason.