10

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?

ulak blade
  • 2,515
  • 5
  • 37
  • 81

2 Answers2

9

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.

solidpixel
  • 10,688
  • 1
  • 20
  • 33
  • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer – ulak blade Nov 22 '18 at 23:01
  • 1
    You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues. – solidpixel Nov 22 '18 at 23:04
  • 1
    Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain? – ulak blade Nov 22 '18 at 23:09
  • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: https://software.intel.com/en-us/articles/practical-approach-to-vulkan-part-1 – Ekzuzy Nov 23 '18 at 14:39
9

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.

krOoze
  • 12,301
  • 1
  • 20
  • 34