nikitablack
nikitablack

Reputation: 4663

Update push constant in primary command buffer but use in secondary?

I have multiple secondary command buffers which are responsible for different geometry rendering. But the camera matrix obviously should stay the same. I wanted to update the camera matrix through push constants but I can't understand - should I do it for every secondary command buffer or I can do it only once - in the primary command buffer?

On one side push constants are the part of the pipeline state (specified in pipeline state layout) which is not inherited by secondary command buffers. But on the other side, there's a so-called "Pipeline Layout Compatibility", which I do not fully understand, but looks like it allows to update push constant once and use the updated values in subsequent commands.

Upvotes: 1

Views: 927

Answers (1)

Ekzuzy
Ekzuzy

Reputation: 3437

In general (as You have noted) state is not inherited between command buffers. This means that You need to setup state (that is relevant for drawing or compute operations) in each command buffer separately. There are some exceptions to this rule but they are not connected with the problem You are talking about here.

So yes, You need to set values of push constants in each command buffer separately.

As for pipeline layout compatibility You are referring to, this means that when You set some pipeline state for a given pipeline and then when You bind another pipeline with a compatible layout, You don't have to set the same state again. It is preserved between pipelines with compatible layouts. So again, yes, You can "update push constant once and use the updated values in subsequent commands". But this must happen in the same command buffer. You can use updated values in the pipelines bound to the same command buffer. But if You are in another command buffer, You need to setup relevant state once again. What's more - after You execute secondary command buffers from a primary command buffer, You need to set state in this primary command buffer once again too. In other words, primary command buffer forgets its state after executing secondary command buffers.

Upvotes: 1

Related Questions