LonelyQuantum
LonelyQuantum

Reputation: 41

Vulkan vkResetCommandPool vs vkResetCommandBuffer

The description of vkResetCommandPool just says

Resetting a command pool recycles all of the resources from all of the command buffers allocated from the command pool back to the command pool. All command buffers that have been allocated from the command pool are put in the initial state.

Is it the same as resetting all the existing command buffers allocated from the command pool, which is the same as calling vkResetCommandBuffer for each single buffer assuming that the command pool was created with VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT.

I am wondering whether the additional control brought by VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT will impact the performance. If I have a few swapchain images and want to reset my command buffer when drawing each frame. Is it better to create a separate command pool for each swapchain image and reset the corresponding command pool when drawing every frame, or just create a single command pool with VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT and reset the corresponding command buffer when drawing each frame?

Upvotes: 2

Views: 1976

Answers (2)

Fifnmar
Fifnmar

Reputation: 494

It's common practice to reset the pool in one go. Not only is it likely to give better performance, but it's simpler to manage. Few games manage the lifetime of individual command buffers, unless for ancilliary (secondary) command buffers.

When in doubt, enable the best practice check in your vk_layer_settings.txt:

khronos_validation.validate_best_practices = true

EDIT: as reminded in the comments, resetting the pool actually resets all buffers it allocated but won't free the buffers, so it's valid use to keep a buffer without freeing/reallocating when you call "reset pool".

Upvotes: 2

solidpixel
solidpixel

Reputation: 12084

The answer is mostly going to be "it depends". How many command buffers do you have per frame?

If you have many command buffers per frame, it's probably less expensive to have one pool per frame and reset the pool.

If you have few command buffers per frame then it's probably cheaper to reset individual command buffers.

That said, it's entirely implementation-defined behaviour, so if you have a concern about it write a small benchmark and test your hypothesis.

Upvotes: 3

Related Questions