使用 VAO 时,VBO 中的交错是否会提高性能 [英] Does interleaving in VBOs speed up performance when using VAOs

查看:41
本文介绍了使用 VAO 时,VBO 中的交错是否会提高性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用交错 VBO 而不是使用多个 VBO 时,通常会加快速度.这在使用 VAO 时也有效吗?

You usually get a speed up when you use interleaved VBOs instead of using multiple VBOs. Is this also valid when using VAOs?

因为有一个用于位置的 VBO 和一个用于法线等的 VBO 更方便.您可以在多个 VAO 中使用一个 VBO.

Because it's much more convenient to have a VBO for the positions, and one for the normals etc. And you can use one VBO in multiple VAOs.

推荐答案

VAOs

  • 为了共享更大的数据集,一个包含单个顶点 (attrib) 数组的专用缓冲区肯定是一种可行的方法,而人们仍然可以在另一个缓冲区中交错特定数组并使用 VAO 将它们组合起来.

  • For sharing larger data sets, a dedicated buffer containing a single vertex (attrib) array is surely a way to go, while one could still interleave specific arrays in another buffer and combine them using a VAO.

VAO 处理所有这些缓冲区和顶点(attrib)数组状态的绑定,例如数组缓冲区绑定和带有(缓冲区)指针和启用/禁用标志的 attrib 条目.除了它的便利性之外,它旨在快速完成这项工作,更不用说简单的 API 调用,它可以立即更改所有状态,而无需繁琐的启用和禁用 attrib 数组.它基本上完成了我们之前必须手动完成的工作.然而,使用我自己的类似 VAO 的实现,我无法测量任何性能损失,即使在进行大量绑定时也是如此.在我看来,主要优点是它的方便.

A VAO handles the binding of all those buffers and the vertex (attrib) array states such as array buffer bindings and attrib entries with (buffer) pointers and enable/disable flags. Aside from its convenience, it is designed for doing this job quickly, not to mention the simple API call, which changes all states at once, without the tedious enabling and disabling of attrib arrays. It basically does, what we had to do manually before. However, with my own VAO-like implementation, I could not measure any performance loss, even when doing lots of binds. From my point of view, the major advantage is its convenience.

因此,VAO 不会根据 glDraw* 来决定绘图性能,但它会对状态更改的开销产生影响.

So, a VAO doesn't decide on drawing performance in terms of glDraw*, but it can have an impact on the overhead of state changes.

交错数据格式...

  • ...导致更少的 GPU 缓存压力,因为单个顶点的顶点坐标和属性不会分散在内存中.它们连续地适合少数缓存行,而分散的属性可能会导致更多缓存更新并因此被逐出.最坏的情况可能是每个缓存行一次一个(属性)元素,因为内存位置遥远,而顶点以不确定/非连续的方式被拉取,可能没有预测和预取.GPU 非常在这方面类似于 CPU.

  • ...cause less GPU cache pressure, because the vertex coordinate and attributes of a single vertex aren't scattered all over in memory. They fit consecutively into few cache lines, whereas scattered attributes could cause more cache updates and therefore evictions. The worst case scenario could be one (attribute) element per cache line at a time because of distant memory locations, while vertices get pulled in a non-deterministic/non-contiguous manner, where possibly no prediction and prefetching kicks in. GPUs are very similar to CPUs in this matter.

...对于满足已弃用的交错格式,其中兼容数据源的数据集可以直接读入映射的 GPU 内存.正是出于这些原因,我最终使用当前的 API 重新实现了这些交错格式.

...are also very useful for various external formats, which satisfy the deprecated interleaved formats, where datasets of compatible data sources can be read straight into mapped GPU memory. I ended up re-implementing these interleaved formats with the current API for exactly those reasons.

...应该像简单数组一样布局对齐友好.混合具有不同大小/对齐要求的各种数据类型可能需要填充以对 GPU 和 CPU 友好.这是我所知道的唯一缺点,因为实施起来比较困难.

...should be layouted alignment friendly just like simple arrays. Mixing various data types with different size/alignment requirements may need padding to be GPU and CPU friendly. This is the only downside I know of, appart from the more difficult implementation.

...不要阻止您指向其中的单个属性数组进行共享.

...do not prevent you from pointing to single attrib arrays in them for sharing.

交错很可能会提高绘制性能.

Interleaving will most probably improve draw performance.

结论:

根据我的经验,最好为顶点数据源和编译"的 VAO 设计干净的接口,这样可以适当地封装 VAO 工厂.然后可以更改此工厂以从数据源初始化交错、分离或混合的顶点缓冲区布局,而不会破坏任何内容.这对于分析特别有用.

From what I experienced, it is best to have cleanly designed interfaces for vertex data sources and 'compiled' VAOs, where one can encapsulate the VAO factory appropriately. This factory can then be altered to initialize interleaved, separate or mixed vertex buffer layouts from data sources, without breaking anything. This is especially useful for profiling.

说了那么多废话,我的建议很简单:在优化之前和优化之前进行适当且充分抽象的设计.

After all that babbling, my advice is simple: Proper and sufficiently abstracted design before and for optimization.

这篇关于使用 VAO 时,VBO 中的交错是否会提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆