Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vulkan: why both primary command buffer and secondary command buffers need to set framebuffer and renderpass?

Tags:

c++

vulkan

// Contains the list of secondary command buffers to be submitted
std::vector<VkCommandBuffer> secondaryCommandBuffers;

// Inheritance info for the secondary command buffers
VkCommandBufferInheritanceInfo inheritanceInfo = {};
...
inheritanceInfo.renderPass = renderpass;   <-------------
inheritanceInfo.framebuffer = frameBuffer; <-------------
...

VkCommandBufferBeginInfo secondaryCommandBufferBeginInfo = {};
...
commandBufferBeginInfo.pInheritanceInfo = &inheritanceInfo;
...
vkBeginCommandBuffer(secondaryCommandBuffers[i], &secondaryCommandBufferBeginInfo);
vkEndCommandBuffer(secondaryCommandBuffers[i]);


// renderPassBeginInfo for the primary command buffer
VkRenderPassBeginInfo renderPassBeginInfo = {};
...
renderPassBeginInfo.renderPass = renderPass;    <-------------
renderPassBeginInfo.framebuffer = frameBuffer;  <-------------

vkBeginCommandBuffer(primaryCommandBuffer, &cmdBufInfo);
vkCmdBeginRenderPass(primaryCommandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
vkCmdExecuteCommands(primaryCommandBuffer, secondaryCommandBuffers.size(), secondaryCommandBuffers.data());
vkEndCommandBuffer(primaryCommandBuffer);

Why do secondary command buffers already set framebuffer and renderpass, and also framebuffer and renderpass for primary command buffer?

Must it be set to the same?

like image 532
Javin Yang Avatar asked Nov 04 '25 01:11

Javin Yang


1 Answers

Secondary command buffers which contain rendering commands must execute within a render pass, and wholly within a specific subpass of that render pass (hence VkCommandBufferInheritanceInfo::subpass). This is their purpose.

The framebuffer parameter is optional and may be VK_NULL_HANDLE.

The render pass model essentially requires all aspects of command generation to be able to determine what is going on. How rendering commands get generated depends in many ways on which subpass of which render pass is being used. That's central to the whole mechanism.

The primary/secondary CB distinction allows the structure of a render pass operation to be defined within a primary command buffer (which contains the begin, end, and subpass switching operations), while the actual rendering commands can be built in secondary command buffers on other threads. But in order for those other threads to do their jobs, they have to know about how they're being used. Hence the need for the render pass.

like image 115
Nicol Bolas Avatar answered Nov 06 '25 17:11

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!