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

查看:223
本文介绍了使用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.

推荐答案

VAO

  • 要共享更大的数据集,一定要使用一个包含单个顶点(阵列)数组的专用缓冲区,而仍然可以将特定的数组插入另一个缓冲区并使用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.

...不要阻止您指向它们中的单个attrib数组进行共享.

...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天全站免登陆