Michael-Lfx / GPU_Tuning

MIT License
9 stars 0 forks source link

[Vulkan] Secondary Command Buffer #4

Open Michael-Lfx opened 5 years ago

Michael-Lfx commented 5 years ago

使用场景与性能改善

We won't make use of the secondary command buffer functionality here, but you can imagine that it's helpful to reuse common operations from primary command buffers.

Ref: https://vulkan-tutorial.com/Drawing_a_triangle/Drawing/Command_buffers

What are primary and secondary command buffers?

The primary command buffer does not have any parent command buffer. However, the secondary command buffers are always executed from the primary command buffers behaving as its parent. The secondary command buffers ar not directly submitted into the device queue; these are recorded into the primary command buffer and executed using the

void vkCmdExecuteCommands(VkCommandBuffer commandBuffer, 
                                                      uint32_t commandBufferCount, 
                                                      const VkCommandBuffer* pCommandBuffers);

Tip How are secondary command buffers are useful?

Secondary command buffers are useful in recording command operations into modular units. These modular capsules can be attached to any of you desired primary buffer as required. In the absence of the secondary command buffer, such common operations will be recorded as part of the primary buffer, making them bulky and resulting in redundancy pollution.

Ref: Learning Vulkan

vkCmdDrawIndirect

if you have different instances/indices per submission then use indirect draws i.e. vkCmdDrawIndirect this will pull the necessary data for the draw from a GPU buffer which you can update without re-recording the command buffer

bhlzlx commented 5 years ago

据红宝书最后一部分讲, secondary command buffer 主要是为了方便 CPU 并行生成指令,供 primary command buffer 提交用的,因此它的设计初衷应该是为了方便CPU端更快的生成指令,然后更快的提交,而不是给GPU优化更快执行的。所以如果不是复杂的游戏场景,而是普通的app是不需要这种设计的。

Michael-Lfx commented 5 years ago

我也是关注它的CPU编码消耗,还没在我们业务场景中对比它与全部用 Primary Command Buffer的CPU耗时差异。

bhlzlx commented 5 years ago
bhlzlx commented 5 years ago

secondary command buffer 举个例子哈,静态场景,绘制物体,一段时间内都不会变,这个时候用 secondary command buffer 我觉得应该会很好,省了很多操作,这应该算是 common operations 吧。这个改善程度也要看场景,我们心中能明白它省在什么环节上了,这就行了。