camelCase
camelCase

Reputation: 187

Rerecording secondary command buffers

I tried the use of secondary command buffers and run into a problem. After resizing my window, both primary and secondary command buffers are rerecorded.
If the secondary command buffers are updated and the primary command buffers, that those contain, do not have been submitted yet, the validation layers throw a

Calling vkBeginCommandBuffer() on active CB 0x0x166dbc0 before it has completed. You must check CB fence before this call.

error. To fix this, I currently ensure, that all primary command buffers are at least once submitted, before updating the secondary command buffers.

Is there an easier way to avoid this problem, as I waste the rendering of up to 7 frames (number of framebuffers in my swapchain) with this solution?

Upvotes: 2

Views: 1355

Answers (1)

krOoze
krOoze

Reputation: 13306

Command buffer must not be still in use when you try to re-record it. You need to use VkFence (or some equivalent: vkDeviceWaitIdle() or vkQueueWaitIdle()) to make sure it is not.

There's usually lot to do when resizing and it is not expected to be frequent operation, so:

Just use vkDeviceWaitIdle() when reacting to the resize event (then recreate all entities that need it).

As for secondary command buffers, there is this counter-intuitive statement in the spec:

A secondary command buffer is considered to be pending execution from the time its execution is recorded into a primary buffer (via vkCmdExecuteCommands) until the final time that primary buffer’s submission to a queue completes.

So reading it literaly it is "pending execution", as soon as it is recorded in primary buffer.

(Might be unintended interpretation by the spec makers... I raised it as #414 Issue.)

Upvotes: 2

Related Questions