XNA/DirectX:您应该始终使用索引吗?
我正在为植被实现广告牌,其中广告牌当然是由两个三角形组成的单个四边形。 顶点数据存储在顶点缓冲区中,但我应该担心索引吗? 我知道,当您使用索引时,就发送到显卡的顶点而言,地形等方面的节省可能是巨大的,但在广告牌上使用索引意味着每个四边形将有 4 个顶点,而不是 6 个,因为每个四边形完全是与其他人分开。
由于存在额外的间接级别,索引的使用实际上是否有可能降低性能? 或者说这根本没有任何意义?
我问这个问题是因为使用索引会让事情稍微复杂化,我很好奇我是否没有做额外的工作,只会让事情变慢(无论是在理论上还是在实践中实际上很明显)。
这是使用 XNA,但应该适用于 DirectX。
I'm implementing billboards for vegetation where a billboard is of course a single quad consisting of two triangles. The vertex data is stored in a vertex buffer, but should I bother with indices? I understand that the savings on things like terrain can be huge in terms of vertices sent to the graphics card when you use indices, but using indices on billboards means that I'll have 4 vertices per quad rather than 6, since each quad is completely separate from the others.
And is it possible that the use of indices actually reduces performance because there is an extra level of indirection? Or isn't that of any significance at all?
I'm asking this because using indices would slightly complicate matters and I'm curious to know if I'm not doing extra work that just makes things slower (whether just in theory or actually noticeable in practice).
This is using XNA, but should apply to DirectX.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用索引不仅可以通过向卡发送更少的数据来节省带宽,而且还可以减少顶点着色器必须完成的工作量。 如果有索引用作键,则可以缓存顶点着色器的结果。
如果您渲染大量广告牌植被并且不更改索引缓冲区,我认为您应该会看到一个小的增益。
Using indices not only saves on bandwidth, by sending less data to the card, but also reduces the amount of work the vertex shader has to do. The results of the vertex shader can be cached if there is an index to use as a key.
If you render lots of this billboarded vegetation and don't change your index buffer, I think you should see a small gain.
当涉及到非常原始的几何时,使用索引可能没有任何意义,在这种情况下我什至不会关心性能,即使是适度的硬件也会每秒渲染数百万个三角形。
现在,从技术上讲,您不知道硬件如何在内部处理数据,它可能会将它们转换为索引,因为这是最流行的几何表示形式。
When it comes to very primitive gemotery then it might won't make any sense to use indices, I won't even bother with performance in that case, even the modest HW will render millions of triangles a seconds.
Now, technically, you don't know how the HW will handle the data internally, it might convert them to indices anyway because that's the most popular form of geometry presentation.