What are the advantages of secondary command buffers?

Hello guys,
i have read everything in the spec about secondary command-buffers, but it’s not really clear when i should use them and when not.
So what are the advantages of secondary command buffers? and when should i use them?

The biggest difference is that secondary command buffers are not tied to a render pass and as such can be reused in as many render and sub passes as you like.

There is no general rule as to when to use primary only or secondary, but if your scenes get more complex and you want to reuse several rendering parts then you’d go with secondary commands buffers that you can then also generate on the fly.

Mh i didn’t understand that. Would you mind to explain it a bit more? How command buffers are tied to a render pass?

EDIT: Ah i think i know what you mean. In the inheritance info, we have to specify a renderpass and a secondary-command-buffer with the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT can be executed by several primary ones, right?

Secondary command buffers are useful for the following cases:

  1. Threading lots of rendering operations. If you have a lot of things being rendered to the same framebuffer, you don’t have to build them in sequence. You can build secondary CBs on different threads, then stick them all in a primary CB later.

  2. Making semi-permanent or permanent command buffers. You can design your rendering so that it only depends on values in memory, rather than manufactured CBs. By making them secondary CBs, you can use them in tandem with non-static geometry.

[QUOTE=Alfonse Reinheart;40998]Secondary command buffers are useful for the following cases:

  1. Threading lots of rendering operations. If you have a lot of things being rendered to the same framebuffer, you don’t have to build them in sequence. You can build secondary CBs on different threads, then stick them all in a primary CB later.[/QUOTE]

But i can achieve the same thing with only primary CBs right? Are - in this case - secondary CBs faster?

Primary command buffers cannot be executed within the same renderpass instance. So while you could do it, you would have to have lots of begin/end renderpass operations, which would kill performance on a lot of hardware.

Consider a simple deferred renderer. You have a subpass for geometry, a subpass for lighting, a subpass for blended objects, and a subpass for tone mapping. You would want at least one CB for each process, likely more for the geometry pass (since it has the most per-stage operations).

If you use primary CBs, you must split these into different renderpass instances. And you don’t have to. Indeed, the subpass architecture was designed to be able to handle this situation. This is what secondary command buffers are for.

Got it now! I will definitely mention you in my bachelor-thesis for your awesome help! :smiley: (And Sascha of course too)