简体   繁体   English

vulkan pushConstant vs 统一缓冲区更新

[英]vulkan pushConstant vs uniform buffer update

So I am reading the vulkan book now and got a problem about the push Constant and ubo update.所以我现在正在阅读 vulkan 的书,并且遇到了关于 push Constant 和 ubo 更新的问题。

After I set up all the pipeline and descriptor stuff.在我设置了所有管道和描述符之后。 Basically I just need the copy the buffer to the UBO buffer such as memcpy then I am done.基本上我只需要将缓冲区复制到 UBO 缓冲区,例如 memcpy,然后我就完成了。 Basically I can understand the issue about the whole pipeline needs to wait for this "buffer" ready then change it's content.基本上我可以理解整个管道需要等待这个“缓冲区”准备好然后改变它的内容的问题。 So it will be slow.所以会很慢。

On the other hand, when I use push constant, there is no such a problem.另一方面,当我使用 push 常量时,就没有这样的问题。 Although it's small (say 256 bytes big).虽然它很小(比如 256 字节大)。

So far so good.到目前为止,一切都很好。

However, on the second thought, I find that if I am updating the UBO, I don't need to change the command buffer, or re-record it, I can submit the old CB since it's still the same.但是,转念一想,我发现如果我在更新 UBO,我不需要更改命令缓冲区,或者重新记录它,我可以提交旧的 CB,因为它仍然是一样的。 Then if I want to update by using Push Constant, I have to reset the CB and record it again then submit it.然后如果我想使用 Push Constant 更新,我必须重置 CB 并再次记录,然后提交。

So won't this be an issue?那么这不会是一个问题吗? How to make sure which one is faster?如何确定哪个更快?

Thanks.谢谢。

Lots of people get confused on this issue, because the Vulkan Tutorial pre-records commands and Vulkan Guide re-record commands every frame.很多人对这个问题感到困惑,因为Vulkan 教程会预先录制命令,而Vulkan 指南会在每一帧重新录制命令。

When people say to use push constants for per-frame changing data like transform matrices and time data, there's the implicit assumption that you are recording command buffer per frame .当人们说对每帧变化的数据(如变换矩阵和时间数据)使用推送常量时,隐含的假设是您正在记录每帧的命令缓冲区 Push constants essentially hitch a ride with the rest of your commands when submitted, which is also how they avoid synchronization and cache flushing to operate.推送常量本质上是在提交时使用命令的 rest 搭便车,这也是它们避免同步和缓存刷新操作的方式。

Now, in a lot of scenarios, re-recording command buffers can be easier and not significantly more costly than re-use .现在,在很多情况下,重新记录命令缓冲区可能比重新使用更容易,而且成本不会显着增加 And indeed, re-using command buffers when things change can be a real pain to manage.事实上,当事情发生变化时重新使用命令缓冲区可能是一个真正的痛苦管理。 Command buffers are meant to be fast to record.命令缓冲区旨在快速记录。 Still, the Vulkan tutorial went with pre-recording everything, which is also a valid approach though potentially harder to maintain at scale.尽管如此,Vulkan 教程还是预先录制了所有内容,这也是一种有效的方法,尽管可能难以大规模维护。

At the time the tutorial was created, the Vulkan Tutorial was essentially one of the only resources available to learn vulkan in a structured manner.在创建教程时,Vulkan 教程本质上是唯一可用于以结构化方式学习 vulkan 的资源之一 Even though command buffers are quick to record, pre-recording command buffers eliminates even more CPU overhead and exemplifies Vulkan's "Never be draw call limited again" mantra to eliminating CPU overhead in graphics applications.尽管命令缓冲区可以快速记录,但预记录命令缓冲区消除了更多的 CPU 开销,并体现了 Vulkan 的“不再受绘图调用限制”的口号,以消除图形应用程序中的 CPU 开销。

As for the speed comparison, you'll have to benchmark, but I would not necessarily choose one or the other for "speed" reasons.至于速度比较,您必须进行基准测试,但出于“速度”的原因,我不一定会选择其中一个。 If you pre-record, you don't want to re-orient your entire rendering architecture just to take advantage of push constants.如果您预先录制,您不想为了利用推送常量而重新定位整个渲染架构。 If you don't pre-record, there's no reason not to use push constants, they are just straight up easier to deal with.如果你不预先记录,没有理由使用推送常量,它们只是更容易处理。

It seems like currently you are pre-recording.看来您目前正在预录制。 I would not bother with push constants at all for this kind of data.对于这种数据,我根本不会打扰推送常量。 I would also not focus on these kinds of issues until you get more familiar with vulkan, as it is very easy to get caught in the weeds with optimization in vulkan, strategies for optimization are no where near as uniform as in the CPU space.在您更熟悉 vulkan 之前,我也不会关注这类问题,因为在 vulkan 中进行优化很容易陷入困境,优化策略远不如 CPU 空间中的统一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM