Do I really have to re-record all command buffers when using imgui in Vulkan?

Hello
I’m checking out Sascha Willems’ example repository since I would like to have imgui in my Vulkan renderer as well.

There is one thing that stuns me though: Whenever imgui gets updated, it re-records all command buffers again?

if (imgui_overlay->update() || imgui_overlay->updated) {
    record_command_buffers();// what? really??
    imgui_overlay->updated = false;
}

That can’t be good. Aren’t command buffers supposed to be recorded ahead of rendering? Is there really no other way to work with imgui than to do it this way?

Thanks
Johannes.

Any scene that is at all dynamic is going to have some degree of CB rerecording. Whether it’s to change descriptors, to modify push constant values, or whatever, you will probably need to rebuild at least some of your CBs anything something about your scene changes.

Even something as simple as changing the value of the camera matrix will likely involve rebuilding the CBs for that scene. You can’t write to memory the GPU is currently (potentially) reading from, so if you want to change the memory storing the camera without waiting for the GPU to finish the last frame, you’re going to need to write the camera matrix to a different piece of memory. So you’ll need some way to communicate the location of that memory to all of the drawing commands that need it. And that communication is going to be something that is stored in a CB (a push-constant value, a dynamic UBO descriptor, etc). And that stored value needs to change.

So yes, the broad expectation for real scenes is that you’re going to be rebuilding quite a lot of your CBs every frame, more or less.